upgrade to python3 libraries
[testsuite.git] / robot / resources / test_templates / vnf_orchestration_with_cds_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 Resource        ../global_properties.robot
21 Resource        ../json_templater.robot
22 Resource        ../so_interface.robot
23
24 Library         OpenstackLibrary
25 Library         UUID
26 Library         Collections
27 Library         String
28 Library         JSONUtils
29
30 Library         RequestsLibrary
31 Library    OperatingSystem
32 Library    HEATUtils
33 Library    StringTemplater
34 Library    Collections
35
36 *** Variables ***
37 ${service_template}    robot/assets/cds/service-Vfirewall0911-template.yml
38 ${env}      robot/assets/cds/env.yml
39 ${so_request_template}    robot/assets/cds/template_so_request.json    
40 ${vnf_template_name}    robot/assets/cds/template_vnf.json
41 ${vfmodule_template_name}       robot/assets/cds/template_vfmodule.json
42 ${so_uri_path}          /onap/so/infra/serviceInstantiation/v7/serviceInstances
43 *** Variables ***
44
45 #**************** TEST CASE VARIABLES **************************
46 ${TENANT_NAME}
47 ${TENANT_ID}
48 ${REGIONS}
49 ${CUSTOMER_NAME}
50 ${STACK_NAME}
51 ${STACK_NAMES}
52 ${SERVICE}
53 ${VVG_SERVER_ID}
54 ${SERVICE_INSTANCE_ID}
55
56 *** Keywords ***
57 Orchestrate VNF With CDS Template
58     [Documentation]   Use openECOMP to Orchestrate a service.
59     [Arguments]    ${customer_name}    ${service}    ${product_family}    ${tenant}
60     Orchestrate VNF With CDS    ${customer_name}    ${service}    ${product_family}    ${tenant}
61
62 Orchestrate VNF With CDS
63     [Documentation]   Use openECOMP to Orchestrate a service.
64     [Arguments]    ${customer_name}    ${service}    ${product_family}    ${tenant}     ${project_name}=Project-Demonstration   ${owning_entity}=OE-Demonstration
65     ${lcp_region}=   Get Openstack Region
66     ${uuid}=    Generate UUID
67     Set Test Variable    ${CUSTOMER_NAME}    ${customer_name}_${uuid}
68     Set Test Variable    ${SERVICE}    ${service}
69     ${list}=    Create List
70     Set Test Variable    ${STACK_NAMES}   ${list}
71     ${service_instance_name}=    Catenate    Service_Ete_Name${uuid}
72     ${dict}=  Create Dictionary
73     Set To Dictionary   ${dict}   service_instance_name=${service_instance_name}
74
75     ${templatedata}=    Template Yaml To Json    ${service_template}
76     ${jsondata}=     Evaluate     json.loads('''${templatedata}''')      json
77     Set To Dictionary   ${dict}   service_type=${jsondata['metadata']['type']}
78     Set To Dictionary   ${dict}   service_model_name=${jsondata['metadata']['name']}
79     Set To Dictionary   ${dict}   service_model_UUID=${jsondata['metadata']['UUID']}
80     Set To Dictionary   ${dict}   service_model_invariantUUID=${jsondata['metadata']['invariantUUID']}
81     
82     ${envdata}=    Env Yaml To Json    ${env}
83     ${envjson}=    Evaluate     json.loads('''${envdata}''')      json
84     Set To Dictionary   ${dict}   subscriber_id=${envjson['subscriber_id']}
85     Set To Dictionary   ${dict}   subscription_service_type=${envjson['subscription_service_type']}
86     Set To Dictionary   ${dict}   cloud_region=${envjson['cloud_region']}
87     Set To Dictionary   ${dict}   tenant_id=${envjson['tenant_id']}
88
89     ${list}=    Create List
90     ${vnfs}=   Get From Dictionary    ${jsondata['topology_template']}   node_templates
91     ${keys}=   Get Dictionary Keys    ${vnfs}
92     :FOR   ${key}  IN  @{keys}
93     \    ${vnf}=   Get From Dictionary    ${vnfs}   ${key}
94     \    Get VNF Info   ${key}  ${vnf}  ${dict}
95     \    ${vf_modules}=    Get From Dictionary   ${jsondata['topology_template']}    groups
96     \    ${value}=      Evaluate        "${key}".replace("-","").replace(" ","")
97     \    ${value}=      Convert To Lowercase    ${value}
98     \    ${vfmodules}=  Get VFModule Info        ${jsondata}    ${value}          ${dict}
99     \    Set To Dictionary      ${dict}   vf_modules=${vfmodules}
100     \    ${vnf_template}=       OperatingSystem.Get File    ${vnf_template_name}
101     \    ${vnf_payload}=        Template String         ${vnf_template}         ${dict}
102     \    ${data}=       Catenate        [${vnf_payload}]
103    
104     Set To Dictionary           ${dict}         vnfs=${data}
105     ${resp}=    OperatingSystem.Get File    ${so_request_template}
106     ${request}=     Template String    ${resp}    ${dict}
107     Log To Console     --------request--------
108     Log to console     ${request}
109     Log To Console     --------end request--------
110     ${resp}=    Run MSO Post Request    ${so_uri_path}          ${request}
111     Log To Console      --------response-------
112     ${json_string}=    Evaluate    json.dumps(${resp.json()})    json
113     Log To Console      ${json_string}
114     Log To Console    instanceId=${resp.json()['requestReferences']['instanceId']}
115     ${requestId}=    Catenate    ${resp.json()['requestReferences']['requestId']}
116     Log To Console    requestId=${requestId}
117     Log To Console      -------end response-------
118     # Poll MSO Get Request    ${GLOBAL_MSO_STATUS_PATH}${request_id}   COMPLETE
119
120
121 Get VNF Info
122     [Documentation]     Get VNF Info
123     [Arguments]         ${vnf_name}     ${vnfjson}      ${dict}
124     ${metadata}=        Get From Dictionary     ${vnfjson}      metadata
125     Set To Dictionary   ${dict}   vnf_name=${vnf_name}
126     Set To Dictionary   ${dict}   vnf_model_name=${metadata['name']}
127     Set To Dictionary   ${dict}   vnf_model_version_id=${metadata['UUID']}
128     Set To Dictionary   ${dict}   vnf_model_customization_name=${metadata['name']}
129     Set To Dictionary   ${dict}   vnf_model_customization_id=${metadata['customizationUUID']}
130         
131
132 Get VFModule Info
133     [Documentation]   Dig the vf module names from the VID service model
134     [Arguments]   ${jsondata}   ${vnf}   ${dict}
135     ${vfModules}=   Get From Dictionary    ${jsondata['topology_template']}   groups
136     ${keys}=   Get Dictionary Keys    ${vfModules}
137     ${data}=   Catenate
138     ${delim}=   Catenate
139     :FOR   ${key}  IN  @{keys}
140     \    ${module}=   Get From Dictionary    ${vfModules}   ${key}
141     \    Log to console         ${vnf} ${key}
142     \    Run keyword if         "${vnf}" in "${key}"    set vfmodule param      ${key}    ${module}     ${dict}
143     \    ${vfmodule_template}=       OperatingSystem.Get File    ${vfmodule_template_name}
144     \    ${vfmodule_payload}=   Template String         ${vfmodule_template}            ${dict}
145     \    ${data}=       Catenate    ${data}   ${delim}   ${vfmodule_payload}
146     \    ${delim}=      Catenate        ,
147     Log To Console      ${data}
148     [Return]    ${data}
149
150 set vfmodule param
151     [Documentation]    Set vfmodule parameters
152     [Arguments]         ${vfmodule_name}   ${vfmodule}  ${dict}
153     Set To Dictionary   ${dict}   vf_module_model_type=${vfmodule['type']}
154     Set To Dictionary   ${dict}   vf_module_model_name=${vfmodule['metadata']['vfModuleModelName']}
155     Set To Dictionary   ${dict}   vf_module_model_version_id=${vfmodule['metadata']['vfModuleModelUUID']}
156     Set To Dictionary   ${dict}   vf_module_model_customization_id=${vfmodule['metadata']['vfModuleModelCustomizationUUID']}
157     Set To Dictionary   ${dict}   vf_module_name=${vfmodule_name}
158