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
This commit is contained in:
parent
a5ea58fec9
commit
4e76f9590b
novaclient
@ -16,6 +16,7 @@
|
||||
|
||||
import datetime
|
||||
|
||||
import mock
|
||||
from oslo.utils import strutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
@ -2185,3 +2186,26 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
def delete_os_server_groups_2cbd51f4_fafe_4cdb_801b_cf913a6f288b(
|
||||
self, **kw):
|
||||
return (202, {}, None)
|
||||
|
||||
|
||||
class FakeSessionClient(fakes.FakeClient, client.Client):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
client.Client.__init__(self, 'username', 'password',
|
||||
'project_id', 'auth_url',
|
||||
extensions=kwargs.get('extensions'))
|
||||
self.client = FakeSessionMockClient(**kwargs)
|
||||
|
||||
|
||||
class FakeSessionMockClient(base_client.SessionClient, FakeHTTPClient):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
self.callstack = []
|
||||
self.auth = mock.Mock()
|
||||
self.session = mock.Mock()
|
||||
|
||||
self.auth.get_auth_ref.return_value.project_id = 'tenant_id'
|
||||
|
||||
def request(self, url, method, **kwargs):
|
||||
return self._cs_request(url, method, **kwargs)
|
||||
|
@ -2338,6 +2338,16 @@ class ShellTest(utils.TestCase):
|
||||
self.assert_called('DELETE', '/os-server-groups/12345', pos=-2)
|
||||
|
||||
|
||||
class ShellWithSessionClientTest(ShellTest):
|
||||
|
||||
def setUp(self):
|
||||
"""Run before each test."""
|
||||
super(ShellWithSessionClientTest, self).setUp()
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'novaclient.client.get_client_class',
|
||||
lambda *_: fakes.FakeSessionClient))
|
||||
|
||||
|
||||
class GetSecgroupTest(utils.TestCase):
|
||||
def test_with_integer(self):
|
||||
cs = mock.Mock(**{
|
||||
|
@ -3876,10 +3876,15 @@ def _quota_update(manager, identifier, args):
|
||||
def do_quota_show(cs, args):
|
||||
"""List the quotas for a tenant/user."""
|
||||
|
||||
if not args.tenant:
|
||||
_quota_show(cs.quotas.get(cs.client.tenant_id, user_id=args.user))
|
||||
if args.tenant:
|
||||
project_id = args.tenant
|
||||
elif isinstance(cs.client, client.SessionClient):
|
||||
auth = cs.client.auth
|
||||
project_id = auth.get_auth_ref(cs.client.session).project_id
|
||||
else:
|
||||
_quota_show(cs.quotas.get(args.tenant, user_id=args.user))
|
||||
project_id = cs.client.tenant_id
|
||||
|
||||
_quota_show(cs.quotas.get(project_id, user_id=args.user))
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
@ -3890,10 +3895,15 @@ def do_quota_show(cs, args):
|
||||
def do_quota_defaults(cs, args):
|
||||
"""List the default quotas for a tenant."""
|
||||
|
||||
if not args.tenant:
|
||||
_quota_show(cs.quotas.defaults(cs.client.tenant_id))
|
||||
if args.tenant:
|
||||
project_id = args.tenant
|
||||
elif isinstance(cs.client, client.SessionClient):
|
||||
auth = cs.client.auth
|
||||
project_id = auth.get_auth_ref(cs.client.session).project_id
|
||||
else:
|
||||
_quota_show(cs.quotas.defaults(args.tenant))
|
||||
project_id = cs.client.tenant_id
|
||||
|
||||
_quota_show(cs.quotas.defaults(project_id))
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
|
Loading…
x
Reference in New Issue
Block a user