4 Library StringTemplater
5 Library OperatingSystem
6 Library ONAPLibrary.ServiceMapping
7 Library ONAPLibrary.Templating
9 Resource openstack/keystone_interface.robot
10 Resource openstack/heat_interface.robot
11 Resource openstack/nova_interface.robot
12 Resource openstack/neutron_interface.robot
13 Resource aai/aai_interface.robot
14 Resource aai/create_vnfc.robot
17 ${MULTIPART_PATH} /bulkadd
18 ${NAMED_QUERY_PATH} /aai/search/named-query
19 ${NAMED_QUERY_TEMPLATE} aai/named_query.jinja
21 ${BASE_URI} /cloud-infrastructure/cloud-regions/cloud-region/\${cloud}/\${region}
22 ${IMAGE_URI} ${BASE_URI}/images/image/\${image_id}
23 ${FLAVOR_URI} ${BASE_URI}/flavors/flavor/\${flavor}
24 ${VSERVER_URI} ${BASE_URI}/tenants/tenant/\${tenant}/vservers/vserver/\${vserver_id}
25 ${L_INTERFACE_URI} ${VSERVER_URI}/l-interfaces/l-interface/\${linterface_id}
26 ${VSERVER_NAME} \${vserver_name}
28 #******************** Test Case Variables ****************
34 [Documentation] Run the Heatbridge against the stack to generate the bulkadd message
35 ... Execute the build add
36 ... Validate the add results by running the named query
37 [Arguments] ${stack_name} ${service_instance_id} ${service} ${ipv4_oam_address}
38 Return From Keyword If '${service}' == 'vVG'
39 Run Openstack Auth Request auth
40 ${stack_info}= Wait for Stack to Be Deployed auth ${stack_name}
41 ${stack_id}= Get From Dictionary ${stack_info} id
42 ${tenant_id}= Get From Dictionary ${stack_info} OS::project_id
43 ${vnf_id}= Get From Dictionary ${stack_info} vnf_id
44 ${KeyIsPresent}= Run Keyword And Return Status Dictionary Should Contain Key ${stack_info} ${ipv4_oam_address}
45 ${ipv4_vnf_address}= Run Keyword If ${KeyIsPresent} Get From Dictionary ${stack_info} ${ipv4_oam_address}
46 Run Set VNF Params ${vnf_id} ${ipv4_vnf_address} ACTIVE Active
47 ### Create a vnfc for each vServer ###
48 ${stack_resources}= Get Stack Resources auth ${stack_name} ${stack_id}
49 ${resource_list}= Get From Dictionary ${stack_resources} resources
50 :FOR ${resource} IN @{resource_list}
51 \ Run Keyword If '${resource['resource_type']}' == 'OS::Nova::Server' Run Create VNFC auth ${resource['physical_resource_id']} ${service}
52 ${keystone_api_version}= Run Keyword If '${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}'=='' Get KeystoneAPIVersion
53 ... ELSE Set Variable ${GLOBAL_INJECTED_OPENSTACK_KEYSTONE_API_VERSION}
54 ${url} ${path}= Get Keystone Url And Path ${keystone_api_version}
55 ${openstack_identity_url}= Catenate ${url}${path}
56 ${region}= Get Openstack Region
57 ${user} ${pass}= Get Openstack Credentials
58 Run Keyword If '${keystone_api_version}'=='v2.0' Init Bridge ${openstack_identity_url} ${user} ${pass} ${tenant_id} ${region} ${GLOBAL_AAI_CLOUD_OWNER}
59 ... ELSE Init Bridge ${openstack_identity_url} ${user} ${pass} ${tenant_id} ${region} ${GLOBAL_AAI_CLOUD_OWNER} ${GLOBAL_INJECTED_OPENSTACK_DOMAIN_ID} ${GLOBAL_INJECTED_OPENSTACK_PROJECT_NAME}
60 ${request}= Bridge Data ${stack_id}
62 ${resp}= Run A&AI Put Request ${VERSIONED_INDEX_PATH}${MULTIPART_PATH} ${request}
63 ${status_string}= Convert To String ${resp.status_code}
64 Should Match Regexp ${status_string} ^(201|200)$
65 ${reverse_heatbridge}= Generate Reverse Heatbridge From Stack Info ${stack_info}
66 Set Test Variable ${REVERSE_HEATBRIDGE} ${reverse_heatbridge}
67 Run Validation Query ${stack_info} ${service} ${vnf_id}
70 [Documentation] Create a VNFC for a vServer
71 [Arguments] ${alias} ${vserver_id} ${service}
72 ${resp}= Get Openstack Server By Id ${alias} ${vserver_id}
73 Return From Keyword If '${resp.status_code}' != '200'
74 ${info}= Set Variable ${resp.json()}
75 ${keys}= Create Dictionary
76 Set To Dictionary ${keys} vserver_name=${info['server']['name']}
77 ${vnfc_name}= Template String ${VSERVER_NAME} ${keys}
78 ${vnfc_nc}= Set Variable ${service}
79 ${vnfc_func}= Set Variable ${service}
80 Create VNFC If Not Exists ${vnfc_name} ${vnfc_nc} ${vnfc_func}
83 [Documentation] Run A&AI query to validate the bulk add
84 [Arguments] ${stack_info} ${service} ${vnf_id}
85 Return from Keyword If '${service}' == ''
86 Set Directory default ./demo/service_mapping
87 ${payload}= Run Get Generic VNF by VnfId ${vnf_id}
88 ${vnf_type}= Catenate ${payload.json()[vnf-type]}
89 ${server_name_parameter}= Get Validate Name Mapping default ${service} ${vnf_type}
90 ${vserver_name}= Get From Dictionary ${stack_info} ${server_name_parameter}
91 Run Vserver Query ${vserver_name}
94 [Documentation] Run A&AI query to validate the bulk add
95 [Arguments] ${vserver_name}
96 ${dict}= Create Dictionary vserver_name=${vserver_name}
97 Create Environment aai ${GLOBAL_TEMPLATE_FOLDER}
98 ${request}= Apply Template aai ${NAMED_QUERY_TEMPLATE} ${dict}
99 ${resp}= Run A&AI Post Request ${NAMED_QUERY_PATH} ${request}
100 Should Be Equal As Strings ${resp.status_code} 200
104 [Documentation] Run A&A GET and PUT to set prov-status, orchestration status, and ipv4-oam-address
105 [Arguments] ${vnf_id} ${ipv4_vnf_address} ${prov_status}=ACTIVE ${orch_status}=Active
106 ${payload}= Run Get Generic VNF by VnfId ${vnf_id}
107 ${vnf_type}= Catenate ${payload.json()[vnf-type]}
108 #${payload_json}= evaluate json.loads('''${payload}''') json
109 set to dictionary ${payload} vnf-type ${prov_status}
110 set to dictionary ${payload} orchestration-status ${orch_status}
111 set to dictionary ${payload} ipv4-oam-address ${ipv4_vnf_address}
112 ${payload_string}= evaluate json.dumps(${payload}) json
114 ${put_resp}= Run A&AI Put Request ${VERSIONED_INDEX_PATH}/network/generic-vnfs/generic-vnf/${vnf_id} ${payload_string}
115 ${status_string}= Convert To String ${put_resp.status_code}
116 Should Match Regexp ${status_string} ^(200|201)$
117 Log To Console Set VNF ProvStatus: ${vnf_id} to ${prov_status}
119 Run Get Generic VNF By VnfId
120 [Documentation] Get VNF GET Payload with resource ID
121 [Arguments] ${vnf_id}
122 ${resp}= Run A&AI Get Request ${VERSIONED_INDEX_PATH}/network/generic-vnfs/generic-vnf?vnf-id=${vnf_id}
123 Should Be Equal As Strings ${resp.status_code} 200
124 [Return] ${resp.json()}
126 Execute Reverse Heatbridge
127 [Documentation] VID has already torn down the stack, reverse HB
128 Return From Keyword If len(${REVERSE_HEATBRIDGE}) == 0
129 :FOR ${uri} IN @{REVERSE_HEATBRIDGE}
130 \ Run Keyword And Ignore Error Delete A&AI Entity ${uri}
132 Generate Reverse Heatbridge From Stack Name
133 [Arguments] ${stack_name}
134 Run Openstack Auth Request auth
135 ${stack_info}= Wait for Stack to Be Deployed auth ${stack_name} timeout=10s
136 ${reverse_heatbridge}= Generate Reverse Heatbridge From Stack Info ${stack_info}
137 [Return] ${reverse_heatbridge}
139 Generate Reverse Heatbridge From Stack Info
140 [Arguments] ${stack_info}
141 ${reverse_heatbridge}= Create List
142 ${stack_name}= Get From Dictionary ${stack_info} name
143 ${stack_id}= Get From Dictionary ${stack_info} id
144 ${tenant_id}= Get From Dictionary ${stack_info} OS::project_id
145 ${region}= Get Openstack Region
146 ${keys}= Create Dictionary region=${region} cloud=${GLOBAL_AAI_CLOUD_OWNER} tenant=${tenant_id}
147 ${stack_resources}= Get Stack Resources auth ${stack_name} ${stack_id}
148 ${resource_list}= Get From Dictionary ${stack_resources} resources
149 :FOR ${resource} IN @{resource_list}
151 \ Run Keyword If '${resource['resource_type']}' == 'OS::Neutron::Port' Generate Linterface Uri auth ${resource['physical_resource_id']} ${reverse_heatbridge} ${keys}
152 :FOR ${resource} IN @{resource_list}
154 \ Run Keyword If '${resource['resource_type']}' == 'OS::Nova::Server' Generate Vserver Uri auth ${resource['physical_resource_id']} ${reverse_heatbridge} ${keys} ${resource_list}
155 [Return] ${reverse_heatbridge}
158 [Documentation] Run teardown against the server to generate a message that removes it
159 [Arguments] ${alias} ${port_id} ${reverse_heatbridge} ${keys} ${resource_list}
160 ${resp}= Get Openstack Server By Id ${alias} ${port_id}
161 Return From Keyword If '${resp.status_code}' != '200'
162 ${info}= Set Variable ${resp.json()}
163 Set To Dictionary ${keys} vserver_id=${info['server']['id']}
164 Set To Dictionary ${keys} flavor=${info['server']['flavor']['id']}
165 Set To Dictionary ${keys} image_id=${info['server']['image']['id']}
166 ${uri}= Template String ${VSERVER_URI} ${keys}
167 Append To List ${reverse_heatbridge} ${uri}
168 ${uri}= Template String ${FLAVOR_URI} ${keys}
169 Append To List ${reverse_heatbridge} ${uri}
170 ${uri}= Template String ${IMAGE_URI} ${keys}
171 Append To List ${reverse_heatbridge} ${uri}
173 Generate Linterface Uri
174 [Documentation] Run teardown against the server to generate a message that removes it
175 [Arguments] ${alias} ${server_id} ${reverse_heatbridge} ${keys}
176 ${resp}= Get Openstack Port By Id ${alias} ${server_id}
177 Return From Keyword If '${resp.status_code}' != '200'
178 ${info}= Set Variable ${resp.json()}
179 Set To Dictionary ${keys} vserver_id=${info['port']['device_id']}
180 Set To Dictionary ${keys} linterface_id=${info['port']['name']}
181 ${uri}= Template String ${L_INTERFACE_URI} ${keys}
182 Append To List ${reverse_heatbridge} ${uri}