Fix region support in mistralclient

Although mistral client already supports '--os-region-name', but it's
not passed to mistral service properly. Even user has specified
region when using CLI, mistral will still ignore the region when
initialize other openstack service client

Change-Id: Ia06779e7a5b657d044066ea4df6e4a18d035d27f
This commit is contained in:
Lingxian Kong 2017-03-22 13:47:44 +13:00
parent 63f1fd5ab5
commit 6ae1bad9a0
4 changed files with 61 additions and 41 deletions

View File

@ -30,6 +30,7 @@ CERT_KEY = 'key'
INSECURE = 'insecure'
PROJECT_ID = 'project_id'
USER_ID = 'user_id'
REGION_NAME = 'region_name'
TARGET_AUTH_TOKEN = 'target_auth_token'
TARGET_AUTH_URI = 'target_auth_url'
@ -64,6 +65,7 @@ class HTTPClient(object):
self.user_id = kwargs.get(USER_ID)
self.cacert = kwargs.get(CACERT)
self.insecure = kwargs.get(INSECURE, False)
self.region_name = kwargs.get(REGION_NAME)
self.ssl_options = {}
self.target_auth_token = kwargs.get(TARGET_AUTH_TOKEN)
@ -160,6 +162,9 @@ class HTTPClient(object):
if self.user_id:
headers['X-User-Id'] = self.user_id
if self.region_name:
headers['X-Region-Name'] = self.region_name
if self.target_auth_token:
headers['X-Target-Auth-Token'] = self.target_auth_token

View File

@ -564,6 +564,7 @@ class MistralShell(app.App):
project_id=self.options.tenant_id or self.options.project_id,
endpoint_type=self.options.endpoint_type,
service_type=self.options.service_type,
region_name=self.options.region_name,
auth_token=self.options.token,
cacert=self.options.os_cacert,
insecure=self.options.insecure,

View File

@ -33,13 +33,15 @@ EXPECTED_URL = API_BASE_URL + API_URL
AUTH_TOKEN = uuidutils.generate_uuid()
PROJECT_ID = uuidutils.generate_uuid()
USER_ID = uuidutils.generate_uuid()
REGION_NAME = 'fake_region'
PROFILER_HMAC_KEY = 'SECRET_HMAC_KEY'
PROFILER_TRACE_ID = uuidutils.generate_uuid()
EXPECTED_AUTH_HEADERS = {
'x-auth-token': AUTH_TOKEN,
'X-Project-Id': PROJECT_ID,
'X-User-Id': USER_ID
'X-User-Id': USER_ID,
'X-Region-Name': REGION_NAME
}
EXPECTED_REQ_OPTIONS = {
@ -76,7 +78,8 @@ class HTTPClientTest(base.BaseTestCase):
API_BASE_URL,
auth_token=AUTH_TOKEN,
project_id=PROJECT_ID,
user_id=USER_ID
user_id=USER_ID,
region_name=REGION_NAME
)
@mock.patch.object(
@ -149,6 +152,7 @@ class HTTPClientTest(base.BaseTestCase):
auth_token=AUTH_TOKEN,
project_id=PROJECT_ID,
user_id=USER_ID,
region_name=REGION_NAME,
target_auth_url=target_auth_url,
target_auth_token=target_auth_token,
target_project_id=target_project_id,

View File

@ -20,107 +20,117 @@ import mistralclient.tests.unit.base_shell_test as base
class TestShell(base.BaseShellTests):
@mock.patch('mistralclient.api.client.client')
def test_command_no_mistral_url(self, mock):
def test_command_no_mistral_url(self, client_mock):
self.shell(
'workbook-list'
)
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('', params[1]['mistral_url'])
@mock.patch('mistralclient.api.client.client')
def test_command_with_mistral_url(self, mock):
def test_command_with_mistral_url(self, client_mock):
self.shell(
'--os-mistral-url=http://localhost:8989/v2 workbook-list'
)
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('http://localhost:8989/v2',
params[1]['mistral_url'])
@mock.patch('mistralclient.api.client.determine_client_version')
def test_mistral_version(self, mock):
def test_mistral_version(self, client_mock):
self.shell(
'--os-mistral-version=v1 workbook-list'
)
self.assertTrue(mock.called)
mistral_version = mock.call_args
self.assertTrue(client_mock.called)
mistral_version = client_mock.call_args
self.assertEqual('v1', mistral_version[0][0])
@mock.patch('mistralclient.api.client.determine_client_version')
def test_no_mistral_version(self, mock):
def test_no_mistral_version(self, client_mock):
self.shell('workbook-list')
self.assertTrue(mock.called)
mistral_version = mock.call_args
self.assertTrue(client_mock.called)
mistral_version = client_mock.call_args
self.assertEqual('v2', mistral_version[0][0])
@mock.patch('mistralclient.api.client.client')
def test_service_type(self, mock):
def test_service_type(self, client_mock):
self.shell('--os-mistral-service-type=test workbook-list')
self.assertTrue(mock.called)
parmters = mock.call_args
self.assertTrue(client_mock.called)
parmters = client_mock.call_args
self.assertEqual('test', parmters[1]['service_type'])
@mock.patch('mistralclient.api.client.client')
def test_no_service_type(self, mock):
def test_no_service_type(self, client_mock):
self.shell('workbook-list')
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('workflowv2', params[1]['service_type'])
@mock.patch('mistralclient.api.client.client')
def test_endpoint_type(self, mock):
def test_endpoint_type(self, client_mock):
self.shell('--os-mistral-endpoint-type=adminURL workbook-list')
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('adminURL', params[1]['endpoint_type'])
@mock.patch('mistralclient.api.client.client')
def test_no_endpoint_type(self, mock):
def test_no_endpoint_type(self, client_mock):
self.shell('workbook-list')
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('publicURL', params[1]['endpoint_type'])
@mock.patch('mistralclient.api.client.client')
def test_auth_url(self, mock):
def test_auth_url(self, client_mock):
self.shell(
'--os-auth-url=https://127.0.0.1:35357/v3 '
'--os-username=admin '
'--os-password=1234 '
'workbook-list'
)
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url'])
@mock.patch('mistralclient.api.client.client')
def test_no_auth_url(self, mock):
def test_no_auth_url(self, client_mock):
self.shell('workbook-list')
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('', params[1]['auth_url'])
@mock.patch('mistralclient.api.client.client')
def test_default_auth_url_with_os_password(self, mock):
def test_default_auth_url_with_os_password(self, client_mock):
self.shell('--os-username=admin --os-password=1234 workbook-list')
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('http://localhost:35357/v3', params[1]['auth_url'])
@mock.patch('mistralclient.api.client.client')
def test_default_auth_url_with_os_auth_token(self, mock):
def test_default_auth_url_with_os_auth_token(self, client_mock):
self.shell(
'--os-auth-token=abcd1234 '
'workbook-list'
)
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('http://localhost:35357/v3', params[1]['auth_url'])
@mock.patch('mistralclient.api.client.client')
def test_profile(self, mock):
def test_profile(self, client_mock):
self.shell('--profile=SECRET_HMAC_KEY workbook-list')
self.assertTrue(mock.called)
params = mock.call_args
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('SECRET_HMAC_KEY', params[1]['profile'])
@mock.patch('mistralclient.api.client.client')
def test_region_name(self, client_mock):
self.shell('--os-region-name=RegionOne workbook-list')
self.assertTrue(client_mock.called)
params = client_mock.call_args
self.assertEqual('RegionOne', params[1]['region_name'])