aboutsummaryrefslogtreecommitdiffstats
path: root/robot/resources/openstack/openstack_common.robot
blob: 04ac162c4900ebdea3198a73a4e3a5ecdf931448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
*** Settings ***
Documentation     The private interface for interacting with Openstack. It handles low level stuff like managing the authtoken and Openstack required fields

Library           Collections
Library           ONAPLibrary.Openstack
Library         RequestsLibrary
Library           ONAPLibrary.Utilities
Resource    ../global_properties.robot

*** Variables ***
#**************** Test Case Variables ******************
${OPENSTACK_SERVICE_REGION}

*** Keywords ***
Internal Get Openstack
    [Documentation]    Runs an Openstack Get Request and returns the response
    [Arguments]    ${alias}    ${service_type}    ${url_ext}   ${data_path}=
    ${region}=   Get Openstack Region
    ${resp}=   Internal Get Openstack With Region   ${alias}    ${service_type}    ${region}   ${url_ext}   ${data_path}
    [Return]    ${resp}

Internal Get Openstack With Region
    [Documentation]    Runs an Openstack Get Request and returns the response
    [Arguments]    ${alias}    ${service_type}    ${region}   ${url_ext}   ${data_path}=
    Log    Internal Get Openstack values alias=${alias} service_type=${service_type} region=${region} url_ext=${url_ext} data_path=${data_path}
    ${url}=    Get Openstack Service Url    ${alias}     ${service_type}    ${region}
    ${uuid}=    Generate UUID4
    ${session_alias}=    Catenate    openstack-${uuid}
    ${session}=    Create Session   ${session_alias}  ${url}${url_ext}        verify=True
    ${token}=    Get Openstack Token    ${alias}
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}     X-Auth-Token=${token}
    ${resp}=  Get Request   ${session_alias}  ${data_path}     headers=${headers}
    Log    Received response from openstack ${resp.text}
    [Return]    ${resp}

Internal Post Openstack
    [Documentation]    Runs an Openstack Post Response and returns the response
    [Arguments]    ${alias}    ${service_type}    ${url_ext}   ${data_path}=    ${data}=
    ${region}=   Get Openstack Region
    Log    Internal Post Openstack values alias=${alias} service_type=${service_type} region=${region} url_ext=${url_ext} data_path=${data_path}
    ${url}=    Get Openstack Service Url    ${alias}     ${service_type}    ${region}
    ${uuid}=    Generate UUID4
    ${session_alias}=    Catenate    openstack-${uuid}
    ${session}=    Create Session   ${session_alias}  ${url}${url_ext}        verify=True
    ${token}=    Get Openstack Token    ${alias}
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}     X-Auth-Token=${token}
    ${resp}=  Post Request  ${session_alias}  ${data_path}     data=${data}    headers=${headers}
    Log    Received response from openstack ${resp.text}
    [Return]    ${resp}

Internal Delete Openstack
    [Documentation]    Runs an Openstack Delete Request and returns the response
    [Arguments]    ${alias}    ${service_type}    ${url_ext}   ${data_path}=
    ${region}=   Get Openstack Region
    Log    Internal Post Openstack values alias=${alias} service_type=${service_type} region=${region} url_ext=${url_ext} data_path=${data_path}
    ${url}=    Get Openstack Service Url    ${alias}     ${service_type}    ${region}
    ${uuid}=    Generate UUID4
    ${session_alias}=    Catenate    openstack-${uuid}
    ${session}=    Create Session   ${session_alias}  ${url}${url_ext}        verify=True
    ${token}=    Get Openstack Token    ${alias}
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}     X-Auth-Token=${token}
    ${resp}=  Delete Request  ${session_alias}  ${data_path}    headers=${headers}
    Log    Received response from openstack ${resp.text}
    [Return]    ${resp}

Get Openstack Region
    [Documentation]   Returns the current openstack region test variable
    ...               Defaults to the openstack region of the Robot VM
    Return From Keyword If   len('${OPENSTACK_SERVICE_REGION}') > 0   ${OPENSTACK_SERVICE_REGION}
    Set Test Variable   ${OPENSTACK_SERVICE_REGION}   ${GLOBAL_INJECTED_REGION}
    Log   Setting OPENSTACK_SERVICE_REGION=${OPENSTACK_SERVICE_REGION}
    [Return]   ${OPENSTACK_SERVICE_REGION}

Set Openstack Region Test Variable
    [Documentation]   Sets the openstack service region of the current test case
    ...               To be used to override the service region of the Robot VM (default)
    [Arguments]   ${openstack_service_region}
    Set Test Variable   ${OPENSTACK_SERVICE_REGION}   ${openstack_service_region}