summaryrefslogtreecommitdiffstats
path: root/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py
diff options
context:
space:
mode:
authorAaron Rosen <arosen@nicira.com>2013-03-25 10:17:17 -0700
committerAaron Rosen <arosen@nicira.com>2013-03-25 14:41:02 -0700
commit3492a7bfc54cb9d581d8a119a08448c01039e80c (patch)
treec6d1bd6263556905f6c40693f617db4dbf48f3a0 /nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py
parentae2aa3c2c2211d9c5670a05b02782706b4c19f01 (diff)
downloadnova-3492a7bfc54cb9d581d8a119a08448c01039e80c.tar.gz
nova-3492a7bfc54cb9d581d8a119a08448c01039e80c.tar.xz
nova-3492a7bfc54cb9d581d8a119a08448c01039e80c.zip
Fix /servers/<instance-id>os-security-groups using quantum
When using quantum security groups: GET /servers/<instance-id>/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
Diffstat (limited to 'nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py')
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py35
1 files changed, 28 insertions, 7 deletions
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':