blob: e51e3db8e8bc59fe0f451529fc6fb0c371ba50d8 [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
9Resource ../global_properties.robot
10Resource ../json_templater.robot
11Resource openstack_common.robot
12
13*** Variables ***
14${OPENSTACK_KEYSTONE_API_VERSION} /v2.0
15${OPENSTACK_KEYSTONE_AUTH_PATH} /tokens
16${OPENSTACK_KEYSTONE_AUTH_BODY_FILE} robot/assets/templates/keystone_get_auth.template
17${OPENSTACK_KEYSTONE_TENANT_PATH} /tenants
18
19*** Keywords ***
20Run Openstack Auth Request
21 [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
22 [Arguments] ${alias} ${username}= ${password}=
23 ${username} ${password}= Set Openstack Credentials ${username} ${password}
Jerry Flood596db382017-10-27 08:37:37 -040024 ${url} ${path}= Get Keystone Url And Path
25 ${session}= Create Session keystone ${url} verify=True
DR695Hccff30b2017-02-17 18:44:24 -050026 ${uuid}= Generate UUID
27 ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_BODY_FILE}
Yang Xuf7087f52017-09-11 00:10:43 -040028 ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID}
DR695Hccff30b2017-02-17 18:44:24 -050029 ${data}= Fill JSON Template ${data_template} ${arguments}
Jerry Flood596db382017-10-27 08:37:37 -040030 ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050031 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID}
32 Log Sending authenticate post request ${data_path} with headers ${headers} and data ${data}
33 ${resp}= Post Request keystone ${data_path} data=${data} headers=${headers}
Gary Wuc761cec2017-04-19 09:52:19 -070034 Should Be True 200 <= ${resp.status_code} < 300
jf986099c63292017-03-09 15:28:42 -050035 Save Openstack Auth ${alias} ${resp.text}
DR695Hccff30b2017-02-17 18:44:24 -050036 Log Received response from keystone ${resp.text}
jf986099c63292017-03-09 15:28:42 -050037
DR695Hccff30b2017-02-17 18:44:24 -050038Get Openstack Tenants
39 [Documentation] Returns all the openstack tenant info
40 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050041 ${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 -050042 [Return] ${resp.json()}
jf986099c63292017-03-09 15:28:42 -050043
DR695Hccff30b2017-02-17 18:44:24 -050044Get Openstack Tenant
45 [Documentation] Returns the openstack tenant info for the specified tenantid
46 [Arguments] ${alias} ${tenant_id}
jf986099c63292017-03-09 15:28:42 -050047 ${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 -050048 [Return] ${resp.json()}
jf986099c63292017-03-09 15:28:42 -050049
DR695Hccff30b2017-02-17 18:44:24 -050050Set Openstack Credentials
51 [Arguments] ${username} ${password}
jf986099c63292017-03-09 15:28:42 -050052 Return From Keyword If '${username}' != '' ${username} ${password}
53 ${user} ${pass}= Get Openstack Credentials
54 [Return] ${user} ${pass}
55
56Get Openstack Credentials
Yang Xuf7087f52017-09-11 00:10:43 -040057 [Return] ${GLOBAL_INJECTED_OPENSTACK_USERNAME} ${GLOBAL_INJECTED_OPENSTACK_PASSWORD}
Jerry Flood596db382017-10-27 08:37:37 -040058
59Get Keystone Url And Path
60 [Documentation] Handle arbitrary keystone identiit url. Add v2.0 if not present.
61 ${pieces}= URL Parse ${GLOBAL_INJECTED_KEYSTONE}
62 ${url}= Catenate ${pieces.scheme}://${pieces.netloc}
63 ${version}= Evaluate ''
64 ${version}= Set Variable If '${OPENSTACK_KEYSTONE_API_VERSION}' not in '${pieces.path}' ${OPENSTACK_KEYSTONE_API_VERSION} ${version}
65 ${path}= Catenate ${pieces.path}${version}
66 [Return] ${url} ${path}