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 ONAPLibrary.Openstack
4 Library RequestsLibrary
5 Library ONAPLibrary.Utilities
7 Library OperatingSystem
9 Resource ../global_properties.robot
10 Resource ../json_templater.robot
11 Resource openstack_common.robot
14 ${OPENSTACK_KEYSTONE_API_v3_VERSION} /v3
15 ${OPENSTACK_KEYSTONE_API_v2_VERSION} /v2.0
16 ${OPENSTACK_KEYSTONE_AUTH_v3_PATH} /auth/tokens
17 ${OPENSTACK_KEYSTONE_AUTH_v2_PATH} /tokens
18 ${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE} robot/assets/templates/keystone_get_v2_auth.template
19 ${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE} robot/assets/templates/keystone_get_v3_auth.template
20 ${OPENSTACK_KEYSTONE_TENANT_PATH} /tenants
23 Run Openstack Auth Request
24 [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
25 [Arguments] ${alias} ${username}= ${password}=
26 ${username} ${password}= Set Openstack Credentials ${username} ${password}
27 ${keystone_api_version}= Run Keyword If '${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}'=='' Get KeystoneAPIVersion
28 ... ELSE Set Variable ${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}
29 ${url} ${path}= Get Keystone Url And Path ${keystone_api_version}
30 ${session}= Create Session keystone ${url} verify=True
31 ${uuid}= Generate UUID4
32 ${data_path} ${data}= Run Keyword If '${keystone_api_version}'=='v2.0' Get KeyStoneAuthv2 Data ${username} ${password} ${path}
33 ... ELSE Get KeyStoneAuthv3 Data ${username} ${password} ${path}
34 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID}
35 Log Sending authenticate post request ${data_path} with headers ${headers} and data ${data}
36 ${resp}= Post Request keystone ${data_path} data=${data} headers=${headers}
37 Should Be True 200 <= ${resp.status_code} < 300
38 ${auth_token}= Evaluate ''
39 ${auth_token}= Run Keyword If '${keystone_api_version}'=='v3' Get From Dictionary ${resp.headers} X-Subject-Token
40 Log Keystone API Version is ${keystone_api_version}
41 Save Openstack Auth ${alias} ${resp.text} ${auth_token} ${keystone_api_version}
42 Log Received response from keystone ${resp.text}
44 Get KeystoneAPIVersion
45 [Documentation] Get Keystone API version
46 ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE}
47 ${url}= Catenate ${pieces.scheme}://${pieces.netloc}
48 Log Keystone URL is ${url}
49 ${session}= Create Session keystone ${url} verify=True
50 ${uuid}= Generate UUID4
51 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json
52 ${resp}= Get Request keystone / headers=${headers}
53 Log Received response from keystone ${resp.text}
54 Should Be Equal As Strings ${resp.status_code} 300
55 ${versions}= Get From Dictionary ${resp.json()} versions
56 ${values}= Get From Dictionary ${versions} values
57 :FOR ${value} IN @{values}
58 \ ${status}= Get Variable Value ${value["status"]}
59 \ Run Keyword If '${status}'=='stable' Exit For Loop
60 ${href}= Set Variable ${value["links"][0]["href"]}
61 ${keystone}= Set Variable ${GLOBAL_INJECTED_KEYSTONE}
62 ${version}= Remove String ${href} ${keystone} /
63 Return From Keyword If '${version}'=='v2.0' or '${version}'=='v3' ${version}
64 Fail Keystone API version not found or not supported
66 Get KeyStoneAuthv2 Data
67 [Documentation] Returns all the data for keystone auth v2 api
68 [Arguments] ${username} ${password} ${path}
69 ${arguments}= Create Dictionary username=${username} password=${password} tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID}
70 ${data}= Fill JSON Template File ${OPENSTACK_KEYSTONE_AUTH_v2_BODY_FILE} ${arguments}
71 ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v2_PATH}
72 [Return] ${data_path} ${data}
74 Get KeyStoneAuthv3 Data
75 [Documentation] Returns all the data for keystone auth v3 api
76 [Arguments] ${username} ${password} ${path}
77 ${arguments}= Create Dictionary username=${username} password=${password} domain_id=${GLOBAL_INJECTED_OPENSTACK_DOMAIN_ID} project_name=${GLOBAL_INJECTED_OPENSTACK_PROJECT_NAME}
78 ${data}= Fill JSON Template File ${OPENSTACK_KEYSTONE_AUTH_v3_BODY_FILE} ${arguments}
79 ${data_path}= Catenate ${path}${OPENSTACK_KEYSTONE_AUTH_v3_PATH}
80 [Return] ${data_path} ${data}
83 [Documentation] Returns all the openstack tenant info
85 ${resp}= Internal Get Openstack With Region ${alias} ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE} region= url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH} data_path=
86 [Return] ${resp.json()}
89 [Documentation] Returns the openstack tenant info for the specified tenantid
90 [Arguments] ${alias} ${tenant_id}
91 ${resp}= Internal Get Openstack With Region ${alias} ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE} region= url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH} data_path=/${tenant_id}
92 [Return] ${resp.json()}
94 Set Openstack Credentials
95 [Arguments] ${username} ${password}
96 Return From Keyword If '${username}' != '' ${username} ${password}
97 ${user} ${pass}= Get Openstack Credentials
98 [Return] ${user} ${pass}
100 Get Openstack Credentials
101 [Documentation] Returns the Decripted Password and openstack username using same api_key.txt as SO
102 ${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'
103 [Return] ${GLOBAL_INJECTED_OPENSTACK_USERNAME} ${DECRYPTED_OPENSTACK_PASSWORD}
106 Get Keystone Url And Path
107 [Arguments] ${keystone_api_version}
108 [Documentation] Handle arbitrary keystone identiit url. Add v2.0 if not present.
109 ${url} ${path}= Run Keyword If '${keystone_api_version}'=='v2.0' Set API Version ${OPENSTACK_KEYSTONE_API_v2_VERSION}
110 ... ELSE Set API Version ${OPENSTACK_KEYSTONE_API_v3_VERSION}
111 Log Path is ${url} ${path}
112 [Return] ${url} ${path}
115 [Documentation] Decides the API version to be used
116 [Arguments] ${openstack_version}
117 ${pieces}= Url Parse ${GLOBAL_INJECTED_KEYSTONE}
118 ${url}= Catenate ${pieces.scheme}://${pieces.netloc}
119 ${version}= Evaluate ''
120 ${version}= Set Variable If '${openstack_version}' not in '${pieces.path}' ${openstack_version} ${version}
121 ${path}= Catenate ${pieces.path}${version}
122 [Return] ${url} ${path}