Raise 409 when removing security group from instance
currently when attempting to remove a security group from instance, nova api returns 500 when there are more than one secuity groups with such name in the project. This patch makes it return 409 Conflict, using the same logic as already present when adding a security group to the instance in such scenario of duplicate names for security groups. Change-Id: I28ad999c49d4e11add54405b89185b3f56f165b5 Closes-Bug: 1889655
This commit is contained in:
@@ -665,6 +665,8 @@ def remove_from_instance(context, instance, security_group_name):
|
||||
neutron, 'security_group',
|
||||
security_group_name,
|
||||
context.project_id)
|
||||
except n_exc.NeutronClientNoUniqueMatch as e:
|
||||
raise exception.NoUniqueMatch(e)
|
||||
except n_exc.NeutronClientException as e:
|
||||
if e.status_code == 404:
|
||||
msg = (_("Security group %(name)s is not found for "
|
||||
|
||||
@@ -373,6 +373,22 @@ class TestNeutronDriver(test.NoDBTestCase):
|
||||
self.mocked_client.update_port.assert_called_once_with(
|
||||
port_id, {'port': {'security_groups': [sg_id]}})
|
||||
|
||||
def test_add_to_instance_duplicate_sg_name(self):
|
||||
sg_name = 'web_server'
|
||||
with mock.patch.object(neutronv20, 'find_resourceid_by_name_or_id',
|
||||
side_effect=n_exc.NeutronClientNoUniqueMatch):
|
||||
self.assertRaises(exception.NoUniqueMatch,
|
||||
sg_api.add_to_instance, self.context,
|
||||
objects.Instance(uuid=uuids.instance), sg_name)
|
||||
|
||||
def test_remove_from_instance_duplicate_sg_name(self):
|
||||
sg_name = 'web_server'
|
||||
with mock.patch.object(neutronv20, 'find_resourceid_by_name_or_id',
|
||||
side_effect=n_exc.NeutronClientNoUniqueMatch):
|
||||
self.assertRaises(exception.NoUniqueMatch,
|
||||
sg_api.remove_from_instance, self.context,
|
||||
objects.Instance(uuid=uuids.instance), sg_name)
|
||||
|
||||
|
||||
class TestNeutronDriverWithoutMock(test.NoDBTestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user