blob: fa37733cd3e52ebe5ac637db892d264fa25bd6e6 [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
10Library HttpLibrary.HTTP
DR695Hccff30b2017-02-17 18:44:24 -050011Resource ../global_properties.robot
12Resource ../json_templater.robot
13Resource openstack_common.robot
14
15*** Variables ***
Ah2f3b8462018-10-04 11:56:36 +053016${OPENSTACK_KEYSTONE_API_v3_VERSION} /v3
17${OPENSTACK_KEYSTONE_API_v2_VERSION} /v2.0
18${OPENSTACK_KEYSTONE_AUTH_v3_PATH} /auth/tokens
19${OPENSTACK_KEYSTONE_AUTH_v2_PATH} /tokens
20${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE} robot/assets/templates/keystone_get_v2_auth.template
21${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE} robot/assets/templates/keystone_get_v3_auth.template
DR695Hccff30b2017-02-17 18:44:24 -050022${OPENSTACK_KEYSTONE_TENANT_PATH} /tenants
23
24*** Keywords ***
25Run Openstack Auth Request
26 [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
27 [Arguments] ${alias} ${username}= ${password}=
28 ${username} ${password}= Set Openstack Credentials ${username} ${password}
Ah2f3b8462018-10-04 11:56:36 +053029 ${keystone_api_version}= Run Keyword If '${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}'=='' Get KeystoneAPIVersion
30 ... ELSE Set Variable ${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}
31 ${url} ${path}= Get Keystone Url And Path ${keystone_api_version}
Jerry Flood596db382017-10-27 08:37:37 -040032 ${session}= Create Session keystone ${url} verify=True
DR695Hccff30b2017-02-17 18:44:24 -050033 ${uuid}= Generate UUID
Ah2f3b8462018-10-04 11:56:36 +053034 ${data_path} ${data}= Run Keyword If '${keystone_api_version}'=='v2.0' Get KeyStoneAuthv2 Data ${username} ${password} ${path}
35 ... ELSE Get KeyStoneAuthv3 Data ${username} ${password} ${path}
DR695Hccff30b2017-02-17 18:44:24 -050036 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID}
37 Log Sending authenticate post request ${data_path} with headers ${headers} and data ${data}
38 ${resp}= Post Request keystone ${data_path} data=${data} headers=${headers}
Gary Wuc761cec2017-04-19 09:52:19 -070039 Should Be True 200 <= ${resp.status_code} < 300
Ah2f3b8462018-10-04 11:56:36 +053040 ${auth_token}= Evaluate ''
41 ${auth_token}= Run Keyword If '${keystone_api_version}'=='v3' Get From Dictionary ${resp.headers} X-Subject-Token
42 Log Keystone API Version is ${keystone_api_version}
43 Save Openstack Auth ${alias} ${resp.text} ${auth_token} ${keystone_api_version}
DR695Hccff30b2017-02-17 18:44:24 -050044 Log Received response from keystone ${resp.text}
jf986099c63292017-03-09 15:28:42 -050045
Ah2f3b8462018-10-04 11:56:36 +053046Get KeystoneAPIVersion
47 [Documentation] Get Keystone API version
48 ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE}
49 ${url}= Catenate ${pieces.scheme}://${pieces.netloc}
50 Log Keystone URL is ${url}
51 ${session}= Create Session keystone ${url} verify=True
52 ${uuid}= Generate UUID
53 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json
54 ${resp}= Get Request keystone / headers=${headers}
55 Log Received response from keystone ${resp.text}
56 Should Be Equal As Strings ${resp.status_code} 300
57 ${json}= Parse Json ${resp.content}
58 ${versions}= Get From Dictionary ${json} versions
59 ${values}= Get From Dictionary ${versions} values
60 : FOR ${value} IN @{values}
61 \ ${status}= Get Variable Value ${value["status"]}
62 \ Run Keyword If '${status}'=='stable' Exit For Loop
63 ${href}= Set Variable ${value["links"][0]["href"]}
64 ${keystone}= Set Variable ${GLOBAL_INJECTED_KEYSTONE}
65 ${version}= Remove String ${href} ${keystone} /
66 Return From Keyword If '${version}'=='v2.0' or '${version}'=='v3' ${version}
67 Fail Keystone API version not found or not supported
68
69Get KeyStoneAuthv2 Data
70 [Documentation] Returns all the data for keystone auth v2 api
71 [Arguments] ${username} ${password} ${path}
72 ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE}
73 ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID}
74 ${data}= Fill JSON Template ${data_template} ${arguments}
75 ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v2_PATH}
76 [Return] ${data_path} ${data}
77
78Get KeyStoneAuthv3 Data
79 [Documentation] Returns all the data for keystone auth v3 api
80 [Arguments] ${username} ${password} ${path}
81 ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE}
82 ${arguments}= Create Dictionary username=${username} password=${password} domain_id=${GLOBAL_INJECTED_OPENSTACK_DOMAIN_ID} project_name=${GLOBAL_INJECTED_OPENSTACK_PROJECT_NAME}
83 ${data}= Fill JSON Template ${data_template} ${arguments}
84 ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v3_PATH}
85 [Return] ${data_path} ${data}
86
DR695Hccff30b2017-02-17 18:44:24 -050087Get Openstack Tenants
88 [Documentation] Returns all the openstack tenant info
89 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050090 ${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 -050091 [Return] ${resp.json()}
jf986099c63292017-03-09 15:28:42 -050092
DR695Hccff30b2017-02-17 18:44:24 -050093Get Openstack Tenant
94 [Documentation] Returns the openstack tenant info for the specified tenantid
95 [Arguments] ${alias} ${tenant_id}
jf986099c63292017-03-09 15:28:42 -050096 ${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 -050097 [Return] ${resp.json()}
jf986099c63292017-03-09 15:28:42 -050098
DR695Hccff30b2017-02-17 18:44:24 -050099Set Openstack Credentials
100 [Arguments] ${username} ${password}
jf986099c63292017-03-09 15:28:42 -0500101 Return From Keyword If '${username}' != '' ${username} ${password}
102 ${user} ${pass}= Get Openstack Credentials
103 [Return] ${user} ${pass}
104
105Get Openstack Credentials
Brian Freeman00f125e2018-09-05 13:03:48 -0500106 [Documentation] Returns the Decripted Password and openstack username using same api_key.txt as SO
ehananb762e862018-10-19 14:55:16 +0100107 ${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 -0500108 [Return] ${GLOBAL_INJECTED_OPENSTACK_USERNAME} ${DECRYPTED_OPENSTACK_PASSWORD}
109
Jerry Flood596db382017-10-27 08:37:37 -0400110
111Get Keystone Url And Path
Ah2f3b8462018-10-04 11:56:36 +0530112 [Arguments] ${keystone_api_version}
Jerry Flood596db382017-10-27 08:37:37 -0400113 [Documentation] Handle arbitrary keystone identiit url. Add v2.0 if not present.
Ah2f3b8462018-10-04 11:56:36 +0530114 ${url} ${path}= Run Keyword If '${keystone_api_version}'=='v2.0' Set API Version ${OPENSTACK_KEYSTONE_API_v2_VERSION}
115 ... ELSE Set API Version ${OPENSTACK_KEYSTONE_API_v3_VERSION}
116 Log Path is ${url} ${path}
117 [Return] ${url} ${path}
118
119Set API Version
120 [Documentation] Decides the API version to be used
121 [Arguments] ${openstack_version}
DR695Hb034c282018-02-23 18:33:19 -0500122 ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE}
Jerry Flood596db382017-10-27 08:37:37 -0400123 ${url}= Catenate ${pieces.scheme}://${pieces.netloc}
124 ${version}= Evaluate ''
Ah2f3b8462018-10-04 11:56:36 +0530125 ${version}= Set Variable If '${openstack_version}' not in '${pieces.path}' ${openstack_version} ${version}
Jerry Flood596db382017-10-27 08:37:37 -0400126 ${path}= Catenate ${pieces.path}${version}
Brian Freeman00f125e2018-09-05 13:03:48 -0500127 [Return] ${url} ${path}