[APPC] Remove APPC junk
[testsuite.git] / robot / resources / demo_preload.robot
1 *** Settings ***
2 Documentation     This test template encapsulates the VNF Orchestration use case.
3
4 Resource        test_templates/model_test_template.robot
5 Resource        test_templates/model_test_template_vcperescust.robot
6 Resource        test_templates/vnf_orchestration_test_template.robot
7 Resource        sdc_interface.robot
8 Resource        vid/vid_interface.robot
9 Resource        consul_interface.robot
10 Resource        policy_interface.robot
11 Resource        aai/create_availability_zone.robot
12 Resource    so/direct_instantiate.robot
13
14 Library         ONAPLibrary.Utilities
15 Library         Collections
16 Library         OperatingSystem
17 Library         SeleniumLibrary
18 Library         RequestsLibrary
19 Library         ONAPLibrary.Templating    WITH NAME    Templating
20 Library         ONAPLibrary.AAI    WITH NAME    AAI
21 Library         ONAPLibrary.SO    WITH NAME    SO
22
23 *** Variables ***
24
25 ${ADD_DEMO_CUSTOMER_BODY}   aai/add_demo_customer.jinja
26 ${AAI_INDEX_PATH}     /aai/v8
27 ${VF_MODULES_NAME}     _Demo_VFModules.json
28 ${FILE_CACHE}    /share/
29 ${DEMO_PREFIX}   demo
30 ${VPKG_MODULE_LABEL}    base_vpkg
31
32
33 *** Keywords ***
34 Load Customer And Models
35     [Documentation]   Use ONAP to Orchestrate a service.
36     [Arguments]    ${customer_name}
37     Load Customer  ${customer_name}
38     Load Models  ${customer_name}
39
40 Load Customer
41     [Documentation]   Use ONAP to Orchestrate a service.
42     [Arguments]    ${customer_name}
43     ${tenant_id}    ${tenant_name}=    Setup Orchestrate VNF   ${GLOBAL_AAI_CLOUD_OWNER}   SharedNode    OwnerType    v1    CloudZone
44     ${region}=   Get Openstack Region
45     Create Customer For VNF Demo    ${customer_name}    ${customer_name}    INFRA    ${GLOBAL_AAI_CLOUD_OWNER}    ${region}   ${tenant_id}
46     Create Customer For VNF Demo    ${customer_name}    ${customer_name}    INFRA    ${GLOBAL_AAI_CLOUD_OWNER}    RegionTlab  50b190410b2a4c229d8a6044a80ab7c1
47     Create Availability Zone If Not Exists    ${GLOBAL_AAI_CLOUD_OWNER}    ${region}   ${GLOBAL_AAI_AVAILABILITY_ZONE_NAME}
48
49 Load Models
50     [Documentation]   Load Basic Test VNF Models
51     [Arguments]    ${customer_name}
52     Log   ${\n}Distributing vFWCL
53     Distribute Model   vFWCL   ${DEMO_PREFIX}VFWCL
54     Log   Distibuting vLB
55     Distribute Model   vLB   ${DEMO_PREFIX}VLB
56     Log   Distibuting vLB_CDS
57     Distribute Model   vLB_CDS   ${DEMO_PREFIX}VLB_CDS  True
58
59 Load vCPE Models
60     [Documentation]   Load vCPE Models
61     [Arguments]    ${customer_name}
62     Log   Distibuting vCPEInfra
63     Distribute Model   vCPEInfra   ${DEMO_PREFIX}VCPEInfra
64     Log   Distibuting vCPEvBNG
65     Distribute Model   vCPEvBNG   ${DEMO_PREFIX}VCPEvBNG
66     Log   Distibuting vCPEvBRGEMU
67     Distribute Model   vCPEvBRGEMU   ${DEMO_PREFIX}VCPEvBRGEMU
68     Log   Distibuting vCPEvGMUX
69     Distribute Model   vCPEvGMUX    ${DEMO_PREFIX}VCPEvGMUX
70     Log   Distibuting vCPEvGW (this is not vCPEResCust service)
71     Distribute Model   vCPEvGW    ${DEMO_PREFIX}VCPEvGW
72
73 Distribute Model
74     [Arguments]   ${service}   ${modelName}  ${cds}=False   ${instantiationType}=A-la-carte  ${resourceType}=VF
75     Model Distribution For Directory    ${service}   ${modelName}  ${cds}  ${instantiationType}  ${resourceType}
76
77 Create Customer For VNF Demo
78     [Documentation]    Create demo customer for the demo
79     [Arguments]    ${customer_name}   ${customer_id}   ${customer_type}    ${clouder_owner}    ${cloud_region_id}    ${tenant_id}
80     Create Service If Not Exists    vFW
81     Create Service If Not Exists    vFWCL
82     Create Service If Not Exists    vLB
83     Create Service If Not Exists    vCPE
84     Create Service If Not Exists    vIMS
85     Create Service If Not Exists    gNB
86     ${arguments}=    Create Dictionary    subscriber_name=${customer_name}    global_customer_id=${customer_id}    subscriber_type=${customer_type}     cloud_owner=${clouder_owner}  cloud_region_id=${cloud_region_id}    tenant_id=${tenant_id}
87     Set To Dictionary   ${arguments}       service1=vFWCL       service2=vLB   service3=vCPE   service4=vIMS  service5=gNB   service6=vFW
88     Templating.Create Environment    aai    ${GLOBAL_TEMPLATE_FOLDER}
89     ${data}=   Templating.Apply Template    aai   ${ADD_DEMO_CUSTOMER_BODY}    ${arguments}
90     ${put_resp}=    AAI.Run Put Request     ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}${ROOT_CUSTOMER_PATH}${customer_id}    ${data}    auth=${GLOBAL_AAI_AUTHENTICATION}
91     ${status_string}=    Convert To String    ${put_resp.status_code}
92     Should Match Regexp    ${status_string}    ^(200|201|412)$
93
94 Preload User Model
95     [Documentation]   Preload the demo data for the passed VNF with the passed module name
96     [Arguments]   ${vnf_name}   ${vf_module_name}    ${service}    ${service_instance_id}    ${vnf}=${service}
97     # Go to A&AI and get information about the VNF we need to preload
98     ${status}  ${generic_vnf}=   Run Keyword And Ignore Error   Get Service Instance    ${vnf_name}
99     Run Keyword If   '${status}' == 'FAIL'   FAIL   VNF Name: ${vnf_name} is not found.
100     ${vnf_type}=   Set Variable   ${generic_vnf['vnf-type']}
101     ${relationships}=   Set Variable   ${generic_vnf['relationship-list']['relationship']}
102     ${relationship_data}=    Get Relationship Data   ${relationships}
103     ${customer_id}=   Catenate
104     :FOR    ${r}   IN   @{relationship_data}
105     \   ${service}=   Set Variable If    '${r['relationship-key']}' == 'service-subscription.service-type'   ${r['relationship-value']}    ${service}
106     \   ${service_instance_id}=   Set Variable If    '${r['relationship-key']}' == 'service-instance.service-instance-id'   ${r['relationship-value']}   ${service_instance_id}
107     \   ${customer_id}=    Set Variable If   '${r['relationship-key']}' == 'customer.global-customer-id'   ${r['relationship-value']}   ${customer_id}
108     ${invariantUUID}=   Get Persona Model Id     ${service_instance_id}    ${service}    ${customer_id}
109
110     # We still need the vf module names. We can get them from VID using the persona_model_id (invariantUUID) from A&AI
111     Setup Browser
112     Login To VID GUI
113     ${vf_modules}=   Get Module Names from VID    ${invariantUUID}
114     Log    ${generic_vnf}
115     Log   ${service_instance_id},${vnf_name},${vnf_type},${vf_module_name},${vf_modules},${service}
116     Preload Vnf    ${service_instance_id}   ${vnf_name}   ${vnf_type}   ${vf_module_name}    ${vf_modules}    ${vnf}    demo    ${service}
117     [Teardown]    Close All Browsers
118
119 Preload User Model GRA
120     [Documentation]   Preload the demo data for the passed VNF with the passed module name via GRA
121     [Arguments]   ${vnf_name}   ${vf_module_name}   ${service}    ${service_instance_id}    ${vnf}=${service}
122     # Go to A&AI and get information about the VNF we need to preload
123     ${status}  ${generic_vnf}=   Run Keyword And Ignore Error   Get Service Instance    ${vnf_name}
124     Run Keyword If   '${status}' == 'FAIL'   FAIL   VNF Name: ${vnf_name} is not found.
125     ${vnf_type}=   Set Variable   ${generic_vnf['vnf-type']}
126     ${relationships}=   Set Variable   ${generic_vnf['relationship-list']['relationship']}
127     ${relationship_data}=    Get Relationship Data   ${relationships}
128     ${customer_id}=   Catenate
129     :FOR    ${r}   IN   @{relationship_data}
130     \   ${service}=   Set Variable If    '${r['relationship-key']}' == 'service-subscription.service-type'   ${r['relationship-value']}    ${service}
131     \   ${service_instance_id}=   Set Variable If    '${r['relationship-key']}' == 'service-instance.service-instance-id'   ${r['relationship-value']}   ${service_instance_id}
132     \   ${customer_id}=    Set Variable If   '${r['relationship-key']}' == 'customer.global-customer-id'   ${r['relationship-value']}   ${customer_id}
133     ${invariantUUID}=   Get Persona Model Id     ${service_instance_id}    ${service}    ${customer_id}
134
135     # We still need the vf module names. We can get them from VID using the persona_model_id (invariantUUID) from A&AI
136     Setup Browser
137     Login To VID GUI
138     ${vf_modules}=   Get Module Names from VID    ${invariantUUID}
139     Log    ${generic_vnf}
140     Log   ${service_instance_id},${vnf_name},${vnf_type},${vf_module_name},${vf_modules},${service}
141     Preload Gra    ${service_instance_id}   ${vnf_name}   ${vnf_type}   ${vf_module_name}    ${vf_modules}  ${vnf}   demo   ${service}
142     [Teardown]    Close All Browsers
143
144
145 Get Relationship Data
146     [Arguments]   ${relationships}
147     :FOR    ${r}   IN   @{relationships}
148     \     ${status}   ${relationship_data}   Run Keyword And Ignore Error    Set Variable   ${r['relationship-data']}
149     \     Return From Keyword If    '${status}' == 'PASS'   ${relationship_data}
150
151
152 Get Generic VNF By ID
153     [Arguments]   ${vnf_id}
154     ${resp}=    AAI.Run Get Request    ${AAI_FRONTEND_ENDPOINT}    ${AAI_INDEX PATH}/network/generic-vnfs/generic-vnf?vnf-id=${vnf_id}    auth=${GLOBAL_AAI_AUTHENTICATION}
155     Should Be Equal As Strings  ${resp.status_code}     200
156     [Return]   ${resp.json()}
157
158 Get Service Instance
159     [Arguments]   ${vnf_name}
160     ${resp}=    AAI.Run Get Request    ${AAI_FRONTEND_ENDPOINT}    ${AAI_INDEX PATH}/network/generic-vnfs/generic-vnf?vnf-name=${vnf_name}    auth=${GLOBAL_AAI_AUTHENTICATION}
161     Should Be Equal As Strings  ${resp.status_code}     200
162     [Return]   ${resp.json()}
163
164 Get Persona Model Id
165     [Documentation]    Query and Validates A&AI Service Instance
166     [Arguments]    ${service_instance_id}    ${service_type}   ${customer_id}
167     ${resp}=    AAI.Run Get Request    ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}${CUSTOMER SPEC PATH}${customer_id}${SERVICE SUBSCRIPTIONS}${service_type}${SERVICE INSTANCE}${service_instance_id}    auth=${GLOBAL_AAI_AUTHENTICATION}
168     ${persona_model_id}=   Get From DIctionary   ${resp.json()['service-instance'][0]}    model-invariant-id
169     [Return]   ${persona_model_id}
170
171 Instantiate VNF
172     [Arguments]   ${service}   ${vf_module_label}=NULL
173     ${tenant_id}    ${tenant_name}=    Setup Orchestrate VNF    ${GLOBAL_AAI_CLOUD_OWNER}    SharedNode    OwnerType    v1    CloudZone
174     ${uuid}=    Generate UUID4
175     ${vf_module_name_list}   ${generic_vnfs}    ${server_id}    ${service_instance_id}    ${catalog_resource_ids}   ${catalog_service_id}    ${uris_to_delete}=    Orchestrate VNF    DemoCust_${uuid}    ${service}   ${service}    ${tenant_id}    ${tenant_name}
176     ${stack_name} =     Get From List   ${vf_module_name_list}  -1
177     Save For Delete    ${tenant_id}    ${tenant_name}    ${server_id}    DemoCust_${uuid}    ${service_instance_id}    ${stack_name}    ${catalog_service_id}    ${catalog_resource_ids}
178     :FOR  ${vf_module_name}  IN   @{vf_module_name_list}
179     \   Log   VNF Module Name=${vf_module_name}
180     # Don't get from SO for now due to SO-1186
181     # ${model_invariant_id}=  Run SO Get ModelInvariantId   ${suite_service_model_name}  ${vf_module_label}
182     ${model_invariant_id}=   Set Variable   ${EMPTY}
183     :FOR    ${vf_module}    IN    @{generic_vnfs}
184     \    ${generic_vnf}=    Get From Dictionary    ${generic_vnfs}    ${vf_module}
185     \    ${model_invariant_id}=    Set Variable If    '${vf_module_label}' in '${vf_module}'   ${generic_vnf['model-invariant-id']}    ${model_invariant_id}
186     Log   Update old vFWCL Policy for ModelInvariantID=${model_invariant_id}
187     ${status}   ${value}=   Run Keyword And Ignore Error  Update vFWCL Operational and Monitoring Policies    ${model_invariant_id}
188     Log   Update Tca ControlLoopName
189     Update Tca ControlLoopName    ${model_invariant_id}
190
191 Instantiate VNF CDS
192     [Arguments]   ${service}   ${vf_module_label}=NULL
193     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vLB_CDS   demoVLB_CDS  True
194     ${resp}=  Get Service Catalog  demoVLB_CDS
195     ${service-uuid}=     Set Variable    ${resp['uuid']}
196     ${service-invariantUUID}=     Set Variable    ${resp['invariantUUID']}
197     ${requestid}=   CDS Service Instantiate  demoVLB_CDS  ${service-uuid}  ${service-invariantUUID}
198     ${auth}=  Create List  ${GLOBAL_SO_CATDB_USERNAME }  ${GLOBAL_SO_PASSWORD}
199     SO.Run Polling Get Request  ${GLOBAL_SO_APIHAND_ENDPOINT}  ${GLOBAL_SO_ORCHESTRATION_REQUESTS_PATH}/${requestid}  tries=30   interval=60  auth=${auth}
200
201 Instantiate Demo VNF
202     [Arguments]   ${service}   ${vf_module_label}=NULL
203     ${tenant_id}    ${tenant_name}=    Setup Orchestrate VNF    ${GLOBAL_AAI_CLOUD_OWNER}    SharedNode    OwnerType    v1    CloudZone
204     ${vf_module_name}    ${service}    ${generic_vnfs}=   Orchestrate Demo VNF    Demonstration    ${service}   ${service}    ${tenant_id}    ${tenant_name}
205     Log   VNF Module Name=${vf_module_name}
206     # Don't get from SO for now due to SO-1186
207     # ${model_invariant_id}=  Run SO Get ModelInvariantId   ${suite_service_model_name}  ${vf_module_label}
208     ${model_invariant_id}=   Set Variable   ${EMPTY}
209     :FOR    ${vf_module}    IN    @{generic_vnfs}
210     \    ${generic_vnf}=    Get From Dictionary    ${generic_vnfs}    ${vf_module}
211     \    ${model_invariant_id}=    Set Variable If    '${vf_module_label}' in '${vf_module}'   ${generic_vnf['model-invariant-id']}    ${model_invariant_id}
212     Log   ModelInvariantID=${model_invariant_id}
213     ${status}   ${value}=   Run Keyword And Ignore Error  Update vFWCL Operational and Monitoring Policies    ${model_invariant_id}
214
215 Save For Delete
216     [Documentation]   Create a variable file to be loaded for save for delete
217     [Arguments]    ${tenant_id}    ${tenant_name}    ${vvg_server_id}    ${customer_name}    ${service_instance_id}    ${stack_name}    ${catalog_service_id}    ${catalog_resource_ids}
218     ${dict}=    Create Dictionary
219     Set To Dictionary   ${dict}   TENANT_NAME=${tenant_name}
220     Set To Dictionary   ${dict}   TENANT_ID=${tenant_id}
221     Set To Dictionary   ${dict}   CUSTOMER_NAME=${customer_name}
222     Set To Dictionary   ${dict}   STACK_NAME=${stack_name}
223     Set To Dictionary   ${dict}   VVG_SERVER_ID=${vvg_server_id}
224     Set To Dictionary   ${dict}   SERVICE_INSTANCE_ID=${service_instance_id}
225     Set To Dictionary   ${dict}   CATALOG_SERVICE_ID=${catalog_service_id}
226
227     ${vars}=    Catenate
228     ${keys}=   Get Dictionary Keys    ${dict}
229     :FOR   ${key}   IN   @{keys}
230     \    ${value}=   Get From Dictionary   ${dict}   ${key}
231     \    ${vars}=   Catenate   ${vars}${key} = "${value}"\n
232
233     ${comma}=   Catenate
234     ${vars}=    Catenate   ${vars}CATALOG_RESOURCE_IDS = [
235     :FOR   ${id}   IN    @{catalog_resource_ids}
236     \    ${vars}=    Catenate  ${vars}${comma} "${id}"
237     \    ${comma}=   Catenate   ,
238     ${vars}=    Catenate  ${vars}]\n
239     OperatingSystem.Create File   ${FILE_CACHE}/${stack_name}.py   ${vars}
240     OperatingSystem.Create File   ${FILE_CACHE}/lastVNF4HEATBRIGE.py   ${vars}