diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-27 02:12:22 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-27 02:12:22 +0000 |
| commit | e06ab5877462c83f6574b0304331e3ff906ddb14 (patch) | |
| tree | 6fcbc9709990da1646354b9a08e86085fb66f25e | |
| parent | 41a585f2133e6f7479d13b2fc5aede6d5ee978ef (diff) | |
| parent | 5d40fb635b1abac3828245124e392a4c9af52f60 (diff) | |
| download | nova-e06ab5877462c83f6574b0304331e3ff906ddb14.tar.gz nova-e06ab5877462c83f6574b0304331e3ff906ddb14.tar.xz nova-e06ab5877462c83f6574b0304331e3ff906ddb14.zip | |
Merge "get_instance_security_groups() fails if no name on security group"
| -rw-r--r-- | nova/network/security_group/quantum_driver.py | 2 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py | 29 |
2 files changed, 20 insertions, 11 deletions
diff --git a/nova/network/security_group/quantum_driver.py b/nova/network/security_group/quantum_driver.py index ea7dac825..bd99f0a40 100644 --- a/nova/network/security_group/quantum_driver.py +++ b/nova/network/security_group/quantum_driver.py @@ -306,7 +306,7 @@ class SecurityGroupAPI(security_group_base.SecurityGroupBase): # Since the name is optional for # quantum security groups if not name: - name = security_group['id'] + name = security_group ret.append({'name': name}) except KeyError: # This should only happen due to a race condition 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 94bc36b1f..8eab9224d 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 @@ -133,8 +133,6 @@ class TestQuantumSecurityGroups( device_id=test_security_groups.FAKE_UUID1) 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' @@ -196,8 +194,6 @@ class TestQuantumSecurityGroups( 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) body = dict(addSecurityGroup=dict(name="test")) req = fakes.HTTPRequest.blank('/v2/fake/servers/1/action') @@ -233,8 +229,6 @@ class TestQuantumSecurityGroups( 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) body = dict(removeSecurityGroup=dict(name="test")) req = fakes.HTTPRequest.blank('/v2/fake/servers/1/action') @@ -258,16 +252,31 @@ class TestQuantumSecurityGroups( {'name': sg2['name']}], test_security_groups.FAKE_UUID2: [{'name': sg2['name']}, {'name': sg3['id']}]} - 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) security_group_api = self.controller.security_group_api bindings = ( security_group_api.get_instances_security_groups_bindings( context.get_admin_context())) self.assertEquals(bindings, expected) + def test_get_instance_security_groups(self): + sg1 = self._create_sg_template(name='test1').get('security_group') + sg2 = self._create_sg_template(name='test2').get('security_group') + # test name='' is replaced with id + sg3 = self._create_sg_template(name='').get('security_group') + net = self._create_network() + self._create_port( + network_id=net['network']['id'], security_groups=[sg1['id'], + sg2['id'], + sg3['id']], + device_id=test_security_groups.FAKE_UUID1) + + expected = [{'name': sg1['name']}, {'name': sg2['name']}, + {'name': sg3['id']}] + security_group_api = self.controller.security_group_api + sgs = security_group_api.get_instance_security_groups( + context.get_admin_context(), test_security_groups.FAKE_UUID1) + self.assertEquals(sgs, expected) + class TestQuantumSecurityGroupRulesTestCase(TestQuantumSecurityGroupsTestCase): def setUp(self): |
