From 3492a7bfc54cb9d581d8a119a08448c01039e80c Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Mon, 25 Mar 2013 10:17:17 -0700 Subject: Fix /servers/os-security-groups using quantum When using quantum security groups: GET /servers//os-security-groups aways returns an empty list. This patch adds a call to get_instance_security_groups in the api implemenation of security groups. This method passes both the instance_id and instance_uuid so the api layer does not need to be aware of which underlying implementation is being used. The instance_id is needed when using nova and when using quantum the instance_uuid is needed so both need to be passed. Fixes bug 1159793 Change-Id: I372adcf93c55d4e6469ef08429ec260d3387f9fe --- .../contrib/test_quantum_security_groups.py | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py b/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py index a8eadd2a6..98526bdad 100644 --- a/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py +++ b/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py @@ -125,10 +125,22 @@ class TestQuantumSecurityGroups( pass def test_get_security_group_by_instance(self): - pass - - def test_get_security_group_by_instance_non_existing(self): - pass + sg = self._create_sg_template().get('security_group') + net = self._create_network() + self._create_port( + network_id=net['network']['id'], security_groups=[sg['id']], + device_id=test_security_groups.FAKE_UUID) + expected = [{'rules': [], 'tenant_id': 'fake_tenant', 'id': sg['id'], + 'name': 'test', 'description': 'test-description'}] + self.stubs.Set(nova.db, 'instance_get', + test_security_groups.return_server) + self.stubs.Set(nova.db, 'instance_get_by_uuid', + test_security_groups.return_server_by_uuid) + req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/os-security-groups' + % test_security_groups.FAKE_UUID) + res_dict = self.server_controller.index( + req, test_security_groups.FAKE_UUID)['security_groups'] + self.assertEquals(expected, res_dict) def test_get_security_group_by_id(self): sg = self._create_sg_template().get('security_group') @@ -508,7 +520,8 @@ class MockClient(object): ret = {'status': 'ACTIVE', 'id': str(uuid.uuid4()), 'mac_address': p.get('mac_address', 'fa:16:3e:b8:f5:fb'), 'port_security_enabled': p.get('port_security_enabled'), - 'device_owner': str(uuid.uuid4())} + 'device_id': p.get('device_id', str(uuid.uuid4())), + 'security_groups': p.get('security_groups', [])} fields = ['network_id', 'security_groups', 'admin_state_up'] for field in fields: @@ -611,8 +624,16 @@ class MockClient(object): [network for network in self._fake_networks.values()]} def list_ports(self, **_params): - return {'ports': - [port for port in self._fake_ports.values()]} + ret = [] + device_id = _params.get('device_id') + for port in self._fake_ports.values(): + if device_id: + if device_id == port['device_id']: + print port + ret.append(port) + else: + ret.append(port) + return {'ports': ret} def list_subnets(self, **_params): return {'subnets': -- cgit