onap on kubernetes source files
[oom.git] / kubernetes / config / docker / init / src / config / robot / 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/vnf_orchestration_test_template.robot
6 Resource        asdc_interface.robot
7
8 Library         UUID
9 Library         Collections
10 Library         OperatingSystem
11 Library         HttpLibrary.HTTP
12 Library         ExtendedSelenium2Library
13 Library         RequestsLibrary
14
15 *** Variables ***
16
17 ${ADD_DEMO_CUSTOMER_BODY}   robot/assets/templates/aai/add_demo_customer.template
18 ${AAI_INDEX_PATH}     /aai/v8
19 ${VF_MODULES_NAME}     _Demo_VFModules.json
20 ${FILE_CACHE}    /share/
21
22 *** Keywords ***
23 Load Customer And Models
24     [Documentation]   Use openECOMP to Orchestrate a service.
25     [Arguments]    ${customer_name}
26     Load Customer  ${customer_name}
27     Load Models  ${customer_name}
28
29 Load Customer
30     [Documentation]   Use openECOMP to Orchestrate a service.
31     [Arguments]    ${customer_name}
32     Setup Orchestrate VNF   ${GLOBAL_AAI_CLOUD_OWNER}   SharedNode    OwnerType    v1    CloudZone
33     Set Test Variable    ${CUSTOMER_NAME}    ${customer_name}
34     ${region}=   Get Openstack Region
35     Create Customer For VNF Demo    ${CUSTOMER_NAME}    ${CUSTOMER_NAME}    INFRA    ${GLOBAL_AAI_CLOUD_OWNER}    ${region}   ${TENANT_ID}
36
37 Load Models
38     [Documentation]   Use openECOMP to Orchestrate a service.
39     [Arguments]    ${customer_name}
40     Set Test Variable    ${CUSTOMER_NAME}    ${customer_name}
41     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vFW   demoVFW
42     ${status}   ${value}=   Run Keyword And Ignore Error   Distribute Model   vLB   demoVLB
43
44 Distribute Model
45     [Arguments]   ${service}   ${modelName}
46     ${service_model_type}     ${vnf_type}    ${vf_modules}=   Model Distribution For Directory    ${service}   ${modelName}
47
48 Create Customer For VNF Demo
49     [Documentation]    Create demo customer for the demo
50     [Arguments]    ${customer_name}   ${customer_id}   ${customer_type}    ${clouder_owner}    ${cloud_region_id}    ${tenant_id}
51     ${data_template}=    OperatingSystem.Get File    ${ADD_DEMO_CUSTOMER_BODY}
52     ${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}
53     Set To Dictionary   ${arguments}       service1=vFW       service2=vLB
54     ${data}=    Fill JSON Template    ${data_template}    ${arguments}
55         ${put_resp}=    Run A&AI Put Request     ${INDEX PATH}${ROOT_CUSTOMER_PATH}${customer_id}    ${data}
56     ${status_string}=    Convert To String    ${put_resp.status_code}
57     Should Match Regexp    ${status_string}    ^(201|412)$
58     Create Service If Not Exists    vFW
59     Create Service If Not Exists    vLB
60
61 Preload User Model
62     [Documentation]   Preload the demo data for the passed VNF with the passed module name
63     [Arguments]   ${vnf_name}   ${vf_module_name}
64     # Go to A&AI and get information about the VNF we need to preload
65     ${status}  ${generic_vnf}=   Run Keyword And Ignore Error   Get Service Instance    ${vnf_name}
66     Run Keyword If   '${status}' == 'FAIL'   FAIL   VNF Name: ${vnf_name} is not found.
67     ${vnf_type}=   Set Variable   ${generic_vnf['vnf-type']}
68     ${relationships}=   Set Variable   ${generic_vnf['relationship-list']['relationship']}
69     ${relationship_data}=    Get Relationship Data   ${relationships}
70     ${customer_id}=   Catenate
71     :for    ${r}   in   @{relationship_data}
72     \   ${service}=   Set Variable If    '${r['relationship-key']}' == 'service-subscription.service-type'   ${r['relationship-value']}    ${service}
73     \   ${service_instance_id}=   Set Variable If    '${r['relationship-key']}' == 'service-instance.service-instance-id'   ${r['relationship-value']}   ${service_instance_id}
74     \   ${customer_id}=    Set Variable If   '${r['relationship-key']}' == 'customer.global-customer-id'   ${r['relationship-value']}   ${customer_id}
75     ${invariantUUID}=   Get Persona Model Id     ${service_instance_id}    ${service}    ${customer_id}
76
77     # We still need the vf module names. We can get them from VID using the persona_model_id (invariantUUID) from A&AI
78     Setup Browser
79     Login To VID GUI
80     ${vf_modules}=   Get Module Names from VID    ${invariantUUID}
81     Log    ${generic_vnf}
82     Log   ${service_instance_id},${vnf_name},${vnf_type},${vf_module_name},${vf_modules},${service}
83     Preload Vnf    ${service_instance_id}   ${vnf_name}   ${vnf_type}   ${vf_module_name}    ${vf_modules}    ${service}    demo
84     [Teardown]    Close All Browsers
85
86
87 Get Relationship Data
88     [Arguments]   ${relationships}
89     :for    ${r}   in   @{relationships}
90     \     ${status}   ${relationship_data}   Run Keyword And Ignore Error    Set Variable   ${r['relationship-data']}
91     \     Return From Keyword If    '${status}' == 'PASS'   ${relationship_data}
92
93
94 Get Service Instance
95     [Arguments]   ${vnf_name}
96     ${resp}=    Run A&AI Get Request      ${AAI_INDEX PATH}/network/generic-vnfs/generic-vnf?vnf-name=${vnf_name}
97     Should Be Equal As Strings  ${resp.status_code}     200
98     [Return]   ${resp.json()}
99
100 Get Persona Model Id
101     [Documentation]    Query and Validates A&AI Service Instance
102     [Arguments]    ${service_instance_id}    ${service_type}   ${customer_id}
103         ${resp}=    Run A&AI Get Request      ${INDEX PATH}${CUSTOMER SPEC PATH}${customer_id}${SERVICE SUBSCRIPTIONS}${service_type}${SERVICE INSTANCE}${service_instance_id}
104     ${persona_model_id}=   Get From DIctionary   ${resp.json()['service-instance'][0]}    persona-model-id
105     [Return]   ${persona_model_id}
106
107
108 Get Model UUID from VID
109     [Documentation]    Must use UI since rest call get redirect to portal and get DNS error
110     ...    Search all services and match on the invariantUUID
111     [Arguments]   ${invariantUUID}
112     Go To     ${GLOBAL_VID_SERVER}${VID_ENV}/rest/models/services
113     ${resp}=   Get Text   xpath=//body/pre
114     ${json}=   To Json    ${resp}
115     :for   ${dict}  in  @{json}
116     \    ${uuid}=   Get From DIctionary   ${dict}   uuid
117     \    ${inv}=   Get From DIctionary   ${dict}    invariantUUID
118     \    Return From Keyword If   "${invariantUUID}" == "${inv}"   ${uuid}
119     [Return]    ""
120
121
122 Get Module Names from VID
123     [Documentation]    Must use UI since rest call get redirect to portal and get DNS error
124     ...    Given the invariantUUID of the model, mock up the vf_modules list passed to Preload VNF
125     [Arguments]   ${invariantUUID}
126     ${id}=   Get Model UUID from VID    ${invariantUUID}
127     Go To     ${GLOBAL_VID_SERVER}${VID_ENV}/rest/models/services/${id}
128     ${resp}=   Get Text   xpath=//body/pre
129     ${json}=   To Json    ${resp}
130     ${modules}=   Create List
131     ${vnfs}=   Get From Dictionary    ${json}   vnfs
132     ${keys}=   Get Dictionary Keys    ${vnfs}
133     :for   ${key}  in  @{keys}
134     \    Add VFModule   ${vnfs['${key}']}   ${modules}
135     [Return]    ${modules}
136
137 Add VFModule
138     [Documentation]   Dig the vf module names from the VID service model
139     [Arguments]   ${vnf}   ${modules}
140     ${vfModules}=   Get From Dictionary    ${vnf}   vfModules
141     ${keys}=   Get Dictionary Keys    ${vfModules}
142     :for   ${key}  in  @{keys}
143     \    ${module}=   Get From Dictionary    ${vfModules}   ${key}
144     \    ${dict}=    Create Dictionary   name=${module['name']}
145     \    Append to List   ${modules}   ${dict}
146
147
148
149
150
151
152 APPC Mount Point
153     [Arguments]   ${vf_module_name}
154     Run Openstack Auth Request    auth
155     ${status}   ${stack_info}=   Run Keyword and Ignore Error    Wait for Stack to Be Deployed    auth    ${vf_module_name}   timeout=120s
156     Run Keyword if   '${status}' == 'FAIL'   FAIL   ${vf_module_name} Stack is not found
157     ${stack_id}=    Get From Dictionary    ${stack_info}    id
158     ${server_list}=    Get Openstack Servers    auth
159     ${vpg_name_0}=    Get From Dictionary    ${stack_info}    vpg_name_0
160     ${vpg_public_ip}=    Get Server Ip    ${server_list}    ${stack_info}   vpg_name_0    network_name=public
161     ${vpg_oam_ip}=    Get From Dictionary    ${stack_info}    vpg_private_ip_1
162     ${appc}=    Create Mount Point In APPC    ${vpg_name_0}    ${vpg_oam_ip}
163
164 Instantiate VNF
165     [Arguments]   ${service}
166     Setup Orchestrate VNF    ${GLOBAL_AAI_CLOUD_OWNER}    SharedNode    OwnerType    v1    CloudZone
167     ${vf_module_name}    ${service}=    Orchestrate VNF    DemoCust    ${service}   ${service}    ${TENANT_NAME}
168     Save For Delete
169     Log to Console   Customer Name=${CUSTOMER_NAME}
170     Log to Console   VNF Module Name=${vf_module_name}
171
172 Save For Delete
173     [Documentation]   Create a variable file to be loaded for save for delete
174     ${dict}=    Create Dictionary
175     Set To Dictionary   ${dict}   TENANT_NAME=${TENANT_NAME}
176     Set To Dictionary   ${dict}   TENANT_ID=${TENANT_ID}
177     Set To Dictionary   ${dict}   CUSTOMER_NAME=${CUSTOMER_NAME}
178     Set To Dictionary   ${dict}   STACK_NAME=${STACK_NAME}
179     Set To Dictionary   ${dict}   SERVICE=${SERVICE}
180     Set To Dictionary   ${dict}   VVG_SERVER_ID=${VVG_SERVER_ID}
181     Set To Dictionary   ${dict}   SERVICE_INSTANCE_ID=${SERVICE_INSTANCE_ID}
182
183     Set To Dictionary   ${dict}   VLB_CLOSED_LOOP_DELETE=${VLB_CLOSED_LOOP_DELETE}
184     Set To Dictionary   ${dict}   VLB_CLOSED_LOOP_VNF_ID=${VLB_CLOSED_LOOP_VNF_ID}
185
186     Set To Dictionary   ${dict}   CATALOG_SERVICE_ID=${CATALOG_SERVICE_ID}
187
188     ${vars}=    Catenate
189     ${keys}=   Get Dictionary Keys    ${dict}
190     :for   ${key}   in   @{keys}
191     \    ${value}=   Get From Dictionary   ${dict}   ${key}
192     \    ${vars}=   Catenate   ${vars}${key} = "${value}"\n
193
194     ${comma}=   Catenate
195     ${vars}=    Catenate   ${vars}CATALOG_RESOURCE_IDS = [
196     :for   ${id}   in    @{CATALOG_RESOURCE_IDS}
197     \    ${vars}=    Catenate  ${vars}${comma} "${id}"
198     \    ${comma}=   Catenate   ,
199     ${vars}=    Catenate  ${vars}]\n
200     OperatingSystem.Create File   ${FILE_CACHE}/${STACK_NAME}.py   ${vars}
201
202