6e2cd9a41f145ff2f4a7aeeab0a0eec1d02a01e3
[testsuite.git] / robot / resources / test_templates / vnf_orchestration_test_template.robot
1 *** Settings ***
2 Documentation     This test template encapsulates the VNF Orchestration use case.
3
4 Resource        ../vid/create_service_instance.robot
5 Resource        ../vid/vid_interface.robot
6 Resource        ../aai/service_instance.robot
7 Resource        ../vid/create_vid_vnf.robot
8 Resource        ../vid/teardown_vid.robot
9 Resource        ../sdngc_interface.robot
10 Resource        model_test_template.robot
11
12 Resource        ../aai/create_zone.robot
13 Resource        ../aai/create_customer.robot
14 Resource        ../aai/create_complex.robot
15 Resource        ../aai/create_tenant.robot
16 Resource        ../aai/create_service.robot
17 Resource        ../openstack/neutron_interface.robot
18 Resource        ../heatbridge.robot
19
20
21 Library         OpenstackLibrary
22 Library             ExtendedSelenium2Library
23 Library         UUID
24 Library         Collections
25 Library         JSONUtils
26
27
28
29 *** Variables ***
30
31 #**************** TEST CASE VARIABLES **************************
32 ${TENANT_NAME}
33 ${TENANT_ID}
34 ${REGIONS}
35 ${CUSTOMER_NAME}
36 ${STACK_NAME}
37 ${STACK_NAMES}
38 ${SERVICE}
39 ${VVG_SERVER_ID}
40 ${SERVICE_INSTANCE_ID}
41
42 *** Keywords ***
43 Orchestrate VNF Template
44     [Documentation]   Use openECOMP to Orchestrate a service.
45     [Arguments]    ${customer_name}    ${service}    ${product_family}    ${tenant}
46     Orchestrate VNF   ${customer_name}    ${service}    ${product_family}    ${tenant}
47     Delete VNF
48
49 Orchestrate VNF
50     [Documentation]   Use openECOMP to Orchestrate a service.
51     [Arguments]    ${customer_name}    ${service}    ${product_family}    ${tenant}  ${project_name}=Project-Demonstration   ${owning_entity}=OE-Demonstration
52     ${lcp_region}=   Get Openstack Region
53     ${uuid}=    Generate UUID
54     Set Test Variable    ${CUSTOMER_NAME}    ${customer_name}_${uuid}
55     Set Test Variable    ${SERVICE}    ${service}
56     ${list}=    Create List
57     Set Test Variable    ${STACK_NAMES}   ${list}
58     ${service_name}=    Catenate    Service_Ete_Name${uuid}
59     ${service_type}=    Set Variable    ${service}
60     ${service_model_type}     ${vnf_type}    ${vf_modules}   ${catalog_resources}=    Model Distribution For Directory    ${service}
61     Run Keyword If   '${service}' == 'vVG'    Create VVG Server    ${uuid}
62     Create Customer For VNF    ${CUSTOMER_NAME}    ${CUSTOMER_NAME}    INFRA    ${service_type}    ${GLOBAL_AAI_CLOUD_OWNER}
63     Setup Browser
64     Login To VID GUI
65     ${service_instance_id}=   Wait Until Keyword Succeeds    300s   5s    Create VID Service Instance    ${customer_name}    ${service_model_type}    ${service}     ${service_name}   ${project_name}   ${owning_entity}
66     Set Test Variable   ${SERVICE_INSTANCE_ID}   ${service_instance_id}
67     Validate Service Instance    ${service_instance_id}    ${service}      ${customer_name}
68     ${vnflist}=   Get From Dictionary    ${GLOBAL_SERVICE_VNF_MAPPING}    ${service}
69     :for   ${vnf}   in   @{vnflist}
70     \   ${vnf_name}=    Catenate    Ete_${vnf}_${uuid}
71     \   ${vf_module_name}=    Catenate    Vfmodule_Ete_${vnf}_${uuid}
72     \   ${vnf_type}=   Get VNF Type   ${catalog_resources}   ${vnf}
73     \   ${vf_module}=    Get VF Module    ${catalog_resources}   ${vnf}
74     \   Append To List   ${STACK_NAMES}   ${vf_module_name}
75     \   Wait Until Keyword Succeeds    300s   5s    Create VID VNF    ${service_instance_id}    ${vnf_name}    ${product_family}    ${lcp_region}    ${tenant}    ${vnf_type}   ${CUSTOMER_NAME}
76     \   ${vf_module_type}   ${closedloop_vf_module}=   Preload Vnf    ${service_instance_id}   ${vnf_name}   ${vnf_type}   ${vf_module_name}    ${vf_module}    ${vnf}    ${uuid}
77     \   ${vf_module_id}=   Create VID VNF module    ${service_instance_id}    ${vf_module_name}    ${lcp_region}    ${tenant}     ${vf_module_type}   ${CUSTOMER_NAME}   ${vnf_name}
78     \   ${generic_vnf}=   Validate Generic VNF    ${vnf_name}    ${vnf_type}    ${service_instance_id}
79     \   VLB Closed Loop Hack   ${service}   ${generic_vnf}   ${closedloop_vf_module}
80     \   Set Test Variable    ${STACK_NAME}   ${vf_module_name}
81     \   Append To List   ${STACK_NAMES}   ${STACK_NAME}
82     \   Run Keyword and Ignore Error   Execute Heatbridge    ${vf_module_name}    ${service_instance_id}    ${vnf}
83     \   Run Keyword and Ignore Error   Validate VF Module      ${vf_module_name}    ${vnf}
84     [Return]     ${vf_module_name}    ${service}
85
86
87 Get VNF Type
88     [Documentation]    To support services with multiple VNFs, we need to dig the vnf type out of the SDC catalog resources to select in the VID UI
89     [Arguments]   ${resources}   ${vnf}
90     ${cr}=   Get Catalog Resource    ${resources}    ${vnf}
91     ${vnf_type}=   Get From Dictionary   ${cr}   name
92     [Return]   ${vnf_type}
93
94 Get VF Module
95     [Documentation]    To support services with multiple VNFs, we need to dig the vnf type out of the SDC catalog resources to select in the VID UI
96     [Arguments]   ${resources}   ${vnf}
97     ${cr}=   Get Catalog Resource    ${resources}    ${vnf}
98     ${vf_module}=    Find Element In Array    ${cr['groups']}    type    org.openecomp.groups.VfModule
99     [Return]  ${vf_module}
100
101 Get Catalog Resource
102     [Documentation]    To support services with multiple VNFs, we need to dig the vnf type out of the SDC catalog resources to select in the VID UI
103     [Arguments]   ${resources}   ${vnf}
104
105     ${base_name}=  Get Name Pattern   ${vnf}
106     ${keys}=    Get Dictionary Keys    ${resources}
107
108     :for   ${key}   in    @{keys}
109     \    ${cr}=   Get From Dictionary    ${resources}    ${key}
110     \    Return From Keyword If   '${base_name}' in '${cr['allArtifacts']['heat1']['artifactDisplayName']}'    ${cr}
111     \    Run Keyword If    'heat2' in ${cr['allArtifacts']}    Return From Keyword If   '${base_name}' in '${cr['allArtifacts']['heat2']['artifactDisplayName']}'    ${cr}
112     Fail    Unable to find catalog resource for ${vnf} ${base_name}
113
114 Get Name Pattern
115     [Documentation]    To support services with multiple VNFs, we need to dig the vnf type out of the SDC catalog resources to select in the VID UI
116     [Arguments]   ${vnf}
117     ${list}=   Get From Dictionary    ${GLOBAL_SERVICE_TEMPLATE_MAPPING}   ${vnf}
118     :for    ${dict}   in   @{list}
119     \   ${base_name}=   Get From Dictionary    ${dict}    name_pattern
120     \   Return From Keyword If   '${dict['isBase']}' == 'true'   ${base_name}
121     Fail  Unable to locate base name pattern
122
123
124
125 Create Customer For VNF
126     [Documentation]    VNF Orchestration Test setup....
127     ...                Create Tenant if not exists, Create Customer, Create Service and related relationships
128     [Arguments]    ${customer_name}    ${customer_id}    ${customer_type}    ${service_type}    ${cloud_owner}
129     ${cloud_region_id}=   Get Openstack Region
130     Create Service If Not Exists    ${service_type}
131     ${resp}=    Create Customer    ${customer_name}    ${customer_id}    ${customer_type}    ${service_type}   ${cloud_owner}  ${cloud_region_id}    ${TENANT_ID}
132         Should Be Equal As Strings      ${resp}         201
133
134 Setup Orchestrate VNF
135     [Documentation]    Called before each test case to ensure tenant and region data
136     ...                required by the Orchstrate VNF exists in A&AI
137     [Arguments]        ${cloud_owner}  ${cloud_type}    ${owner_defined_type}    ${cloud_region_version}    ${cloud_zone}
138     Initialize Tenant From Openstack
139     Initialize Regions From Openstack
140     :FOR    ${region}    IN    @{REGIONS}
141     \    Inventory Tenant If Not Exists    ${cloud_owner}  ${region}  ${cloud_type}    ${owner_defined_type}    ${cloud_region_version}    ${cloud_zone}    ${TENANT_ID}    ${TENANT_NAME}
142     Inventory Zone If Not Exists
143     Inventory Complex If Not Exists    ${GLOBAL_AAI_COMPLEX_NAME}   ${GLOBAL_AAI_PHYSICAL_LOCATION_ID}   ${GLOBAL_AAI_CLOUD_OWNER}   ${GLOBAL_INJECTED_REGION}   ${GLOBAL_AAI_CLOUD_OWNER_DEFINED_TYPE}
144     Log   Orchestrate VNF setup complete
145
146 Initialize Tenant From Openstack
147     [Documentation]    Initialize the tenant test variables
148     Run Openstack Auth Request    auth
149     ${tenants}=    Get Current Openstack Tenant     auth
150     ${tenant_name}=    Evaluate    $tenants.get("name")
151     ${tenant_id}=     Evaluate    $tenants.get("id")
152     Set Test Variable   ${TENANT_NAME}   ${tenant_name}
153     Set Test Variable   ${TENANT_ID}     ${tenant_id}
154
155 Initialize Regions From Openstack
156     [Documentation]    Initialize the regions test variable
157     Run Openstack Auth Request    auth
158     ${regs}=    Get Openstack Regions    auth
159     Set Test Variable   ${REGIONS}     ${regs}
160
161 Create VVG Server
162     [Documentation]    For the VolumeGroup test case, create a server to attach the volume group to be orchestrated.
163     [Arguments]    ${uuid}
164     Run Openstack Auth Request    auth
165     ${vvg_server_name}=    Catenate   vVG_${uuid}
166     ${server}=   Add Server For Image Name  auth    ${vvg_server_name}   ${GLOBAL_INJECTED_VM_IMAGE_NAME}   ${GLOBAL_INJECTED_VM_FLAVOR}   ${GLOBAL_INJECTED_PUBLIC_NET_ID}
167     ${server}=       Get From Dictionary   ${server}   server
168     ${server_id}=    Get From Dictionary   ${server}   id
169     Set Test Variable    ${VVG_SERVER_ID}   ${server_id}
170     ${vvg_params}=    Get VVG Preload Parameters
171     Set To Dictionary   ${vvg_params}   nova_instance   ${server_id}
172     Wait for Server to Be Active    auth    ${server_id}
173
174 Get VVG Preload Parameters
175     [Documentation]   Get preload parameters for the VVG test case so we can include
176     ...               the nova_instance id of the attached server
177     ${test_dict}=    Get From Dictionary    ${GLOBAL_PRELOAD_PARAMETERS}    Vnf-Orchestration
178     ${vvg_params}   Get From Dictionary    ${test_dict}    vvg_preload.template
179     [Return]    ${vvg_params}
180
181 Delete VNF
182     [Documentation]    Called at the end of a test case to tear down the VNF created by Orchestrate VNF
183     ${lcp_region}=   Get Openstack Region
184     ${list}=    Create List
185     Set Test Variable    ${KEYPAIRS}   ${list}
186     # remove duplicates, sort vFW-> vPKG , revers to get vPKG > vFWSNK
187     ${sorted_stack_names}=    Create List
188     ${sorted_stack_names}=  Remove Duplicates   ${STACK_NAMES}
189     Sort List   ${sorted_stack_names}
190     Reverse List   ${sorted_stack_names}
191     :for   ${stack}   in   @{sorted_stack_names}
192     \     Get Stack Keypairs   ${stack}
193     Teardown VVG Server
194     Teardown VLB Closed Loop Hack
195     Run Keyword and Ignore Error   Teardown VID   ${SERVICE_INSTANCE_ID}   ${lcp_region}   ${TENANT_NAME}   ${CUSTOMER_NAME}
196     #
197     :for   ${stack}   in   @{sorted_stack_names}
198     \    Run Keyword and Ignore Error    Teardown Stack    ${stack}
199     \    Log    Stack Deleted ${stack}
200     # only needed if stack deleted but not keypair
201     :for   ${key_pair}   in   @{KEYPAIRS}
202     \    Run Keyword and Ignore Error    Delete Stack Keypair  ${key_pair}
203     \    Log    Key pair Deleted ${key_pair}
204     Log    VNF Deleted
205
206 Teardown VNF
207     [Documentation]    Called at the end of a test case to tear down the VNF created by Orchestrate VNF
208     Run Keyword If   '${TEST STATUS}' == 'PASS'   Teardown Model Distribution
209     Run Keyword If   '${TEST STATUS}' == 'PASS'   Clean A&AI Inventory
210     Close All Browsers
211     Log    Teardown VNF implemented for successful tests only
212
213 Teardown VVG Server
214     [Documentation]   Teardown the server created as a place to mount the Volume Group.
215     Return From Keyword if   '${VVG_SERVER_ID}' == ''
216     Delete Server   auth   ${VVG_SERVER_ID}
217     Wait for Server To Be Deleted    auth    ${VVG_SERVER_ID}
218     ${vvg_params}=    Get VVG Preload Parameters
219     Remove from Dictionary   ${vvg_params}   nova_instance
220     Log    Teardown VVG Server Completed
221
222 Get Stack Keypairs
223     [Documentation]  Get keypairs from openstack
224     [Arguments]   ${stack}
225     Run Openstack Auth Request    auth
226     ${stack_info}=    Get Stack Details    auth    ${stack}
227     Log    ${stack_info}
228     ${stack_id}=    Get From Dictionary    ${stack_info}    id
229     ${key_pair_status}   ${keypair_name}=   Run Keyword And Ignore Error   Get From Dictionary    ${stack_info}    key_name
230     Append To List   ${KEYPAIRS}   ${keypair_name}
231
232 Delete Stack Keypair
233     [Documentation]  Delete keypairs from openstack
234     [Arguments]   ${keypair_name}
235     Run Openstack Auth Request    auth
236     Run Keyword   Delete Openstack Keypair    auth    ${keypair_name}
237
238 Teardown Stack
239     [Documentation]    OBSOLETE - Called at the end of a test case to tear down the Stack created by Orchestrate VNF
240     [Arguments]   ${stack}
241     Run Openstack Auth Request    auth
242     ${stack_info}=    Get Stack Details    auth    ${stack}
243     Log    ${stack_info}
244     ${stack_id}=    Get From Dictionary    ${stack_info}    id
245     ${key_pair_status}   ${keypair_name}=   Run Keyword And Ignore Error   Get From Dictionary    ${stack_info}    key_name
246     Delete Openstack Stack      auth    ${stack}    ${stack_id}
247     Log    Deleted ${stack} ${stack_id}
248     Run Keyword If   '${key_pair_status}' == 'PASS'   Delete Openstack Keypair    auth    ${keypair_name}
249     #Teardown VLB Closed Loop Hack
250
251 Clean A&AI Inventory
252     [Documentation]    Clean up Tenant in A&AI, Create Customer, Create Service and related relationships
253     Delete Customer    ${CUSTOMER_NAME}