summaryrefslogtreecommitdiff
path: root/heat/tests/test_resource.py
diff options
context:
space:
mode:
authorricolin <rico.lin@easystack.cn>2017-05-18 14:55:26 +0800
committerRico Lin <rico.lin@easystack.cn>2017-07-21 08:09:49 +0000
commit4a15c3387a258a66b366d6ace63c47192bb53fd1 (patch)
tree444c5cae94d333ceae4abfc0aaa36b1add0ad49c /heat/tests/test_resource.py
parentd85361bd9f44fda03cdb9e39f53c4b4180d3dd04 (diff)
downloadheat-4a15c3387a258a66b366d6ace63c47192bb53fd1.tar.gz
Only validate properties once during create resource
While create a resource, we might retry to create or delete that resource. Within every action properties validate was act as pre-function before actually call any action. While the first creat run, if anything goes wrong during property validation, a validation error will raise right away. Which will definitely riase in the very first action run. But if it successed, it still required to revalidate each time an action triggered (whatever is creat or delete). This patch will ignore properties validate if it's not the first create run. Closes-Bug: #1691672 Change-Id: Ibf592a254a862613eddb77ea5933ec6ba0cd2d1a
Diffstat (limited to 'heat/tests/test_resource.py')
-rw-r--r--heat/tests/test_resource.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py
index 8189a16f7..0c1fdf614 100644
--- a/heat/tests/test_resource.py
+++ b/heat/tests/test_resource.py
@@ -1022,6 +1022,37 @@ class ResourceTest(common.HeatTestCase):
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
+ @mock.patch.object(properties.Properties, 'validate')
+ @mock.patch.object(timeutils, 'retry_backoff_delay')
+ def test_create_validate(self, m_re, m_v):
+ tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
+ {'Foo': 'abc'})
+ res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
+
+ generic_rsrc.ResourceWithProps.handle_create = mock.Mock()
+ generic_rsrc.ResourceWithProps.handle_delete = mock.Mock()
+ m_v.side_effect = [True, exception.StackValidationFailed()]
+ generic_rsrc.ResourceWithProps.handle_create.side_effect = [
+ exception.ResourceInError(resource_name='test_resource',
+ resource_status='ERROR',
+ resource_type='GenericResourceType',
+ resource_action='CREATE',
+ status_reason='just because'),
+ exception.ResourceInError(resource_name='test_resource',
+ resource_status='ERROR',
+ resource_type='GenericResourceType',
+ resource_action='CREATE',
+ status_reason='just because'),
+ None
+ ]
+
+ generic_rsrc.ResourceWithProps.handle_delete.return_value = None
+ m_re.return_value = 0.01
+ scheduler.TaskRunner(res.create)()
+ self.assertEqual(2, m_re.call_count)
+ self.assertEqual(1, m_v.call_count)
+ self.assertEqual((res.CREATE, res.COMPLETE), res.state)
+
def test_create_fail_retry(self):
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo',
{'Foo': 'abc'})