diff options
author | Zane Bitter <zbitter@redhat.com> | 2019-12-17 23:04:44 -0500 |
---|---|---|
committer | Kevin Carter (cloudnull) <kevin@cloudnull.com> | 2020-07-14 10:54:25 +0000 |
commit | 3327b40fde0f071b4820c59dd88c6c5565d79406 (patch) | |
tree | 12c378e75f90d82ccaaea9a84e80e68a8a79d05e | |
parent | 82f63c992f5382e412acd7929dee31f1c4fa9943 (diff) | |
download | heat-3327b40fde0f071b4820c59dd88c6c5565d79406.tar.gz |
Check external resources after creation
The method Resource.check() is not a generator function, but it does
return a generator in most cases. Simply calling the function does not
cause the resource to actually be checked. Only in the case where the
resource did not provide a handle_check() method would it do anything at
all - and in that case it simply changes the state to CHECK_COMPLETE.
Yield the generator function so that the resource will actually be
checked if the resource type supports it.
Change-Id: I2a78b6f6235529a95838307e3d38731d31ff5c4b
Task: 37828
(cherry picked from commit 5c6038f7a272238eef8978a4b26ab4ae4efd745b)
-rw-r--r-- | heat/engine/resource.py | 2 | ||||
-rw-r--r-- | heat/tests/generic_resource.py | 6 | ||||
-rw-r--r-- | heat/tests/test_resource.py | 9 |
3 files changed, 16 insertions, 1 deletions
diff --git a/heat/engine/resource.py b/heat/engine/resource.py index c33e68c09..470cec2e3 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -1215,7 +1215,7 @@ class Resource(status.ResourceStatus): yield self._do_action(self.ADOPT, resource_data={ 'resource_id': self.external_id}) - self.check() + yield self.check() return # This method can be called when we replace a resource, too. In that diff --git a/heat/tests/generic_resource.py b/heat/tests/generic_resource.py index 2fd87e830..9e41f3d6f 100644 --- a/heat/tests/generic_resource.py +++ b/heat/tests/generic_resource.py @@ -60,6 +60,12 @@ class GenericResource(resource.Resource): self.type()) +class CheckableResource(GenericResource): + def handle_check(self): + LOG.warning(('Checking generic resource (Type "%s")'), + self.type()) + + class CancellableResource(GenericResource): def check_create_complete(self, cookie): return True diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 1bac44654..2d30bd464 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -366,6 +366,15 @@ class ResourceTest(common.HeatTestCase): self.assertEqual((res.CHECK, res.COMPLETE), res.state) self.assertEqual('f00d', res.resource_id) + def test_create_from_external_with_check(self): + tmpl = rsrc_defn.ResourceDefinition( + 'test_resource', 'GenericResourceType', + external_id='f00d') + res = generic_rsrc.CheckableResource('test_resource', tmpl, self.stack) + scheduler.TaskRunner(res.create)() + self.assertEqual((res.CHECK, res.COMPLETE), res.state) + self.assertEqual('f00d', res.resource_id) + def test_create_from_external_not_found(self): external_id = 'f00d' tmpl = rsrc_defn.ResourceDefinition( |