From 1892c2851d33eb2f5e6bb1faf0610c710888cd68 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 26 Mar 2012 20:38:03 +0000 Subject: [PATCH] Allow self-referential groups to be created fixes bug 965674 Change-Id: I41db135f6437e1f1cb496528ae4d134c0d9cb744 --- nova/api/openstack/compute/contrib/security_groups.py | 4 ---- .../openstack/compute/contrib/test_security_groups.py | 9 ++++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index 3c7a0dcbe4ff..0d85c7b8786d 100644 --- a/nova/api/openstack/compute/contrib/security_groups.py +++ b/nova/api/openstack/compute/contrib/security_groups.py @@ -414,10 +414,6 @@ class SecurityGroupRulesController(SecurityGroupControllerBase): msg = _("Parent or group id is not integer") raise exception.InvalidInput(reason=msg) - if parent_group_id == group_id: - msg = _("Parent group id and group id cannot be same") - raise exception.InvalidInput(reason=msg) - values['group_id'] = group_id #check if groupId exists db.security_group_get(context, group_id) diff --git a/nova/tests/api/openstack/compute/contrib/test_security_groups.py b/nova/tests/api/openstack/compute/contrib/test_security_groups.py index a9422cd26d3c..0cf66ec6e290 100644 --- a/nova/tests/api/openstack/compute/contrib/test_security_groups.py +++ b/nova/tests/api/openstack/compute/contrib/test_security_groups.py @@ -784,11 +784,14 @@ class TestSecurityGroupRules(test.TestCase): req, {'security_group_rule': rule}) def test_create_with_same_group_parent_id_and_group_id(self): - rule = security_group_rule_template(group_id=2) + rule = security_group_rule_template(group_id=1, parent_group_id=1) req = fakes.HTTPRequest.blank('/v2/fake/os-security-group-rules') - self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, - req, {'security_group_rule': rule}) + res_dict = self.controller.create(req, {'security_group_rule': rule}) + security_group_rule = res_dict['security_group_rule'] + self.assertNotEquals(security_group_rule['id'], 0) + self.assertEquals(security_group_rule['parent_group_id'], 1) + self.assertEquals(security_group_rule['id'], 1) def _test_create_with_no_ports_and_no_group(self, proto): rule = {'ip_protocol': proto, 'parent_group_id': '2'}