Merge "Add healthcheck for Data-Router"
[testsuite.git] / robot / resources / heatbridge.robot
1 *** Settings ***
2 Library     HeatBridge
3 Library     Collections
4 Library     StringTemplater
5 Library     OperatingSystem
6 Library     UUID
7
8 Resource    openstack/keystone_interface.robot
9 Resource    openstack/heat_interface.robot
10 Resource    openstack/nova_interface.robot
11 Resource    openstack/neutron_interface.robot
12 Resource    aai/aai_interface.robot
13
14 *** Variables ***
15 ${MULTIPART_PATH}  /bulkadd
16 ${NAMED_QUERY_PATH}  /aai/search/named-query
17 ${NAMED_QUERY_TEMPLATE}    robot/assets/templates/aai/named_query.template
18
19 ${BASE_URI}   /cloud-infrastructure/cloud-regions/cloud-region/\${cloud}/\${region}
20 ${IMAGE_URI}   ${BASE_URI}/images/image/\${image_id}
21 ${FLAVOR_URI}   ${BASE_URI}/flavors/flavor/\${flavor}
22 ${VSERVER_URI}   ${BASE_URI}/tenants/tenant/\${tenant}/vservers/vserver/\${vserver_id}
23 ${L_INTERFACE_URI}   ${VSERVER_URI}/l-interfaces/l-interface/\${linterface_id}
24
25 #******************** Test Case Variables ****************
26 ${REVERSE_HEATBRIDGE}
27
28
29 *** Keywords ***
30 Execute Heatbridge
31     [Documentation]   Run the Heatbridge against the stack to generate the bulkadd message
32     ...    Execute the build add
33     ...    Validate the add results by running the named query
34     [Arguments]    ${stack_name}    ${service_instance_id}    ${service}    ${ipv4_oam_address}
35     Return From Keyword If    '${service}' == 'vVG'
36     Run Openstack Auth Request    auth
37     ${stack_info}=    Wait for Stack to Be Deployed    auth    ${stack_name}
38     ${stack_id}=    Get From Dictionary    ${stack_info}    id
39     ${tenant_id}=   Get From Dictionary    ${stack_info}    OS::project_id
40     ${vnf_id}=    Get From Dictionary    ${stack_info}    vnf_id
41     ${KeyIsPresent}=    Run Keyword And Return Status       Dictionary Should Contain Key       ${stack_info}      ${ipv4_oam_address}
42     ${ipv4_vnf_address}=   Run Keyword If      ${KeyIsPresent}     Get From Dictionary  ${stack_info}      ${ipv4_oam_address}
43     Run Set VNF Params  ${vnf_id}  ${ipv4_vnf_address}  PROV  Active
44     ${url}   ${path}=   Get Keystone Url And Path
45     ${openstack_identity_url}=    Catenate    ${url}${path}
46     ${region}=   Get Openstack Region
47     ${user}   ${pass}=   Get Openstack Credentials
48     Init Bridge    ${openstack_identity_url}    ${user}    ${pass}    ${tenant_id}    ${region}   ${GLOBAL_AAI_CLOUD_OWNER}
49     ${request}=    Bridge Data    ${stack_id}
50     Log    ${request}
51     ${resp}=    Run A&AI Put Request    ${VERSIONED_INDEX_PATH}${MULTIPART_PATH}    ${request}  
52     ${status_string}=    Convert To String    ${resp.status_code}
53     Should Match Regexp    ${status_string}     ^(201|200)$
54     ${reverse_heatbridge}=   Generate Reverse Heatbridge From Stack Info   ${stack_info}
55     Set Test Variable   ${REVERSE_HEATBRIDGE}   ${reverse_heatbridge}
56     Run Validation Query    ${stack_info}    ${service}
57
58
59 Run Validation Query
60     [Documentation]    Run A&AI query to validate the bulk add
61     [Arguments]    ${stack_info}    ${service}
62     Return from Keyword If    '${service}' == ''
63     ${server_name_parameter}=    Get From Dictionary    ${GLOBAL_VALIDATE_NAME_MAPPING}    ${service}
64     ${vserver_name}=    Get From Dictionary    ${stack_info}   ${server_name_parameter}
65     Run Vserver Query   ${vserver_name}
66
67 Run Vserver Query
68     [Documentation]    Run A&AI query to validate the bulk add
69     [Arguments]    ${vserver_name}
70     ${dict}=    Create Dictionary    vserver_name=${vserver_name}
71     ${request}=    OperatingSystem.Get File    ${NAMED_QUERY_TEMPLATE}
72     ${request}=    Template String    ${request}    ${dict}
73     ${resp}=    Run A&AI Post Request    ${NAMED_QUERY_PATH}    ${request}
74     Should Be Equal As Strings    ${resp.status_code}    200
75
76
77 Run Set VNF Params
78     [Documentation]  Run A&A GET and PUT to set prov-status, orchestration status, and ipv4-oam-address
79     [Arguments]   ${vnf_id}  ${ipv4_vnf_address}  ${prov_status}=PROV  ${orch_status}=Active
80     ${payload}=  Run Get Generic VNF by VnfId   ${vnf_id}
81
82     #${payload_json}=    evaluate    json.loads('''${payload}''')    json
83     set to dictionary    ${payload}    prov-status    ${prov_status}
84     set to dictionary    ${payload}    orchestration-status   ${orch_status}
85     set to dictionary    ${payload}    ipv4-oam-address  ${ipv4_vnf_address}
86     ${payload_string}=    evaluate    json.dumps(${payload})    json
87
88     ${put_resp}=    Run A&AI Put Request      ${VERSIONED_INDEX_PATH}/network/generic-vnfs/generic-vnf/${vnf_id}    ${payload_string}
89     ${status_string}=    Convert To String    ${put_resp.status_code}
90     Should Match Regexp    ${status_string}    ^(200|201)$
91     Log To Console    Set VNF ProvStatus: ${vnf_id} to ${prov_status}
92
93 Run Get Generic VNF By VnfId
94     [Documentation]  Get VNF GET Payload with resource ID
95     [Arguments]   ${vnf_id}
96     ${resp}=    Run A&AI Get Request      ${VERSIONED_INDEX_PATH}/network/generic-vnfs/generic-vnf?vnf-id=${vnf_id}
97     Should Be Equal As Strings  ${resp.status_code}     200
98     [Return]   ${resp.json()}
99
100 Execute Reverse Heatbridge
101     [Documentation]   VID has already torn down the stack, reverse HB
102     Return From Keyword If   len(${REVERSE_HEATBRIDGE}) == 0
103     :for   ${uri}    in   @{REVERSE_HEATBRIDGE}
104     \    Run Keyword And Ignore Error    Delete A&AI Entity   ${uri}
105
106 Generate Reverse Heatbridge From Stack Name
107     [Arguments]   ${stack_name}
108     Run Openstack Auth Request    auth
109     ${stack_info}=    Wait for Stack to Be Deployed    auth    ${stack_name}   timeout=10s
110     ${reverse_heatbridge}=    Generate Reverse Heatbridge From Stack Info   ${stack_info}
111     [Return]    ${reverse_heatbridge}
112
113 Generate Reverse Heatbridge From Stack Info
114     [Arguments]   ${stack_info}
115     ${reverse_heatbridge}=    Create List
116     ${stack_name}=    Get From Dictionary    ${stack_info}    name
117     ${stack_id}=    Get From Dictionary    ${stack_info}    id
118     ${tenant_id}=   Get From Dictionary    ${stack_info}    OS::project_id
119     ${region}=   Get Openstack Region
120     ${keys}=    Create Dictionary   region=${region}   cloud=${GLOBAL_AAI_CLOUD_OWNER}   tenant=${tenant_id}
121     ${stack_resources}=    Get Stack Resources    auth    ${stack_name}    ${stack_id}
122     ${resource_list}=    Get From Dictionary    ${stack_resources}    resources
123     :FOR   ${resource}    in    @{resource_list}
124     \    Log     ${resource}
125     \    Run Keyword If    '${resource['resource_type']}' == 'OS::Neutron::Port'    Generate Linterface Uri    auth    ${resource['physical_resource_id']}   ${reverse_heatbridge}   ${keys}
126     :FOR   ${resource}    in    @{resource_list}
127     \    Log     ${resource}
128     \    Run Keyword If    '${resource['resource_type']}' == 'OS::Nova::Server'    Generate Vserver Uri    auth    ${resource['physical_resource_id']}  ${reverse_heatbridge}   ${keys}   ${resource_list}
129     [Return]    ${reverse_heatbridge}
130
131 Generate Vserver Uri
132     [Documentation]   Run teardown against the server to generate a message that removes it
133     [Arguments]    ${alias}    ${port_id}   ${reverse_heatbridge}   ${keys}   ${resource_list}
134     ${resp}=    Get Openstack Server By Id   ${alias}     ${port_id}
135     Return From Keyword If   '${resp.status_code}' != '200'
136     ${info}=   Set Variable   ${resp.json()}
137     Set To Dictionary   ${keys}   vserver_id=${info['server']['id']}
138     Set To Dictionary   ${keys}   flavor=${info['server']['flavor']['id']}
139     Set To Dictionary   ${keys}   image_id=${info['server']['image']['id']}
140     ${uri}=   Template String    ${VSERVER_URI}    ${keys}
141     Append To List  ${reverse_heatbridge}   ${uri}
142     ${uri}=   Template String    ${FLAVOR_URI}    ${keys}
143     Append To List  ${reverse_heatbridge}   ${uri}
144     ${uri}=   Template String    ${IMAGE_URI}    ${keys}
145     Append To List  ${reverse_heatbridge}   ${uri}
146
147 Generate Linterface Uri
148     [Documentation]   Run teardown against the server to generate a message that removes it
149     [Arguments]    ${alias}    ${server_id}   ${reverse_heatbridge}   ${keys}
150     ${resp}=    Get Openstack Port By Id   ${alias}     ${server_id}
151     Return From Keyword If   '${resp.status_code}' != '200'
152     ${info}=   Set Variable   ${resp.json()}
153     Set To Dictionary   ${keys}   vserver_id=${info['port']['device_id']}
154     Set To Dictionary   ${keys}   linterface_id=${info['port']['name']}
155     ${uri}=   Template String    ${L_INTERFACE_URI}    ${keys}
156     Append To List  ${reverse_heatbridge}   ${uri}
157