1 # Copyright 2016-2017 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from django.test import TestCase, Client
19 from rest_framework import status
21 from lcm.pub.database.models import NfInstModel, JobModel, NSInstModel, VmInstModel, OOFDataModel
22 from lcm.pub.exceptions import NSLCMException
23 from lcm.pub.utils import restcall
24 from lcm.pub.utils.jobutil import JOB_MODEL_STATUS
25 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
26 from lcm.pub.utils.timeutil import now_time
27 from lcm.pub.utils.values import ignore_case_get
28 from lcm.ns_vnfs.biz.create_vnfs import CreateVnfs
29 from lcm.ns_vnfs.biz.heal_vnfs import NFHealService
30 from lcm.ns_vnfs.biz.scale_vnfs import NFManualScaleService
31 from lcm.ns_vnfs.biz.terminate_nfs import TerminateVnfs
32 from lcm.ns_vnfs.const import VNF_STATUS, INST_TYPE
33 from lcm.ns_vnfs.biz import create_vnfs
34 from lcm.ns_vnfs.biz.place_vnfs import PlaceVnfs
37 class TestGetVnfViews(TestCase):
39 self.client = Client()
40 self.nf_inst_id = str(uuid.uuid4())
41 NfInstModel(nfinstid=self.nf_inst_id, nf_name='vnf1', vnfm_inst_id='1', vnf_id='vnf_id1',
42 status=VNF_STATUS.ACTIVE, create_time=now_time(), lastuptime=now_time()).save()
45 NfInstModel.objects.all().delete()
47 def test_get_vnf(self):
48 response = self.client.get("/api/nslcm/v1/ns/vnfs/%s" % self.nf_inst_id)
49 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
50 context = json.loads(response.content)
51 self.failUnlessEqual(self.nf_inst_id, context['vnfInstId'])
54 class TestCreateVnfViews(TestCase):
56 self.ns_inst_id = str(uuid.uuid4())
57 self.job_id = str(uuid.uuid4())
59 "nsInstanceId": self.ns_inst_id,
60 "additionalParamForNs": {
61 "inputs": json.dumps({
65 "additionalParamForVnf": [
67 "vnfprofileid": "VBras",
69 "inputs": json.dumps({
73 "vnfminstanceid": "1",
80 self.client = Client()
81 NSInstModel(id=self.ns_inst_id, name='ns', nspackage_id='1', nsd_id='nsd_id', description='description',
82 status='instantiating', nsd_model=json.dumps(nsd_model_dict), create_time=now_time(),
83 lastuptime=now_time()).save()
86 NfInstModel.objects.all().delete()
87 JobModel.objects.all().delete()
89 @mock.patch.object(CreateVnfs, 'run')
90 def test_create_vnf(self, mock_run):
91 response = self.client.post("/api/nslcm/v1/ns/vnfs", data=self.data)
92 self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
93 context = json.loads(response.content)
94 self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstId']).exists())
96 @mock.patch.object(restcall, 'call_req')
97 def test_create_vnf_thread(self, mock_call_req):
98 nf_inst_id, job_id = create_vnfs.prepare_create_params()
100 "/api/ztevnfmdriver/v1/1/vnfs":
101 [0, json.JSONEncoder().encode({"jobId": self.job_id, "vnfInstanceId": 3}), '200'],
102 "/api/catalog/v1/vnfpackages/zte_vbras":
103 [0, json.JSONEncoder().encode(nf_package_info), '200'],
104 "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
105 [0, json.JSONEncoder().encode(vnfm_info), '200'],
106 "/api/resmgr/v1/vnf":
107 [0, json.JSONEncoder().encode({}), '200'],
108 "/api/resmgr/v1/vnfinfo":
109 [0, json.JSONEncoder().encode({}), '200'],
110 "/network/generic-vnfs/generic-vnf/%s" % nf_inst_id:
111 [0, json.JSONEncoder().encode({}), '201'],
112 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
113 [0, json.JSONEncoder().encode(vim_info), '201'],
114 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1":
115 [0, json.JSONEncoder().encode({}), '201'],
116 "/api/ztevnfmdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
117 [0, json.JSONEncoder().encode({"jobid": self.job_id,
118 "responsedescriptor": {"progress": "100",
119 "status": JOB_MODEL_STATUS.FINISHED,
121 "statusdescription": "creating",
123 "responsehistorylist": [
125 "status": JOB_MODEL_STATUS.PROCESSING,
127 "statusdescription": "creating",
128 "errorcode": "0"}]}}), '200']}
130 def side_effect(*args):
131 return mock_vals[args[4]]
132 mock_call_req.side_effect = side_effect
134 'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
135 'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
136 'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
137 'vnf_index': ignore_case_get(self.data, 'vnfIndex')
139 CreateVnfs(data, nf_inst_id, job_id).run()
140 self.assertTrue(NfInstModel.objects.get(nfinstid=nf_inst_id).status, VNF_STATUS.ACTIVE)
142 @mock.patch.object(restcall, 'call_req')
143 @mock.patch.object(CreateVnfs, 'build_homing_request')
144 def test_send_homing_request(self, mock_build_req, mock_call_req):
145 nf_inst_id, job_id = create_vnfs.prepare_create_params()
146 OOFDataModel.objects.all().delete()
149 "transactionId": "1234",
150 "requestStatus": "accepted"
152 mock_build_req.return_value = {
154 "transactionId": "1234",
158 "requestType": "create",
160 "optimizers": ["placement"],
164 "placementDemands": [
166 "resourceModuleName": "vG",
167 "serviceResourceId": "1234",
168 "resourceModelInfo": {
169 "modelInvariantId": "1234",
170 "modelVersionId": "1234"
176 "serviceInstanceId": "1234",
177 "serviceName": "1234",
179 "modelInvariantId": "5678",
180 "modelVersionId": "7890"
184 mock_call_req.return_value = [0, json.JSONEncoder().encode(resp), '202']
186 'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
187 'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
188 'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
189 'vnf_index': ignore_case_get(self.data, 'vnfIndex')
191 CreateVnfs(data, nf_inst_id, job_id).send_homing_request_to_OOF()
192 ret = OOFDataModel.objects.filter(request_id="1234", transaction_id="1234")
193 self.assertIsNotNone(ret)
196 class TestTerminateVnfViews(TestCase):
198 self.client = Client()
199 self.ns_inst_id = str(uuid.uuid4())
200 self.nf_inst_id = '1'
201 self.vnffg_id = str(uuid.uuid4())
202 self.vim_id = str(uuid.uuid4())
203 self.job_id = str(uuid.uuid4())
205 self.tenant = "tenantname"
209 "vnfdName": "PGW001",
210 "vnfProvider": "zte",
211 "vnfdVersion": "V00001",
212 "vnfVersion": "V5.10.20",
215 "description": "PGW VNFD description",
217 "vnfExtendType": "driver"
220 NSInstModel.objects.all().delete()
221 NfInstModel.objects.all().delete()
222 VmInstModel.objects.all().delete()
223 NSInstModel(id=self.ns_inst_id, name="ns_name").save()
224 NfInstModel.objects.create(nfinstid=self.nf_inst_id,
228 ns_inst_id='111,2-2-2',
235 mnfinstid=self.nf_uuid,
237 vnfd_model=self.vnfd_model)
238 VmInstModel.objects.create(vmid="1",
241 insttype=INST_TYPE.VNF,
242 instid=self.nf_inst_id,
247 NSInstModel.objects.all().delete()
248 NfInstModel.objects.all().delete()
250 @mock.patch.object(TerminateVnfs, 'run')
251 def test_terminate_vnf_url(self, mock_run):
253 "terminationType": "forceful",
254 "gracefulTerminationTimeout": "600"}
256 response = self.client.post("/api/nslcm/v1/ns/terminatevnf/%s" % self.nf_inst_id, data=req_data)
257 self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
259 @mock.patch.object(restcall, 'call_req')
260 def test_terminate_vnf(self, mock_call_req):
261 job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
263 nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
265 self.failUnlessEqual(1, 1)
267 self.failUnlessEqual(1, 0)
270 "vnf-id": "vnf-id-test111",
271 "vnf-name": "vnf-name-test111",
272 "vnf-type": "vnf-type-test111",
274 "is-closed-loop-disabled": False,
275 "resource-version": "1505465356262"
279 "responsedescriptor": {
281 "status": JOB_MODEL_STATUS.FINISHED,
283 "statusdescription": "creating",
285 "responsehistorylist": [
288 "status": JOB_MODEL_STATUS.PROCESSING,
290 "statusdescription": "creating",
298 "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
299 [0, json.JSONEncoder().encode(vnfm_info), '200'],
300 "/api/ztevnfmdriver/v1/1/vnfs/111/terminate":
301 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
302 "/api/resmgr/v1/vnf/1":
303 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
304 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
305 [0, json.JSONEncoder().encode(vim_info), '201'],
306 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?depth=all":
307 [0, json.JSONEncoder().encode(vserver_info), '201'],
308 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?resource-version=1505465356263":
309 [0, json.JSONEncoder().encode({}), '200'],
310 "/api/ztevnfmdriver/v1/1/jobs/" + job_id + "?responseId=0":
311 [0, json.JSONEncoder().encode(job_info), '200'],
312 "/network/generic-vnfs/generic-vnf/1?depth=all":
313 [0, json.JSONEncoder().encode(vnf_info), '200'],
314 "/network/generic-vnfs/generic-vnf/1?resource-version=1505465356262":
315 [0, json.JSONEncoder().encode({}), '200']
318 def side_effect(*args):
319 return mock_vals[args[4]]
320 mock_call_req.side_effect = side_effect
323 "terminationType": "forceful",
324 "gracefulTerminationTimeout": "600"
327 TerminateVnfs(req_data, self.nf_inst_id, job_id).run()
328 nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
330 self.failUnlessEqual(1, 0)
332 self.failUnlessEqual(1, 1)
335 class TestScaleVnfViews(TestCase):
337 self.client = Client()
338 self.ns_inst_id = str(uuid.uuid4())
339 self.nf_inst_id = str(uuid.uuid4())
340 self.vnffg_id = str(uuid.uuid4())
341 self.vim_id = str(uuid.uuid4())
342 self.job_id = str(uuid.uuid4())
344 self.tenant = "tenantname"
345 NSInstModel(id=self.ns_inst_id, name="ns_name").save()
346 NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
347 vnfm_inst_id='1', ns_inst_id='111,2-2-2',
348 max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
349 status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
350 vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
351 '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
352 '"productType": "CN","vnfType": "PGW",'
353 '"description": "PGW VNFD description",'
354 '"isShared":true,"vnfExtendType":"driver"}}')
357 NSInstModel.objects.all().delete()
358 NfInstModel.objects.all().delete()
360 def test_scale_vnf(self):
363 "flavour_id": "flavour1",
368 "instances_minimum_number": 1,
369 "instances_maximum_number": 4,
370 "local_affinity_antiaffinity_rule": [
372 "affinity_antiaffinity": "affinity",
381 "name": "demo_aspect",
382 "description": "demo_aspect",
383 "associated_group": "elementGroup1",
389 "group_id": "elementGroup1",
392 "name": "elementGroup1",
394 "members": ["gsu_vm", "pfu_vm"]
402 "aspectId": "demo_aspect1",
404 "additionalParam": vnfd_info
408 "aspectId": "demo_aspect2",
410 "additionalParam": vnfd_info
415 NFManualScaleService(self.nf_inst_id, req_data).run()
416 nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
417 self.assertIsNotNone(nsIns)
419 @mock.patch.object(NFManualScaleService, "send_nf_scaling_request")
420 def test_scale_vnf_success(self, mock_send_nf_scaling_request):
423 "flavour_id": "flavour1",
428 "instances_minimum_number": 1,
429 "instances_maximum_number": 4,
430 "local_affinity_antiaffinity_rule": [
432 "affinity_antiaffinity": "affinity",
441 "name": "demo_aspect",
442 "description": "demo_aspect",
443 "associated_group": "elementGroup1",
449 "group_id": "elementGroup1",
452 "name": "elementGroup1",
454 "members": ["gsu_vm", "pfu_vm"]
462 "aspectId": "demo_aspect1",
464 "additionalParam": vnfd_info
468 "aspectId": "demo_aspect2",
470 "additionalParam": vnfd_info
474 scale_service = NFManualScaleService(self.nf_inst_id, req_data)
476 nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
477 self.assertIsNotNone(nsIns)
479 jobs = JobModel.objects.filter(jobid=scale_service.job_id)
480 self.assertIsNotNone(100, jobs[0].progress)
483 class TestHealVnfViews(TestCase):
485 self.client = Client()
486 self.ns_inst_id = str(uuid.uuid4())
487 self.nf_inst_id = str(uuid.uuid4())
490 self.job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, self.nf_inst_id)
492 NSInstModel(id=self.ns_inst_id, name="ns_name").save()
493 NfInstModel.objects.create(nfinstid=self.nf_inst_id,
497 ns_inst_id='111,2-2-2',
504 mnfinstid=self.nf_uuid,
506 vnfd_model=json.dumps({
509 "vnfdName": "PGW001",
510 "vnfProvider": "zte",
511 "vnfdVersion": "V00001",
512 "vnfVersion": "V5.10.20",
515 "description": "PGW VNFD description",
517 "vnfExtendType": "driver"
522 NSInstModel.objects.all().delete()
523 NfInstModel.objects.all().delete()
525 @mock.patch.object(restcall, "call_req")
526 def test_heal_vnf(self, mock_call_req):
529 "/api/ztevnfmdriver/v1/1/vnfs/111/heal":
530 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
531 "/external-system/esr-vnfm-list/esr-vnfm/1":
532 [0, json.JSONEncoder().encode(vnfm_info), '200'],
533 "/api/resmgr/v1/vnf/1":
534 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
535 "/api/ztevnfmdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
536 [0, json.JSONEncoder().encode({
537 "jobId": self.job_id,
538 "responsedescriptor": {
540 "status": JOB_MODEL_STATUS.FINISHED,
542 "statusdescription": "creating",
544 "responsehistorylist": [{
546 "status": JOB_MODEL_STATUS.PROCESSING,
548 "statusdescription": "creating",
554 def side_effect(*args):
555 return mock_vals[args[4]]
557 mock_call_req.side_effect = side_effect
568 NFHealService(self.nf_inst_id, req_data).run()
570 self.assertEqual(NfInstModel.objects.get(nfinstid=self.nf_inst_id).status, VNF_STATUS.ACTIVE)
572 @mock.patch.object(NFHealService, "run")
573 def test_heal_vnf_non_existing_vnf(self, mock_biz):
574 mock_biz.side_effect = NSLCMException("VNF Not Found")
587 self.assertRaises(NSLCMException, NFHealService(nf_inst_id, req_data).run)
588 self.assertEqual(len(NfInstModel.objects.filter(nfinstid=nf_inst_id)), 0)
591 class TestGetVnfmInfoViews(TestCase):
593 self.client = Client()
594 self.vnfm_id = str(uuid.uuid4())
599 @mock.patch.object(restcall, "call_req")
600 def test_get_vnfm_info(self, mock_call_req):
602 "vnfm-id": "example-vnfm-id-val-62576",
603 "vim-id": "example-vim-id-val-35114",
604 "certificate-url": "example-certificate-url-val-90242",
605 "esr-system-info-list": {
608 "esr-system-info-id": "example-esr-system-info-id-val-78484",
609 "system-name": "example-system-name-val-23790",
610 "type": "example-type-val-52596",
611 "vendor": "example-vendor-val-47399",
612 "version": "example-version-val-42051",
613 "service-url": "example-service-url-val-10731",
614 "user-name": "example-user-name-val-65946",
615 "password": "example-password-val-22505",
616 "system-type": "example-system-type-val-27221",
617 "protocal": "example-protocal-val-54632",
618 "ssl-cacert": "example-ssl-cacert-val-45965",
619 "ssl-insecure": True,
620 "ip-address": "example-ip-address-val-19212",
621 "port": "example-port-val-57641",
622 "cloud-domain": "example-cloud-domain-val-26296",
623 "default-tenant": "example-default-tenant-val-87724"
628 r1 = [0, json.JSONEncoder().encode(vnfm_info_aai), '200']
629 mock_call_req.side_effect = [r1]
630 esr_system_info = ignore_case_get(ignore_case_get(vnfm_info_aai, "esr-system-info-list"), "esr-system-info")
632 "vnfmId": vnfm_info_aai["vnfm-id"],
633 "name": vnfm_info_aai["vnfm-id"],
634 "type": ignore_case_get(esr_system_info[0], "type"),
635 "vimId": vnfm_info_aai["vim-id"],
636 "vendor": ignore_case_get(esr_system_info[0], "vendor"),
637 "version": ignore_case_get(esr_system_info[0], "version"),
638 "description": "vnfm",
639 "certificateUrl": vnfm_info_aai["certificate-url"],
640 "url": ignore_case_get(esr_system_info[0], "service-url"),
641 "userName": ignore_case_get(esr_system_info[0], "user-name"),
642 "password": ignore_case_get(esr_system_info[0], "password"),
646 response = self.client.get("/api/nslcm/v1/vnfms/%s" % self.vnfm_id)
647 self.failUnlessEqual(status.HTTP_200_OK, response.status_code, response.content)
648 context = json.loads(response.content)
649 self.assertEqual(expect_data, context)
652 class TestGetVimInfoViews(TestCase):
654 self.client = Client()
655 self.vim_id = "zte_test"
660 @mock.patch.object(restcall, "call_req")
661 def test_get_vim_info(self, mock_call_req):
662 r1 = [0, json.JSONEncoder().encode(vim_info), '200']
663 mock_call_req.side_effect = [r1]
664 esr_system_info = ignore_case_get(ignore_case_get(vim_info, "esr-system-info-list"), "esr-system-info")
666 "vimId": self.vim_id,
668 "url": ignore_case_get(esr_system_info[0], "service-url"),
669 "userName": ignore_case_get(esr_system_info[0], "user-name"),
670 "password": ignore_case_get(esr_system_info[0], "password"),
671 # "tenant": ignore_case_get(tenants[0], "tenant-id"),
672 "tenant": ignore_case_get(esr_system_info[0], "default-tenant"),
673 "vendor": ignore_case_get(esr_system_info[0], "vendor"),
674 "version": ignore_case_get(esr_system_info[0], "version"),
675 "description": "vim",
677 "type": ignore_case_get(esr_system_info[0], "type"),
681 response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
682 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
683 context = json.loads(response.content)
684 self.assertEqual(expect_data["url"], context["url"])
687 class TestPlaceVnfViews(TestCase):
689 self.vnf_inst_id = "1234"
690 self.vnf_inst_name = "vG"
691 self.client = Client()
692 OOFDataModel.objects.all().delete()
693 OOFDataModel.objects.create(
695 transaction_id="1234",
696 request_status="init",
697 request_module_name=self.vnf_inst_name,
698 service_resource_id=self.vnf_inst_id,
706 OOFDataModel.objects.all().delete()
708 @mock.patch.object(restcall, 'call_req')
709 def test_place_vnf(self, mock_call_req):
712 "flavorName": "HPA.flavor.1",
715 PlaceVnfs(vnf_place_request).extract()
716 db_info = OOFDataModel.objects.filter(request_id=vnf_place_request.get("requestId"), transaction_id=vnf_place_request.get("transactionId"))
717 self.assertEqual(db_info[0].request_status, "completed")
718 self.assertEqual(db_info[0].vim_id, "CloudOwner1_DLLSTX1A")
719 self.assertEqual(db_info[0].cloud_owner, "CloudOwner1")
720 self.assertEqual(db_info[0].cloud_region_id, "DLLSTX1A")
721 self.assertEqual(db_info[0].vdu_info, json.dumps(vdu_info_json))
723 def test_place_vnf_with_invalid_response(self):
726 "transactionId": "1234",
727 "statusMessage": "xx",
728 "requestStatus": "pending",
730 "placementSolutions": [
733 "resourceModuleName": self.vnf_inst_name,
734 "serviceResourceId": self.vnf_inst_id,
736 "identifierType": "serviceInstanceId",
740 "cloudOwner": "CloudOwner1 "
746 "licenseSolutions": [
748 "resourceModuleName": "string",
749 "serviceResourceId": "string",
750 "entitlementPoolUUID": [
753 "licenseKeyGroupUUID": [
756 "entitlementPoolInvariantUUID": [
759 "licenseKeyGroupInvariantUUID": [
766 PlaceVnfs(resp).extract()
767 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
768 self.assertEqual(db_info[0].request_status, "pending")
769 self.assertEqual(db_info[0].vim_id, "none")
770 self.assertEqual(db_info[0].cloud_owner, "none")
771 self.assertEqual(db_info[0].cloud_region_id, "none")
772 self.assertEqual(db_info[0].vdu_info, "none")
774 def test_place_vnf_with_no_assignment_info(self):
777 "transactionId": "1234",
778 "statusMessage": "xx",
779 "requestStatus": "completed",
781 "placementSolutions": [
784 "resourceModuleName": self.vnf_inst_name,
785 "serviceResourceId": self.vnf_inst_id,
787 "identifierType": "serviceInstanceId",
791 "cloudOwner": "CloudOwner1 "
796 "licenseSolutions": [
798 "resourceModuleName": "string",
799 "serviceResourceId": "string",
800 "entitlementPoolUUID": [
803 "licenseKeyGroupUUID": [
806 "entitlementPoolInvariantUUID": [
809 "licenseKeyGroupInvariantUUID": [
816 PlaceVnfs(resp).extract()
817 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
818 self.assertEqual(db_info[0].request_status, "completed")
819 self.assertEqual(db_info[0].vim_id, "none")
820 self.assertEqual(db_info[0].cloud_owner, "none")
821 self.assertEqual(db_info[0].cloud_region_id, "none")
822 self.assertEqual(db_info[0].vdu_info, "none")
824 def test_place_vnf_no_directives(self):
827 "transactionId": "1234",
828 "statusMessage": "xx",
829 "requestStatus": "completed",
831 "placementSolutions": [
834 "resourceModuleName": self.vnf_inst_name,
835 "serviceResourceId": self.vnf_inst_id,
837 "identifierType": "serviceInstanceId",
841 "cloudOwner": "CloudOwner1 "
844 {"key": "locationId",
853 "resourceModuleName": "string",
854 "serviceResourceId": "string",
855 "entitlementPoolUUID": [
858 "licenseKeyGroupUUID": [
861 "entitlementPoolInvariantUUID": [
864 "licenseKeyGroupInvariantUUID": [
871 PlaceVnfs(resp).extract()
872 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
873 self.assertEqual(db_info[0].request_status, "completed")
874 self.assertEqual(db_info[0].vim_id, "none")
875 self.assertEqual(db_info[0].cloud_owner, "none")
876 self.assertEqual(db_info[0].cloud_region_id, "none")
877 self.assertEqual(db_info[0].vdu_info, "none")
879 def test_place_vnf_with_no_solution(self):
882 "transactionId": "1234",
883 "statusMessage": "xx",
884 "requestStatus": "completed",
886 "placementSolutions": [],
887 "licenseSoutions": []
890 PlaceVnfs(resp).extract()
891 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
892 self.assertEqual(db_info[0].request_status, "completed")
893 self.assertEqual(db_info[0].vim_id, "no-solution")
894 self.assertEqual(db_info[0].cloud_owner, "no-solution")
895 self.assertEqual(db_info[0].cloud_region_id, "no-solution")
896 self.assertEqual(db_info[0].vdu_info, "no-solution")
900 'local_storages': [],
913 'vdu_id': u'vdu_omm.001',
914 'image_file': u'opencos_sss_omm_img_release_20150723-1-disk1',
926 'support_scaling': False,
929 'storage_policy': '',
932 'availability_zone': '',
938 'inject_data_list': [
945 'local_affinity_antiaffinity_rule': {
948 'template_id': u'omm.001',
949 'manual_scale_select_vim': False
951 'description': u'singleommvm'
965 'image_file': u'sss',
977 'support_scaling': False,
980 'storage_policy': '',
983 'availability_zone': '',
989 'inject_data_list': [
996 'local_affinity_antiaffinity_rule': {
1000 'manual_scale_select_vim': False
1002 'description': u'ompvm'
1005 'volumn_storages': [
1016 'image_file': u'sss',
1028 'support_scaling': False,
1031 'storage_policy': '',
1034 'availability_zone': '',
1040 'inject_data_list': [
1047 'local_affinity_antiaffinity_rule': {
1050 'template_id': u'2',
1051 'manual_scale_select_vim': False
1053 'description': u'ompvm'
1056 'volumn_storages': [
1067 'image_file': u'sss',
1079 'support_scaling': False,
1082 'storage_policy': '',
1085 'availability_zone': '',
1091 'inject_data_list': [
1098 'local_affinity_antiaffinity_rule': {
1101 'template_id': u'3',
1102 'manual_scale_select_vim': False
1104 'description': u'ompvm'
1107 'volumn_storages': [
1117 'vdu_id': u'vdu_10',
1118 'image_file': u'sss',
1130 'support_scaling': False,
1133 'storage_policy': '',
1136 'availability_zone': '',
1142 'inject_data_list': [
1149 'local_affinity_antiaffinity_rule': {
1152 'template_id': u'10',
1153 'manual_scale_select_vim': False
1155 'description': u'ppvm'
1158 'volumn_storages': [
1168 'vdu_id': u'vdu_11',
1169 'image_file': u'sss',
1181 'support_scaling': False,
1184 'storage_policy': '',
1187 'availability_zone': '',
1193 'inject_data_list': [
1200 'local_affinity_antiaffinity_rule': {
1203 'template_id': u'11',
1204 'manual_scale_select_vim': False
1206 'description': u'ppvm'
1209 'volumn_storages': [
1219 'vdu_id': u'vdu_12',
1220 'image_file': u'sss',
1232 'support_scaling': False,
1235 'storage_policy': '',
1238 'availability_zone': '',
1244 'inject_data_list': [
1251 'local_affinity_antiaffinity_rule': {
1254 'template_id': u'12',
1255 'manual_scale_select_vim': False
1257 'description': u'ppvm'
1260 'volumn_storages': [
1268 'policy_id': u'policy_scale_sss-vnf-template',
1270 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'
1279 'name': u'opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1281 'disk_format': u'VMDK',
1282 'file_url': u'./zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1283 'container_type': 'vm',
1285 'hypervisor_type': 'kvm'
1287 'image_file_id': u'opencos_sss_omm_img_release_20150723-1-disk1'
1292 'name': u'sss.vmdk',
1294 'disk_format': u'VMDK',
1295 'file_url': u'./zte-cn-sss-main-image/NE/sss.vmdk',
1296 'container_type': 'vm',
1298 'hypervisor_type': 'kvm'
1300 'image_file_id': u'sss'
1313 'domain_type': u'CN',
1314 'version': u'v4.14.10',
1315 'vmnumber_overquota_alarm': False,
1318 'vnfd_version': u'V00000001',
1319 'id': u'sss-vnf-template',
1320 'name': u'sss-vnf-template'
1329 "externalDataNetworkName": {
1353 "plugin_info": "vbrasplugin_1.0",
1355 "is_shared": "False",
1356 "request_reclassification": "False",
1357 "vnfd_version": "1.0.0",
1359 "nsh_aware": "True",
1360 "cross_dc": "False",
1361 "externalDataNetworkName": {
1362 "get_input": "externalDataNetworkName"
1384 "vl_id": "ext_mnet_network",
1387 "network_type": "vlan",
1388 "name": "externalMNetworkName",
1389 "dhcp_enabled": False,
1397 "end_ip": "190.168.100.100",
1398 "gateway_ip": "190.168.100.1",
1399 "start_ip": "190.168.100.2",
1400 "cidr": "190.168.100.0/24",
1402 "network_name": "sub_mnet",
1414 "invariant_id": "vbras_ns",
1415 "description": "vbras_ns",
1424 "vserver-id": "example-vserver-id-val-70924",
1425 "vserver-name": "example-vserver-name-val-61674",
1426 "vserver-name2": "example-vserver-name2-val-19234",
1427 "prov-status": "example-prov-status-val-94916",
1428 "vserver-selflink": "example-vserver-selflink-val-26562",
1430 "is-closed-loop-disabled": True,
1431 "resource-version": "1505465356263",
1435 "volume-id": "example-volume-id-val-71854",
1436 "volume-selflink": "example-volume-selflink-val-22433"
1443 "interface-name": "example-interface-name-val-24351",
1444 "interface-role": "example-interface-role-val-43242",
1445 "v6-wan-link-ip": "example-v6-wan-link-ip-val-4196",
1446 "selflink": "example-selflink-val-61295",
1447 "interface-id": "example-interface-id-val-95879",
1448 "macaddr": "example-macaddr-val-37302",
1449 "network-name": "example-network-name-val-44254",
1450 "management-option": "example-management-option-val-49009",
1451 "interface-description": "example-interface-description-val-99923",
1452 "is-port-mirrored": True,
1454 "prov-status": "example-prov-status-val-4698",
1455 "is-ip-unnumbered": True,
1456 "allowed-address-pairs": "example-allowed-address-pairs-val-5762",
1460 "vlan-interface": "example-vlan-interface-val-58193",
1461 "vlan-id-inner": 54452151,
1462 "vlan-id-outer": 70239293,
1463 "speed-value": "example-speed-value-val-18677",
1464 "speed-units": "example-speed-units-val-46185",
1465 "vlan-description": "example-vlan-description-val-81675",
1466 "backdoor-connection": "example-backdoor-connection-val-44608",
1467 "vpn-key": "example-vpn-key-val-7946",
1468 "orchestration-status": "example-orchestration-status-val-33611",
1470 "prov-status": "example-prov-status-val-8288",
1471 "is-ip-unnumbered": True,
1472 "l3-interface-ipv4-address-list": [
1474 "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-25520",
1475 "l3-interface-ipv4-prefix-length": 69931928,
1476 "vlan-id-inner": 86628520,
1477 "vlan-id-outer": 62729236,
1478 "is-floating": True,
1479 "neutron-network-id": "example-neutron-network-id-val-64021",
1480 "neutron-subnet-id": "example-neutron-subnet-id-val-95049"
1483 "l3-interface-ipv6-address-list": [
1485 "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-64310",
1486 "l3-interface-ipv6-prefix-length": 57919834,
1487 "vlan-id-inner": 79150122,
1488 "vlan-id-outer": 59789973,
1489 "is-floating": True,
1490 "neutron-network-id": "example-neutron-network-id-val-31713",
1491 "neutron-subnet-id": "example-neutron-subnet-id-val-89568"
1500 "pci-id": "example-pci-id-val-16747",
1501 "vf-vlan-filter": "example-vf-vlan-filter-val-4613",
1502 "vf-mac-filter": "example-vf-mac-filter-val-68168",
1503 "vf-vlan-strip": True,
1504 "vf-vlan-anti-spoof-check": True,
1505 "vf-mac-anti-spoof-check": True,
1506 "vf-mirrors": "example-vf-mirrors-val-6270",
1507 "vf-broadcast-allow": True,
1508 "vf-unknown-multicast-allow": True,
1509 "vf-unknown-unicast-allow": True,
1510 "vf-insert-stag": True,
1511 "vf-link-status": "example-vf-link-status-val-49266",
1512 "neutron-network-id": "example-neutron-network-id-val-29493"
1519 "interface-name": "example-interface-name-val-98222",
1520 "interface-role": "example-interface-role-val-78360",
1521 "v6-wan-link-ip": "example-v6-wan-link-ip-val-76921",
1522 "selflink": "example-selflink-val-27117",
1523 "interface-id": "example-interface-id-val-11260",
1524 "macaddr": "example-macaddr-val-60378",
1525 "network-name": "example-network-name-val-16258",
1526 "management-option": "example-management-option-val-35097",
1527 "interface-description": "example-interface-description-val-10475",
1528 "is-port-mirrored": True,
1530 "prov-status": "example-prov-status-val-65203",
1531 "is-ip-unnumbered": True,
1532 "allowed-address-pairs": "example-allowed-address-pairs-val-65028"
1536 "l3-interface-ipv4-address-list": [
1538 "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-72779",
1539 "l3-interface-ipv4-prefix-length": 55956636,
1540 "vlan-id-inner": 98174431,
1541 "vlan-id-outer": 20372128,
1542 "is-floating": True,
1543 "neutron-network-id": "example-neutron-network-id-val-39596",
1544 "neutron-subnet-id": "example-neutron-subnet-id-val-51109"
1547 "l3-interface-ipv6-address-list": [
1549 "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-95203",
1550 "l3-interface-ipv6-prefix-length": 57454747,
1551 "vlan-id-inner": 53421060,
1552 "vlan-id-outer": 16006050,
1553 "is-floating": True,
1554 "neutron-network-id": "example-neutron-network-id-val-54216",
1555 "neutron-subnet-id": "example-neutron-subnet-id-val-1841"
1565 "vnfm-id": "example-vnfm-id-val-97336",
1566 "vim-id": "zte_test",
1567 "certificate-url": "example-certificate-url-val-18046",
1568 "resource-version": "example-resource-version-val-42094",
1569 "esr-system-info-list": {
1570 "esr-system-info": [
1572 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1573 "system-name": "example-system-name-val-19801",
1574 "type": "ztevnfmdriver",
1575 "vendor": "example-vendor-val-50079",
1576 "version": "example-version-val-93146",
1577 "service-url": "example-service-url-val-68090",
1578 "user-name": "example-user-name-val-14470",
1579 "password": "example-password-val-84190",
1580 "system-type": "example-system-type-val-42773",
1581 "protocal": "example-protocal-val-85736",
1582 "ssl-cacert": "example-ssl-cacert-val-33989",
1583 "ssl-insecure": True,
1584 "ip-address": "example-ip-address-val-99038",
1585 "port": "example-port-val-27323",
1586 "cloud-domain": "example-cloud-domain-val-55163",
1587 "default-tenant": "example-default-tenant-val-99383",
1588 "resource-version": "example-resource-version-val-15424"
1595 "cloud-owner": "example-cloud-owner-val-97336",
1596 "cloud-region-id": "example-cloud-region-id-val-35532",
1597 "cloud-type": "example-cloud-type-val-18046",
1598 "owner-defined-type": "example-owner-defined-type-val-9413",
1599 "cloud-region-version": "example-cloud-region-version-val-85706",
1600 "identity-url": "example-identity-url-val-71252",
1601 "cloud-zone": "example-cloud-zone-val-27112",
1602 "complex-name": "example-complex-name-val-85283",
1603 "sriov-automation": True,
1604 "cloud-extra-info": "example-cloud-extra-info-val-90854",
1605 "cloud-epa-caps": "example-cloud-epa-caps-val-2409",
1606 "resource-version": "example-resource-version-val-42094",
1607 "esr-system-info-list": {
1608 "esr-system-info": [
1610 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1611 "system-name": "example-system-name-val-19801",
1612 "type": "example-type-val-24477",
1613 "vendor": "example-vendor-val-50079",
1614 "version": "example-version-val-93146",
1615 "service-url": "example-service-url-val-68090",
1616 "user-name": "example-user-name-val-14470",
1617 "password": "example-password-val-84190",
1618 "system-type": "example-system-type-val-42773",
1619 "protocal": "example-protocal-val-85736",
1620 "ssl-cacert": "example-ssl-cacert-val-33989",
1621 "ssl-insecure": True,
1622 "ip-address": "example-ip-address-val-99038",
1623 "port": "example-port-val-27323",
1624 "cloud-domain": "example-cloud-domain-val-55163",
1625 "default-tenant": "admin",
1626 "resource-version": "example-resource-version-val-15424"
1633 "csarId": "zte_vbras",
1636 "vnfPackageId": "zte_vbras",
1637 "vnfdProvider": "1",
1641 "vnfdModel": vnfd_model_dict,
1647 vnf_place_request = {
1648 "requestId": "1234",
1649 "transactionId": "1234",
1650 "statusMessage": "xx",
1651 "requestStatus": "completed",
1653 "placementSolutions": [
1656 "resourceModuleName": "vG",
1657 "serviceResourceId": "1234",
1659 "identifierType": "serviceInstanceId",
1663 "cloudOwner": "CloudOwner1"
1669 {"key": "locationId",
1672 {"key": "locationType",
1673 "value": "openstack-cloud"
1676 "value": "CloudOwner1_DLLSTX1A"
1678 {"key": "physicalLocationId",
1679 "value": "DLLSTX1223"
1681 {"key": "oofDirectives",
1686 "type": "tocsa.nodes.nfv.Vdu.Compute",
1689 "type": "flavor_directive",
1692 "attribute_name": "flavor_name",
1693 "attribute_value": "HPA.flavor.1"
1706 "attribute_name": " ",
1707 "attribute_value": " "
1720 "licenseSolutions": [
1722 "resourceModuleName": "string",
1723 "serviceResourceId": "string",
1724 "entitlementPoolUUID": [
1727 "licenseKeyGroupUUID": [
1730 "entitlementPoolInvariantUUID": [
1733 "licenseKeyGroupInvariantUUID": [