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 <shardy@redhat.com>
This commit is contained in:
parent
ac84fae5d3
commit
b3744f28af
@ -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())
|
||||
|
@ -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',
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
@ -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')
|
||||
|
@ -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()
|
||||
|
||||
|
@ -148,7 +148,7 @@ class LoadBalancerTest(unittest.TestCase):
|
||||
pass
|
||||
|
||||
self.assertEqual(lb.LoadBalancer.UPDATE_REPLACE,
|
||||
resource.handle_update())
|
||||
resource.handle_update({}))
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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']
|
||||
|
Loading…
Reference in New Issue
Block a user