Permalink
Browse files

Merge "Don't delete security group in use from OS API."

  • Loading branch information...
2 parents bfa6b0b + f006c92 commit 48c08d048bfe8c60cf3cd03c1078e2605bbb0a18 Jenkins committed with openstack-gerrit Feb 24, 2012
@@ -239,6 +239,9 @@ def delete(self, req, id):
context = req.environ['nova.context']
authorize(context)
security_group = self._get_security_group(context, id)
+ if db.security_group_in_use(context, security_group.id):
+ msg = _("Security group is still in use")
+ raise exc.HTTPBadRequest(explanation=msg)
LOG.audit(_("Delete security group %s"), id, context=context)
db.security_group_destroy(context, security_group.id)
self.sgh.trigger_security_group_destroy_refresh(
@@ -331,6 +331,25 @@ def test_delete_security_group_by_non_existing_id(self):
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
req, '11111111')
+ def test_delete_security_group_in_use(self):
+ sg = security_group_template(id=1, rules=[])
+
+ def security_group_in_use(context, id):
+ return True
+
+ def return_security_group(context, group_id):
+ self.assertEquals(sg['id'], group_id)
+ return security_group_db(sg)
+
+ self.stubs.Set(nova.db, 'security_group_in_use',
+ security_group_in_use)
+ self.stubs.Set(nova.db, 'security_group_get',
+ return_security_group)
+
+ req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/1')
+ self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
+ req, '1')
+
def test_associate_by_non_existing_security_group_name(self):
body = dict(addSecurityGroup=dict(name='non-existing'))

0 comments on commit 48c08d0

Please sign in to comment.