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 |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 5 | Library UUID |
| 6 | Library Collections |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 7 | Library OperatingSystem |
| 8 | Resource ../global_properties.robot |
| 9 | Resource ../json_templater.robot |
| 10 | Resource openstack_common.robot |
| 11 | |
| 12 | *** Variables *** |
| 13 | ${OPENSTACK_KEYSTONE_API_VERSION} /v2.0 |
| 14 | ${OPENSTACK_KEYSTONE_AUTH_PATH} /tokens |
| 15 | ${OPENSTACK_KEYSTONE_AUTH_BODY_FILE} robot/assets/templates/keystone_get_auth.template |
| 16 | ${OPENSTACK_KEYSTONE_TENANT_PATH} /tenants |
| 17 | |
| 18 | *** Keywords *** |
| 19 | Run Openstack Auth Request |
| 20 | [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 |
| 21 | [Arguments] ${alias} ${username}= ${password}= |
| 22 | ${username} ${password}= Set Openstack Credentials ${username} ${password} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 23 | ${session}= Create Session keystone ${GLOBAL_INJECTED_KEYSTONE} verify=True |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 24 | ${uuid}= Generate UUID |
| 25 | ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_BODY_FILE} |
Yang Xu | f7087f5 | 2017-09-11 00:10:43 -0400 | [diff] [blame] | 26 | ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 27 | ${data}= Fill JSON Template ${data_template} ${arguments} |
| 28 | ${data_path}= Catenate ${OPENSTACK_KEYSTONE_API_VERSION}${OPENSTACK_KEYSTONE_AUTH_PATH} |
| 29 | ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID} |
| 30 | Log Sending authenticate post request ${data_path} with headers ${headers} and data ${data} |
| 31 | ${resp}= Post Request keystone ${data_path} data=${data} headers=${headers} |
Gary Wu | c761cec | 2017-04-19 09:52:19 -0700 | [diff] [blame] | 32 | Should Be True 200 <= ${resp.status_code} < 300 |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 33 | Save Openstack Auth ${alias} ${resp.text} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 34 | Log Received response from keystone ${resp.text} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 35 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 36 | Get Openstack Tenants |
| 37 | [Documentation] Returns all the openstack tenant info |
| 38 | [Arguments] ${alias} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 39 | ${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] | 40 | [Return] ${resp.json()} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 41 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 42 | Get Openstack Tenant |
| 43 | [Documentation] Returns the openstack tenant info for the specified tenantid |
| 44 | [Arguments] ${alias} ${tenant_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 45 | ${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] | 46 | [Return] ${resp.json()} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 47 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 48 | Set Openstack Credentials |
| 49 | [Arguments] ${username} ${password} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 50 | Return From Keyword If '${username}' != '' ${username} ${password} |
| 51 | ${user} ${pass}= Get Openstack Credentials |
| 52 | [Return] ${user} ${pass} |
| 53 | |
| 54 | Get Openstack Credentials |
Yang Xu | f7087f5 | 2017-09-11 00:10:43 -0400 | [diff] [blame] | 55 | [Return] ${GLOBAL_INJECTED_OPENSTACK_USERNAME} ${GLOBAL_INJECTED_OPENSTACK_PASSWORD} |