From 1ddb1bc515749c5033687b926049f67d66a4ffb1 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 17 May 2013 16:23:50 +0800 Subject: Add update method of security group name and description make it possible to edit the name and description of common security groups, we can not rename the default. Fixes: bug #918393 Change-Id: Id6e02cd1054452889282b3ff4fb04b2071980cc8 --- .../contrib/test_quantum_security_groups.py | 4 ++ .../compute/contrib/test_security_groups.py | 48 ++++++++++++++++++++++ nova/tests/test_db_api.py | 13 ++++++ 3 files changed, 65 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py b/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py index 94bc36b1f..270a5eac3 100644 --- a/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py +++ b/nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py @@ -116,6 +116,10 @@ class TestQuantumSecurityGroups( # Enforced by Quantum server. pass + def test_update_security_group(self): + # Enforced by Quantum server. + pass + def test_get_security_group_list(self): self._create_sg_template().get('security_group') req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups') 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 b1a5b3fdf..1406ed97a 100644 --- a/nova/tests/api/openstack/compute/contrib/test_security_groups.py +++ b/nova/tests/api/openstack/compute/contrib/test_security_groups.py @@ -408,6 +408,54 @@ class TestSecurityGroups(test.TestCase): self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete, req, self.fake_id) + def test_update_security_group(self): + sg = security_group_template(id=2, rules=[]) + sg_update = security_group_template(id=2, rules=[], + name='update_name', description='update_desc') + + def return_security_group(context, group_id): + self.assertEquals(sg['id'], group_id) + return security_group_db(sg) + + def return_update_security_group(context, group_id, values): + self.assertEquals(sg_update['id'], group_id) + self.assertEquals(sg_update['name'], values['name']) + self.assertEquals(sg_update['description'], values['description']) + return security_group_db(sg_update) + + self.stubs.Set(nova.db, 'security_group_update', + return_update_security_group) + self.stubs.Set(nova.db, 'security_group_get', + return_security_group) + + req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/2') + res_dict = self.controller.update(req, '2', + {'security_group': sg_update}) + + expected = {'security_group': sg_update} + self.assertEquals(res_dict, expected) + + def test_update_security_group_name_to_default(self): + sg = security_group_template(id=2, rules=[], name='default') + + 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_get', + return_security_group) + + req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/2') + self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, + req, '2', {'security_group': sg}) + + def test_update_default_security_group_fail(self): + sg = security_group_template() + + req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/1') + self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, + req, '1', {'security_group': sg}) + def test_delete_security_group_by_id(self): sg = security_group_template(id=1, rules=[]) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 4afefdfc8..6fef9a5f7 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -1110,6 +1110,19 @@ class DbApiTestCase(DbTestCase): ec2_id = db.get_ec2_snapshot_id_by_uuid(self.context, 'fake-uuid') self.assertEqual(ref['id'], ec2_id) + def test_security_group_update(self): + ctxt = context.get_admin_context() + values = {'security_group': {'tenant_id': '123', + 'name': 'test', 'description': 'test-description'}} + sg = db.security_group_create(ctxt, values) + + values['security_group']['name'] = 'test_name' + values['security_group']['description'] = 'test_desc' + sg = db.security_group_update(ctxt, sg['id'], values) + self.assertNotEqual(None, sg) + self.assertEqual(sg['security_group']['name'], 'test_name') + self.assertEqual(sg['security_group']['description'], 'test_desc') + def test_bw_usage_calls(self): ctxt = context.get_admin_context() now = timeutils.utcnow() -- cgit