Region name related command line arguments are added

New os-region-name and os-target-region-name introduced and
passed to keystone-client and to the mistral server also.
Related mistral server change also needed.

Change-Id: Ia2bef40fffae70408c57321e11f2c0899a943d2a
Related-Bug: #1633345
This commit is contained in:
Istvan Imre 2016-10-13 16:00:50 +02:00
parent 741e6b1816
commit df6fe96b5a
5 changed files with 36 additions and 4 deletions

View File

@ -34,6 +34,7 @@ TARGET_AUTH_URI = 'target_auth_url'
TARGET_PROJECT_ID = 'target_project_id'
TARGET_USER_ID = 'target_user_id'
TARGET_SERVICE_CATALOG = 'target_service_catalog'
TARGET_REGION_NAME = 'target_region_name'
USER_ID = 'user_id'
osprofiler_web = importutils.try_import("osprofiler.web")
@ -61,6 +62,7 @@ class HTTPClient(object):
self.target_user_id = kwargs.get(TARGET_USER_ID)
self.target_project_id = kwargs.get(TARGET_PROJECT_ID)
self.target_service_catalog = kwargs.get(TARGET_SERVICE_CATALOG)
self.target_region_name = kwargs.get(TARGET_REGION_NAME)
self.cacert = kwargs.get(CACERT)
self.insecure = kwargs.get(INSECURE, False)
self.ssl_options = {}
@ -148,6 +150,9 @@ class HTTPClient(object):
if self.target_user_id:
headers['X-Target-User-Id'] = self.target_user_id
if self.target_region_name:
headers['X-Target-Region-Name'] = self.target_region_name
if self.target_service_catalog:
headers['X-Target-Service-Catalog'] = base64.b64encode(
self.target_service_catalog.encode('utf-8')

View File

@ -50,6 +50,7 @@ class KeystoneAuthHandler(auth.AuthHandler):
project_name = req.get('project_name')
project_id = req.get('project_id')
cacert = req.get('cacert')
region_name = req.get('region_name')
insecure = req.get('insecure', False)
target_username = req.get('target_username')
target_api_key = req.get('target_api_key')
@ -59,6 +60,7 @@ class KeystoneAuthHandler(auth.AuthHandler):
target_auth_token = req.get('target_auth_token')
target_user_id = req.get('target_user_id')
target_cacert = req.get('target_cacert')
target_region_name = req.get('target_region_name')
target_insecure = req.get('target_insecure')
if project_name and project_id:
@ -101,7 +103,8 @@ class KeystoneAuthHandler(auth.AuthHandler):
try:
mistral_url = keystone.service_catalog.url_for(
service_type=service_type,
endpoint_type=endpoint_type
endpoint_type=endpoint_type,
region_name=region_name
)
except Exception:
mistral_url = None
@ -121,7 +124,8 @@ class KeystoneAuthHandler(auth.AuthHandler):
auth_url=target_auth_url,
endpoint=target_auth_url,
cacert=target_cacert,
insecure=target_insecure
insecure=target_insecure,
region_name=target_region_name
)
target_keystone.authenticate()

View File

@ -315,6 +315,14 @@ class MistralShell(app.App):
help='Authentication CA Certificate (Env: OS_CACERT)'
)
parser.add_argument(
'--os-region-name',
action='store',
dest='region_name',
default=env('OS_REGION_NAME'),
help='Region name (Env: OS_REGION_NAME)'
)
parser.add_argument(
'--insecure',
action='store_true',
@ -414,6 +422,15 @@ class MistralShell(app.App):
' (Env: OS_TARGET_CACERT)'
)
parser.add_argument(
'--os-target-region-name',
action='store',
dest='target_region_name',
default=env('OS_TARGET_REGION_NAME'),
help='Region name for target cloud'
'(Env: OS_TARGET_REGION_NAME)'
)
parser.add_argument(
'--target_insecure',
action='store_true',
@ -499,6 +516,7 @@ class MistralShell(app.App):
target_project_id=self.options.target_tenant_id,
target_auth_token=self.options.target_token,
target_cacert=self.options.target_cacert,
target_region_name=self.options.target_region_name,
target_insecure=self.options.target_insecure,
**kwargs
)

View File

@ -133,7 +133,8 @@ class BaseClientTests(base.BaseTestCase):
client.client(
target_username='tmistral',
target_project_name='tmistralp',
target_auth_url=AUTH_HTTP_URL_v3
target_auth_url=AUTH_HTTP_URL_v3,
target_region_name='tregion'
)
self.assertTrue(http_client_mock.called)
@ -148,6 +149,7 @@ class BaseClientTests(base.BaseTestCase):
'target_auth_url': AUTH_HTTP_URL_v3,
'target_project_name': 'tmistralp',
'target_username': 'tmistral',
'target_region_name': 'tregion',
'target_service_catalog': '"{}"'
}

View File

@ -139,6 +139,7 @@ class HTTPClientTest(base.BaseTestCase):
target_user_id = 'target_user'
target_project_id = 'target_project'
target_service_catalog = 'this should be there'
target_region = 'target region name'
target_client = httpclient.HTTPClient(
API_BASE_URL,
@ -149,7 +150,8 @@ class HTTPClientTest(base.BaseTestCase):
target_auth_token=target_auth_token,
target_project_id=target_project_id,
target_user_id=target_user_id,
target_service_catalog=target_service_catalog
target_service_catalog=target_service_catalog,
target_region_name=target_region
)
target_client.get(API_URL)
@ -159,6 +161,7 @@ class HTTPClientTest(base.BaseTestCase):
expected_options["headers"]["X-Target-Auth-Token"] = target_auth_token
expected_options["headers"]["X-Target-User-Id"] = target_user_id
expected_options["headers"]["X-Target-Project-Id"] = target_project_id
expected_options["headers"]["X-Target-Region-Name"] = target_region
catalog = base64.b64encode(target_service_catalog.encode('utf-8'))
expected_options["headers"]["X-Target-Service-Catalog"] = catalog