# 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)
+ tenant_id = filters.get('tenant_id')
+ if tenant_id:
+ tenant_id = tenant_id[0]
+ else:
+ tenant_id = context.tenant_id
+ self._ensure_default_security_group(context, tenant_id)
marker_obj = self._get_marker_obj(context, 'security_group', limit,
marker)
return self._get_collection(context,
return
port_sg = p.get(ext_sg.SECURITYGROUPS, [])
+ filters = {'id': port_sg}
+ tenant_id = p.get('tenant_id')
+ if tenant_id:
+ filters['tenant_id'] = [tenant_id]
valid_groups = set(g['id'] for g in
self.get_security_groups(context, fields=['id'],
- filters={'id': port_sg}))
+ filters=filters))
requested_groups = set(port_sg)
port_sg_missing = requested_groups - valid_groups
neutron_context=neutron_context).get('security_groups')
self.assertEqual(len(sg), 1)
+ def test_security_group_port_create_creates_default_security_group(self):
+ res = self._create_network(self.fmt, 'net1', True,
+ tenant_id='not_admin',
+ set_context=True)
+ net1 = self.deserialize(self.fmt, res)
+ res = self._create_port(self.fmt, net1['network']['id'],
+ tenant_id='not_admin', set_context=True)
+ sg = self._list('security-groups').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')