From d17505462db3876a781016b16464e8ed967ae50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Charlier?= Date: Tue, 3 Jan 2012 17:00:29 +0100 Subject: [PATCH] Fix Quota ant SecurityGroup resources refreshing. The Quota and SecurityGroup resources were not refreshed correctly. Change-Id: I5b0a9efc07bc7ef05673256df5785aca931f64d8 --- novaclient/v1_1/quotas.py | 7 +++++-- novaclient/v1_1/security_groups.py | 3 --- tests/v1_1/test_quotas.py | 9 +++++++++ tests/v1_1/test_security_groups.py | 9 +++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/novaclient/v1_1/quotas.py b/novaclient/v1_1/quotas.py index 461540b11..ef67ae420 100644 --- a/novaclient/v1_1/quotas.py +++ b/novaclient/v1_1/quotas.py @@ -18,8 +18,11 @@ from novaclient import base class QuotaSet(base.Resource): - def get(self): - self.manager.get(self) + @property + def id(self): + """QuotaSet does not have a 'id' attribute but base.Resource needs it + to self-refresh and QuotaSet is indexed by tenant_id""" + return self.tenant_id def update(self, *args, **kwargs): self.manager.update(self.tenant_id, *args, **kwargs) diff --git a/novaclient/v1_1/security_groups.py b/novaclient/v1_1/security_groups.py index 56e64d692..a62ff0fbf 100644 --- a/novaclient/v1_1/security_groups.py +++ b/novaclient/v1_1/security_groups.py @@ -27,9 +27,6 @@ class SecurityGroup(base.Resource): def delete(self): self.manager.delete(self) - def get(self): - self.manager.get(self) - class SecurityGroupManager(base.ManagerWithFind): resource_class = SecurityGroup diff --git a/tests/v1_1/test_quotas.py b/tests/v1_1/test_quotas.py index 7e8bb6fe9..61e06ef67 100644 --- a/tests/v1_1/test_quotas.py +++ b/tests/v1_1/test_quotas.py @@ -36,3 +36,12 @@ class QuotaSetsTest(utils.TestCase): q = cs.quotas.get('test') q.update(volumes=2) cs.assert_called('PUT', '/os-quota-sets/test') + + def test_refresh_quota(self): + q = cs.quotas.get('test') + q2 = cs.quotas.get('test') + self.assertEqual(q.volumes, q2.volumes) + q2.volumes = 0 + self.assertNotEqual(q.volumes, q2.volumes) + q2.get() + self.assertEqual(q.volumes, q2.volumes) diff --git a/tests/v1_1/test_security_groups.py b/tests/v1_1/test_security_groups.py index fe92ae31b..6fa2632a0 100644 --- a/tests/v1_1/test_security_groups.py +++ b/tests/v1_1/test_security_groups.py @@ -31,3 +31,12 @@ class SecurityGroupsTest(utils.TestCase): sg = cs.security_groups.create("foo", "foo barr") cs.assert_called('POST', '/os-security-groups') self.assertTrue(isinstance(sg, security_groups.SecurityGroup)) + + def test_refresh_security_group(self): + sg = cs.security_groups.get(1) + sg2 = cs.security_groups.get(1) + self.assertEqual(sg.name, sg2.name) + sg2.name = "should be test" + self.assertNotEqual(sg.name, sg2.name) + sg2.get() + self.assertEqual(sg.name, sg2.name)