summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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(