From faf24498fc1f09ef2e975709482ad9985f18e913 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Fri, 29 Mar 2013 16:59:41 -0700 Subject: quantum security group driver nova list shows same group When using the quantum security group driver nova list shows the same security group for all instances. This patch fixes this and corrects the unit test that was hiding this bug. This also adds a unit test to check that the default security group is added to the response when not specified. Fixes bug 1162077 Change-Id: I7a10f81af1bb6c93f634dc0de27841afe0f1f0ea --- .../api/openstack/compute/contrib/security_groups.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index 50d30d6b3..c019011f5 100644 --- a/nova/api/openstack/compute/contrib/security_groups.py +++ b/nova/api/openstack/compute/contrib/security_groups.py @@ -481,35 +481,37 @@ class SecurityGroupsOutputController(wsgi.Controller): # instance from the request. The reason for this is if using # quantum security groups the requested security groups for the # instance are not in the db and have not been sent to quantum yet. - instance_sgs = [] if req.method != 'POST': for server in servers: - instance_sgs = ( + groups = ( self.security_group_api.get_instance_security_groups( context, server['id'])) + if groups: + server[key] = groups + # In this section of code len(servers) == 1 as you can only POST + # one server in an API request. else: try: # try converting to json req_obj = json.loads(req.body) # Add security group to server, if no security group was in # request add default since that is the group it is part of - instance_sgs = req_obj['server'].get( + servers[0][key] = req_obj['server'].get( key, [{'name': 'default'}]) except ValueError: root = minidom.parseString(req.body) sg_root = root.getElementsByTagName(key) + groups = [] if sg_root: security_groups = sg_root[0].getElementsByTagName( 'security_group') for security_group in security_groups: - instance_sgs.append( + groups.append( {'name': security_group.getAttribute('name')}) - if not instance_sgs: - instance_sgs = [{'name': 'default'}] + if not groups: + groups = [{'name': 'default'}] - if instance_sgs: - for server in servers: - server[key] = instance_sgs + servers[0][key] = groups def _show(self, req, resp_obj): if not softauth(req.environ['nova.context']): -- cgit