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