Merge "Small refactoring translation mechanism"
This commit is contained in:
@@ -1039,7 +1039,17 @@ class Resource(object):
|
||||
"""
|
||||
rules = self.translation_rules(properties) or []
|
||||
for rule in rules:
|
||||
rule.execute_rule(client_resolve)
|
||||
try:
|
||||
rule.execute_rule(client_resolve)
|
||||
except exception.ResourcePropertyConflict as ex:
|
||||
path = [self.stack.t.RESOURCES, self.name,
|
||||
self.stack.t.get_section_name(
|
||||
self.stack.t.RES_PROPERTIES)]
|
||||
raise exception.StackValidationFailed(
|
||||
error='Property error',
|
||||
path=path,
|
||||
message=ex.message
|
||||
)
|
||||
|
||||
def cancel_grace_period(self):
|
||||
if self.status != self.IN_PROGRESS:
|
||||
|
||||
@@ -355,5 +355,5 @@ class TranslationRule(object):
|
||||
for item in translation_data:
|
||||
if item.get(translation_key) is not None:
|
||||
del item[translation_key]
|
||||
else:
|
||||
elif translation_data.get(translation_key) is not None:
|
||||
del translation_data[translation_key]
|
||||
|
||||
@@ -1036,14 +1036,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 define the following properties at the same time: "
|
||||
err_msg = ("Property error: resources.volume2.properties: 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(exception.ResourcePropertyConflict,
|
||||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
stack.get, 'volume2')
|
||||
self.assertEqual(err_msg, six.text_type(ex))
|
||||
|
||||
|
||||
@@ -1215,13 +1215,15 @@ class ServersTest(common.HeatTestCase):
|
||||
'network': network_name}])
|
||||
|
||||
resource_defns = tmpl.resource_definitions(stack)
|
||||
ex = self.assertRaises(exception.ResourcePropertyConflict,
|
||||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
servers.Server,
|
||||
'server_validate_with_networks',
|
||||
resource_defns['WebServer'], stack)
|
||||
|
||||
self.assertIn("Cannot define the following properties at the "
|
||||
"same time: ['network', 'uuid'].",
|
||||
self.assertIn("Property error: "
|
||||
"Resources.server_validate_with_networks.Properties: "
|
||||
"Cannot define the following properties at the same "
|
||||
"time: ['network', 'uuid'].",
|
||||
six.text_type(ex))
|
||||
|
||||
def test_server_validate_with_network_empty_ref(self):
|
||||
@@ -2726,9 +2728,10 @@ class ServersTest(common.HeatTestCase):
|
||||
(tmpl, stack) = self._setup_test_stack('mapping',
|
||||
test_templ=test_templ)
|
||||
resource_defns = tmpl.resource_definitions(stack)
|
||||
msg = ("Cannot define the following properties at the same time: "
|
||||
msg = ("Property error: resources.server.properties: Cannot define "
|
||||
"the following properties at the same time: "
|
||||
"['image', 'image_id'].")
|
||||
exc = self.assertRaises(exception.ResourcePropertyConflict,
|
||||
exc = self.assertRaises(exception.StackValidationFailed,
|
||||
servers.Server, 'server',
|
||||
resource_defns['server'], stack)
|
||||
self.assertEqual(msg, six.text_type(exc))
|
||||
|
||||
@@ -417,6 +417,9 @@ class TestTranslationRule(common.HeatTestCase):
|
||||
schema={
|
||||
'red': properties.Schema(
|
||||
properties.Schema.STRING
|
||||
),
|
||||
'check': properties.Schema(
|
||||
properties.Schema.STRING
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -434,7 +437,16 @@ class TestTranslationRule(common.HeatTestCase):
|
||||
['far', 'red'])
|
||||
rule.execute_rule()
|
||||
|
||||
self.assertEqual([{'red': None}, {'red': None}], props.get('far'))
|
||||
self.assertEqual([{'check': None, 'red': None},
|
||||
{'check': None, 'red': None}], props.get('far'))
|
||||
|
||||
# check if no data translation still is correct
|
||||
props = properties.Properties(schema, {'far': [{'check': 'yep'}]})
|
||||
rule = translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.DELETE,
|
||||
['far', 'red'])
|
||||
self.assertIsNone(rule.execute_rule())
|
||||
|
||||
def test_delete_rule_other(self):
|
||||
schema = {
|
||||
|
||||
Reference in New Issue
Block a user