diff options
author | Ah <Ashwini.Ah@arris.com> | 2018-10-04 11:56:36 +0530 |
---|---|---|
committer | Ah <Ashwini.Ah@arris.com> | 2018-10-04 11:57:27 +0530 |
commit | 2f3b84630ab4176c95f7d8a1cb6cc1fedb28ef54 (patch) | |
tree | 98002e689df48f36f0102d8bbec39b52700bc25a /robot | |
parent | a31243463c77f5cae6350ccf625b2f5cb9ca8855 (diff) |
Programmatically determining keystone api version
Issue-ID: TEST-39
Change-Id: If000bd3aa02447b9cab195bf48fc8fa050766514
Signed-off-by: Ah <Ashwini.Ah@arris.com>
Diffstat (limited to 'robot')
-rw-r--r-- | robot/resources/heatbridge.robot | 7 | ||||
-rw-r--r-- | robot/resources/openstack/keystone_interface.robot | 78 |
2 files changed, 73 insertions, 12 deletions
diff --git a/robot/resources/heatbridge.robot b/robot/resources/heatbridge.robot index 8e8d6a0e..5182d6b2 100644 --- a/robot/resources/heatbridge.robot +++ b/robot/resources/heatbridge.robot @@ -41,11 +41,14 @@ Execute Heatbridge ${KeyIsPresent}= Run Keyword And Return Status Dictionary Should Contain Key ${stack_info} ${ipv4_oam_address} ${ipv4_vnf_address}= Run Keyword If ${KeyIsPresent} Get From Dictionary ${stack_info} ${ipv4_oam_address} Run Set VNF Params ${vnf_id} ${ipv4_vnf_address} PROV Active - ${url} ${path}= Get Keystone Url And Path + ${keystone_api_version}= Run Keyword If '${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}'=='' Get KeystoneAPIVersion + ... ELSE Set Variable ${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION} + ${url} ${path}= Get Keystone Url And Path ${keystone_api_version} ${openstack_identity_url}= Catenate ${url}${path} ${region}= Get Openstack Region ${user} ${pass}= Get Openstack Credentials - Init Bridge ${openstack_identity_url} ${user} ${pass} ${tenant_id} ${region} ${GLOBAL_AAI_CLOUD_OWNER} + Run Keyword If '${keystone_api_version}'=='v2.0' Init Bridge ${openstack_identity_url} ${user} ${pass} ${tenant_id} ${region} ${GLOBAL_AAI_CLOUD_OWNER} + ... ELSE Init Bridge ${openstack_identity_url} ${user} ${pass} ${tenant_id} ${region} ${GLOBAL_AAI_CLOUD_OWNER} ${GLOBAL_INJECTED_OPENSTACK_DOMAIN_ID} ${GLOBAL_INJECTED_OPENSTACK_PROJECT_NAME} ${request}= Bridge Data ${stack_id} Log ${request} ${resp}= Run A&AI Put Request ${VERSIONED_INDEX_PATH}${MULTIPART_PATH} ${request} diff --git a/robot/resources/openstack/keystone_interface.robot b/robot/resources/openstack/keystone_interface.robot index b18674f7..f3e017ce 100644 --- a/robot/resources/openstack/keystone_interface.robot +++ b/robot/resources/openstack/keystone_interface.robot @@ -6,14 +6,19 @@ Library HTTPUtils Library UUID Library Collections Library OperatingSystem +Library String +Library HttpLibrary.HTTP Resource ../global_properties.robot Resource ../json_templater.robot Resource openstack_common.robot *** Variables *** -${OPENSTACK_KEYSTONE_API_VERSION} /v2.0 -${OPENSTACK_KEYSTONE_AUTH_PATH} /tokens -${OPENSTACK_KEYSTONE_AUTH_BODY_FILE} robot/assets/templates/keystone_get_auth.template +${OPENSTACK_KEYSTONE_API_v3_VERSION} /v3 +${OPENSTACK_KEYSTONE_API_v2_VERSION} /v2.0 +${OPENSTACK_KEYSTONE_AUTH_v3_PATH} /auth/tokens +${OPENSTACK_KEYSTONE_AUTH_v2_PATH} /tokens +${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE} robot/assets/templates/keystone_get_v2_auth.template +${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE} robot/assets/templates/keystone_get_v3_auth.template ${OPENSTACK_KEYSTONE_TENANT_PATH} /tenants *** Keywords *** @@ -21,19 +26,63 @@ Run Openstack Auth Request [Documentation] Runs an Openstack Auth Request and returns the token and service catalog. you need to include the token in future request's x-auth-token headers. Service catalog describes what can be called [Arguments] ${alias} ${username}= ${password}= ${username} ${password}= Set Openstack Credentials ${username} ${password} - ${url} ${path}= Get Keystone Url And Path + ${keystone_api_version}= Run Keyword If '${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}'=='' Get KeystoneAPIVersion + ... ELSE Set Variable ${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION} + ${url} ${path}= Get Keystone Url And Path ${keystone_api_version} ${session}= Create Session keystone ${url} verify=True ${uuid}= Generate UUID - ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_BODY_FILE} - ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID} - ${data}= Fill JSON Template ${data_template} ${arguments} - ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_PATH} + ${data_path} ${data}= Run Keyword If '${keystone_api_version}'=='v2.0' Get KeyStoneAuthv2 Data ${username} ${password} ${path} + ... ELSE Get KeyStoneAuthv3 Data ${username} ${password} ${path} ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID} Log Sending authenticate post request ${data_path} with headers ${headers} and data ${data} ${resp}= Post Request keystone ${data_path} data=${data} headers=${headers} Should Be True 200 <= ${resp.status_code} < 300 - Save Openstack Auth ${alias} ${resp.text} + ${auth_token}= Evaluate '' + ${auth_token}= Run Keyword If '${keystone_api_version}'=='v3' Get From Dictionary ${resp.headers} X-Subject-Token + Log Keystone API Version is ${keystone_api_version} + Save Openstack Auth ${alias} ${resp.text} ${auth_token} ${keystone_api_version} + Log Received response from keystone ${resp.text} + +Get KeystoneAPIVersion + [Documentation] Get Keystone API version + ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE} + ${url}= Catenate ${pieces.scheme}://${pieces.netloc} + Log Keystone URL is ${url} + ${session}= Create Session keystone ${url} verify=True + ${uuid}= Generate UUID + ${headers}= Create Dictionary Accept=application/json Content-Type=application/json + ${resp}= Get Request keystone / headers=${headers} Log Received response from keystone ${resp.text} + Should Be Equal As Strings ${resp.status_code} 300 + ${json}= Parse Json ${resp.content} + ${versions}= Get From Dictionary ${json} versions + ${values}= Get From Dictionary ${versions} values + : FOR ${value} IN @{values} + \ ${status}= Get Variable Value ${value["status"]} + \ Run Keyword If '${status}'=='stable' Exit For Loop + ${href}= Set Variable ${value["links"][0]["href"]} + ${keystone}= Set Variable ${GLOBAL_INJECTED_KEYSTONE} + ${version}= Remove String ${href} ${keystone} / + Return From Keyword If '${version}'=='v2.0' or '${version}'=='v3' ${version} + Fail Keystone API version not found or not supported + +Get KeyStoneAuthv2 Data + [Documentation] Returns all the data for keystone auth v2 api + [Arguments] ${username} ${password} ${path} + ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE} + ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID} + ${data}= Fill JSON Template ${data_template} ${arguments} + ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v2_PATH} + [Return] ${data_path} ${data} + +Get KeyStoneAuthv3 Data + [Documentation] Returns all the data for keystone auth v3 api + [Arguments] ${username} ${password} ${path} + ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE} + ${arguments}= Create Dictionary username=${username} password=${password} domain_id=${GLOBAL_INJECTED_OPENSTACK_DOMAIN_ID} project_name=${GLOBAL_INJECTED_OPENSTACK_PROJECT_NAME} + ${data}= Fill JSON Template ${data_template} ${arguments} + ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v3_PATH} + [Return] ${data_path} ${data} Get Openstack Tenants [Documentation] Returns all the openstack tenant info @@ -60,10 +109,19 @@ Get Openstack Credentials Get Keystone Url And Path + [Arguments] ${keystone_api_version} [Documentation] Handle arbitrary keystone identiit url. Add v2.0 if not present. + ${url} ${path}= Run Keyword If '${keystone_api_version}'=='v2.0' Set API Version ${OPENSTACK_KEYSTONE_API_v2_VERSION} + ... ELSE Set API Version ${OPENSTACK_KEYSTONE_API_v3_VERSION} + Log Path is ${url} ${path} + [Return] ${url} ${path} + +Set API Version + [Documentation] Decides the API version to be used + [Arguments] ${openstack_version} ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE} ${url}= Catenate ${pieces.scheme}://${pieces.netloc} ${version}= Evaluate '' - ${version}= Set Variable If '${OPENSTACK_KEYSTONE_API_VERSION}' not in '${pieces.path}' ${OPENSTACK_KEYSTONE_API_VERSION} ${version} + ${version}= Set Variable If '${openstack_version}' not in '${pieces.path}' ${openstack_version} ${version} ${path}= Catenate ${pieces.path}${version} [Return] ${url} ${path} |