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 |
| 9 | Resource ../global_properties.robot |
| 10 | Resource ../json_templater.robot |
| 11 | Resource 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 *** |
| 20 | Run 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 Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 24 | ${url} ${path}= Get Keystone Url And Path |
| 25 | ${session}= Create Session keystone ${url} verify=True |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 26 | ${uuid}= Generate UUID |
| 27 | ${data_template}= OperatingSystem.Get File ${OPENSTACK_KEYSTONE_AUTH_BODY_FILE} |
Yang Xu | f7087f5 | 2017-09-11 00:10:43 -0400 | [diff] [blame] | 28 | ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 29 | ${data}= Fill JSON Template ${data_template} ${arguments} |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 30 | ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_PATH} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 31 | ${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 Wu | c761cec | 2017-04-19 09:52:19 -0700 | [diff] [blame] | 34 | Should Be True 200 <= ${resp.status_code} < 300 |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 35 | Save Openstack Auth ${alias} ${resp.text} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 36 | Log Received response from keystone ${resp.text} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 37 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 38 | Get Openstack Tenants |
| 39 | [Documentation] Returns all the openstack tenant info |
| 40 | [Arguments] ${alias} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 41 | ${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] | 42 | [Return] ${resp.json()} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 43 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 44 | Get Openstack Tenant |
| 45 | [Documentation] Returns the openstack tenant info for the specified tenantid |
| 46 | [Arguments] ${alias} ${tenant_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 47 | ${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] | 48 | [Return] ${resp.json()} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 49 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 50 | Set Openstack Credentials |
| 51 | [Arguments] ${username} ${password} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 52 | Return From Keyword If '${username}' != '' ${username} ${password} |
| 53 | ${user} ${pass}= Get Openstack Credentials |
| 54 | [Return] ${user} ${pass} |
| 55 | |
| 56 | Get Openstack Credentials |
Yang Xu | f7087f5 | 2017-09-11 00:10:43 -0400 | [diff] [blame] | 57 | [Return] ${GLOBAL_INJECTED_OPENSTACK_USERNAME} ${GLOBAL_INJECTED_OPENSTACK_PASSWORD} |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 58 | |
| 59 | Get Keystone Url And Path |
| 60 | [Documentation] Handle arbitrary keystone identiit url. Add v2.0 if not present. |
DR695H | b034c28 | 2018-02-23 18:33:19 -0500 | [diff] [blame^] | 61 | ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE} |
Jerry Flood | 596db38 | 2017-10-27 08:37:37 -0400 | [diff] [blame] | 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} |