onap on kubernetes source files
[oom.git] / kubernetes / config / docker / init / src / config / robot / robot / resources / openstack / heat_interface.robot
1 *** Settings ***
2 Documentation     The interface for interacting with Openstack Heat API.
3 Library           OpenstackLibrary
4 Library               RequestsLibrary
5 Library           UUID
6 Library    OperatingSystem
7 Library    HEATUtils
8 Library    StringTemplater
9 Library    Collections
10 Resource    ../global_properties.robot
11 Resource    ../json_templater.robot
12 Resource    openstack_common.robot
13
14 *** Variables ***
15 ${OPENSTACK_HEAT_API_VERSION}    /v1
16 ${OPENSTACK_HEAT_STACK_PATH}    /stacks
17 ${OPENSTACK_HEAT_ADD_STACK_TEMPLATE}    robot/assets/templates/heat_add_stack.template
18
19
20 *** Keywords ***
21 Get Openstack Stacks
22     [Documentation]    Returns the openstack stacks info
23     [Arguments]    ${alias}
24     ${resp}=    Internal Get Openstack    ${alias}    ${GLOBAL_OPENSTACK_HEAT_SERVICE_TYPE}    ${OPENSTACK_HEAT_STACK_PATH}
25     [Return]    ${resp.json()}
26
27 Get Openstack Stack
28     [Documentation]    Returns the openstack stacks info for the given stack name
29     [Arguments]    ${alias}    ${stack_name}
30     ${resp}=    Internal Get Openstack    ${alias}    ${GLOBAL_OPENSTACK_HEAT_SERVICE_TYPE}    ${OPENSTACK_HEAT_STACK_PATH}    /${stack_name}
31     [Return]    ${resp.json()}
32
33 Create Openstack Stack
34     [Documentation]    Takes an openstack heat yaml and returns the created stack
35     [Arguments]    ${alias}    ${request}
36     ${resp}=    Internal Post Openstack    ${alias}    ${GLOBAL_OPENSTACK_HEAT_SERVICE_TYPE}    ${OPENSTACK_HEAT_STACK_PATH}    data_path=    data=${request}
37     [Return]    ${resp.json()}
38
39 Make Add Stack Request
40     [Documentation]    Makes a JSON Add Stack Request from  YAML template and env files
41     [Arguments]    ${name}    ${template}    ${env}
42     ${templatedata}=    Template Yaml To Json    ${template}
43     ${envdata}=    Env Yaml To Json    ${env}
44     ${dict}=  Create Dictionary     template=${templatedata}    parameters=${envdata}    stack_name=${name}
45     ${resp}=    OperatingSystem.Get File    ${OPENSTACK_HEAT_ADD_STACK_TEMPLATE}
46     ${request}=     Template String    ${resp}    ${dict}
47     Log    $request
48     [Return]    ${request}
49
50 Delete Openstack Stack
51     [Documentation]    Deletes and Openstack Stack for the passed name and id
52     [Arguments]    ${alias}    ${stack_name}    ${stack_id}
53     ${data_path}=    Catenate    /${stack_name}/${stack_id}
54     ${resp}=    Internal Delete Openstack    ${alias}    ${GLOBAL_OPENSTACK_HEAT_SERVICE_TYPE}    ${OPENSTACK_HEAT_STACK_PATH}    data_path=${data_path}
55     Should Be Equal As Strings    204  ${resp.status_code}
56     [Return]    ${resp}
57
58 Get Stack Details
59     [Documentation]    Gets all of the information necessary for tearing down an existing Openstack Stack
60     [Arguments]    ${alias}    ${stack_name}
61     ${resp}=    Internal Get Openstack    ${alias}    ${GLOBAL_OPENSTACK_HEAT_SERVICE_TYPE}    ${OPENSTACK_HEAT_STACK_PATH}    /${stack_name}
62     ${result}=    Stack Info Parse    ${resp.json()}
63     [Return]     ${result}
64
65 Get Stack Template
66     [Documentation]    Gets all of the template information of an existing Openstack Stack
67     [Arguments]    ${alias}    ${stack_name}    ${stack_id}
68     ${data_path}=    Catenate    /${stack_name}/${stack_id}/template
69     ${resp}=    Internal Get Openstack    ${alias}    ${GLOBAL_OPENSTACK_HEAT_SERVICE_TYPE}    ${OPENSTACK_HEAT_STACK_PATH}    ${data_path}
70     ${template}=        Catenate    ${resp.json()}
71     [Return]    ${template}
72
73 Get Stack Resources
74     [Documentation]    Gets all of the resources of an existing Openstack Stack
75     [Arguments]    ${alias}    ${stack_name}    ${stack_id}
76     ${data_path}=    Catenate    /${stack_name}/${stack_id}/resources
77     ${resp}=    Internal Get Openstack    ${alias}    ${GLOBAL_OPENSTACK_HEAT_SERVICE_TYPE}    ${OPENSTACK_HEAT_STACK_PATH}    ${data_path}
78     [Return]    ${resp.json()}
79
80 Wait for Stack to Be Deployed
81     [Arguments]    ${alias}   ${stack_name}    ${timeout}=600s
82     ${stack_info}=    Wait Until Keyword Succeeds    ${timeout}    30 sec    Get Deployed Stack    ${alias}    ${stack_name}
83     ${status}=   Get From Dictionary    ${stack_info}    stack_status
84     Should Be Equal    ${status}    CREATE_COMPLETE
85     [Return]    ${stack_info}
86
87 Get Deployed Stack
88     [Arguments]    ${alias}    ${stack_name}
89     ${stack_info}=    Get Stack Details    ${alias}    ${stack_name}
90     ${status}=   Get From Dictionary    ${stack_info}    stack_status
91     Should Not Be Equal    ${status}    CREATE_IN_PROGRESS
92     [Return]    ${stack_info}