summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorAaron Rosen <arosen@nicira.com>2013-05-21 21:18:29 -0700
committerAaron Rosen <arosen@nicira.com>2013-05-21 22:24:35 -0700
commit0604e77654d0c7eb5fda9600e9ca604da656d856 (patch)
treec6f2099bd3b50b333b7674bec1454d634d1d34f8 /nova/tests
parent5d40fb635b1abac3828245124e392a4c9af52f60 (diff)
downloadnova-0604e77654d0c7eb5fda9600e9ca604da656d856.tar.gz
nova-0604e77654d0c7eb5fda9600e9ca604da656d856.tar.xz
nova-0604e77654d0c7eb5fda9600e9ca604da656d856.zip
Optimize SecurityGroupsOutputController by len(servers)
The following patch adds an optimization for _extend_servers() so that it calls get_instance_security_groups() when len(servers) == 1, and get_instances_security_groups_bindings() when > 1. In addition, this patch adds a return statement if not len(servers) as there is no reason to perform a query if there are no servers. Fixes bug 1182730 Change-Id: I149bf32176d60e72d76576168d15995f7215b657
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py17
1 files changed, 17 insertions, 0 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 8eab9224d..ee65f3707 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
@@ -426,6 +426,13 @@ class TestQuantumSecurityGroupsOutputTest(TestQuantumSecurityGroupsTestCase):
self.assertEquals(group.get('name'), 'default')
def test_show(self):
+ def fake_get_instance_security_groups(inst, context, id):
+ return [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
+
+ self.stubs.Set(quantum_driver.SecurityGroupAPI,
+ 'get_instance_security_groups',
+ fake_get_instance_security_groups)
+
url = '/v2/fake/servers'
image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
@@ -444,6 +451,16 @@ class TestQuantumSecurityGroupsOutputTest(TestQuantumSecurityGroupsTestCase):
name = 'fake-2-%s' % i
self.assertEqual(group.get('name'), name)
+ # Test that show (GET) returns the same information as create (POST)
+ url = '/v2/fake/servers/' + test_security_groups.UUID3
+ res = self._make_request(url)
+ self.assertEqual(res.status_int, 200)
+ server = self._get_server(res.body)
+
+ for i, group in enumerate(self._get_groups(server)):
+ name = 'fake-2-%s' % i
+ self.assertEqual(group.get('name'), name)
+
def test_detail(self):
url = '/v2/fake/servers/detail'
res = self._make_request(url)