Added --tenant option for keystone authentication
We had 'admin' tenant hardcoded, while for notifications we want other tenants to be allowed to do notifications via the CLI. DocImpact Related-Bug: #1371757 Change-Id: I26399a62440710b63d8fec94213700fb03ab66e8
This commit is contained in:
@@ -50,6 +50,8 @@ class Action(object):
|
||||
if getattr(params, 'user') and getattr(params, 'password'):
|
||||
APIClient.user = params.user
|
||||
APIClient.password = params.password
|
||||
# tenant is set by default to 'admin' in parser.add_argument
|
||||
APIClient.tenant = params.tenant
|
||||
APIClient.initialize_keystone_client()
|
||||
|
||||
self.serializer = Serializer.from_params(params)
|
||||
|
||||
@@ -129,6 +129,7 @@ class Parser:
|
||||
def add_keystone_credentials_args(self):
|
||||
self.credential_flags.append('--user')
|
||||
self.credential_flags.append('--password')
|
||||
self.credential_flags.append('--tenant')
|
||||
self.parser.add_argument(
|
||||
"--user",
|
||||
dest="user",
|
||||
@@ -143,6 +144,13 @@ class Parser:
|
||||
help="credentials for keystone authentication password",
|
||||
default=None
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"--tenant",
|
||||
dest="tenant",
|
||||
type=str,
|
||||
help="credentials for keystone authentication tenant",
|
||||
default="admin"
|
||||
)
|
||||
|
||||
def add_version_args(self):
|
||||
for args in (get_version_arg(), get_fuel_version_arg()):
|
||||
|
||||
@@ -47,6 +47,7 @@ class Client(object):
|
||||
self.ostf_root = urlparse.urljoin(self.root, "/ostf/")
|
||||
self.user = conf.KEYSTONE_USER
|
||||
self.password = conf.KEYSTONE_PASS
|
||||
self.tenant = 'admin'
|
||||
self._keystone_client = None
|
||||
self._auth_required = None
|
||||
|
||||
@@ -86,7 +87,7 @@ class Client(object):
|
||||
username=self.user,
|
||||
password=self.password,
|
||||
auth_url=self.keystone_base,
|
||||
tenant_name="admin")
|
||||
tenant_name=self.tenant)
|
||||
self._keystone_client.session.auth = self._keystone_client
|
||||
self._keystone_client.authenticate()
|
||||
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
|
||||
import os
|
||||
import urllib2
|
||||
|
||||
from mock import Mock
|
||||
from mock import patch
|
||||
|
||||
from fuelclient import fuelclient_settings
|
||||
from fuelclient.tests import base
|
||||
|
||||
|
||||
@@ -301,22 +303,73 @@ class TestDeployChanges(base.BaseTestCase):
|
||||
|
||||
class TestAuthentication(base.UnitTestCase):
|
||||
|
||||
def validate_credentials_response(self,
|
||||
args,
|
||||
username=None,
|
||||
password=None,
|
||||
tenant_name=None):
|
||||
conf = fuelclient_settings.get_settings()
|
||||
|
||||
self.assertEqual(args['username'], username)
|
||||
self.assertEqual(args['password'], password)
|
||||
self.assertEqual(args['tenant_name'], tenant_name)
|
||||
pr = urllib2.urlparse.urlparse(args['auth_url'])
|
||||
self.assertEqual(conf.SERVER_ADDRESS, pr.hostname)
|
||||
self.assertEqual(int(conf.LISTEN_PORT), int(pr.port))
|
||||
self.assertEqual('/keystone/v2.0', pr.path)
|
||||
|
||||
@patch('fuelclient.client.requests')
|
||||
@patch('fuelclient.client.auth_client')
|
||||
def test_wrong_credentials(self, mkeystone_cli, mrequests):
|
||||
def test_credentials(self, mkeystone_cli, mrequests):
|
||||
mkeystone_cli.return_value = Mock(auth_token='')
|
||||
mrequests.get_request.return_value = Mock(status_code=200)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password=a', 'node'])
|
||||
mkeystone_cli.Client.assert_called_with(
|
||||
['fuel', '--user=a', '--password=b', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
tenant_name='admin',
|
||||
password='a',
|
||||
auth_url='http://127.0.0.1:8003/keystone/v2.0')
|
||||
password='b',
|
||||
tenant_name='admin'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password', 'a', 'node'])
|
||||
mkeystone_cli.Client.assert_called_with(
|
||||
['fuel', '--user=a', '--password', 'b', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
tenant_name='admin',
|
||||
password='a',
|
||||
auth_url='http://127.0.0.1:8003/keystone/v2.0')
|
||||
password='b',
|
||||
tenant_name='admin'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user=a', '--password=b', '--tenant=t', 'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', '--user', 'a', '--password', 'b', '--tenant', 't',
|
||||
'node'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', 'node', '--user=a', '--password=b', '--tenant=t'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
self.execute(
|
||||
['fuel', 'node', '--user', 'a', '--password', 'b',
|
||||
'--tenant', 't'])
|
||||
self.validate_credentials_response(
|
||||
mkeystone_cli.Client.call_args[1],
|
||||
username='a',
|
||||
password='b',
|
||||
tenant_name='t'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user