Merge "Implement handle_update for FloatingIPAssociation resource"

This commit is contained in:
Jenkins 2014-06-10 08:26:40 +00:00 committed by Gerrit Code Review
commit c23067fc81
2 changed files with 108 additions and 4 deletions

View File

@ -149,16 +149,20 @@ class FloatingIPAssociation(neutron.NeutronResource):
FLOATINGIP_ID: properties.Schema(
properties.Schema.STRING,
_('ID of the floating IP to associate.'),
required=True
required=True,
update_allowed=True
),
PORT_ID: properties.Schema(
properties.Schema.STRING,
_('ID of an existing port with at least one IP address to '
'associate with this floating IP.')
'associate with this floating IP.'),
required=True,
update_allowed=True
),
FIXED_IP_ADDRESS: properties.Schema(
properties.Schema.STRING,
_('IP address to use if the port has multiple addresses.')
_('IP address to use if the port has multiple addresses.'),
update_allowed=True
),
}
@ -183,6 +187,36 @@ class FloatingIPAssociation(neutron.NeutronResource):
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
(floatingip_id, port_id) = self.resource_id.split(':')
neutron_client = self.neutron()
# if the floatingip_id is changed, disassociate the port which
# associated with the old floatingip_id
if self.FLOATINGIP_ID in prop_diff:
try:
neutron_client.update_floatingip(
floatingip_id,
{'floatingip': {'port_id': None}})
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
# associate the floatingip with the new port
floatingip_id = (prop_diff.get(self.FLOATINGIP_ID) or
floatingip_id)
port_id = prop_diff.get(self.PORT_ID) or port_id
fixed_ip_address = (prop_diff.get(self.FIXED_IP_ADDRESS) or
self.properties.get(self.FIXED_IP_ADDRESS))
request_body = {
'floatingip': {
'port_id': port_id,
'fixed_ip_address': fixed_ip_address}}
neutron_client.update_floatingip(floatingip_id, request_body)
self.resource_id_set('%s:%s' % (floatingip_id, port_id))
def resource_mapping():
if clients.neutronclient is None:

View File

@ -2028,6 +2028,7 @@ class NeutronFloatingIPTest(HeatTestCase):
"status": "ACTIVE",
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})
# create as
neutronclient.Client.update_floatingip(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
{
@ -2037,7 +2038,50 @@ class NeutronFloatingIPTest(HeatTestCase):
"status": "ACTIVE",
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})
# update as with port_id
neutronclient.Client.update_floatingip(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
{
'floatingip': {
'port_id': u'2146dfbf-ba77-4083-8e86-d052f671ece5',
'fixed_ip_address': None}}
).AndReturn({'floatingip': {
"status": "ACTIVE",
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})
# update as with floatingip_id
neutronclient.Client.update_floatingip(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
{'floatingip': {
'port_id': None
}}).AndReturn(None)
neutronclient.Client.update_floatingip(
'2146dfbf-ba77-4083-8e86-d052f671ece5',
{
'floatingip': {
'port_id': u'2146dfbf-ba77-4083-8e86-d052f671ece5',
'fixed_ip_address': None}}
).AndReturn({'floatingip': {
"status": "ACTIVE",
"id": "2146dfbf-ba77-4083-8e86-d052f671ece5"
}})
# update as with both
neutronclient.Client.update_floatingip(
'2146dfbf-ba77-4083-8e86-d052f671ece5',
{'floatingip': {
'port_id': None
}}).AndReturn(None)
neutronclient.Client.update_floatingip(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
{
'floatingip': {
'port_id': u'ade6fcac-7d47-416e-a3d7-ad12efe445c1',
'fixed_ip_address': None}}
).AndReturn({'floatingip': {
"status": "ACTIVE",
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})
# delete as
neutronclient.Client.update_floatingip(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
{'floatingip': {
@ -2094,6 +2138,32 @@ class NeutronFloatingIPTest(HeatTestCase):
port_id = p.FnGetRefId()
self.assertEqual('%s:%s' % (fip_id, port_id), fipa_id)
# test update FloatingIpAssociation with port_id
update_snippet = copy.deepcopy(fipa.parsed_template())
update_port_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
update_snippet['Properties']['port_id'] = update_port_id
scheduler.TaskRunner(fipa.update, update_snippet)()
self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)
# test update FloatingIpAssociation with floatingip_id
update_snippet = copy.deepcopy(fipa.parsed_template())
update_flip_id = '2146dfbf-ba77-4083-8e86-d052f671ece5'
update_snippet['Properties']['floatingip_id'] = update_flip_id
scheduler.TaskRunner(fipa.update, update_snippet)()
self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)
# test update FloatingIpAssociation with port_id and floatingip_id
update_snippet = copy.deepcopy(fipa.parsed_template())
update_flip_id = 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
update_port_id = 'ade6fcac-7d47-416e-a3d7-ad12efe445c1'
update_snippet['Properties']['floatingip_id'] = update_flip_id
update_snippet['Properties']['port_id'] = update_port_id
scheduler.TaskRunner(fipa.update, update_snippet)()
self.assertEqual((fipa.UPDATE, fipa.COMPLETE), fipa.state)
scheduler.TaskRunner(fipa.delete)()
scheduler.TaskRunner(p.delete)()
scheduler.TaskRunner(fip.delete)()