summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuangtianhua <huangtianhua@huawei.com>2015-10-12 11:47:57 +0800
committerThomas Herve <therve@redhat.com>2016-01-18 14:10:16 +0100
commitec446e1fb56bb073b71197fa9f5594d885ae27b4 (patch)
treed765a17323c3e068df2551c7ba3dfe65645dffd0
parent0a1daa7d2e049077fef03d1134a993b81e5739b0 (diff)
downloadheat-ec446e1fb56bb073b71197fa9f5594d885ae27b4.tar.gz
Do not return None when get_attr if res is in SNAPSHOT/CHECK
To get attribute instead of return None if resource is in SNAPSHOT or CHECK action. This patch allow to get_attr for hot template version '2013-05-23' also. Change-Id: I318f4c158ebe0a4afbb3f0bcbe9d856d90f0a4bb Closes-Bug: #1505054 (cherry picked from commit 20825d991e77c5aad6c596240143c48dd9e205c6)
-rw-r--r--heat/engine/cfn/functions.py3
-rw-r--r--heat/engine/hot/functions.py2
-rw-r--r--heat/tests/test_hot.py78
3 files changed, 80 insertions, 3 deletions
diff --git a/heat/engine/cfn/functions.py b/heat/engine/cfn/functions.py
index 0ab287c9c..1432c5eeb 100644
--- a/heat/engine/cfn/functions.py
+++ b/heat/engine/cfn/functions.py
@@ -196,7 +196,8 @@ class GetAtt(function.Function):
attribute = function.resolve(self._attribute)
r = self._resource()
- if (r.action in (r.CREATE, r.ADOPT, r.SUSPEND, r.RESUME, r.UPDATE)):
+ if r.action in (r.CREATE, r.ADOPT, r.SUSPEND, r.RESUME,
+ r.UPDATE, r.ROLLBACK, r.SNAPSHOT, r.CHECK):
return r.FnGetAtt(attribute)
else:
return None
diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py
index 2147a5de0..dfc23e48b 100644
--- a/heat/engine/hot/functions.py
+++ b/heat/engine/hot/functions.py
@@ -145,7 +145,7 @@ class GetAtt(GetAttThenSelect):
r = self._resource()
if (r.status in (r.IN_PROGRESS, r.COMPLETE) and
r.action in (r.CREATE, r.ADOPT, r.SUSPEND, r.RESUME,
- r.UPDATE)):
+ r.UPDATE, r.CHECK, r.SNAPSHOT)):
return r.FnGetAtt(attribute, *path_components)
else:
return None
diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py
index cff124d5c..0cec2b27b 100644
--- a/heat/tests/test_hot.py
+++ b/heat/tests/test_hot.py
@@ -63,6 +63,13 @@ resources:
type: GenericResourceType
''')
+hot_tpl_generic_resource_20141016 = template_format.parse('''
+heat_template_version: 2014-10-16
+resources:
+ resource1:
+ type: GenericResourceType
+''')
+
hot_tpl_complex_attrs = template_format.parse('''
heat_template_version: 2013-05-23
resources:
@@ -70,6 +77,13 @@ resources:
type: ResourceWithComplexAttributesType
''')
+hot_tpl_complex_attrs_20141016 = template_format.parse('''
+heat_template_version: 2014-10-16
+resources:
+ resource1:
+ type: ResourceWithComplexAttributesType
+''')
+
hot_tpl_mapped_props = template_format.parse('''
heat_template_version: 2013-05-23
resources:
@@ -1158,6 +1172,7 @@ class StackAttributesTest(common.HeatTestCase):
self.m.ReplayAll()
scenarios = [
+ # for hot template 2013-05-23, get_attr: hot_funcs.GetAttThenSelect
('get_flat_attr',
dict(hot_tpl=hot_tpl_generic_resource,
snippet={'Value': {'get_attr': ['resource1', 'foo']}},
@@ -1208,6 +1223,59 @@ class StackAttributesTest(common.HeatTestCase):
'none',
'who_cares']}},
resource_name='resource1',
+ expected={'Value': None})),
+ # for hot template version 2014-10-16 and 2015-04-30,
+ # get_attr: hot_funcs.GetAtt
+ ('get_flat_attr',
+ dict(hot_tpl=hot_tpl_generic_resource_20141016,
+ snippet={'Value': {'get_attr': ['resource1', 'foo']}},
+ resource_name='resource1',
+ expected={'Value': 'resource1'})),
+ ('get_list_attr',
+ dict(hot_tpl=hot_tpl_complex_attrs_20141016,
+ snippet={'Value': {'get_attr': ['resource1', 'list', 0]}},
+ resource_name='resource1',
+ expected={
+ 'Value':
+ generic_rsrc.ResourceWithComplexAttributes.list[0]})),
+ ('get_flat_dict_attr',
+ dict(hot_tpl=hot_tpl_complex_attrs_20141016,
+ snippet={'Value': {'get_attr': ['resource1',
+ 'flat_dict',
+ 'key2']}},
+ resource_name='resource1',
+ expected={
+ 'Value':
+ generic_rsrc.ResourceWithComplexAttributes.
+ flat_dict['key2']})),
+ ('get_nested_attr_list',
+ dict(hot_tpl=hot_tpl_complex_attrs_20141016,
+ snippet={'Value': {'get_attr': ['resource1',
+ 'nested_dict',
+ 'list',
+ 0]}},
+ resource_name='resource1',
+ expected={
+ 'Value':
+ generic_rsrc.ResourceWithComplexAttributes.
+ nested_dict['list'][0]})),
+ ('get_nested_attr_dict',
+ dict(hot_tpl=hot_tpl_complex_attrs_20141016,
+ snippet={'Value': {'get_attr': ['resource1',
+ 'nested_dict',
+ 'dict',
+ 'a']}},
+ resource_name='resource1',
+ expected={
+ 'Value':
+ generic_rsrc.ResourceWithComplexAttributes.
+ nested_dict['dict']['a']})),
+ ('get_attr_none',
+ dict(hot_tpl=hot_tpl_complex_attrs_20141016,
+ snippet={'Value': {'get_attr': ['resource1',
+ 'none',
+ 'who_cares']}},
+ resource_name='resource1',
expected={'Value': None}))
]
@@ -1227,8 +1295,16 @@ class StackAttributesTest(common.HeatTestCase):
(rsrc.CREATE, rsrc.COMPLETE),
(rsrc.RESUME, rsrc.IN_PROGRESS),
(rsrc.RESUME, rsrc.COMPLETE),
+ (rsrc.SUSPEND, rsrc.IN_PROGRESS),
+ (rsrc.SUSPEND, rsrc.COMPLETE),
(rsrc.UPDATE, rsrc.IN_PROGRESS),
- (rsrc.UPDATE, rsrc.COMPLETE)):
+ (rsrc.UPDATE, rsrc.COMPLETE),
+ (rsrc.SNAPSHOT, rsrc.IN_PROGRESS),
+ (rsrc.SNAPSHOT, rsrc.COMPLETE),
+ (rsrc.CHECK, rsrc.IN_PROGRESS),
+ (rsrc.CHECK, rsrc.COMPLETE),
+ (rsrc.ADOPT, rsrc.IN_PROGRESS),
+ (rsrc.ADOPT, rsrc.COMPLETE)):
rsrc.state_set(action, status)
resolved = function.resolve(self.stack.t.parse(self.stack,