Merge "get_security_groups now creates default security group"

This commit is contained in:
Jenkins 2013-05-14 18:43:24 +00:00 committed by Gerrit Code Review
commit 63fcb98f2b
3 changed files with 19 additions and 4 deletions

View File

@ -136,7 +136,14 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
def get_security_groups(self, context, filters=None, fields=None,
sorts=None, limit=None,
marker=None, page_reverse=False):
marker=None, page_reverse=False, default_sg=False):
# If default_sg is True do not call _ensure_default_security_group()
# so this can be done recursively. Context.tenant_id is checked
# because all the unit tests do not explicitly set the context on
# GETS. TODO(arosen) context handling can probably be improved here.
if not default_sg and context.tenant_id:
self._ensure_default_security_group(context, context.tenant_id)
marker_obj = self._get_marker_obj(context, 'security_group', limit,
marker)
return self._get_collection(context,
@ -423,7 +430,8 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
:returns: the default security group id.
"""
filters = {'name': ['default'], 'tenant_id': [tenant_id]}
default_group = self.get_security_groups(context, filters)
default_group = self.get_security_groups(context, filters,
default_sg=True)
if not default_group:
security_group = {'security_group': {'name': 'default',
'tenant_id': tenant_id,

View File

@ -1032,12 +1032,13 @@ class MidonetPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
return super(MidonetPluginV2, self).delete_security_group(
context, id)
def get_security_groups(self, context, filters=None, fields=None):
def get_security_groups(self, context, filters=None, fields=None,
default_sg=False):
LOG.debug(_("MidonetPluginV2.get_security_groups called: "
"filters=%(filters)r fields=%(fields)r"),
{'filters': filters, 'fields': fields})
return super(MidonetPluginV2, self).get_security_groups(
context, filters, fields)
context, filters, fields, default_sg=default_sg)
def get_security_group(self, context, id, fields=None, tenant_id=None):
LOG.debug(_("MidonetPluginV2.get_security_group called: id=%(id)s "

View File

@ -445,6 +445,12 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
self._delete('security-groups', sg['security_groups'][0]['id'],
409, quantum_context=quantum_context)
def test_security_group_list_creates_default_security_group(self):
quantum_context = context.Context('', 'test-tenant')
sg = self._list('security-groups',
quantum_context=quantum_context).get('security_groups')
self.assertEqual(len(sg), 1)
def test_default_security_group_rules(self):
with self.network():
res = self.new_list_request('security-groups')