blob: 3fe13c71cd0c9867c9eff866400d3babbabd3ee0 [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
2Documentation The main interface for interacting with Openstack Keystone API. It handles low level stuff like managing the authtoken and Openstack required fields
3Library OpenstackLibrary
4Library RequestsLibrary
Jerry Flood596db382017-10-27 08:37:37 -04005Library HTTPUtils
jf986099c63292017-03-09 15:28:42 -05006Library UUID
7Library Collections
DR695Hccff30b2017-02-17 18:44:24 -05008Library OperatingSystem
Ah2f3b8462018-10-04 11:56:36 +05309Library String
DR695Hccff30b2017-02-17 18:44:24 -050010Resource ../global_properties.robot
11Resource ../json_templater.robot
12Resource openstack_common.robot
13
14*** Variables ***
Ah2f3b8462018-10-04 11:56:36 +053015${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
DR695Hccff30b2017-02-17 18:44:24 -050021${OPENSTACK_KEYSTONE_TENANT_PATH} /tenants
22
23*** Keywords ***
24Run 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}
Ah2f3b8462018-10-04 11:56:36 +053028 ${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 Flood596db382017-10-27 08:37:37 -040031 ${session}= Create Session keystone ${url} verify=True
DR695Hccff30b2017-02-17 18:44:24 -050032 ${uuid}= Generate UUID
Ah2f3b8462018-10-04 11:56:36 +053033 ${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}
DR695Hccff30b2017-02-17 18:44:24 -050035 ${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 Wuc761cec2017-04-19 09:52:19 -070038 Should Be True 200 <= ${resp.status_code} < 300
Ah2f3b8462018-10-04 11:56:36 +053039 ${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}
DR695Hccff30b2017-02-17 18:44:24 -050043 Log Received response from keystone ${resp.text}
jf986099c63292017-03-09 15:28:42 -050044
Ah2f3b8462018-10-04 11:56:36 +053045Get 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
DR695H0ca56d12019-05-14 11:48:20 -040056 ${versions}= Get From Dictionary ${resp.json()} versions
Ah2f3b8462018-10-04 11:56:36 +053057 ${values}= Get From Dictionary ${versions} values
DR695H910097e2019-05-08 13:55:32 -040058 :FOR ${value} IN @{values}
Ah2f3b8462018-10-04 11:56:36 +053059 \ ${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
67Get 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
76Get 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
DR695Hccff30b2017-02-17 18:44:24 -050085Get Openstack Tenants
86 [Documentation] Returns all the openstack tenant info
87 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050088 ${resp}= Internal Get Openstack With Region ${alias} ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE} region= url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH} data_path=
DR695Hccff30b2017-02-17 18:44:24 -050089 [Return] ${resp.json()}
jf986099c63292017-03-09 15:28:42 -050090
DR695Hccff30b2017-02-17 18:44:24 -050091Get Openstack Tenant
92 [Documentation] Returns the openstack tenant info for the specified tenantid
93 [Arguments] ${alias} ${tenant_id}
jf986099c63292017-03-09 15:28:42 -050094 ${resp}= Internal Get Openstack With Region ${alias} ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE} region= url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH} data_path=/${tenant_id}
DR695Hccff30b2017-02-17 18:44:24 -050095 [Return] ${resp.json()}
jf986099c63292017-03-09 15:28:42 -050096
DR695Hccff30b2017-02-17 18:44:24 -050097Set Openstack Credentials
98 [Arguments] ${username} ${password}
jf986099c63292017-03-09 15:28:42 -050099 Return From Keyword If '${username}' != '' ${username} ${password}
100 ${user} ${pass}= Get Openstack Credentials
101 [Return] ${user} ${pass}
102
103Get Openstack Credentials
Brian Freeman00f125e2018-09-05 13:03:48 -0500104 [Documentation] Returns the Decripted Password and openstack username using same api_key.txt as SO
ehananb762e862018-10-19 14:55:16 +0100105 ${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 Freeman00f125e2018-09-05 13:03:48 -0500106 [Return] ${GLOBAL_INJECTED_OPENSTACK_USERNAME} ${DECRYPTED_OPENSTACK_PASSWORD}
107
Jerry Flood596db382017-10-27 08:37:37 -0400108
109Get Keystone Url And Path
Ah2f3b8462018-10-04 11:56:36 +0530110 [Arguments] ${keystone_api_version}
Jerry Flood596db382017-10-27 08:37:37 -0400111 [Documentation] Handle arbitrary keystone identiit url. Add v2.0 if not present.
Ah2f3b8462018-10-04 11:56:36 +0530112 ${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
117Set API Version
118 [Documentation] Decides the API version to be used
119 [Arguments] ${openstack_version}
DR695Hb034c282018-02-23 18:33:19 -0500120 ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE}
Jerry Flood596db382017-10-27 08:37:37 -0400121 ${url}= Catenate ${pieces.scheme}://${pieces.netloc}
122 ${version}= Evaluate ''
Ah2f3b8462018-10-04 11:56:36 +0530123 ${version}= Set Variable If '${openstack_version}' not in '${pieces.path}' ${openstack_version} ${version}
Jerry Flood596db382017-10-27 08:37:37 -0400124 ${path}= Catenate ${pieces.path}${version}
Brian Freeman00f125e2018-09-05 13:03:48 -0500125 [Return] ${url} ${path}