blob: 9db7657fad156e0bc8246ae52e7c44d8b14bb640 [file] [log] [blame]
zhaoliping123906480b2020-04-22 11:52:56 +08001#!/usr/bin/python
2
3# Prerequisites for machine to run this
4# Put in required parameters in vcpe_config.json
5# Install python-pip (apt install python-pip)
6# Install requests
7# Install ONAP CLI
8# Must have connectivity to the ONAP, openstack is already configured.
9# Configuration File, the parameters will be modified according to the Lab env
10# Put in vnf and ns CSAR file under csar folder
11
12import json
13import os
14import uuid
15import requests
16import unittest
17import time
18import urllib3
19urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
20
21
22class VcpeToscaTest(unittest.TestCase):
23 def setUp(self):
24 file_path = os.path.dirname(os.path.abspath(__file__))
25 with open(file_path + "/config/vcpe_config.json", encoding='utf-8') as self.config_file:
26 self.config_params = self.get_parameters()
27 self.aai_header = {
28 "Accept": "application/json",
29 "Content-Type": "application/json",
30 'X-TransactionId': "9999",
31 'Real-Time': "true",
32 'X-FromAppId': "jimmy-postman",
33 "Authorization": "Basic QUFJOkFBSQ=="
34 }
35 self.base_url = self.config_params["msb_url"]
36 print("Set cli command environment--beginning")
37 os.environ["OPEN_CLI_PRODUCT_IN_USE"] = self.config_params["open_cli_product"]
38 os.environ["OPEN_CLI_HOME"] = self.config_params["open_cli_home"]
39 print("Set cli command environment--successful")
40
41 print("Create cloud complex--beginning")
42 self.create_complex()
43 print("Create cloud complex--successful")
44
45 print("Register all clouds--beginning")
46 self.register_all_clouds()
47 print("Register all clouds--successful")
48 time.sleep(30)
49
50 print("create vCPE service")
51 self.create_service_type()
52
53 print("create customer")
54 self.create_customer()
55
56 print("Get tenant id")
57 self.get_tenant_id()
58
59 print("add customer and subscription")
60 self.add_customer_subscription()
61
62 print("Register vnfm")
63 self.register_vnfm()
64
65 def tearDown(self):
66 if self.ns_instance_id:
67 self.terminateNs()
68 self.deleteNs()
69
70 if self.ns_package_id:
71 self.delete_ns_package()
72
73 if self.vnf_package_list:
74 self.delete_vnf_package()
75
76 if self.esr_vnfm_id and self.esr_vnfm_version:
77 self.unregister_vnfm()
78
79 if self.subscription_version:
80 print("Remove service subscription")
81 self.remove_customer_subscription()
82
83 if self.customer_version:
84 print("Remove customer %s" % self.config_params["customer_name"])
85 self.delete_customer()
86
87 if self.service_type_version:
88 print("Remove service type %s" % self.config_params["service_name"])
89 self.delete_service_type()
90
91 if self.cloud_version:
92 print("Remove cloud %s" % self.config_params["cloud-owner"])
93 self.delete_cloud_helper()
94
95 time.sleep(30)
96
97 if self.complex_version:
98 self.get_complex_resource_version()
99 print("Remove complex %s" % self.config_params["complex_name"])
100 self.delete_complex()
101
102 def get_parameters(self):
103 parameters = json.load(self.config_file)
104 return parameters
105
106 @staticmethod
107 def get_out_helper_2(in_string):
108 out_list = ((in_string.replace('|', '')).replace('+', '')).split()
109 return out_list
110
111 def create_complex(self):
112 self.complex_version = None
113 complex_create_string = "oclip complex-create -j {} -r {} -x {} -y {} -lt {} -l {} -i {} -lo {} \
114 -S {} -la {} -g {} -w {} -z {} -k {} -o {} -q {} -m {} -u {} -p {}".format(
115 self.config_params["street2"], self.config_params["physical_location"],
116 self.config_params["complex_name"], self.config_params["data_center_code"],
117 self.config_params["latitude"], self.config_params["region"],
118 self.config_params["street1"], self.config_params["longitude"],
119 self.config_params["state"], self.config_params["lata"],
120 self.config_params["city"], self.config_params["postal-code"],
121 self.config_params["complex_name"], self.config_params["country"],
122 self.config_params["elevation"], self.config_params["identity_url"],
123 self.config_params["aai_url"], self.config_params["aai_username"],
124 self.config_params["aai_password"])
125 os.system(complex_create_string)
126
127 self.get_complex_resource_version()
128
129 def get_complex_resource_version(self):
130 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
131 complex_url = self.base_url + "/aai/v11/cloud-infrastructure/complexes"
132 complex_list_response = requests.get(url=complex_url, headers=self.aai_header, verify=False)
133 if complex_list_response.status_code == 200:
134 for complex in (complex_list_response.json())["complex"]:
135 if complex['physical-location-id'] == self.config_params["complex_name"]:
136 self.complex_version = complex['resource-version']
137 print("Complex %s resource-version is %s."
138 % (self.config_params["complex_name"], self.complex_version))
139
140 def delete_complex(self):
141 complex_delete_string = 'oclip complex-delete -x {} -y {} -m {} -u {} -p {}'.format(
142 self.config_params["complex_name"], self.complex_version, self.config_params["aai_url"],
143 self.config_params["aai_username"], self.config_params["aai_password"])
144 os.system(complex_delete_string)
145 print("Delete complex--successful")
146 self.complex_version = None
147
148 def register_cloud_helper(self, cloud_region, values):
149 print("Create Cloud--beginning")
150 self.cloud_version = None
151 cloud_create_string = 'oclip cloud-create -e {} -b {} ' \
152 '-x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} -r {} -Q {} -i {} -g {} \
153 -z {} -k {} -c {} -m {} -u {} -p {}' \
154 .format(values.get("esr-system-info-id"), values.get("user-name"),
155 self.config_params["cloud-owner"],
156 cloud_region, values.get("password"),
157 values.get("cloud-region-version"), values.get("default-tenant"),
158 values.get("service-url"), self.config_params["complex_name"],
159 values.get("cloud-type"), self.config_params["owner-defined-type"],
160 values.get("system-type"), values.get("identity-url"),
161 self.config_params["cloud-zone"], values.get("ssl-insecure"),
162 values.get("system-status"), values.get("cloud-domain"),
163 self.config_params["aai_url"],
164 self.config_params["aai_username"],
165 self.config_params["aai_password"])
166
167 os.system(cloud_create_string)
168 print("Create Cloud--successful")
169
170 print("Associate Cloud with complex--beginning")
171 complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(
172 self.config_params["complex_name"],
173 cloud_region, self.config_params["cloud-owner"], self.config_params["aai_url"],
174 self.config_params["aai_username"],
175 self.config_params["aai_password"])
176 os.system(complex_associate_string)
177 print("Associate Cloud with complex--successful")
178
179 print("Register Cloud with Multicloud--beginning")
180 multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(
181 self.config_params["cloud-owner"], cloud_region, self.config_params["multicloud_url"])
182 os.system(multicloud_register_string)
183 print("Register Cloud with Multicloud--successful")
184
185 cloud_url = self.base_url + "/aai/v11/cloud-infrastructure/cloud-regions"
186 cloud_list_response = requests.get(url=cloud_url, headers=self.aai_header, verify=False)
187 if cloud_list_response.status_code == 200:
188 for cloud in (cloud_list_response.json())["cloud-region"]:
189 if cloud['cloud-owner'] == self.config_params["cloud-owner"]:
190 self.cloud_version = cloud['resource-version']
191 print("Cloud %s resource-version is %s."
192 % (self.config_params["cloud-owner"], self.cloud_version))
193
194 def register_all_clouds(self):
195 cloud_dictionary = self.config_params["cloud_region_data"]
196 for cloud_region, cloud_region_values in cloud_dictionary.items():
197 self.register_cloud_helper(cloud_region, cloud_region_values)
198
199 def delete_cloud_helper(self):
200 print("Multicloud-cloud-delete--beginning")
201 cloud_region = list(self.config_params["cloud_region_data"].keys())[0]
202 header = {'content-type': 'application/json', 'accept': 'application/json'}
203 multicloud_url = self.base_url + "/api/multicloud-titaniumcloud/v1/{}/{}" \
204 .format(self.config_params["cloud-owner"], cloud_region)
205 requests.delete(url=multicloud_url, headers=header, verify=False)
206 print("Multicloud-cloud-delete----successful")
207 self.customer_version = None
208
209 def create_service_type(self):
210 self.service_type_version = None
211 create_string = "oclip service-type-create -x {} -y {} -m {} -u {} -p {}".format(
212 self.config_params["service_name"], self.config_params["service_name"], self.config_params["aai_url"],
213 self.config_params["aai_username"], self.config_params["aai_password"])
214 os.system(create_string)
215
216 service_tpe_list_url = self.base_url + "/aai/v11/service-design-and-creation/services"
217 service_type_list_response = requests.get(url=service_tpe_list_url, headers=self.aai_header, verify=False)
218 if service_type_list_response.status_code == 200:
219 for service in (service_type_list_response.json())["service"]:
220 if service["service-id"] == self.config_params["service_name"]:
221 self.service_type_version = service['resource-version']
222 print("Service type %s resource-version is %s."
223 % (self.config_params["service_name"], self.service_type_version))
224
225 def delete_service_type(self):
226 print("delete service type--beginning")
227 service_delete_string = 'oclip service-type-delete -x {} -y {} -m {} -u {} -p {}'.format(
228 self.config_params["service_name"], self.service_type_version, self.config_params["aai_url"],
229 self.config_params["aai_username"], self.config_params["aai_password"])
230 os.system(service_delete_string)
231 print("delete service type--successful")
232 self.service_type_version = None
233
234 def create_customer(self):
235 self.customer_version = None
236 create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format(
237 self.config_params["customer_name"],
238 self.config_params["subscriber_name"],
239 self.config_params["aai_url"],
240 self.config_params["aai_username"],
241 self.config_params["aai_password"])
242 os.system(create_string)
243
244 customer_list_url = self.base_url + "/aai/v11/business/customers"
245 customer_list_response = requests.get(url=customer_list_url, headers=self.aai_header, verify=False)
246 if customer_list_response.status_code == 200:
247 for cutsomer in (customer_list_response.json())["customer"]:
248 if cutsomer['global-customer-id'] == self.config_params["customer_name"]:
249 self.customer_version = cutsomer['resource-version']
250 print("Customer %s resource-version is %s."
251 % (self.config_params["customer_name"], self.customer_version))
252
253 def delete_customer(self):
254 print("delete customer--beginning")
255 customer_delete_string = 'oclip customer-delete -x {} -y {} -m {} -u {} -p {}'.format(
256 self.config_params["customer_name"], self.customer_version, self.config_params["aai_url"],
257 self.config_params["aai_username"], self.config_params["aai_password"])
258 os.system(customer_delete_string)
259 print("delete customer--successful")
260 self.customer_version = None
261
262 def get_tenant_id(self):
263 print("Get tenant id--beginning")
264 self.tenant_id = None
265 cloud_dictionary = self.config_params["cloud_region_data"]
266 cloud_region = list(self.config_params["cloud_region_data"].keys())[0]
267
268 tenant_list_url = self.base_url + "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/{}/{}/tenants" \
269 .format(self.config_params["cloud-owner"], cloud_region)
270
271 for cloud_region, cloud_region_values in cloud_dictionary.items():
272 tenant_name = cloud_region_values.get("default-tenant")
273 tenant_list_response = requests.get(url=tenant_list_url, headers=self.aai_header, verify=False)
274 if tenant_list_response.status_code == 200:
275 for tenant in (tenant_list_response.json())["tenant"]:
276 if tenant['tenant-name'] == tenant_name:
277 self.tenant_id = tenant['tenant-id']
278 print("Tenant id is %s ." % self.tenant_id)
279
280 def add_customer_subscription(self):
281 self.subscription_version = None
282 subscription_check = 0
283 for cloud_region, cloud_region_values in (self.config_params["cloud_region_data"]).items():
284 if subscription_check == 0:
285 subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} " \
286 "-y {} -r {} -m {} -u {} -p {}" \
287 .format(self.config_params["customer_name"],
288 self.tenant_id,
289 self.config_params["cloud-owner"],
290 self.config_params["service_name"],
291 cloud_region_values.get("default-tenant"),
292 cloud_region, self.config_params["aai_url"],
293 self.config_params["aai_username"],
294 self.config_params["aai_password"])
295 else:
296 subscription_string = "oclip subscription-cloud-add -x {} -c {} " \
297 "-z {} -e {} -y {} -r {} -m {} -u {} -p {}" \
298 .format(self.config_params["customer_name"], self.tenant_id,
299 self.config_params["cloud-owner"], self.config_params["service_name"],
300 cloud_region_values.get("default-tenant"), cloud_region,
301 self.config_params["aai_url"],
302 self.config_params["aai_username"],
303 self.config_params["aai_password"])
304 os.system(subscription_string)
305 subscription_check += 1
306
307 subscription_url = self.base_url + "/aai/v11/business/customers/customer/{}" \
308 "/service-subscriptions/service-subscription/{}" \
309 .format(self.config_params["customer_name"], self.config_params["service_name"])
310 resp = requests.get(url=subscription_url, headers=self.aai_header, verify=False)
311 if resp.status_code == 200:
312 self.subscription_version = resp.json()['resource-version']
313 print("Subscription resource-version is %s." % self.subscription_version)
314
315 def remove_customer_subscription(self):
316 print("Remove subscription--beginning")
317 subscription_delete_string = 'oclip subscription-delete -x {} -y {} -g {} -m {} -u {} -p {}'.format(
318 self.config_params["customer_name"], self.config_params["service_name"], self.subscription_version,
319 self.config_params["aai_url"],
320 self.config_params["aai_username"], self.config_params["aai_password"])
321 os.system(subscription_delete_string)
322 print("Delete subscription--successful")
323
324 def register_vnfm_helper(self, vnfm_key, values):
325 print("Create vnfm--beginning")
326 self.esr_vnfm_version = None
327 self.esr_vnfm_id = str(uuid.uuid4())
328 vnfm_create_string = 'oclip vnfm-create -b {} -c {} -e {} -v {} -g {} -x {} ' \
329 '-y {} -i {} -j {} -q {} -m {} -u {} -p {}' \
330 .format(vnfm_key, values.get("type"), values.get("vendor"),
331 values.get("version"), values.get("url"), values.get("vim-id"),
332 self.esr_vnfm_id, values.get("user-name"), values.get("user-password"),
333 values.get("vnfm-version"), self.config_params["aai_url"],
334 self.config_params["aai_username"], self.config_params["aai_password"])
335
336 os.system(vnfm_create_string)
337 print("Create vnfm--successful")
338
339 vnfm_url = self.base_url + "/aai/v11/external-system/esr-vnfm-list"
340 resp = requests.get(url=vnfm_url, headers=self.aai_header, verify=False)
341 if resp.status_code == 200:
342 for vnfm in (resp.json())["esr-vnfm"]:
343 if vnfm['vnfm-id'] == self.esr_vnfm_id:
344 self.esr_vnfm_version = vnfm['resource-version']
345 print("Vnfm %s resource-version is %s."
346 % (self.esr_vnfm_id, self.esr_vnfm_version))
347
348 def register_vnfm(self):
349 vnfm_params = self.config_params["vnfm_params"]
350 for vnfm_key, vnfm_values in vnfm_params.items():
351 self.register_vnfm_helper(vnfm_key, vnfm_values)
352
353 def unregister_vnfm(self):
354 print("Delete vnfm %s" % self.esr_vnfm_id)
355 print("Delete vnfm--beginning")
356 vnfm_delete_string = 'oclip vnfm-delete -x {} -y {} -m {} -u {} -p {}'.format(
357 self.esr_vnfm_id, self.esr_vnfm_version, self.config_params["aai_url"],
358 self.config_params["aai_username"], self.config_params["aai_password"])
359 os.system(vnfm_delete_string)
360 self.esr_vnfm_version = self.esr_vnfm_id = None
361 print("Delete vnfm--successful")
362
363 def create_ns(self):
364 ns = self.config_params["ns"]
365 data = {
366 "context": {
367 "globalCustomerId": self.config_params["customer_name"],
368 "serviceType": self.config_params["service_name"]
369 },
370 "csarId": self.ns_package_id,
371 "nsName": ns.get("name"),
372 "description": "description"
373 }
374 ns_header = {'content-type': 'application/json', 'accept': 'application/json'}
375 ns_url = self.base_url + "/api/nslcm/v1/ns"
376 ns_resp = requests.post(ns_url, data=json.dumps(data), headers=ns_header, verify=False)
377 if 201 == ns_resp.status_code:
378 ns_instance_id = ns_resp.json().get("nsInstanceId")
379 print("create ns successfully, the ns instance id is %s" % ns_instance_id)
380 return ns_instance_id
381 else:
382 raise Exception("Create ns failed.")
383
384 def instantiate_ns(self):
385 print("Instantiate ns beginning")
386 constraints = [
387 {
388 "vnfProfileId": x,
389 "locationConstraints": {
390 "vimId": self.config_params["location"]
391 }
392 } for x in self.vnfdId_list]
393 data = {
394 "additionalParamForNs": {
395 "sdnControllerId": self.config_params["sdc-controller-id"]
396 },
397 "locationConstraints": constraints
398 }
399
400 header = {'content-type': 'application/json', 'accept': 'application/json'}
401 instance_url = self.base_url + "/api/nslcm/v1/ns/" + self.ns_instance_id + "/instantiate"
402 instance_resp = requests.post(instance_url, data=json.dumps(data), headers=header, verify=False)
403 if 200 == instance_resp.status_code:
404 ns_instance_jod_id = instance_resp.json().get("jobId")
405 print("Instantiate ns successfully, the job id is %s" % ns_instance_jod_id)
406 return ns_instance_jod_id
407 else:
408 raise Exception("Instantiate ns failed.")
409
410 def create_ns_package(self):
411 print("Create ns package is beginning")
412 ns = self.config_params["ns"]
413 ns_url = self.base_url + "/api/nsd/v1/ns_descriptors"
414 ns_headers = {'content-type': 'application/json', 'accept': 'application/json'}
415 ns_data = {'userDefinedData': {ns.get("key"): ns.get("value")}}
416 ns_package_reps = requests.post(ns_url, data=json.dumps(ns_data), headers=ns_headers, verify=False)
417 if 201 == ns_package_reps.status_code:
418 print("Create ns package successful, the ns package id is %s"
419 % (ns_package_reps.json()["id"]))
420 return ns_package_reps.json()["id"]
421 else:
422 raise Exception("ICreate ns package failed.")
423
424 def delete_ns_package(self):
425 print("Delete ns package %s is beginning" % self.ns_package_id)
426 vnf_url = self.base_url + "/api/nsd/v1/ns_descriptors/%s" % self.ns_package_id
427 resp = requests.delete(url=vnf_url, verify=False)
428 if 204 == resp.status_code:
429 print("Delete ns package %s successfully." % self.ns_package_id)
430 self.ns_package_id = None
431 else:
432 print("Delete ns package %s failed." % self.ns_package_id)
433
434 def create_upload_vnf_package(self):
435 print("Create vnf package is beginning")
436 package_list = []
437 vnfs = self.config_params["vnfs"]
438 vnf_url = self.base_url + "/api/vnfpkgm/v1/vnf_packages"
439 header = {'content-type': 'application/json', 'accept': 'application/json'}
440 for vnf_values in vnfs.values():
441 vnf_data = {'userDefinedData': {vnf_values.get("key"): vnf_values.get("value")}}
442 vnf_package_reps = requests.post(vnf_url, data=json.dumps(vnf_data), headers=header, verify=False)
443 if 201 == vnf_package_reps.status_code:
444 print("Create vnf package successful, the vnf package id is %s"
445 % (vnf_package_reps.json()["id"]))
446 package_id = vnf_package_reps.json()["id"]
447 package_list.append(package_id)
448 vnf_upload_url = '{}/api/vnfpkgm/v1/vnf_packages/{}/package_content' \
449 .format(self.config_params["vfc-url"], package_id)
450 file_path = os.path.dirname(os.path.abspath(__file__))
451 csar_file = file_path + "/" + vnf_values.get("path")
452 with open(csar_file, 'rb') as vnf_file:
453 for i in range(10):
454 resp = requests.put(vnf_upload_url, files={'file': vnf_file}, verify=False)
455 if 202 == resp.status_code:
456 break
457 else:
458 time.sleep(i)
459 return package_list
460
461 def delete_vnf_package(self):
462 print("Delete vnf package is beginning")
463 for vnf_package_id in self.vnf_package_list:
464 vnf_url = self.base_url + "/api/vnfpkgm/v1/vnf_packages/%s" % vnf_package_id
465 resp = requests.delete(url=vnf_url, verify=False)
466 if 204 == resp.status_code:
467 print("Delete vnf package %s successfully." % vnf_package_id)
468 else:
469 print("Delete vnf package %s failed." % vnf_package_id)
470
471 def upload_ns_package(self):
472 ns = self.config_params["ns"]
473 ns_upload_url = '{}/api/nsd/v1/ns_descriptors/{}/nsd_content'.format(self.config_params["vfc-url"],
474 self.ns_package_id)
475 file_path = os.path.dirname(os.path.abspath(__file__))
476 ns_file_path = file_path + "/" + ns["path"]
477 with open(ns_file_path, 'rb') as ns_file:
478 for i in range(10):
479 resp = requests.put(ns_upload_url, files={'file': ns_file}, verify=False)
480 if 204 == resp.status_code:
481 break
482 else:
483 time.sleep(i)
484
485 def get_vnf_package(self):
486 vnfdid_list = []
487 for vnf_package_id in self.vnf_package_list:
488 vnf_package_url = self.base_url + '/api/vnfpkgm/v1/vnf_packages/%s' % vnf_package_id
489 vnf_resp = requests.get(vnf_package_url, verify=False)
490 if 200 == vnf_resp.status_code:
491 vnfdId = vnf_resp.json().get("vnfdId")
492 print("vnfdId is %s" % vnfdId)
493 vnfdid_list.append(vnfdId)
494 return vnfdid_list
495
496 def getVnf(self, vnfs):
497 vnf_list = []
498 for vnf in vnfs:
499 if 'relationship-list' in vnf:
500 for relation in vnf["relationship-list"]["relationship"]:
501 if "service-instance" == relation["related-to"]:
502 if self.ns_instance_id in relation["related-link"]:
503 vnf_list.append(vnf)
504 return vnf_list
505
506 @staticmethod
507 def findVserver(vnf_list):
508 vserver_list = []
509 for vnf in vnf_list:
510 if 'relationship-list' in vnf:
511 for relation in vnf["relationship-list"]["relationship"]:
512 if "vserver" == relation["related-to"]:
513 for relationData in relation["relationship-data"]:
514 if "vserver.vserver-id" == relationData["relationship-key"]:
515 vserver_list.append(relationData["relationship-value"])
516 return vserver_list
517
518 def waitProcessFinished(self, job_id, action):
519 print("Wait for the %s ns finished." % action)
520 job_url = self.base_url + "/api/nslcm/v1/jobs/%s" % job_id
521 progress = 0
522 n = 6000
523 while n > 0:
524 job_resp = requests.get(url=job_url, verify=False)
525 n = n - 1
526 if 200 == job_resp.status_code:
527 if "responseDescriptor" in job_resp.json():
528 progress_rep = (job_resp.json())["responseDescriptor"]["progress"]
529 if 100 != progress_rep:
530 if 255 == progress_rep:
531 print("Ns %s %s failed." % (self.ns_instance_id, action))
532 break
533 elif progress_rep != progress:
534 progress = progress_rep
535 print("Ns %s %s process is %s." % (self.ns_instance_id, action, progress))
536 time.sleep(0.2)
537 else:
538 print("Ns %s %s process is %s." % (self.ns_instance_id, action, progress_rep))
539 print("Ns %s %s successfully." % (self.ns_instance_id, action))
540 break
541
542 def terminateNs(self):
543 print("Terminate ns--beginning")
544 ns_url = self.base_url + "/api/nslcm/v1/ns/%s" % self.ns_instance_id
545 d = {
546 "gracefulTerminationTimeout": 600,
547 "terminationType": "FORCEFUL"
548 }
549 res = requests.post(url=ns_url + "/terminate", data=d, verify=False)
550 self.assertEqual(202, res.status_code)
551 terminate_ns_job_id = res.json()["jobId"]
552 print("Terminate job is %s" % terminate_ns_job_id)
553 self.waitProcessFinished(terminate_ns_job_id, "terminate")
554
555 def deleteNs(self):
556 print("Delete ns %s --beginning" % self.ns_instance_id)
557 ns_url = self.base_url + "/api/nslcm/v1/ns/%s" % self.ns_instance_id
558 res = requests.delete(ns_url, verify=False)
559 if 204 == res.status_code:
560 print("Ns %s delete successfully." % self.ns_instance_id)
561 self.ns_instance_id = None
562
563 def testNs(self):
564 print("Use csar file is uploaded by local")
565 self.vnf_package_list = self.create_upload_vnf_package()
566 self.assertIsNotNone(self.vnf_package_list)
567 time.sleep(60)
568
569 self.ns_package_id = self.create_ns_package()
570 self.assertIsNotNone(self.ns_package_id)
571
572 print("Get vnfdId list.")
573 self.vnfdId_list = self.get_vnf_package()
574
575 print("Upload ns package from csar beginning")
576 self.upload_ns_package()
577 print("Upload ns package from csar successfully")
578
579 print("Create ns beginning")
580 try:
581 self.ns_instance_id = None
582 self.ns_instance_id = self.create_ns()
583 self.assertIsNotNone(self.ns_instance_id)
584 self.ns_instance_jod_id = self.instantiate_ns()
585 except Exception as e:
586 print(e.args[0])
587
588 print("NS %s instantiate job is %s" % (self.ns_instance_id, self.ns_instance_jod_id))
589 self.assertIsNotNone(self.ns_instance_jod_id)
590
591 self.waitProcessFinished(self.ns_instance_jod_id, "instantiate")
592
593 vnf_aai_url = self.base_url + "/aai/v11/network/generic-vnfs"
594 vnf_resp = requests.get(url=vnf_aai_url, headers=self.aai_header, verify=False)
595 self.assertEqual(200, vnf_resp.status_code)
596
597 vnfs = vnf_resp.json()["generic-vnf"]
598 vnf_list = self.getVnf(vnfs)
599 self.assertEqual(5, len(vnf_list))
600 print("There are %s vnfs are created." % len(vnf_list))
601 for vnf in vnf_list:
602 print("The vnf %s are created successfully." % vnf.get("vnf-id"))
603
604 vserver_list = self.findVserver(vnf_list)
605 print("The vserver %s is created successfully." % len(vserver_list))
606 self.assertEqual(8, len(vserver_list))
607
608 cloud_region_id = list(self.config_params["cloud_region_data"].keys())[0]
609
610 for vserver_id in vserver_list:
611 vserver_aai_url = self.base_url + "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region" \
612 "/{}/{}/tenants/tenant/{}/vservers/vserver/{}?depth=all" \
613 .format(self.config_params["cloud-owner"], cloud_region_id, self.tenant_id, vserver_id)
614
615 vserver_resp = requests.get(url=vserver_aai_url, headers=self.aai_header, verify=False)
616 self.assertEqual(200, vserver_resp.status_code)
617 print("The vserver %s is created successfully." % vserver_id)