e51e3db8e8bc59fe0f451529fc6fb0c371ba50d8
[testsuite.git] / robot / resources / openstack / keystone_interface.robot
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
5 Library               HTTPUtils
6 Library           UUID
7 Library           Collections
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}
24     ${url}   ${path}=   Get Keystone Url And Path
25     ${session}=    Create Session       keystone        ${url}    verify=True
26     ${uuid}=    Generate UUID
27     ${data_template}=    OperatingSystem.Get File    ${OPENSTACK_KEYSTONE_AUTH_BODY_FILE}
28     ${arguments}=    Create Dictionary    username=${username}    password=${password}   tenantId=${GLOBAL_INJECTED_OPENSTACK_TENANT_ID}
29     ${data}=    Fill JSON Template    ${data_template}    ${arguments}
30     ${data_path}=    Catenate    ${path}${OPENSTACK_KEYSTONE_AUTH_PATH}
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}
34     Should Be True    200 <= ${resp.status_code} < 300
35     Save Openstack Auth    ${alias}    ${resp.text}
36     Log    Received response from keystone ${resp.text}
37
38 Get Openstack Tenants
39     [Documentation]    Returns all the openstack tenant info
40     [Arguments]    ${alias}
41     ${resp}=    Internal Get Openstack With Region    ${alias}    ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE}    region=    url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH}    data_path=
42     [Return]    ${resp.json()}
43
44 Get Openstack Tenant
45     [Documentation]    Returns the openstack tenant info for the specified tenantid
46     [Arguments]    ${alias}     ${tenant_id}
47     ${resp}=    Internal Get Openstack With Region    ${alias}    ${GLOBAL_OPENSTACK_KEYSTONE_SERVICE_TYPE}    region=    url_ext=${OPENSTACK_KEYSTONE_TENANT_PATH}    data_path=/${tenant_id}
48     [Return]    ${resp.json()}
49
50 Set Openstack Credentials
51     [Arguments]    ${username}    ${password}
52     Return From Keyword If    '${username}' != ''   ${username}    ${password}
53     ${user}   ${pass}=   Get Openstack Credentials
54     [Return]   ${user}   ${pass}
55
56 Get Openstack Credentials
57     [Return]   ${GLOBAL_INJECTED_OPENSTACK_USERNAME}    ${GLOBAL_INJECTED_OPENSTACK_PASSWORD}
58
59 Get 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}