Merge "Add _needs_update() to AWS::EC2::EIPAssociation"
This commit is contained in:
commit
35ed968a21
@ -367,27 +367,6 @@ class ElasticIpAssociation(resource.Resource):
|
||||
self._neutron_add_gateway_router(allocation_id, network_id)
|
||||
self._neutron_update_floating_ip(allocation_id, port_id)
|
||||
|
||||
def _validate_update_properties(self, prop_diff):
|
||||
# according to aws doc, when update allocation_id or eip,
|
||||
# if you also change the InstanceId or NetworkInterfaceId,
|
||||
# should go to Replacement flow
|
||||
if self.ALLOCATION_ID in prop_diff or self.EIP in prop_diff:
|
||||
instance_id = prop_diff.get(self.INSTANCE_ID)
|
||||
ni_id = prop_diff.get(self.NETWORK_INTERFACE_ID)
|
||||
|
||||
if instance_id or ni_id:
|
||||
raise exception.UpdateReplace(self.name)
|
||||
|
||||
# according to aws doc, when update the instance_id or
|
||||
# network_interface_id, if you also change the EIP or
|
||||
# ALLOCATION_ID, should go to Replacement flow
|
||||
if (self.INSTANCE_ID in prop_diff or
|
||||
self.NETWORK_INTERFACE_ID in prop_diff):
|
||||
eip = prop_diff.get(self.EIP)
|
||||
allocation_id = prop_diff.get(self.ALLOCATION_ID)
|
||||
if eip or allocation_id:
|
||||
raise exception.UpdateReplace(self.name)
|
||||
|
||||
def handle_create(self):
|
||||
"""Add a floating IP address to a server."""
|
||||
if self.properties[self.EIP]:
|
||||
@ -432,9 +411,29 @@ class ElasticIpAssociation(resource.Resource):
|
||||
port_id=None,
|
||||
ignore_not_found=True)
|
||||
|
||||
def _needs_update(self, after, before, after_props, before_props,
|
||||
prev_resource, check_init_complete=True):
|
||||
result = super(ElasticIpAssociation, self)._needs_update(
|
||||
after, before, after_props, before_props, prev_resource,
|
||||
check_init_complete=check_init_complete)
|
||||
|
||||
prop_diff = self.update_template_diff_properties(after_props,
|
||||
before_props)
|
||||
|
||||
# according to aws doc, when update allocation_id or eip,
|
||||
# if you also change the InstanceId or NetworkInterfaceId,
|
||||
# should go to Replacement flow
|
||||
if self.ALLOCATION_ID in prop_diff or self.EIP in prop_diff:
|
||||
instance_id = prop_diff.get(self.INSTANCE_ID)
|
||||
ni_id = prop_diff.get(self.NETWORK_INTERFACE_ID)
|
||||
|
||||
if instance_id or ni_id:
|
||||
raise exception.UpdateReplace(self.name)
|
||||
|
||||
return result
|
||||
|
||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||
if prop_diff:
|
||||
self._validate_update_properties(prop_diff)
|
||||
if self.ALLOCATION_ID in prop_diff or self.EIP in prop_diff:
|
||||
self._handle_update_eipInfo(prop_diff)
|
||||
elif (self.INSTANCE_ID in prop_diff or
|
||||
|
@ -867,6 +867,57 @@ class AllocTest(common.HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_update_association_needs_update_InstanceId(self):
|
||||
server = self.fc.servers.list()[0]
|
||||
self._mock_server_get(mock_server=server, multiple=True)
|
||||
|
||||
server_update = self.fc.servers.list()[1]
|
||||
self._mock_server_get(server='5678',
|
||||
mock_server=server_update,
|
||||
multiple=True,
|
||||
mock_again=True)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
t = template_format.parse(eip_template_ipassoc)
|
||||
stack = utils.parse_stack(t)
|
||||
self.create_eip(t, stack, 'IPAddress')
|
||||
before_props = {'InstanceId': {'Ref': 'WebServer'},
|
||||
'EIP': '11.0.0.1'}
|
||||
after_props = {'InstanceId': {'Ref': 'WebServer2'},
|
||||
'EIP': '11.0.0.1'}
|
||||
before = self.create_association(t, stack, 'IPAssoc')
|
||||
after = rsrc_defn.ResourceDefinition(before.name, before.type(),
|
||||
after_props)
|
||||
self.assertTrue(exception.UpdateReplace,
|
||||
before._needs_update(after, before, after_props,
|
||||
before_props, None))
|
||||
|
||||
def test_update_association_needs_update_InstanceId_EIP(self):
|
||||
server = self.fc.servers.list()[0]
|
||||
self._mock_server_get(mock_server=server, multiple=True)
|
||||
|
||||
server_update = self.fc.servers.list()[1]
|
||||
self._mock_server_get(server='5678',
|
||||
mock_server=server_update,
|
||||
multiple=True,
|
||||
mock_again=True)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
t = template_format.parse(eip_template_ipassoc)
|
||||
stack = utils.parse_stack(t)
|
||||
self.create_eip(t, stack, 'IPAddress')
|
||||
before_props = {'InstanceId': {'Ref': 'WebServer'},
|
||||
'EIP': '11.0.0.1'}
|
||||
after_props = {'InstanceId': {'Ref': 'WebServer2'},
|
||||
'EIP': '11.0.0.2'}
|
||||
before = self.create_association(t, stack, 'IPAssoc')
|
||||
after = rsrc_defn.ResourceDefinition(before.name, before.type(),
|
||||
after_props)
|
||||
self.assertRaises(exception.UpdateReplace, before._needs_update,
|
||||
after, before, after_props, before_props, None)
|
||||
|
||||
def test_update_association_with_NetworkInterfaceId_or_InstanceId(self):
|
||||
self.mock_create_floatingip()
|
||||
self.mock_list_ports()
|
||||
|
Loading…
Reference in New Issue
Block a user