]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make get_security_groups() return security group rules
authorAaron Rosen <arosen@nicira.com>
Fri, 25 Jan 2013 19:30:18 +0000 (11:30 -0800)
committerAaron Rosen <arosen@nicira.com>
Mon, 28 Jan 2013 19:49:20 +0000 (11:49 -0800)
In nova, get_security_groups() returns the security groups and their
security group rules. In order to implement the security group proxy
it needs to return this data to nova. This can be done using multiple
requests from nova-api to quantum i.e: get_security_groups(), then
get_security_group() for each group to obtain the rules. If one has a lot
of security groups this will generate a lot of requests. Adding this change
allows all the security groups and their rules to be returned in one shot.

Fix bug 1105399

Change-Id: Ib685960311221ac4e5fe0913c7e00e15ab74accb

quantum/db/securitygroups_db.py
quantum/tests/unit/test_extension_security_group.py

index 9a70856bac439e46b52e491488ac1d78b3f6b38f..7eba36cf53d722ef46bad7494bb71cab6baacb28 100644 (file)
@@ -202,6 +202,8 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
                'description': security_group['description']}
         if security_group.get('external_id'):
             res['external_id'] = security_group['external_id']
+        res['security_group_rules'] = [self._make_security_group_rule_dict(r)
+                                       for r in security_group.rules]
         return self._fields(res, fields)
 
     def _make_security_group_binding_dict(self, security_group, fields=None):
index 86735f473a65e80c26db037fd1eed89c133f881a..879bee8c2a7a7a81786a6508bfc8d44e053b3274 100644 (file)
@@ -281,6 +281,11 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
             res = self.new_list_request('security-groups')
             groups = self.deserialize('json', res.get_response(self.ext_api))
             self.assertEqual(len(groups['security_groups']), 2)
+            for group in groups['security_groups']:
+                if group['name'] == 'default':
+                    self.assertEquals(len(group['security_group_rules']), 2)
+                else:
+                    self.assertEquals(len(group['security_group_rules']), 0)
 
     def test_get_security_group(self):
         name = 'webservers'