DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation The main interface for interacting with Openstack Keystone API. It handles low level stuff like managing the authtoken and Openstack required fields |
| 3 | Library OpenstackLibrary |
| 4 | Library RequestsLibrary |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 5 | Library HTTPUtils |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 6 | Library UUID |
| 7 | Library Collections |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 8 | Library OperatingSystem |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 9 | Library String |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 10 | Resource ../global_properties.robot |
| 11 | Resource ../json_templater.robot |
| 12 | Resource openstack_common.robot |
| 13 | |
| 14 | *** Variables *** |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 15 | ${OPENSTACK_KEYSTONE_API_v3_VERSION} /v3 |
| 16 | ${OPENSTACK_KEYSTONE_API_v2_VERSION} /v2.0 |
| 17 | ${OPENSTACK_KEYSTONE_AUTH_v3_PATH} /auth/tokens |
| 18 | ${OPENSTACK_KEYSTONE_AUTH_v2_PATH} /tokens |
| 19 | ${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE} robot/assets/templates/keystone_get_v2_auth.template |
| 20 | ${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE} robot/assets/templates/keystone_get_v3_auth.template |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 21 | ${OPENSTACK_KEYSTONE_TENANT_PATH} /tenants |
| 22 | |
| 23 | *** Keywords *** |
| 24 | Run Openstack Auth Request |
| 25 | [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 |
| 26 | [Arguments] ${alias} ${username}= ${password}= |
| 27 | ${username} ${password}= Set Openstack Credentials ${username} ${password} |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 28 | ${keystone_api_version}= Run Keyword If '${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}'=='' Get KeystoneAPIVersion |
| 29 | ... ELSE Set Variable ${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION} |
| 30 | ${url} ${path}= Get Keystone Url And Path ${keystone_api_version} |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 31 | ${session}= Create Session keystone ${url} verify=True |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 32 | ${uuid}= Generate UUID |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 33 | ${data_path} ${data}= Run Keyword If '${keystone_api_version}'=='v2.0' Get KeyStoneAuthv2 Data ${username} ${password} ${path} |
| 34 | ... ELSE Get KeyStoneAuthv3 Data ${username} ${password} ${path} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 35 | ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID} |
| 36 | Log Sending authenticate post request ${data_path} with headers ${headers} and data ${data} |
| 37 | ${resp}= Post Request keystone ${data_path} data=${data} headers=${headers} |
Gary Wu | c761cec | 2017-04-19 09:52:19 -0700 | [diff] [blame] | 38 | Should Be True 200 <= ${resp.status_code} < 300 |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 39 | ${auth_token}= Evaluate '' |
| 40 | ${auth_token}= Run Keyword If '${keystone_api_version}'=='v3' Get From Dictionary ${resp.headers} X-Subject-Token |
| 41 | Log Keystone API Version is ${keystone_api_version} |
| 42 | Save Openstack Auth ${alias} ${resp.text} ${auth_token} ${keystone_api_version} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 43 | Log Received response from keystone ${resp.text} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 44 | |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 45 | Get KeystoneAPIVersion |
| 46 | [Documentation] Get Keystone API version |
| 47 | ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE} |
| 48 | ${url}= Catenate ${pieces.scheme}://${pieces.netloc} |
| 49 | Log Keystone URL is ${url} |
| 50 | ${session}= Create Session keystone ${url} verify=True |
| 51 | ${uuid}= Generate UUID |
| 52 | ${headers}= Create Dictionary Accept=application/json Content-Type=application/json |
| 53 | ${resp}= Get Request keystone / headers=${headers} |
| 54 | Log Received response from keystone ${resp.text} |
| 55 | Should Be Equal As Strings ${resp.status_code} 300 |
DR695H | 0ca56d1 | 2019-05-14 11:48:20 -0400 | [diff] [blame] | 56 | ${versions}= Get From Dictionary ${resp.json()} versions |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 57 | ${values}= Get From Dictionary ${versions} values |
DR695H | 910097e | 2019-05-08 13:55:32 -0400 | [diff] [blame] | 58 | :FOR ${value} IN @{values} |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 59 | \ ${status}= Get Variable Value ${value["status"]} |
| 60 | \ Run Keyword If '${status}'=='stable' Exit For Loop |
| 61 | ${href}= Set Variable ${value["links"][0]["href"]} |
| 62 | ${keystone}= Set Variable ${GLOBAL_INJECTED_KEYSTONE} |
| 63 | ${version}= Remove String ${href} ${keystone} / |
| 64 | Return From Keyword If '${version}'=='v2.0' or '${version}'=='v3' ${version} |
| 65 | Fail Keystone API version not found or not supported |
| 66 | |
| 67 | Get KeyStoneAuthv2 Data |
| 68 | [Documentation] Returns all the data for keystone auth v2 api |
| 69 | [Arguments] ${username} ${password} ${path} |
| 70 | ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE} |
| 71 | ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID} |
| 72 | ${data}= Fill JSON Template ${data_template} ${arguments} |
| 73 | ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v2_PATH} |
| 74 | [Return] ${data_path} ${data} |
| 75 | |
| 76 | Get KeyStoneAuthv3 Data |
| 77 | [Documentation] Returns all the data for keystone auth v3 api |
| 78 | [Arguments] ${username} ${password} ${path} |
| 79 | ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE} |
| 80 | ${arguments}= Create Dictionary username=${username} password=${password} domain_id=${GLOBAL_INJECTED_OPENSTACK_DOMAIN_ID} project_name=${GLOBAL_INJECTED_OPENSTACK_PROJECT_NAME} |
| 81 | ${data}= Fill JSON Template ${data_template} ${arguments} |
| 82 | ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v3_PATH} |
| 83 | [Return] ${data_path} ${data} |
| 84 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 85 | Get Openstack Tenants |
| 86 | [Documentation] Returns all the openstack tenant info |
| 87 | [Arguments] ${alias} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 88 | ${resp}= Internal Get Openstack With Region ${alias} ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE} region= url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH} data_path= |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 89 | [Return] ${resp.json()} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 90 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 91 | Get Openstack Tenant |
| 92 | [Documentation] Returns the openstack tenant info for the specified tenantid |
| 93 | [Arguments] ${alias} ${tenant_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 94 | ${resp}= Internal Get Openstack With Region ${alias} ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE} region= url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH} data_path=/${tenant_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 95 | [Return] ${resp.json()} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 96 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 97 | Set Openstack Credentials |
| 98 | [Arguments] ${username} ${password} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 99 | Return From Keyword If '${username}' != '' ${username} ${password} |
| 100 | ${user} ${pass}= Get Openstack Credentials |
| 101 | [Return] ${user} ${pass} |
| 102 | |
| 103 | Get Openstack Credentials |
Brian Freeman | 00f125e | 2018-09-05 13:03:48 -0500 | [diff] [blame] | 104 | [Documentation] Returns the Decripted Password and openstack username using same api_key.txt as SO |
ehanan | b762e86 | 2018-10-19 14:55:16 +0100 | [diff] [blame] | 105 | ${DECRYPTED_OPENSTACK_PASSWORD}= Run echo -n ${GLOBAL_INJECTED_OPENSTACK_API_KEY} | xxd -r -p | openssl enc -aes-128-ecb -d -nosalt -K aa3871669d893c7fb8abbcda31b88b4f | tr -d '\x08' |
Brian Freeman | 00f125e | 2018-09-05 13:03:48 -0500 | [diff] [blame] | 106 | [Return] ${GLOBAL_INJECTED_OPENSTACK_USERNAME} ${DECRYPTED_OPENSTACK_PASSWORD} |
| 107 | |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 108 | |
| 109 | Get Keystone Url And Path |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 110 | [Arguments] ${keystone_api_version} |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 111 | [Documentation] Handle arbitrary keystone identiit url. Add v2.0 if not present. |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 112 | ${url} ${path}= Run Keyword If '${keystone_api_version}'=='v2.0' Set API Version ${OPENSTACK_KEYSTONE_API_v2_VERSION} |
| 113 | ... ELSE Set API Version ${OPENSTACK_KEYSTONE_API_v3_VERSION} |
| 114 | Log Path is ${url} ${path} |
| 115 | [Return] ${url} ${path} |
| 116 | |
| 117 | Set API Version |
| 118 | [Documentation] Decides the API version to be used |
| 119 | [Arguments] ${openstack_version} |
DR695H | b034c28 | 2018-02-23 18:33:19 -0500 | [diff] [blame] | 120 | ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE} |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 121 | ${url}= Catenate ${pieces.scheme}://${pieces.netloc} |
| 122 | ${version}= Evaluate '' |
Ah | 2f3b846 | 2018-10-04 11:56:36 +0530 | [diff] [blame] | 123 | ${version}= Set Variable If '${openstack_version}' not in '${pieces.path}' ${openstack_version} ${version} |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 124 | ${path}= Catenate ${pieces.path}${version} |
Brian Freeman | 00f125e | 2018-09-05 13:03:48 -0500 | [diff] [blame] | 125 | [Return] ${url} ${path} |