summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Chen <chenrui.momo@gmail.com>2015-01-04 16:35:12 +0800
committerRui Chen <chenrui.momo@gmail.com>2015-02-03 10:29:04 +0800
commit4e76f9590b49c925703cbbf42d1e232725465eff (patch)
tree5eed213e66fedf7d5bf03c28a105080abb5f4052
parenta5ea58fec9f655e0ddc1a341f3e27086bf0eaa4b (diff)
Fix issue of quota-show and quota-defaults
quota-show and quota-defaults not work because 'SessionClient' object has no attribute 'tenant_id'. Try to get project_id from auth_ref when cs.client is SessionClient instance. Change-Id: Ic125a99ba34e911485868454c3c7531a34eabdc9 Closes-Bug: #1407388
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Sean Dague <sean@dague.net> Workflow+1: Sean Dague <sean@dague.net> Submitted-by: Jenkins Submitted-at: Tue, 03 Feb 2015 13:46:27 +0000 Reviewed-on: https://review.openstack.org/144866 Project: openstack/python-novaclient Branch: refs/heads/master
-rw-r--r--novaclient/tests/unit/v1_1/fakes.py24
-rw-r--r--novaclient/tests/unit/v1_1/test_shell.py10
-rw-r--r--novaclient/v1_1/shell.py22
3 files changed, 50 insertions, 6 deletions
diff --git a/novaclient/tests/unit/v1_1/fakes.py b/novaclient/tests/unit/v1_1/fakes.py
index 6d97374..7e659cb 100644
--- a/novaclient/tests/unit/v1_1/fakes.py
+++ b/novaclient/tests/unit/v1_1/fakes.py
@@ -16,6 +16,7 @@
16 16
17import datetime 17import datetime
18 18
19import mock
19from oslo.utils import strutils 20from oslo.utils import strutils
20import six 21import six
21from six.moves.urllib import parse 22from six.moves.urllib import parse
@@ -2185,3 +2186,26 @@ class FakeHTTPClient(base_client.HTTPClient):
2185 def delete_os_server_groups_2cbd51f4_fafe_4cdb_801b_cf913a6f288b( 2186 def delete_os_server_groups_2cbd51f4_fafe_4cdb_801b_cf913a6f288b(
2186 self, **kw): 2187 self, **kw):
2187 return (202, {}, None) 2188 return (202, {}, None)
2189
2190
2191class FakeSessionClient(fakes.FakeClient, client.Client):
2192
2193 def __init__(self, *args, **kwargs):
2194 client.Client.__init__(self, 'username', 'password',
2195 'project_id', 'auth_url',
2196 extensions=kwargs.get('extensions'))
2197 self.client = FakeSessionMockClient(**kwargs)
2198
2199
2200class FakeSessionMockClient(base_client.SessionClient, FakeHTTPClient):
2201
2202 def __init__(self, *args, **kwargs):
2203
2204 self.callstack = []
2205 self.auth = mock.Mock()
2206 self.session = mock.Mock()
2207
2208 self.auth.get_auth_ref.return_value.project_id = 'tenant_id'
2209
2210 def request(self, url, method, **kwargs):
2211 return self._cs_request(url, method, **kwargs)
diff --git a/novaclient/tests/unit/v1_1/test_shell.py b/novaclient/tests/unit/v1_1/test_shell.py
index ccece80..cca5d66 100644
--- a/novaclient/tests/unit/v1_1/test_shell.py
+++ b/novaclient/tests/unit/v1_1/test_shell.py
@@ -2338,6 +2338,16 @@ class ShellTest(utils.TestCase):
2338 self.assert_called('DELETE', '/os-server-groups/12345', pos=-2) 2338 self.assert_called('DELETE', '/os-server-groups/12345', pos=-2)
2339 2339
2340 2340
2341class ShellWithSessionClientTest(ShellTest):
2342
2343 def setUp(self):
2344 """Run before each test."""
2345 super(ShellWithSessionClientTest, self).setUp()
2346 self.useFixture(fixtures.MonkeyPatch(
2347 'novaclient.client.get_client_class',
2348 lambda *_: fakes.FakeSessionClient))
2349
2350
2341class GetSecgroupTest(utils.TestCase): 2351class GetSecgroupTest(utils.TestCase):
2342 def test_with_integer(self): 2352 def test_with_integer(self):
2343 cs = mock.Mock(**{ 2353 cs = mock.Mock(**{
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index 6bfbc51..b6f78d8 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -3876,10 +3876,15 @@ def _quota_update(manager, identifier, args):
3876def do_quota_show(cs, args): 3876def do_quota_show(cs, args):
3877 """List the quotas for a tenant/user.""" 3877 """List the quotas for a tenant/user."""
3878 3878
3879 if not args.tenant: 3879 if args.tenant:
3880 _quota_show(cs.quotas.get(cs.client.tenant_id, user_id=args.user)) 3880 project_id = args.tenant
3881 elif isinstance(cs.client, client.SessionClient):
3882 auth = cs.client.auth
3883 project_id = auth.get_auth_ref(cs.client.session).project_id
3881 else: 3884 else:
3882 _quota_show(cs.quotas.get(args.tenant, user_id=args.user)) 3885 project_id = cs.client.tenant_id
3886
3887 _quota_show(cs.quotas.get(project_id, user_id=args.user))
3883 3888
3884 3889
3885@cliutils.arg( 3890@cliutils.arg(
@@ -3890,10 +3895,15 @@ def do_quota_show(cs, args):
3890def do_quota_defaults(cs, args): 3895def do_quota_defaults(cs, args):
3891 """List the default quotas for a tenant.""" 3896 """List the default quotas for a tenant."""
3892 3897
3893 if not args.tenant: 3898 if args.tenant:
3894 _quota_show(cs.quotas.defaults(cs.client.tenant_id)) 3899 project_id = args.tenant
3900 elif isinstance(cs.client, client.SessionClient):
3901 auth = cs.client.auth
3902 project_id = auth.get_auth_ref(cs.client.session).project_id
3895 else: 3903 else:
3896 _quota_show(cs.quotas.defaults(args.tenant)) 3904 project_id = cs.client.tenant_id
3905
3906 _quota_show(cs.quotas.defaults(project_id))
3897 3907
3898 3908
3899@cliutils.arg( 3909@cliutils.arg(