Skip to content

Commit

Permalink
If neutron sends empty body in floatingip-update, vnc_openstack
Browse files Browse the repository at this point in the history
receives body without 'resource' key. Simulate one and ensure any
port association is cleared in such a case.

Change-Id: I7ab14cb45b4896ddd4039f1343178d1984a4ca13
Closes-Bug: 1685314
  • Loading branch information
Hampapur Ajay committed Apr 25, 2017
1 parent b944e95 commit 4a2080d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,14 @@ def plugin_update_floatingip(self, context, floatingip):

try:
cfgdb = self._get_user_cfgdb(context)
if 'resource' in floatingip:
fip_resource = floatingip['resource']
else:
# non-existent body => clear fip to port assoc per neutron api
# simulate empty update for backend
fip_resource = {}
floatingip_info = cfgdb.floatingip_update(context, floatingip['id'],
floatingip['resource'])
fip_resource)
return floatingip_info
except Exception as e:
cgitb_hook(format="text")
Expand Down
56 changes: 56 additions & 0 deletions src/config/vnc_openstack/vnc_openstack/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,62 @@ def test_fixed_ip_conflicts_with_floating_ip(self):
self.delete_resource('security_group', proj_obj.uuid, sg_q['id'])
# end test_fixed_ip_conflicts_with_floating_ip

def test_empty_floating_ip_body_disassociates(self):
proj_obj = self._vnc_lib.project_read(fq_name=['default-domain', 'default-project'])
sg_q = self.create_resource('security_group', proj_obj.uuid)

pvt_net_q = self.create_resource('network', proj_obj.uuid,
extra_res_fields={'router:external': True})
pvt_subnet_q = self.create_resource('subnet', proj_obj.uuid,
extra_res_fields={
'network_id': pvt_net_q['id'],
'cidr': '1.1.1.0/24',
'ip_version': 4,
})
port_q = self.create_resource('port', proj_obj.uuid,
extra_res_fields={
'network_id': pvt_net_q['id'],
'security_groups': [sg_q['id']],
})


pub_net_q = self.create_resource('network', proj_obj.uuid,
extra_res_fields={'router:external': True})
pub_subnet_q = self.create_resource('subnet', proj_obj.uuid,
extra_res_fields={
'network_id': pub_net_q['id'],
'cidr': '10.1.1.0/24',
'ip_version': 4,
})
fip_q = self.create_resource('floatingip', proj_obj.uuid,
extra_res_fields={
'floating_network_id': pub_net_q['id'],
'port_id': port_q['id'],
})

# update fip with no 'resource' key and assert port disassociated
context = {'operation': 'UPDATE',
'user_id': '',
'is_admin': False,
'roles': '',
'tenant_id': proj_obj.uuid}
data = {'id': fip_q['id']}
body = {'context': context, 'data': data}
resp = self._api_svr_app.post_json('/neutron/floatingip', body)
self.assertEqual(resp.status_code, 200)
fip_read = self.read_resource('floatingip', fip_q['id'])
self.assertEqual(fip_read['port_id'], None)

# cleanup
self.delete_resource('port', proj_obj.uuid, port_q['id'])
self.delete_resource('subnet', proj_obj.uuid, pvt_subnet_q['id'])
self.delete_resource('network', proj_obj.uuid, pvt_net_q['id'])
self.delete_resource('floatingip', proj_obj.uuid, fip_q['id'])
self.delete_resource('subnet', proj_obj.uuid, pub_subnet_q['id'])
self.delete_resource('network', proj_obj.uuid, pub_net_q['id'])
self.delete_resource('security_group', proj_obj.uuid, sg_q['id'])
# end test_empty_floating_ip_body_disassociates

def test_floating_ip_list(self):
proj_objs = []
for i in range(3):
Expand Down

0 comments on commit 4a2080d

Please sign in to comment.