Merge "Raise 409 when removing security group from instance"
This commit is contained in:
@@ -664,6 +664,8 @@ def remove_from_instance(context, instance, security_group_name):
|
|||||||
neutron, 'security_group',
|
neutron, 'security_group',
|
||||||
security_group_name,
|
security_group_name,
|
||||||
context.project_id)
|
context.project_id)
|
||||||
|
except n_exc.NeutronClientNoUniqueMatch as e:
|
||||||
|
raise exception.NoUniqueMatch(e)
|
||||||
except n_exc.NeutronClientException as e:
|
except n_exc.NeutronClientException as e:
|
||||||
if e.status_code == 404:
|
if e.status_code == 404:
|
||||||
msg = (_("Security group %(name)s is not found for "
|
msg = (_("Security group %(name)s is not found for "
|
||||||
|
|||||||
@@ -372,6 +372,22 @@ class TestNeutronDriver(test.NoDBTestCase):
|
|||||||
self.mocked_client.update_port.assert_called_once_with(
|
self.mocked_client.update_port.assert_called_once_with(
|
||||||
port_id, {'port': {'security_groups': [sg_id]}})
|
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):
|
class TestNeutronDriverWithoutMock(test.NoDBTestCase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user