From dfad3ad25336a779179817579bd6c7fb4899b595 Mon Sep 17 00:00:00 2001 From: Peter Razumovsky Date: Mon, 4 Apr 2016 13:02:55 +0300 Subject: [PATCH] Change type of raised exception in translation Change exception type to ResourcePropertyConflict for conflicted properties. Change-Id: I171430ca9b90d6878e5fcaaccbafb794b5d35218 --- heat/engine/translation.py | 12 ++++-------- heat/tests/openstack/cinder/test_volume.py | 6 ++++-- heat/tests/openstack/nova/test_server.py | 12 ++++++++---- heat/tests/test_translation_rule.py | 6 ++++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/heat/engine/translation.py b/heat/engine/translation.py index 943391c28c..fbf3dd37e8 100644 --- a/heat/engine/translation.py +++ b/heat/engine/translation.py @@ -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. diff --git a/heat/tests/openstack/cinder/test_volume.py b/heat/tests/openstack/cinder/test_volume.py index 4f6a27ea2f..00aabc95d5 100644 --- a/heat/tests/openstack/cinder/test_volume.py +++ b/heat/tests/openstack/cinder/test_volume.py @@ -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): diff --git a/heat/tests/openstack/nova/test_server.py b/heat/tests/openstack/nova/test_server.py index 9db7f82670..79cdcf113c 100644 --- a/heat/tests/openstack/nova/test_server.py +++ b/heat/tests/openstack/nova/test_server.py @@ -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)) diff --git a/heat/tests/test_translation_rule.py b/heat/tests/test_translation_rule.py index 317c555948..0536707861 100644 --- a/heat/tests/test_translation_rule.py +++ b/heat/tests/test_translation_rule.py @@ -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):