move the main so interface to use onaplibrary
[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        asdc_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
13 Library         ONAPLibrary.Utilities
14 Library         Collections
15 Library         OperatingSystem
16 Library         SeleniumLibrary
17 Library         RequestsLibrary
18 Library         ONAPLibrary.Templating    WITH NAME    Templating
19 Library         ONAPLibrary.AAI    WITH NAME    AAI
20
21 *** Variables ***
22
23 ${ADD_DEMO_CUSTOMER_BODY}   aai/add_demo_customer.jinja
24 ${AAI_INDEX_PATH}     /aai/v8
25 ${VF_MODULES_NAME}     _Demo_VFModules.json
26 ${FILE_CACHE}    /share/
27 ${DEMO_PREFIX}   demo
28 ${VPKG_MODULE_LABEL}    base_vpkg
29
30
31 *** Keywords ***
32 Load Customer And Models
33     [Documentation]   Use openECOMP to Orchestrate a service.
34     [Arguments]    ${customer_name}
35     Load OwningEntity  lineOfBusiness  LOB-${customer_name}
36     Load OwningEntity  platform  Platform-${customer_name}
37     Load OwningEntity  project  Project-${customer_name}
38     Load OwningEntity  owningEntity  OE-${customer_name}
39     Load Customer  ${customer_name}
40     Load Models  ${customer_name}
41
42 Load OwningEntity
43     [Documentation]   Use openECOMP to Orchestrate a service.
44     [Arguments]    ${parameter}   ${name}
45     ${data_path}=  Set Variable  /maintenance/category_parameter/${parameter}
46     ${vid_data}=  Set Variable  {"options":["${name}"]}
47     ${auth}=  Create List  ${GLOBAL_VID_USERNAME}    ${GLOBAL_VID_PASSWORD}
48     Log    Creating session ${data_path}
49     ${session}=    Create Session       vid    ${VID_ENDPOINT}${VID_ENV}     auth=${auth}
50     ${uuid}=    Generate UUID4
51     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    USER_ID=${GLOBAL_VID_USERNAME}    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
52     ${resp}=    Post Request    vid     ${data_path}   data=${vid_data}    headers=${headers}
53         
54 Load Customer
55     [Documentation]   Use openECOMP to Orchestrate a service.
56     [Arguments]    ${customer_name}
57     ${tenant_id}    ${tenant_name}=    Setup Orchestrate VNF   ${GLOBAL_AAI_CLOUD_OWNER}   SharedNode    OwnerType    v1    CloudZone
58     ${region}=   Get Openstack Region
59     Create Customer For VNF Demo    ${customer_name}    ${customer_name}    INFRA    ${GLOBAL_AAI_CLOUD_OWNER}    ${region}   ${tenant_id}
60     Create Customer For VNF Demo    ${customer_name}    ${customer_name}    INFRA    ${GLOBAL_AAI_CLOUD_OWNER}    RegionTlab  50b190410b2a4c229d8a6044a80ab7c1 
61     Create Availability Zone If Not Exists    ${GLOBAL_AAI_CLOUD_OWNER}    ${region}   ${GLOBAL_AAI_AVAILABILITY_ZONE_NAME}
62
63 Load Models
64     [Documentation]   Use openECOMP to Orchestrate a service.
65     [Arguments]    ${customer_name}
66     Log   ${\n}Distributing vFWCL
67     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vFWCL   ${DEMO_PREFIX}VFWCL
68     Log   Distibuting vLB
69     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vLB   ${DEMO_PREFIX}VLB
70     ##${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vCPE   ${DEMO_PREFIX}VCPE
71     ##${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vIMS   ${DEMO_PREFIX}VIMS
72     Log   Distibuting vCPEInfra
73     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vCPEInfra   ${DEMO_PREFIX}VCPEInfra
74     Log   Distibuting vCPEvBNG
75     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vCPEvBNG   ${DEMO_PREFIX}VCPEvBNG
76     Log   Distibuting vCPEvBRGEMU
77     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vCPEvBRGEMU   ${DEMO_PREFIX}VCPEvBRGEMU 
78     Log   Distibuting vCPEvGMUX
79     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vCPEvGMUX    ${DEMO_PREFIX}VCPEvGMUX
80     Log   Distibuting vCPEvGW (this is not vCPEResCust service)
81     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vCPEvGW    ${DEMO_PREFIX}VCPEvGW
82
83 Distribute Model
84     [Arguments]   ${service}   ${modelName}
85     Model Distribution For Directory    ${service}   ${modelName}
86
87 Distribute vCPEResCust Model
88     [Arguments]   ${service}   ${modelName}
89     Model Distribution For vCPEResCust Directory    ${service}   ${modelName}
90
91 Create Customer For VNF Demo
92     [Documentation]    Create demo customer for the demo
93     [Arguments]    ${customer_name}   ${customer_id}   ${customer_type}    ${clouder_owner}    ${cloud_region_id}    ${tenant_id}
94     Create Service If Not Exists    vFW
95     Create Service If Not Exists    vFWCL
96     Create Service If Not Exists    vLB
97     Create Service If Not Exists    vCPE
98     Create Service If Not Exists    vIMS
99     Create Service If Not Exists    gNB
100     ${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}
101     Set To Dictionary   ${arguments}       service1=vFWCL       service2=vLB   service3=vCPE   service4=vIMS  service5=gNB   service6=vFW
102     Templating.Create Environment    aai    ${GLOBAL_TEMPLATE_FOLDER}
103     ${data}=   Templating.Apply Template    aai   ${ADD_DEMO_CUSTOMER_BODY}    ${arguments}
104     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
105     ${put_resp}=    AAI.Run Put Request     ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}${ROOT_CUSTOMER_PATH}${customer_id}    ${data}    auth=${auth}
106     ${status_string}=    Convert To String    ${put_resp.status_code}
107     Should Match Regexp    ${status_string}    ^(200|201|412)$
108
109 Preload User Model
110     [Documentation]   Preload the demo data for the passed VNF with the passed module name
111     [Arguments]   ${vnf_name}   ${vf_module_name}    ${service}    ${service_instance_id}
112     # Go to A&AI and get information about the VNF we need to preload
113     ${status}  ${generic_vnf}=   Run Keyword And Ignore Error   Get Service Instance    ${vnf_name}
114     Run Keyword If   '${status}' == 'FAIL'   FAIL   VNF Name: ${vnf_name} is not found.
115     ${vnf_type}=   Set Variable   ${generic_vnf['vnf-type']}
116     ${relationships}=   Set Variable   ${generic_vnf['relationship-list']['relationship']}
117     ${relationship_data}=    Get Relationship Data   ${relationships}
118     ${customer_id}=   Catenate
119     :FOR    ${r}   IN   @{relationship_data}
120     \   ${service}=   Set Variable If    '${r['relationship-key']}' == 'service-subscription.service-type'   ${r['relationship-value']}    ${service}
121     \   ${service_instance_id}=   Set Variable If    '${r['relationship-key']}' == 'service-instance.service-instance-id'   ${r['relationship-value']}   ${service_instance_id}
122     \   ${customer_id}=    Set Variable If   '${r['relationship-key']}' == 'customer.global-customer-id'   ${r['relationship-value']}   ${customer_id}
123     ${invariantUUID}=   Get Persona Model Id     ${service_instance_id}    ${service}    ${customer_id}
124
125     # We still need the vf module names. We can get them from VID using the persona_model_id (invariantUUID) from A&AI
126     Setup Browser
127     Login To VID GUI
128     ${vf_modules}=   Get Module Names from VID    ${invariantUUID}
129     Log    ${generic_vnf}
130     Log   ${service_instance_id},${vnf_name},${vnf_type},${vf_module_name},${vf_modules},${service}
131     Preload Vnf    ${service_instance_id}   ${vnf_name}   ${vnf_type}   ${vf_module_name}    ${vf_modules}    ${service}    demo
132     [Teardown]    Close All Browsers
133
134
135 Get Relationship Data
136     [Arguments]   ${relationships}
137     :FOR    ${r}   IN   @{relationships}
138     \     ${status}   ${relationship_data}   Run Keyword And Ignore Error    Set Variable   ${r['relationship-data']}
139     \     Return From Keyword If    '${status}' == 'PASS'   ${relationship_data}
140
141
142 Get Generic VNF By ID
143     [Arguments]   ${vnf_id}
144     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
145     ${resp}=    AAI.Run Get Request    ${AAI_FRONTEND_ENDPOINT}    ${AAI_INDEX PATH}/network/generic-vnfs/generic-vnf?vnf-id=${vnf_id}    auth=${auth}
146     Should Be Equal As Strings  ${resp.status_code}     200
147     [Return]   ${resp.json()}
148
149 Get Service Instance
150     [Arguments]   ${vnf_name}
151     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
152     ${resp}=    AAI.Run Get Request    ${AAI_FRONTEND_ENDPOINT}    ${AAI_INDEX PATH}/network/generic-vnfs/generic-vnf?vnf-name=${vnf_name}    auth=${auth}
153     Should Be Equal As Strings  ${resp.status_code}     200
154     [Return]   ${resp.json()}
155
156 Get Persona Model Id
157     [Documentation]    Query and Validates A&AI Service Instance
158     [Arguments]    ${service_instance_id}    ${service_type}   ${customer_id}
159     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
160     ${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=${auth}
161     ${persona_model_id}=   Get From DIctionary   ${resp.json()['service-instance'][0]}    model-invariant-id
162     [Return]   ${persona_model_id}
163
164 APPC Mount Point
165     [Arguments]   ${vf_module_name}
166     Run Openstack Auth Request    auth
167     ${status}   ${stack_info}=   Run Keyword and Ignore Error    Wait for Stack to Be Deployed    auth    ${vf_module_name}   timeout=120s
168     Run Keyword if   '${status}' == 'FAIL'   FAIL   ${vf_module_name} Stack is not found
169     ${stack_id}=    Get From Dictionary    ${stack_info}    id
170     ${server_list}=    Get Openstack Servers    auth
171     ${vpg_name_0}=    Get From Dictionary    ${stack_info}    vpg_name_0
172     ${vnf_id}=    Get From Dictionary    ${stack_info}    vnf_id
173     ${vpg_public_ip}=    Get Server Ip    ${server_list}    ${stack_info}   vpg_name_0    network_name=${GLOBAL_INJECTED_OPENSTACK_PUBLIC_NETWORK}
174     ${appc}=    Create Mount Point In APPC    ${vnf_id}    ${vpg_public_ip}
175
176 Instantiate VNF
177     [Arguments]   ${service}   ${vf_module_label}=NULL
178     ${tenant_id}    ${tenant_name}=    Setup Orchestrate VNF    ${GLOBAL_AAI_CLOUD_OWNER}    SharedNode    OwnerType    v1    CloudZone
179     ${uuid}=    Generate UUID4
180     ${vf_module_name_list}   ${generic_vnfs}    ${server_id}    ${service_instance_id}    ${catalog_resource_ids}   ${catalog_service_id}=    Orchestrate VNF    DemoCust_${uuid}    ${service}   ${service}    ${tenant_id}    ${tenant_name}
181     ${stack_name} =     Get From List   ${vf_module_name_list}  -1
182     Save For Delete    ${tenant_id}    ${tenant_name}    ${server_id}    DemoCust_${uuid}    ${service_instance_id}    ${stack_name}    ${catalog_service_id}    ${catalog_resource_ids}
183     :FOR  ${vf_module_name}  IN   @{vf_module_name_list}
184     \   Log   VNF Module Name=${vf_module_name}
185     # Don't get from MSO for now due to SO-1186
186     # ${model_invariant_id}=  Run MSO Get ModelInvariantId   ${suite_service_model_name}  ${vf_module_label}
187     ${model_invariant_id}=   Set Variable   ${EMPTY}
188     :FOR    ${vf_module}    IN    @{generic_vnfs}
189     \    ${generic_vnf}=    Get From Dictionary    ${generic_vnfs}    ${vf_module}
190     \    ${model_invariant_id}=    Set Variable If    '${vf_module_label}' in '${vf_module}'   ${generic_vnf['model-invariant-id']}    ${model_invariant_id}
191     Log   Update old vFWCL Policy for ModelInvariantID=${model_invariant_id}
192     ${status}   ${value}=   Run Keyword And Ignore Error  Update vVFWCL Policy   ${model_invariant_id}
193     :FOR  ${vf_module_name}  IN   @{vf_module_name_list}
194     \   Log   APPC Mount Point for VNF Module Name=${vf_module_name}
195     \   ${status}   ${value}=   Run Keyword And Ignore Error  APPC Mount Point    ${vf_module_name}
196     Log   Update Tca ControlLoopName
197     Update Tca ControlLoopName    ${model_invariant_id}
198
199 Instantiate Demo VNF
200     [Arguments]   ${service}   ${vf_module_label}=NULL
201     ${tenant_id}    ${tenant_name}=    Setup Orchestrate VNF    ${GLOBAL_AAI_CLOUD_OWNER}    SharedNode    OwnerType    v1    CloudZone
202     ${vf_module_name}    ${service}    ${generic_vnfs}=   Orchestrate Demo VNF    Demonstration    ${service}   ${service}    ${tenant_id}    ${tenant_name}
203     Log   VNF Module Name=${vf_module_name}
204     # Don't get from MSO for now due to SO-1186
205     # ${model_invariant_id}=  Run MSO Get ModelInvariantId   ${suite_service_model_name}  ${vf_module_label}
206     ${model_invariant_id}=   Set Variable   ${EMPTY}
207     :FOR    ${vf_module}    IN    @{generic_vnfs}
208     \    ${generic_vnf}=    Get From Dictionary    ${generic_vnfs}    ${vf_module}
209     \    ${model_invariant_id}=    Set Variable If    '${vf_module_label}' in '${vf_module}'   ${generic_vnf['model-invariant-id']}    ${model_invariant_id}
210     Log   ModelInvariantID=${model_invariant_id}
211     ${status}   ${value}=   Run Keyword And Ignore Error  Update vVFWCL Policy   ${model_invariant_id}
212     ${status}   ${value}=   Run Keyword And Ignore Error  APPC Mount Point    ${vf_module_name}
213
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}
241
242