From b3744f28af6c460f2c029a438e5680ad34d8704c Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Mon, 28 Jan 2013 14:45:24 +0000 Subject: [PATCH] heat engine : pass json snippet into resource handle_update Change handle_update to accept the resource json_snippet, needed to decide if a non-replacement update is possible by comparing pre and post update resource definitions ref blueprint instance-update-stack Change-Id: I7eedce41eae232330f6fce4f098183cbd7fd6768 Signed-off-by: Steven Hardy --- heat/engine/resource.py | 6 +++--- heat/engine/resources/autoscaling.py | 4 ++-- heat/engine/resources/cloud_watch.py | 2 +- heat/engine/resources/dbinstance.py | 2 +- heat/engine/resources/eip.py | 2 +- heat/engine/resources/instance.py | 2 +- heat/engine/resources/loadbalancer.py | 2 +- heat/engine/resources/quantum/quantum.py | 2 +- heat/engine/resources/s3.py | 2 +- heat/engine/resources/security_group.py | 2 +- heat/engine/resources/stack.py | 2 +- heat/engine/resources/swift.py | 2 +- heat/engine/resources/user.py | 4 ++-- heat/engine/resources/volume.py | 4 ++-- heat/engine/resources/vpc.py | 2 +- heat/engine/resources/wait_condition.py | 4 ++-- heat/tests/test_autoscaling.py | 2 +- heat/tests/test_eip.py | 2 +- heat/tests/test_instance_group.py | 2 +- heat/tests/test_loadbalancer.py | 2 +- heat/tests/test_quantum.py | 2 +- heat/tests/test_s3.py | 3 ++- heat/tests/test_swift.py | 2 +- heat/tests/test_user.py | 4 ++-- heat/tests/test_volume.py | 4 ++-- heat/tests/test_vpc.py | 2 +- heat/tests/test_waitcondition.py | 4 ++-- 27 files changed, 37 insertions(+), 36 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index b3de66ad..c8cd53d1 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -260,7 +260,7 @@ class Resource(object): if err: raise ValueError(err) if callable(getattr(self, 'handle_update', None)): - result = self.handle_update() + result = self.handle_update(json_snippet) except Exception as ex: logger.exception('update %s : %s' % (str(self), str(ex))) self.state_set(self.UPDATE_FAILED, str(ex)) @@ -424,7 +424,7 @@ class Resource(object): ''' return base64.b64encode(data) - def handle_update(self): + def handle_update(self, json_snippet=None): raise NotImplementedError("Update not implemented for Resource %s" % type(self)) @@ -442,5 +442,5 @@ class GenericResource(Resource): def handle_create(self): logger.warning('Creating generic resource (Type "%s")' % self.type()) - def handle_update(self): + def handle_update(self, json_snippet=None): logger.warning('Updating generic resource (Type "%s")' % self.type()) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 9935e4ca..1de527ce 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -78,7 +78,7 @@ class InstanceGroup(resource.Resource): def handle_create(self): self.resize(int(self.properties['Size']), raise_on_error=True) - def handle_update(self): + def handle_update(self, json_snippet): # TODO(asalkeld) if the only thing that has changed is the size then # call resize. Maybe have an attribute of the properties that can mark # it "update-able" so each resource doesn't have to figure this out. @@ -205,7 +205,7 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin): self.adjust(num_to_create, adjustment_type='ExactCapacity', raise_on_error=True) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def adjust(self, adjustment, adjustment_type='ChangeInCapacity', diff --git a/heat/engine/resources/cloud_watch.py b/heat/engine/resources/cloud_watch.py index 79a27a8b..e4d6f725 100644 --- a/heat/engine/resources/cloud_watch.py +++ b/heat/engine/resources/cloud_watch.py @@ -81,7 +81,7 @@ class CloudWatchAlarm(resource.Resource): stack_id=self.stack.id) wr.store() - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/dbinstance.py b/heat/engine/resources/dbinstance.py index e22c0d38..49ba870c 100644 --- a/heat/engine/resources/dbinstance.py +++ b/heat/engine/resources/dbinstance.py @@ -216,7 +216,7 @@ class DBInstance(stack_resource.StackResource): templ = template_format.parse(mysql_template) self.create_with_template(templ, self._params()) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/eip.py b/heat/engine/resources/eip.py index 0bcb2e62..c0e4dc4e 100644 --- a/heat/engine/resources/eip.py +++ b/heat/engine/resources/eip.py @@ -49,7 +49,7 @@ class ElasticIp(resource.Resource): self.ipaddress = ips.ip self.resource_id_set(ips.id) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index b2477080..d40e13b0 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -282,7 +282,7 @@ class Instance(resource.Resource): ('nova reported unexpected', self.name, server.status)) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def validate(self): diff --git a/heat/engine/resources/loadbalancer.py b/heat/engine/resources/loadbalancer.py index ebdb72aa..5c7267c4 100644 --- a/heat/engine/resources/loadbalancer.py +++ b/heat/engine/resources/loadbalancer.py @@ -290,7 +290,7 @@ class LoadBalancer(stack_resource.StackResource): self.create_with_template(templ, param) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/quantum/quantum.py b/heat/engine/resources/quantum/quantum.py index d156815a..72d775f0 100644 --- a/heat/engine/resources/quantum/quantum.py +++ b/heat/engine/resources/quantum/quantum.py @@ -84,7 +84,7 @@ class QuantumResource(resource.Resource): raise exception.InvalidTemplateAttribute(resource=name, key=key) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def FnGetRefId(self): diff --git a/heat/engine/resources/s3.py b/heat/engine/resources/s3.py index dbb9ad6f..119e43e8 100644 --- a/heat/engine/resources/s3.py +++ b/heat/engine/resources/s3.py @@ -91,7 +91,7 @@ class S3Bucket(resource.Resource): self.swift().put_container(container, headers) self.resource_id_set(container) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/security_group.py b/heat/engine/resources/security_group.py index 981c00f8..90ad0d68 100644 --- a/heat/engine/resources/security_group.py +++ b/heat/engine/resources/security_group.py @@ -65,7 +65,7 @@ class SecurityGroup(resource.Resource): # unexpected error raise - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/stack.py b/heat/engine/resources/stack.py index c18ef612..1835899d 100644 --- a/heat/engine/resources/stack.py +++ b/heat/engine/resources/stack.py @@ -45,7 +45,7 @@ class NestedStack(stack_resource.StackResource): self.create_with_template(template, self.properties[PROP_PARAMETERS]) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/swift.py b/heat/engine/resources/swift.py index 907b287e..6cbbf180 100644 --- a/heat/engine/resources/swift.py +++ b/heat/engine/resources/swift.py @@ -80,7 +80,7 @@ class SwiftContainer(resource.Resource): self.swift().put_container(container, headers) self.resource_id_set(container) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/user.py b/heat/engine/resources/user.py index 1d6938ec..5eb23638 100644 --- a/heat/engine/resources/user.py +++ b/heat/engine/resources/user.py @@ -49,7 +49,7 @@ class User(resource.Resource): passwd) self.resource_id_set(uid) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): @@ -111,7 +111,7 @@ class AccessKey(resource.Resource): self.resource_id_set(kp.access) self._secret = kp.secret - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index 70587c76..9af2236f 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -47,7 +47,7 @@ class Volume(resource.Resource): else: raise exception.Error(vol.status) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): @@ -91,7 +91,7 @@ class VolumeAttachment(resource.Resource): else: raise exception.Error(vol.status) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/engine/resources/vpc.py b/heat/engine/resources/vpc.py index 1b589cf5..6ddb7d96 100644 --- a/heat/engine/resources/vpc.py +++ b/heat/engine/resources/vpc.py @@ -45,7 +45,7 @@ class VPC(resource.Resource): client.delete_router(router_id) client.delete_network(network_id) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE diff --git a/heat/engine/resources/wait_condition.py b/heat/engine/resources/wait_condition.py index 84f70afd..a88b08c0 100644 --- a/heat/engine/resources/wait_condition.py +++ b/heat/engine/resources/wait_condition.py @@ -99,7 +99,7 @@ class WaitConditionHandle(resource.Resource): return self.keystone().delete_stack_user(self.resource_id) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def FnGetRefId(self): @@ -252,7 +252,7 @@ class WaitCondition(resource.Resource): if status != SUCCESS: raise exception.Error(reason) - def handle_update(self): + def handle_update(self, json_snippet): return self.UPDATE_REPLACE def handle_delete(self): diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index 34a11764..5d93542d 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -121,7 +121,7 @@ class AutoScalingTest(unittest.TestCase): self.assertEqual('WebServerGroup', resource.FnGetRefId()) self.assertEqual('WebServerGroup-0', resource.resource_id) self.assertEqual(asc.AutoScalingGroup.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) resource.delete() self.m.VerifyAll() diff --git a/heat/tests/test_eip.py b/heat/tests/test_eip.py index ae0a940b..92570aa2 100644 --- a/heat/tests/test_eip.py +++ b/heat/tests/test_eip.py @@ -98,7 +98,7 @@ class EIPTest(unittest.TestCase): self.assertEqual('1', resource.FnGetAtt('AllocationId')) self.assertEqual(eip.ElasticIp.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) try: resource.FnGetAtt('Foo') diff --git a/heat/tests/test_instance_group.py b/heat/tests/test_instance_group.py index ee2d2aae..2e2befa2 100644 --- a/heat/tests/test_instance_group.py +++ b/heat/tests/test_instance_group.py @@ -88,7 +88,7 @@ class InstanceGroupTest(unittest.TestCase): self.assertEqual('JobServerGroup', resource.FnGetRefId()) self.assertEqual('JobServerGroup-0', resource.resource_id) self.assertEqual(asc.InstanceGroup.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) resource.delete() diff --git a/heat/tests/test_loadbalancer.py b/heat/tests/test_loadbalancer.py index cf232889..9676287f 100644 --- a/heat/tests/test_loadbalancer.py +++ b/heat/tests/test_loadbalancer.py @@ -148,7 +148,7 @@ class LoadBalancerTest(unittest.TestCase): pass self.assertEqual(lb.LoadBalancer.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) self.m.VerifyAll() diff --git a/heat/tests/test_quantum.py b/heat/tests/test_quantum.py index edb2e057..b1907f19 100644 --- a/heat/tests/test_quantum.py +++ b/heat/tests/test_quantum.py @@ -151,7 +151,7 @@ class QuantumTest(unittest.TestCase): self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', resource.FnGetAtt('id')) - self.assertEqual(net.Net.UPDATE_REPLACE, resource.handle_update()) + self.assertEqual(net.Net.UPDATE_REPLACE, resource.handle_update({})) resource.delete() self.m.VerifyAll() diff --git a/heat/tests/test_s3.py b/heat/tests/test_s3.py index 8150918d..9d1db47d 100644 --- a/heat/tests/test_s3.py +++ b/heat/tests/test_s3.py @@ -117,7 +117,8 @@ class s3Test(unittest.TestCase): except s3.exception.InvalidTemplateAttribute: pass - self.assertEqual(s3.S3Bucket.UPDATE_REPLACE, resource.handle_update()) + self.assertEqual(s3.S3Bucket.UPDATE_REPLACE, + resource.handle_update({})) resource.delete() self.m.VerifyAll() diff --git a/heat/tests/test_swift.py b/heat/tests/test_swift.py index 24f9be3f..8fb8a2db 100644 --- a/heat/tests/test_swift.py +++ b/heat/tests/test_swift.py @@ -152,7 +152,7 @@ class swiftTest(unittest.TestCase): pass self.assertEqual(swift.SwiftContainer.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) resource.delete() self.m.VerifyAll() diff --git a/heat/tests/test_user.py b/heat/tests/test_user.py index 115e9800..2143e9ad 100644 --- a/heat/tests/test_user.py +++ b/heat/tests/test_user.py @@ -91,7 +91,7 @@ class UserTest(unittest.TestCase): self.assertEqual('CREATE_COMPLETE', resource.state) self.assertEqual(user.User.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) resource.resource_id = None self.assertEqual(None, resource.delete()) @@ -138,7 +138,7 @@ class UserTest(unittest.TestCase): resource = self.create_access_key(t, stack, 'HostKeys') self.assertEqual(user.AccessKey.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) self.assertEqual(self.fc.access, resource.resource_id) diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index 9fdc8ce0..b831f6b3 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -110,7 +110,7 @@ class VolumeTest(unittest.TestCase): resource = self.create_volume(t, stack, 'DataVolume') self.assertEqual(fv.status, 'available') - self.assertEqual(resource.handle_update(), vol.Volume.UPDATE_REPLACE) + self.assertEqual(resource.handle_update({}), vol.Volume.UPDATE_REPLACE) fv.status = 'in-use' self.assertEqual(resource.delete(), 'Volume in use') @@ -216,7 +216,7 @@ class VolumeTest(unittest.TestCase): self.assertEqual(fv.status, 'available') resource = self.create_attachment(t, stack, 'MountPoint') - self.assertEqual(resource.handle_update(), vol.Volume.UPDATE_REPLACE) + self.assertEqual(resource.handle_update({}), vol.Volume.UPDATE_REPLACE) self.assertEqual(resource.delete(), None) diff --git a/heat/tests/test_vpc.py b/heat/tests/test_vpc.py index 0544344b..90e9ab22 100644 --- a/heat/tests/test_vpc.py +++ b/heat/tests/test_vpc.py @@ -105,7 +105,7 @@ class QuantumTest(unittest.TestCase): ref_id = resource.FnGetRefId() self.assertEqual('aaaa:bbbb', ref_id) - self.assertEqual(vpc.VPC.UPDATE_REPLACE, resource.handle_update()) + self.assertEqual(vpc.VPC.UPDATE_REPLACE, resource.handle_update({})) self.assertEqual(None, resource.delete()) self.m.VerifyAll() diff --git a/heat/tests/test_waitcondition.py b/heat/tests/test_waitcondition.py index 6a6d2c99..36fdc080 100644 --- a/heat/tests/test_waitcondition.py +++ b/heat/tests/test_waitcondition.py @@ -218,7 +218,7 @@ class WaitConditionTest(unittest.TestCase): self.assertEqual(resource.state, 'CREATE_FAILED') self.assertEqual(wc.WaitCondition.UPDATE_REPLACE, - resource.handle_update()) + resource.handle_update({})) def test_FnGetAtt(self): self.stack = self.create_stack() @@ -322,7 +322,7 @@ class WaitConditionHandleTest(unittest.TestCase): self.assertEqual(expected_url, resource.FnGetRefId()) - self.assertEqual(resource.UPDATE_REPLACE, resource.handle_update()) + self.assertEqual(resource.UPDATE_REPLACE, resource.handle_update({})) def test_metadata_update(self): resource = self.stack.resources['WaitHandle'] -- 2.45.2