Change some exceptions from invalid to missing

This patch changes exceptions from InvalidParameterValue to
MissingParameterValue when a required parameter is missing.

Change-Id: I41eee7427d462f755fddbdac4704a6dfa7be1e26
This commit is contained in:
Yuriy Zveryanskyy 2014-11-25 16:29:23 +02:00
parent d1f728cd40
commit 593ef38029
8 changed files with 23 additions and 18 deletions

View File

@ -119,6 +119,7 @@ class GlanceImageService(base_image_service.BaseImageService,
:raises: InvalidParameterValue if Swift config options are not set
correctly.
:raises: MissingParameterValue if a required parameter is not set.
:raises: ImageUnacceptable if the image info from Glance does not
have a image ID.
"""
@ -152,15 +153,15 @@ class GlanceImageService(base_image_service.BaseImageService,
def _validate_temp_url_config(self):
"""Validate the required settings for a temporary URL."""
if not CONF.glance.swift_temp_url_key:
raise exc.InvalidParameterValue(_(
raise exc.MissingParameterValue(_(
'Swift temporary URLs require a shared secret to be created. '
'You must provide "swift_temp_url_key" as a config option.'))
if not CONF.glance.swift_endpoint_url:
raise exc.InvalidParameterValue(_(
raise exc.MissingParameterValue(_(
'Swift temporary URLs require a Swift endpoint URL. '
'You must provide "swift_endpoint_url" as a config option.'))
if not CONF.glance.swift_account:
raise exc.InvalidParameterValue(_(
raise exc.MissingParameterValue(_(
'Swift temporary URLs require a Swift account string. '
'You must provide "swift_account" as a config option.'))
if CONF.glance.swift_temp_url_duration < 0:

View File

@ -895,16 +895,15 @@ class VendorPassthru(base.VendorInterface):
:param task: a task from TaskManager.
:param kwargs: info for action.
:raises: InvalidParameterValue if kwargs does not contain 'method',
'method' is not supported or a byte string is not given for
'raw_bytes'.
:raises: InvalidParameterValue when an invalid parameter value is
specified.
:raises: MissingParameterValue if a required parameter is missing.
"""
method = kwargs['method']
if method == 'send_raw':
if not kwargs.get('raw_bytes'):
raise exception.InvalidParameterValue(_(
raise exception.MissingParameterValue(_(
'Parameter raw_bytes (string of bytes) was not '
'specified.'))

View File

@ -392,11 +392,14 @@ def validate(task):
file or from keystone.
:param task: a TaskManager instance containing the node to act on.
:raises: InvalidParameterValue if no ports are enrolled for the given node.
:raises: InvalidParameterValue if the URL of the Ironic API service is not
configured in config file and is not accessible via Keystone
catalog.
:raises: MissingParameterValue if no ports are enrolled for the given node.
"""
node = task.node
if not driver_utils.get_node_mac_addresses(task):
raise exception.InvalidParameterValue(_("Node %s does not have "
raise exception.MissingParameterValue(_("Node %s does not have "
"any port associated with it.") % node.uuid)
try:
@ -404,7 +407,7 @@ def validate(task):
CONF.conductor.api_url or keystone.get_service_url()
except (exception.KeystoneFailure,
exception.CatalogNotFound,
exception.KeystoneUnauthorized):
exception.KeystoneUnauthorized) as e:
raise exception.InvalidParameterValue(_(
"Couldn't get the URL of the Ironic API service from the "
"configuration file or keystone catalog."))
"configuration file or keystone catalog. Keystone error: %s") % e)

View File

@ -492,9 +492,11 @@ class SSHPower(base.PowerInterface):
:param task: a TaskManager instance containing the node to act on.
:raises: InvalidParameterValue if any connection parameters are
incorrect or if ssh failed to connect to the node.
:raises: MissingParameterValue if no ports are enrolled for the given
node.
"""
if not driver_utils.get_node_mac_addresses(task):
raise exception.InvalidParameterValue(_("Node %s does not have "
raise exception.MissingParameterValue(_("Node %s does not have "
"any port associated with it.") % task.node.uuid)
try:
_get_connection(task.node)

View File

@ -1061,7 +1061,7 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
def test_vendor_passthru_validate__send_raw_bytes_fail(self):
with task_manager.acquire(self.context, self.node['uuid']) as task:
self.assertRaises(exception.InvalidParameterValue,
self.assertRaises(exception.MissingParameterValue,
self.driver.vendor.validate,
task, method='send_raw')

View File

@ -366,7 +366,7 @@ class PXEDriverTestCase(db_base.DbTestCase):
driver_info=DRV_INFO_DICT)
with task_manager.acquire(self.context, new_node.uuid,
shared=True) as task:
self.assertRaises(exception.InvalidParameterValue,
self.assertRaises(exception.MissingParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(base_image_service.BaseImageService, '_show')

View File

@ -602,7 +602,7 @@ class SSHDriverTestCase(db_base.DbTestCase):
driver_info=db_utils.get_test_ssh_info())
with task_manager.acquire(self.context, new_node.uuid,
shared=True) as task:
self.assertRaises(exception.InvalidParameterValue,
self.assertRaises(exception.MissingParameterValue,
task.driver.power.validate,
task)

View File

@ -694,17 +694,17 @@ class TestGlanceSwiftTempURL(base.TestCase):
def test__validate_temp_url_key_exception(self):
self.config(swift_temp_url_key=None, group='glance')
self.assertRaises(exception.InvalidParameterValue,
self.assertRaises(exception.MissingParameterValue,
self.service._validate_temp_url_config)
def test__validate_temp_url_endpoint_config_exception(self):
self.config(swift_endpoint_url=None, group='glance')
self.assertRaises(exception.InvalidParameterValue,
self.assertRaises(exception.MissingParameterValue,
self.service._validate_temp_url_config)
def test__validate_temp_url_account_exception(self):
self.config(swift_account=None, group='glance')
self.assertRaises(exception.InvalidParameterValue,
self.assertRaises(exception.MissingParameterValue,
self.service._validate_temp_url_config)
def test__validate_temp_url_endpoint_negative_duration(self):