Skip to content

Commit 1d241a1

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Raise 409 when removing security group from instance"
2 parents 82f4dec + 696c8a9 commit 1d241a1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

nova/network/security_group_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ def remove_from_instance(context, instance, security_group_name):
664664
neutron, 'security_group',
665665
security_group_name,
666666
context.project_id)
667+
except n_exc.NeutronClientNoUniqueMatch as e:
668+
raise exception.NoUniqueMatch(e)
667669
except n_exc.NeutronClientException as e:
668670
if e.status_code == 404:
669671
msg = (_("Security group %(name)s is not found for "

nova/tests/unit/network/test_security_group.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,22 @@ def test_add_to_instance_with_bad_request(self):
372372
self.mocked_client.update_port.assert_called_once_with(
373373
port_id, {'port': {'security_groups': [sg_id]}})
374374

375+
def test_add_to_instance_duplicate_sg_name(self):
376+
sg_name = 'web_server'
377+
with mock.patch.object(neutronv20, 'find_resourceid_by_name_or_id',
378+
side_effect=n_exc.NeutronClientNoUniqueMatch):
379+
self.assertRaises(exception.NoUniqueMatch,
380+
sg_api.add_to_instance, self.context,
381+
objects.Instance(uuid=uuids.instance), sg_name)
382+
383+
def test_remove_from_instance_duplicate_sg_name(self):
384+
sg_name = 'web_server'
385+
with mock.patch.object(neutronv20, 'find_resourceid_by_name_or_id',
386+
side_effect=n_exc.NeutronClientNoUniqueMatch):
387+
self.assertRaises(exception.NoUniqueMatch,
388+
sg_api.remove_from_instance, self.context,
389+
objects.Instance(uuid=uuids.instance), sg_name)
390+
375391

376392
class TestNeutronDriverWithoutMock(test.NoDBTestCase):
377393

0 commit comments

Comments
 (0)