From: Steve Baker Date: Wed, 10 Jul 2013 03:05:53 +0000 (+1200) Subject: Put pre-created resources in state INIT COMPLETE. X-Git-Tag: 2014.1~354^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c148cbc8d85aa29d85f40925a3da840e216d0fb9;p=openstack-build%2Fheat-build.git Put pre-created resources in state INIT COMPLETE. Defines an INIT action, and make the resourse state INIT COMPLETE before they are first created. Calls to list resources will now include resource that have not been created yet. This change allows resource topologies to be displayed throughout the creation of the stack. Implements blueprint build-heat-graph Change-Id: I1d98ac21d44ff05183db38d49cbb3599e2812511 --- diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 9a90f6e6..72735348 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -114,8 +114,8 @@ class Metadata(object): class Resource(object): - ACTIONS = (CREATE, DELETE, UPDATE, ROLLBACK, SUSPEND, RESUME - ) = ('CREATE', 'DELETE', 'UPDATE', 'ROLLBACK', + ACTIONS = (INIT, CREATE, DELETE, UPDATE, ROLLBACK, SUSPEND, RESUME + ) = ('INIT', 'CREATE', 'DELETE', 'UPDATE', 'ROLLBACK', 'SUSPEND', 'RESUME') STATUSES = (IN_PROGRESS, FAILED, COMPLETE @@ -182,8 +182,8 @@ class Resource(object): self.data = resource.data else: self.resource_id = None - self.action = None - self.status = None + self.action = self.INIT + self.status = self.COMPLETE self.status_reason = '' self.id = None self.data = [] @@ -381,7 +381,10 @@ class Resource(object): Create the resource. Subclasses should provide a handle_create() method to customise creation. ''' - assert None in (self.action, self.status), 'invalid state for create' + if (self.action, self.status) != (self.INIT, self.COMPLETE): + exc = exception.Error('State %s invalid for create' + % str(self.state)) + raise exception.ResourceFailure(exc) logger.info('creating %s' % str(self)) @@ -495,7 +498,7 @@ class Resource(object): if (self.action, self.status) == (self.DELETE, self.COMPLETE): return # No need to delete if the resource has never been created - if self.action is None: + if self.action == self.INIT: return initial_state = self.state diff --git a/heat/engine/service.py b/heat/engine/service.py index e1de9a60..193eed3f 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -482,8 +482,7 @@ class EngineService(service.Service): name_match = lambda r: True return [api.format_stack_resource(resource) - for resource in stack - if resource.id is not None and name_match(resource)] + for resource in stack if name_match(resource)] @request_context def list_stack_resources(self, cnxt, stack_identity): @@ -492,7 +491,7 @@ class EngineService(service.Service): stack = parser.Stack.load(cnxt, stack=s) return [api.format_stack_resource(resource, detail=False) - for resource in stack if resource.id is not None] + for resource in stack] @request_context def stack_suspend(self, cnxt, stack_identity): diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 3b270b64..d5ac74c0 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -58,7 +58,7 @@ class ResourceTest(HeatTestCase): def test_state_defaults(self): tmpl = {'Type': 'Foo'} res = generic_rsrc.GenericResource('test_res_def', tmpl, self.stack) - self.assertEqual(res.state, (None, None)) + self.assertEqual(res.state, (res.INIT, res.COMPLETE)) self.assertEqual(res.status_reason, '') def test_state_set(self):