Prevents PUT on ip_addresses with empty port list
JIRA:NCP-1631
This commit is contained in:
		| @@ -281,7 +281,13 @@ def update_ip_address(context, id, ip_address): | ||||
|                 msg = "Modification of reset_allocation_time requires admin" | ||||
|                 raise webob.exc.HTTPForbidden(detail=msg) | ||||
|  | ||||
|         port_ids = ip_address['ip_address'].get('port_ids') | ||||
|         port_ids = ip_address['ip_address'].get('port_ids', None) | ||||
|  | ||||
|         if port_ids is not None and not port_ids: | ||||
|             raise exceptions.BadRequest( | ||||
|                 resource="ip_addresses", | ||||
|                 msg="Cannot be updated with empty port_id list") | ||||
|  | ||||
|         if iptype == ip_types.SHARED: | ||||
|             has_owner = address.has_any_shared_owner() | ||||
|  | ||||
|   | ||||
| @@ -118,6 +118,23 @@ class QuarkSharedIPs(BaseFunctionalTest): | ||||
|             with self.assertRaises(exceptions.BadRequest): | ||||
|                 ip_api.update_ip_address(self.context, ip['id'], shared_ip) | ||||
|  | ||||
|     def test_update_shared_ip_with_empty_port_id_list_will_error(self): | ||||
|  | ||||
|         with self._stubs(self.network, self.subnet, self.ports_info4) as ( | ||||
|                 net, sub, ports): | ||||
|  | ||||
|             port_ids = [ports[0]['id'], ports[1]['id']] | ||||
|             shared_ip = {'ip_address': dict(port_ids=port_ids, | ||||
|                                             network_id=net['id'], | ||||
|                                             version=4)} | ||||
|             ip = ip_api.create_ip_address(self.context, shared_ip) | ||||
|             self.assertEqual(ip_types.SHARED, ip['type']) | ||||
|             port_ids = [] | ||||
|             shared_ip = {'ip_addresses': dict(port_ids=port_ids)} | ||||
|  | ||||
|             with self.assertRaises(exceptions.BadRequest): | ||||
|                 ip_api.update_ip_address(self.context, ip['id'], shared_ip) | ||||
|  | ||||
|     def test_update_shared_ip_with_garbage_will_error(self): | ||||
|  | ||||
|         with self._stubs(self.network, self.subnet, self.ports_info4) as ( | ||||
| @@ -269,30 +286,6 @@ class QuarkSharedIPs(BaseFunctionalTest): | ||||
|  | ||||
|             ip_api.update_ip_address(self.context, ip['id'], shared_ip) | ||||
|  | ||||
|     def test_update_shared_ip_with_owned_port_error_deallocate(self): | ||||
|  | ||||
|         with self._stubs(self.network, self.subnet, self.ports_info4) as ( | ||||
|                 net, sub, ports): | ||||
|  | ||||
|             port_ids = [ports[0]['id'], ports[1]['id']] | ||||
|             p_id = ports[0]['id'] | ||||
|  | ||||
|             shared_ip = {'ip_address': dict(port_ids=port_ids, | ||||
|                                             network_id=net['id'], | ||||
|                                             version=4)} | ||||
|             ip = ip_api.create_ip_address(self.context, shared_ip) | ||||
|             self.assertEqual(ip_types.SHARED, ip['type']) | ||||
|  | ||||
|             port_ip_update = ip_api.update_port_for_ip_address | ||||
|             port_ip_update(self.context, ip['id'], p_id, | ||||
|                            self._make_port_body('derp')) | ||||
|  | ||||
|             port_ids = [] | ||||
|             shared_ip = {'ip_address': dict(port_ids=port_ids)} | ||||
|  | ||||
|             with self.assertRaises(self.disassociate_exception): | ||||
|                 ip_api.update_ip_address(self.context, ip['id'], shared_ip) | ||||
|  | ||||
|     def test_update_shared_ip_with_owned_port_error(self): | ||||
|  | ||||
|         with self._stubs(self.network, self.subnet, self.ports_info4) as ( | ||||
|   | ||||
| @@ -553,16 +553,15 @@ class TestQuarkUpdateIPAddress(test_quark_plugin.TestQuarkPlugin): | ||||
|                                                      ip_address) | ||||
|             self.assertEqual(response['port_ids'], []) | ||||
|  | ||||
|     def test_update_ip_address_empty_ports_delete(self): | ||||
|     def test_update_ip_address_empty_ports_does_not_delete_but_errors(self): | ||||
|         port = dict(id=1, network_id=2, ip_addresses=[]) | ||||
|         ip = dict(id=1, address=3232235876, address_readable="192.168.1.100", | ||||
|                   subnet_id=1, network_id=2, version=4) | ||||
|         with self._stubs(ports=[port], addr=ip, addr_ports=True): | ||||
|             ip_address = {'ip_address': {'port_ids': []}} | ||||
|             response = self.plugin.update_ip_address(self.context, | ||||
|                                                      ip['id'], | ||||
|                                                      ip_address) | ||||
|             self.assertEqual(response['port_ids'], []) | ||||
|             with self.assertRaises(exceptions.BadRequest): | ||||
|                 self.plugin.update_ip_address(self.context, ip['id'], | ||||
|                                               ip_address) | ||||
|  | ||||
|  | ||||
| class TestQuarkGetIpAddress(test_quark_plugin.TestQuarkPlugin): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Justin Hammond
					Justin Hammond