diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-29 00:11:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-29 00:11:02 +0000 |
| commit | 6d99004ab93df2e5afce82f313a2e9c9a3768ff1 (patch) | |
| tree | e709a5d028af1eb1f2a3a31ea2d385f0e26cbc39 /nova/tests | |
| parent | ea4c411bca55dc885c466b0068fde02fb289323d (diff) | |
| parent | 1ddb1bc515749c5033687b926049f67d66a4ffb1 (diff) | |
Merge "Add update method of security group name and description"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_quantum_security_groups.py | 4 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_security_groups.py | 48 | ||||
| -rw-r--r-- | nova/tests/test_db_api.py | 13 |
3 files changed, 65 insertions, 0 deletions
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 ee65f3707..7201ad954 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 86c97553b..c6a8e7794 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -1112,6 +1112,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() |
