Change type of raised exception in translation
Change exception type to ResourcePropertyConflict for conflicted properties. Change-Id: I171430ca9b90d6878e5fcaaccbafb794b5d35218
This commit is contained in:
parent
27a1887bc8
commit
dfad3ad253
@ -216,10 +216,8 @@ class TranslationRule(object):
|
||||
if isinstance(translation_data, list):
|
||||
for item in translation_data:
|
||||
if item.get(self.value_name) and item.get(translation_key):
|
||||
raise ValueError(_('Cannot use %(key)s and '
|
||||
'%(name)s at the same time.')
|
||||
% dict(key=translation_key,
|
||||
name=self.value_name))
|
||||
raise exception.ResourcePropertyConflict(
|
||||
props=[translation_key, self.value_name])
|
||||
elif item.get(self.value_name) is not None:
|
||||
item[translation_key] = item[self.value_name]
|
||||
del item[self.value_name]
|
||||
@ -228,10 +226,8 @@ class TranslationRule(object):
|
||||
else:
|
||||
if (translation_data and translation_data.get(translation_key) and
|
||||
value_data and value_data.get(value_key)):
|
||||
raise ValueError(_('Cannot use %(key)s and '
|
||||
'%(name)s at the same time.')
|
||||
% dict(key=translation_key,
|
||||
name=value_key))
|
||||
raise exception.ResourcePropertyConflict(
|
||||
props=[translation_key, value_key])
|
||||
translation_data[translation_key] = value
|
||||
# If value defined with value_path, need to delete value_path
|
||||
# property data after it's replacing.
|
||||
|
@ -1061,13 +1061,15 @@ class CinderVolumeTest(vt_base.BaseVolumeTest):
|
||||
def test_cinder_create_with_image_and_imageRef(self):
|
||||
stack_name = 'test_create_with_image_and_imageRef'
|
||||
combinations = {'imageRef': 'image-456', 'image': 'image-123'}
|
||||
err_msg = "Cannot use image and imageRef at the same time."
|
||||
err_msg = ("Cannot define the following properties at the same time: "
|
||||
"['image', 'imageRef'].")
|
||||
self.stub_ImageConstraint_validate()
|
||||
stack = utils.parse_stack(self.t, stack_name=stack_name)
|
||||
vp = stack.t['Resources']['volume2']['Properties']
|
||||
vp.pop('size')
|
||||
vp.update(combinations)
|
||||
ex = self.assertRaises(ValueError, stack.get, 'volume2')
|
||||
ex = self.assertRaises(exception.ResourcePropertyConflict,
|
||||
stack.get, 'volume2')
|
||||
self.assertEqual(err_msg, six.text_type(ex))
|
||||
|
||||
def test_cinder_create_with_size_snapshot_and_image(self):
|
||||
|
@ -1085,11 +1085,13 @@ class ServersTest(common.HeatTestCase):
|
||||
'network': network_name}])
|
||||
|
||||
resource_defns = tmpl.resource_definitions(stack)
|
||||
ex = self.assertRaises(ValueError, servers.Server,
|
||||
ex = self.assertRaises(exception.ResourcePropertyConflict,
|
||||
servers.Server,
|
||||
'server_validate_with_networks',
|
||||
resource_defns['WebServer'], stack)
|
||||
|
||||
self.assertIn(_('Cannot use network and uuid at the same time.'),
|
||||
self.assertIn("Cannot define the following properties at the "
|
||||
"same time: ['network', 'uuid'].",
|
||||
six.text_type(ex))
|
||||
|
||||
def test_server_validate_with_network_empty_ref(self):
|
||||
@ -2457,8 +2459,10 @@ class ServersTest(common.HeatTestCase):
|
||||
(tmpl, stack) = self._setup_test_stack('mapping',
|
||||
test_templ=test_templ)
|
||||
resource_defns = tmpl.resource_definitions(stack)
|
||||
msg = 'Cannot use image and image_id at the same time.'
|
||||
exc = self.assertRaises(ValueError, servers.Server, 'server',
|
||||
msg = ("Cannot define the following properties at the same time: "
|
||||
"['image', 'image_id'].")
|
||||
exc = self.assertRaises(exception.ResourcePropertyConflict,
|
||||
servers.Server, 'server',
|
||||
resource_defns['server'], stack)
|
||||
self.assertEqual(msg, six.text_type(exc))
|
||||
|
||||
|
@ -359,8 +359,10 @@ class TestTranslationRule(common.HeatTestCase):
|
||||
translation.TranslationRule.REPLACE,
|
||||
['bar'],
|
||||
value_path=['far'])
|
||||
ex = self.assertRaises(ValueError, rule.execute_rule)
|
||||
self.assertEqual('Cannot use bar and far at the same time.',
|
||||
ex = self.assertRaises(exception.ResourcePropertyConflict,
|
||||
rule.execute_rule)
|
||||
self.assertEqual("Cannot define the following properties at the "
|
||||
"same time: ['bar', 'far'].",
|
||||
six.text_type(ex))
|
||||
|
||||
def test_replace_rule_str_value_path(self):
|
||||
|
Loading…
Reference in New Issue
Block a user