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, SubscriptionModel
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.subscribe import SubscriptionDeletion
32 from lcm.ns_vnfs.biz.terminate_nfs import TerminateVnfs
33 from lcm.ns_vnfs.const import VNF_STATUS, INST_TYPE
34 from lcm.ns_vnfs.biz import create_vnfs
35 from lcm.ns_vnfs.biz.place_vnfs import PlaceVnfs
38 class TestGetVnfViews(TestCase):
40 self.client = Client()
41 self.nf_inst_id = str(uuid.uuid4())
42 NfInstModel(nfinstid=self.nf_inst_id, nf_name='vnf1', vnfm_inst_id='1', vnf_id='vnf_id1',
43 status=VNF_STATUS.ACTIVE, create_time=now_time(), lastuptime=now_time()).save()
46 NfInstModel.objects.all().delete()
48 def test_get_vnf(self):
49 response = self.client.get("/api/nslcm/v1/ns/vnfs/%s" % self.nf_inst_id)
50 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
51 context = json.loads(response.content)
52 self.failUnlessEqual(self.nf_inst_id, context['vnfInstId'])
55 class TestCreateVnfViews(TestCase):
57 self.ns_inst_id = str(uuid.uuid4())
58 self.job_id = str(uuid.uuid4())
60 "nsInstanceId": self.ns_inst_id,
61 "additionalParamForNs": {
62 "inputs": json.dumps({
66 "additionalParamForVnf": [
68 "vnfprofileid": "VBras",
70 "inputs": json.dumps({
74 "vnfminstanceid": "1",
81 self.client = Client()
82 NSInstModel(id=self.ns_inst_id, name='ns', nspackage_id='1', nsd_id='nsd_id', description='description',
83 status='instantiating', nsd_model=json.dumps(nsd_model_dict), create_time=now_time(),
84 lastuptime=now_time()).save()
87 NfInstModel.objects.all().delete()
88 JobModel.objects.all().delete()
90 @mock.patch.object(CreateVnfs, 'run')
91 def test_create_vnf(self, mock_run):
92 response = self.client.post("/api/nslcm/v1/ns/vnfs", data=self.data)
93 self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
94 context = json.loads(response.content)
95 self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstId']).exists())
97 @mock.patch.object(restcall, 'call_req')
98 def test_create_vnf_thread(self, mock_call_req):
99 nf_inst_id, job_id = create_vnfs.prepare_create_params()
101 "/api/ztevnfmdriver/v1/1/vnfs":
102 [0, json.JSONEncoder().encode({"jobId": self.job_id, "vnfInstanceId": 3}), '200'],
103 "/api/catalog/v1/vnfpackages/zte_vbras":
104 [0, json.JSONEncoder().encode(nf_package_info), '200'],
105 "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
106 [0, json.JSONEncoder().encode(vnfm_info), '200'],
107 "/api/resmgr/v1/vnf":
108 [0, json.JSONEncoder().encode({}), '200'],
109 "/api/resmgr/v1/vnfinfo":
110 [0, json.JSONEncoder().encode({}), '200'],
111 "/network/generic-vnfs/generic-vnf/%s" % nf_inst_id:
112 [0, json.JSONEncoder().encode({}), '201'],
113 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
114 [0, json.JSONEncoder().encode(vim_info), '201'],
115 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1":
116 [0, json.JSONEncoder().encode({}), '201'],
117 "/api/ztevnfmdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
118 [0, json.JSONEncoder().encode({"jobid": self.job_id,
119 "responsedescriptor": {"progress": "100",
120 "status": JOB_MODEL_STATUS.FINISHED,
122 "statusdescription": "creating",
124 "responsehistorylist": [
126 "status": JOB_MODEL_STATUS.PROCESSING,
128 "statusdescription": "creating",
129 "errorcode": "0"}]}}), '200']}
131 def side_effect(*args):
132 return mock_vals[args[4]]
133 mock_call_req.side_effect = side_effect
135 'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
136 'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
137 'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
138 'vnf_index': ignore_case_get(self.data, 'vnfIndex')
140 CreateVnfs(data, nf_inst_id, job_id).run()
141 self.assertTrue(NfInstModel.objects.get(nfinstid=nf_inst_id).status, VNF_STATUS.ACTIVE)
143 @mock.patch.object(restcall, 'call_req')
144 @mock.patch.object(CreateVnfs, 'build_homing_request')
145 def test_send_homing_request(self, mock_build_req, mock_call_req):
146 nf_inst_id, job_id = create_vnfs.prepare_create_params()
147 OOFDataModel.objects.all().delete()
150 "transactionId": "1234",
151 "requestStatus": "accepted"
153 mock_build_req.return_value = {
155 "transactionId": "1234",
159 "requestType": "create",
161 "optimizers": ["placement"],
165 "placementDemands": [
167 "resourceModuleName": "vG",
168 "serviceResourceId": "1234",
169 "resourceModelInfo": {
170 "modelInvariantId": "1234",
171 "modelVersionId": "1234"
177 "serviceInstanceId": "1234",
178 "serviceName": "1234",
180 "modelInvariantId": "5678",
181 "modelVersionId": "7890"
185 mock_call_req.return_value = [0, json.JSONEncoder().encode(resp), '202']
187 'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
188 'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
189 'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
190 'vnf_index': ignore_case_get(self.data, 'vnfIndex')
192 CreateVnfs(data, nf_inst_id, job_id).send_homing_request_to_OOF()
193 ret = OOFDataModel.objects.filter(request_id="1234", transaction_id="1234")
194 self.assertIsNotNone(ret)
197 class TestTerminateVnfViews(TestCase):
199 self.client = Client()
200 self.ns_inst_id = str(uuid.uuid4())
201 self.nf_inst_id = '1'
202 self.vnffg_id = str(uuid.uuid4())
203 self.vim_id = str(uuid.uuid4())
204 self.job_id = str(uuid.uuid4())
206 self.tenant = "tenantname"
210 "vnfdName": "PGW001",
211 "vnfProvider": "zte",
212 "vnfdVersion": "V00001",
213 "vnfVersion": "V5.10.20",
216 "description": "PGW VNFD description",
218 "vnfExtendType": "driver"
221 NSInstModel.objects.all().delete()
222 NfInstModel.objects.all().delete()
223 VmInstModel.objects.all().delete()
224 NSInstModel(id=self.ns_inst_id, name="ns_name").save()
225 NfInstModel.objects.create(nfinstid=self.nf_inst_id,
229 ns_inst_id='111,2-2-2',
236 mnfinstid=self.nf_uuid,
238 vnfd_model=self.vnfd_model)
239 VmInstModel.objects.create(vmid="1",
242 insttype=INST_TYPE.VNF,
243 instid=self.nf_inst_id,
248 NSInstModel.objects.all().delete()
249 NfInstModel.objects.all().delete()
251 @mock.patch.object(TerminateVnfs, 'run')
252 def test_terminate_vnf_url(self, mock_run):
254 "terminationType": "forceful",
255 "gracefulTerminationTimeout": "600"}
257 response = self.client.post("/api/nslcm/v1/ns/terminatevnf/%s" % self.nf_inst_id, data=req_data)
258 self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
260 @mock.patch.object(restcall, 'call_req')
261 @mock.patch.object(SubscriptionDeletion, 'send_subscription_deletion_request')
262 def test_terminate_vnf(self, mock_send_subscription_deletion_request, mock_call_req):
263 job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
265 nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
267 self.failUnlessEqual(1, 1)
269 self.failUnlessEqual(1, 0)
271 notification_types = ["VnfLcmOperationOccurrenceNotification"],
292 vnf_instance_subscription_filter = {
294 "vnfInstanceIds": '1',
295 "vnfInstanceNames": [],
296 "vnfProductsFromProviders": {}
298 SubscriptionModel.objects.create(
300 notification_types=json.dumps(notification_types),
301 operation_types=json.dumps(operation_types),
302 operation_states=json.dumps(operation_states),
303 vnf_instance_filter=json.dumps(vnf_instance_subscription_filter),
305 # links=json.dumps(...)
309 "vnf-id": "vnf-id-test111",
310 "vnf-name": "vnf-name-test111",
311 "vnf-type": "vnf-type-test111",
313 "is-closed-loop-disabled": False,
314 "resource-version": "1505465356262"
318 "responsedescriptor": {
320 "status": JOB_MODEL_STATUS.FINISHED,
322 "statusdescription": "creating",
324 "responsehistorylist": [
327 "status": JOB_MODEL_STATUS.PROCESSING,
329 "statusdescription": "creating",
337 "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
338 [0, json.JSONEncoder().encode(vnfm_info), '200'],
339 "/api/ztevnfmdriver/v1/1/vnfs/111/terminate":
340 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
341 "/api/resmgr/v1/vnf/1":
342 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
343 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
344 [0, json.JSONEncoder().encode(vim_info), '201'],
345 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?depth=all":
346 [0, json.JSONEncoder().encode(vserver_info), '201'],
347 "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?resource-version=1505465356263":
348 [0, json.JSONEncoder().encode({}), '200'],
349 "/api/ztevnfmdriver/v1/1/jobs/" + job_id + "?responseId=0":
350 [0, json.JSONEncoder().encode(job_info), '200'],
351 "/network/generic-vnfs/generic-vnf/1?depth=all":
352 [0, json.JSONEncoder().encode(vnf_info), '200'],
353 "/network/generic-vnfs/generic-vnf/1?resource-version=1505465356262":
354 [0, json.JSONEncoder().encode({}), '200']
357 def side_effect(*args):
358 return mock_vals[args[4]]
360 mock_call_req.side_effect = side_effect
363 "terminationType": "forceful",
364 "gracefulTerminationTimeout": "600"
367 TerminateVnfs(req_data, self.nf_inst_id, job_id).run()
368 nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
370 self.failUnlessEqual(1, 0)
372 self.failUnlessEqual(1, 1)
375 class TestScaleVnfViews(TestCase):
377 self.client = Client()
378 self.ns_inst_id = str(uuid.uuid4())
379 self.nf_inst_id = str(uuid.uuid4())
380 self.vnffg_id = str(uuid.uuid4())
381 self.vim_id = str(uuid.uuid4())
382 self.job_id = str(uuid.uuid4())
384 self.tenant = "tenantname"
385 NSInstModel(id=self.ns_inst_id, name="ns_name").save()
386 NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
387 vnfm_inst_id='1', ns_inst_id='111,2-2-2',
388 max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
389 status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
390 vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
391 '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
392 '"productType": "CN","vnfType": "PGW",'
393 '"description": "PGW VNFD description",'
394 '"isShared":true,"vnfExtendType":"driver"}}')
397 NSInstModel.objects.all().delete()
398 NfInstModel.objects.all().delete()
400 def test_scale_vnf(self):
403 "flavour_id": "flavour1",
408 "instances_minimum_number": 1,
409 "instances_maximum_number": 4,
410 "local_affinity_antiaffinity_rule": [
412 "affinity_antiaffinity": "affinity",
421 "name": "demo_aspect",
422 "description": "demo_aspect",
423 "associated_group": "elementGroup1",
429 "group_id": "elementGroup1",
432 "name": "elementGroup1",
434 "members": ["gsu_vm", "pfu_vm"]
442 "aspectId": "demo_aspect1",
444 "additionalParam": vnfd_info
448 "aspectId": "demo_aspect2",
450 "additionalParam": vnfd_info
455 NFManualScaleService(self.nf_inst_id, req_data).run()
456 nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
457 self.assertIsNotNone(nsIns)
459 @mock.patch.object(NFManualScaleService, "send_nf_scaling_request")
460 def test_scale_vnf_success(self, mock_send_nf_scaling_request):
463 "flavour_id": "flavour1",
468 "instances_minimum_number": 1,
469 "instances_maximum_number": 4,
470 "local_affinity_antiaffinity_rule": [
472 "affinity_antiaffinity": "affinity",
481 "name": "demo_aspect",
482 "description": "demo_aspect",
483 "associated_group": "elementGroup1",
489 "group_id": "elementGroup1",
492 "name": "elementGroup1",
494 "members": ["gsu_vm", "pfu_vm"]
502 "aspectId": "demo_aspect1",
504 "additionalParam": vnfd_info
508 "aspectId": "demo_aspect2",
510 "additionalParam": vnfd_info
514 scale_service = NFManualScaleService(self.nf_inst_id, req_data)
516 nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
517 self.assertIsNotNone(nsIns)
519 jobs = JobModel.objects.filter(jobid=scale_service.job_id)
520 self.assertIsNotNone(100, jobs[0].progress)
523 class TestHealVnfViews(TestCase):
525 self.client = Client()
526 self.ns_inst_id = str(uuid.uuid4())
527 self.nf_inst_id = str(uuid.uuid4())
530 self.job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, self.nf_inst_id)
532 NSInstModel(id=self.ns_inst_id, name="ns_name").save()
533 NfInstModel.objects.create(nfinstid=self.nf_inst_id,
537 ns_inst_id='111,2-2-2',
544 mnfinstid=self.nf_uuid,
546 vnfd_model=json.dumps({
549 "vnfdName": "PGW001",
550 "vnfProvider": "zte",
551 "vnfdVersion": "V00001",
552 "vnfVersion": "V5.10.20",
555 "description": "PGW VNFD description",
557 "vnfExtendType": "driver"
562 NSInstModel.objects.all().delete()
563 NfInstModel.objects.all().delete()
565 @mock.patch.object(restcall, "call_req")
566 def test_heal_vnf(self, mock_call_req):
569 "/api/ztevnfmdriver/v1/1/vnfs/111/heal":
570 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
571 "/external-system/esr-vnfm-list/esr-vnfm/1":
572 [0, json.JSONEncoder().encode(vnfm_info), '200'],
573 "/api/resmgr/v1/vnf/1":
574 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
575 "/api/ztevnfmdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
576 [0, json.JSONEncoder().encode({
577 "jobId": self.job_id,
578 "responsedescriptor": {
580 "status": JOB_MODEL_STATUS.FINISHED,
582 "statusdescription": "creating",
584 "responsehistorylist": [{
586 "status": JOB_MODEL_STATUS.PROCESSING,
588 "statusdescription": "creating",
594 def side_effect(*args):
595 return mock_vals[args[4]]
597 mock_call_req.side_effect = side_effect
608 NFHealService(self.nf_inst_id, req_data).run()
610 self.assertEqual(NfInstModel.objects.get(nfinstid=self.nf_inst_id).status, VNF_STATUS.ACTIVE)
612 @mock.patch.object(NFHealService, "run")
613 def test_heal_vnf_non_existing_vnf(self, mock_biz):
614 mock_biz.side_effect = NSLCMException("VNF Not Found")
627 self.assertRaises(NSLCMException, NFHealService(nf_inst_id, req_data).run)
628 self.assertEqual(len(NfInstModel.objects.filter(nfinstid=nf_inst_id)), 0)
631 class TestGetVnfmInfoViews(TestCase):
633 self.client = Client()
634 self.vnfm_id = str(uuid.uuid4())
639 @mock.patch.object(restcall, "call_req")
640 def test_get_vnfm_info(self, mock_call_req):
642 "vnfm-id": "example-vnfm-id-val-62576",
643 "vim-id": "example-vim-id-val-35114",
644 "certificate-url": "example-certificate-url-val-90242",
645 "esr-system-info-list": {
648 "esr-system-info-id": "example-esr-system-info-id-val-78484",
649 "system-name": "example-system-name-val-23790",
650 "type": "example-type-val-52596",
651 "vendor": "example-vendor-val-47399",
652 "version": "example-version-val-42051",
653 "service-url": "example-service-url-val-10731",
654 "user-name": "example-user-name-val-65946",
655 "password": "example-password-val-22505",
656 "system-type": "example-system-type-val-27221",
657 "protocal": "example-protocal-val-54632",
658 "ssl-cacert": "example-ssl-cacert-val-45965",
659 "ssl-insecure": True,
660 "ip-address": "example-ip-address-val-19212",
661 "port": "example-port-val-57641",
662 "cloud-domain": "example-cloud-domain-val-26296",
663 "default-tenant": "example-default-tenant-val-87724"
668 r1 = [0, json.JSONEncoder().encode(vnfm_info_aai), '200']
669 mock_call_req.side_effect = [r1]
670 esr_system_info = ignore_case_get(ignore_case_get(vnfm_info_aai, "esr-system-info-list"), "esr-system-info")
672 "vnfmId": vnfm_info_aai["vnfm-id"],
673 "name": vnfm_info_aai["vnfm-id"],
674 "type": ignore_case_get(esr_system_info[0], "type"),
675 "vimId": vnfm_info_aai["vim-id"],
676 "vendor": ignore_case_get(esr_system_info[0], "vendor"),
677 "version": ignore_case_get(esr_system_info[0], "version"),
678 "description": "vnfm",
679 "certificateUrl": vnfm_info_aai["certificate-url"],
680 "url": ignore_case_get(esr_system_info[0], "service-url"),
681 "userName": ignore_case_get(esr_system_info[0], "user-name"),
682 "password": ignore_case_get(esr_system_info[0], "password"),
686 response = self.client.get("/api/nslcm/v1/vnfms/%s" % self.vnfm_id)
687 self.failUnlessEqual(status.HTTP_200_OK, response.status_code, response.content)
688 context = json.loads(response.content)
689 self.assertEqual(expect_data, context)
692 class TestGetVimInfoViews(TestCase):
694 self.client = Client()
695 self.vim_id = "zte_test"
700 @mock.patch.object(restcall, "call_req")
701 def test_get_vim_info(self, mock_call_req):
702 r1 = [0, json.JSONEncoder().encode(vim_info), '200']
703 mock_call_req.side_effect = [r1]
704 esr_system_info = ignore_case_get(ignore_case_get(vim_info, "esr-system-info-list"), "esr-system-info")
706 "vimId": self.vim_id,
708 "url": ignore_case_get(esr_system_info[0], "service-url"),
709 "userName": ignore_case_get(esr_system_info[0], "user-name"),
710 "password": ignore_case_get(esr_system_info[0], "password"),
711 # "tenant": ignore_case_get(tenants[0], "tenant-id"),
712 "tenant": ignore_case_get(esr_system_info[0], "default-tenant"),
713 "vendor": ignore_case_get(esr_system_info[0], "vendor"),
714 "version": ignore_case_get(esr_system_info[0], "version"),
715 "description": "vim",
717 "type": ignore_case_get(esr_system_info[0], "type"),
721 response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
722 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
723 context = json.loads(response.content)
724 self.assertEqual(expect_data["url"], context["url"])
727 class TestPlaceVnfViews(TestCase):
729 self.vnf_inst_id = "1234"
730 self.vnf_inst_name = "vG"
731 self.client = Client()
732 OOFDataModel.objects.all().delete()
733 OOFDataModel.objects.create(
735 transaction_id="1234",
736 request_status="init",
737 request_module_name=self.vnf_inst_name,
738 service_resource_id=self.vnf_inst_id,
746 OOFDataModel.objects.all().delete()
748 @mock.patch.object(restcall, 'call_req')
749 def test_place_vnf(self, mock_call_req):
752 "flavorName": "HPA.flavor.1",
755 PlaceVnfs(vnf_place_request).extract()
756 db_info = OOFDataModel.objects.filter(request_id=vnf_place_request.get("requestId"), transaction_id=vnf_place_request.get("transactionId"))
757 self.assertEqual(db_info[0].request_status, "completed")
758 self.assertEqual(db_info[0].vim_id, "CloudOwner1_DLLSTX1A")
759 self.assertEqual(db_info[0].cloud_owner, "CloudOwner1")
760 self.assertEqual(db_info[0].cloud_region_id, "DLLSTX1A")
761 self.assertEqual(db_info[0].vdu_info, json.dumps(vdu_info_json))
763 def test_place_vnf_with_invalid_response(self):
766 "transactionId": "1234",
767 "statusMessage": "xx",
768 "requestStatus": "pending",
770 "placementSolutions": [
773 "resourceModuleName": self.vnf_inst_name,
774 "serviceResourceId": self.vnf_inst_id,
776 "identifierType": "serviceInstanceId",
780 "cloudOwner": "CloudOwner1 "
786 "licenseSolutions": [
788 "resourceModuleName": "string",
789 "serviceResourceId": "string",
790 "entitlementPoolUUID": [
793 "licenseKeyGroupUUID": [
796 "entitlementPoolInvariantUUID": [
799 "licenseKeyGroupInvariantUUID": [
806 PlaceVnfs(resp).extract()
807 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
808 self.assertEqual(db_info[0].request_status, "pending")
809 self.assertEqual(db_info[0].vim_id, "none")
810 self.assertEqual(db_info[0].cloud_owner, "none")
811 self.assertEqual(db_info[0].cloud_region_id, "none")
812 self.assertEqual(db_info[0].vdu_info, "none")
814 def test_place_vnf_with_no_assignment_info(self):
817 "transactionId": "1234",
818 "statusMessage": "xx",
819 "requestStatus": "completed",
821 "placementSolutions": [
824 "resourceModuleName": self.vnf_inst_name,
825 "serviceResourceId": self.vnf_inst_id,
827 "identifierType": "serviceInstanceId",
831 "cloudOwner": "CloudOwner1 "
836 "licenseSolutions": [
838 "resourceModuleName": "string",
839 "serviceResourceId": "string",
840 "entitlementPoolUUID": [
843 "licenseKeyGroupUUID": [
846 "entitlementPoolInvariantUUID": [
849 "licenseKeyGroupInvariantUUID": [
856 PlaceVnfs(resp).extract()
857 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
858 self.assertEqual(db_info[0].request_status, "completed")
859 self.assertEqual(db_info[0].vim_id, "none")
860 self.assertEqual(db_info[0].cloud_owner, "none")
861 self.assertEqual(db_info[0].cloud_region_id, "none")
862 self.assertEqual(db_info[0].vdu_info, "none")
864 def test_place_vnf_no_directives(self):
867 "transactionId": "1234",
868 "statusMessage": "xx",
869 "requestStatus": "completed",
871 "placementSolutions": [
874 "resourceModuleName": self.vnf_inst_name,
875 "serviceResourceId": self.vnf_inst_id,
877 "identifierType": "serviceInstanceId",
881 "cloudOwner": "CloudOwner1 "
884 {"key": "locationId",
893 "resourceModuleName": "string",
894 "serviceResourceId": "string",
895 "entitlementPoolUUID": [
898 "licenseKeyGroupUUID": [
901 "entitlementPoolInvariantUUID": [
904 "licenseKeyGroupInvariantUUID": [
911 PlaceVnfs(resp).extract()
912 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
913 self.assertEqual(db_info[0].request_status, "completed")
914 self.assertEqual(db_info[0].vim_id, "none")
915 self.assertEqual(db_info[0].cloud_owner, "none")
916 self.assertEqual(db_info[0].cloud_region_id, "none")
917 self.assertEqual(db_info[0].vdu_info, "none")
919 def test_place_vnf_with_no_solution(self):
922 "transactionId": "1234",
923 "statusMessage": "xx",
924 "requestStatus": "completed",
926 "placementSolutions": [],
927 "licenseSoutions": []
930 PlaceVnfs(resp).extract()
931 db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
932 self.assertEqual(db_info[0].request_status, "completed")
933 self.assertEqual(db_info[0].vim_id, "no-solution")
934 self.assertEqual(db_info[0].cloud_owner, "no-solution")
935 self.assertEqual(db_info[0].cloud_region_id, "no-solution")
936 self.assertEqual(db_info[0].vdu_info, "no-solution")
940 'local_storages': [],
953 'vdu_id': u'vdu_omm.001',
954 'image_file': u'opencos_sss_omm_img_release_20150723-1-disk1',
966 'support_scaling': False,
969 'storage_policy': '',
972 'availability_zone': '',
978 'inject_data_list': [
985 'local_affinity_antiaffinity_rule': {
988 'template_id': u'omm.001',
989 'manual_scale_select_vim': False
991 'description': u'singleommvm'
1005 'image_file': u'sss',
1017 'support_scaling': False,
1020 'storage_policy': '',
1023 'availability_zone': '',
1029 'inject_data_list': [
1036 'local_affinity_antiaffinity_rule': {
1039 'template_id': u'1',
1040 'manual_scale_select_vim': False
1042 'description': u'ompvm'
1045 'volumn_storages': [
1056 'image_file': u'sss',
1068 'support_scaling': False,
1071 'storage_policy': '',
1074 'availability_zone': '',
1080 'inject_data_list': [
1087 'local_affinity_antiaffinity_rule': {
1090 'template_id': u'2',
1091 'manual_scale_select_vim': False
1093 'description': u'ompvm'
1096 'volumn_storages': [
1107 'image_file': u'sss',
1119 'support_scaling': False,
1122 'storage_policy': '',
1125 'availability_zone': '',
1131 'inject_data_list': [
1138 'local_affinity_antiaffinity_rule': {
1141 'template_id': u'3',
1142 'manual_scale_select_vim': False
1144 'description': u'ompvm'
1147 'volumn_storages': [
1157 'vdu_id': u'vdu_10',
1158 'image_file': u'sss',
1170 'support_scaling': False,
1173 'storage_policy': '',
1176 'availability_zone': '',
1182 'inject_data_list': [
1189 'local_affinity_antiaffinity_rule': {
1192 'template_id': u'10',
1193 'manual_scale_select_vim': False
1195 'description': u'ppvm'
1198 'volumn_storages': [
1208 'vdu_id': u'vdu_11',
1209 'image_file': u'sss',
1221 'support_scaling': False,
1224 'storage_policy': '',
1227 'availability_zone': '',
1233 'inject_data_list': [
1240 'local_affinity_antiaffinity_rule': {
1243 'template_id': u'11',
1244 'manual_scale_select_vim': False
1246 'description': u'ppvm'
1249 'volumn_storages': [
1259 'vdu_id': u'vdu_12',
1260 'image_file': u'sss',
1272 'support_scaling': False,
1275 'storage_policy': '',
1278 'availability_zone': '',
1284 'inject_data_list': [
1291 'local_affinity_antiaffinity_rule': {
1294 'template_id': u'12',
1295 'manual_scale_select_vim': False
1297 'description': u'ppvm'
1300 'volumn_storages': [
1308 'policy_id': u'policy_scale_sss-vnf-template',
1310 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'
1319 'name': u'opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1321 'disk_format': u'VMDK',
1322 'file_url': u'./zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1323 'container_type': 'vm',
1325 'hypervisor_type': 'kvm'
1327 'image_file_id': u'opencos_sss_omm_img_release_20150723-1-disk1'
1332 'name': u'sss.vmdk',
1334 'disk_format': u'VMDK',
1335 'file_url': u'./zte-cn-sss-main-image/NE/sss.vmdk',
1336 'container_type': 'vm',
1338 'hypervisor_type': 'kvm'
1340 'image_file_id': u'sss'
1353 'domain_type': u'CN',
1354 'version': u'v4.14.10',
1355 'vmnumber_overquota_alarm': False,
1358 'vnfd_version': u'V00000001',
1359 'id': u'sss-vnf-template',
1360 'name': u'sss-vnf-template'
1369 "externalDataNetworkName": {
1393 "plugin_info": "vbrasplugin_1.0",
1395 "is_shared": "False",
1396 "request_reclassification": "False",
1397 "vnfd_version": "1.0.0",
1399 "nsh_aware": "True",
1400 "cross_dc": "False",
1401 "externalDataNetworkName": {
1402 "get_input": "externalDataNetworkName"
1424 "vl_id": "ext_mnet_network",
1427 "network_type": "vlan",
1428 "name": "externalMNetworkName",
1429 "dhcp_enabled": False,
1437 "end_ip": "190.168.100.100",
1438 "gateway_ip": "190.168.100.1",
1439 "start_ip": "190.168.100.2",
1440 "cidr": "190.168.100.0/24",
1442 "network_name": "sub_mnet",
1454 "invariant_id": "vbras_ns",
1455 "description": "vbras_ns",
1464 "vserver-id": "example-vserver-id-val-70924",
1465 "vserver-name": "example-vserver-name-val-61674",
1466 "vserver-name2": "example-vserver-name2-val-19234",
1467 "prov-status": "example-prov-status-val-94916",
1468 "vserver-selflink": "example-vserver-selflink-val-26562",
1470 "is-closed-loop-disabled": True,
1471 "resource-version": "1505465356263",
1475 "volume-id": "example-volume-id-val-71854",
1476 "volume-selflink": "example-volume-selflink-val-22433"
1483 "interface-name": "example-interface-name-val-24351",
1484 "interface-role": "example-interface-role-val-43242",
1485 "v6-wan-link-ip": "example-v6-wan-link-ip-val-4196",
1486 "selflink": "example-selflink-val-61295",
1487 "interface-id": "example-interface-id-val-95879",
1488 "macaddr": "example-macaddr-val-37302",
1489 "network-name": "example-network-name-val-44254",
1490 "management-option": "example-management-option-val-49009",
1491 "interface-description": "example-interface-description-val-99923",
1492 "is-port-mirrored": True,
1494 "prov-status": "example-prov-status-val-4698",
1495 "is-ip-unnumbered": True,
1496 "allowed-address-pairs": "example-allowed-address-pairs-val-5762",
1500 "vlan-interface": "example-vlan-interface-val-58193",
1501 "vlan-id-inner": 54452151,
1502 "vlan-id-outer": 70239293,
1503 "speed-value": "example-speed-value-val-18677",
1504 "speed-units": "example-speed-units-val-46185",
1505 "vlan-description": "example-vlan-description-val-81675",
1506 "backdoor-connection": "example-backdoor-connection-val-44608",
1507 "vpn-key": "example-vpn-key-val-7946",
1508 "orchestration-status": "example-orchestration-status-val-33611",
1510 "prov-status": "example-prov-status-val-8288",
1511 "is-ip-unnumbered": True,
1512 "l3-interface-ipv4-address-list": [
1514 "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-25520",
1515 "l3-interface-ipv4-prefix-length": 69931928,
1516 "vlan-id-inner": 86628520,
1517 "vlan-id-outer": 62729236,
1518 "is-floating": True,
1519 "neutron-network-id": "example-neutron-network-id-val-64021",
1520 "neutron-subnet-id": "example-neutron-subnet-id-val-95049"
1523 "l3-interface-ipv6-address-list": [
1525 "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-64310",
1526 "l3-interface-ipv6-prefix-length": 57919834,
1527 "vlan-id-inner": 79150122,
1528 "vlan-id-outer": 59789973,
1529 "is-floating": True,
1530 "neutron-network-id": "example-neutron-network-id-val-31713",
1531 "neutron-subnet-id": "example-neutron-subnet-id-val-89568"
1540 "pci-id": "example-pci-id-val-16747",
1541 "vf-vlan-filter": "example-vf-vlan-filter-val-4613",
1542 "vf-mac-filter": "example-vf-mac-filter-val-68168",
1543 "vf-vlan-strip": True,
1544 "vf-vlan-anti-spoof-check": True,
1545 "vf-mac-anti-spoof-check": True,
1546 "vf-mirrors": "example-vf-mirrors-val-6270",
1547 "vf-broadcast-allow": True,
1548 "vf-unknown-multicast-allow": True,
1549 "vf-unknown-unicast-allow": True,
1550 "vf-insert-stag": True,
1551 "vf-link-status": "example-vf-link-status-val-49266",
1552 "neutron-network-id": "example-neutron-network-id-val-29493"
1559 "interface-name": "example-interface-name-val-98222",
1560 "interface-role": "example-interface-role-val-78360",
1561 "v6-wan-link-ip": "example-v6-wan-link-ip-val-76921",
1562 "selflink": "example-selflink-val-27117",
1563 "interface-id": "example-interface-id-val-11260",
1564 "macaddr": "example-macaddr-val-60378",
1565 "network-name": "example-network-name-val-16258",
1566 "management-option": "example-management-option-val-35097",
1567 "interface-description": "example-interface-description-val-10475",
1568 "is-port-mirrored": True,
1570 "prov-status": "example-prov-status-val-65203",
1571 "is-ip-unnumbered": True,
1572 "allowed-address-pairs": "example-allowed-address-pairs-val-65028"
1576 "l3-interface-ipv4-address-list": [
1578 "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-72779",
1579 "l3-interface-ipv4-prefix-length": 55956636,
1580 "vlan-id-inner": 98174431,
1581 "vlan-id-outer": 20372128,
1582 "is-floating": True,
1583 "neutron-network-id": "example-neutron-network-id-val-39596",
1584 "neutron-subnet-id": "example-neutron-subnet-id-val-51109"
1587 "l3-interface-ipv6-address-list": [
1589 "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-95203",
1590 "l3-interface-ipv6-prefix-length": 57454747,
1591 "vlan-id-inner": 53421060,
1592 "vlan-id-outer": 16006050,
1593 "is-floating": True,
1594 "neutron-network-id": "example-neutron-network-id-val-54216",
1595 "neutron-subnet-id": "example-neutron-subnet-id-val-1841"
1605 "vnfm-id": "example-vnfm-id-val-97336",
1606 "vim-id": "zte_test",
1607 "certificate-url": "example-certificate-url-val-18046",
1608 "resource-version": "example-resource-version-val-42094",
1609 "esr-system-info-list": {
1610 "esr-system-info": [
1612 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1613 "system-name": "example-system-name-val-19801",
1614 "type": "ztevnfmdriver",
1615 "vendor": "example-vendor-val-50079",
1616 "version": "example-version-val-93146",
1617 "service-url": "example-service-url-val-68090",
1618 "user-name": "example-user-name-val-14470",
1619 "password": "example-password-val-84190",
1620 "system-type": "example-system-type-val-42773",
1621 "protocal": "example-protocal-val-85736",
1622 "ssl-cacert": "example-ssl-cacert-val-33989",
1623 "ssl-insecure": True,
1624 "ip-address": "example-ip-address-val-99038",
1625 "port": "example-port-val-27323",
1626 "cloud-domain": "example-cloud-domain-val-55163",
1627 "default-tenant": "example-default-tenant-val-99383",
1628 "resource-version": "example-resource-version-val-15424"
1635 "cloud-owner": "example-cloud-owner-val-97336",
1636 "cloud-region-id": "example-cloud-region-id-val-35532",
1637 "cloud-type": "example-cloud-type-val-18046",
1638 "owner-defined-type": "example-owner-defined-type-val-9413",
1639 "cloud-region-version": "example-cloud-region-version-val-85706",
1640 "identity-url": "example-identity-url-val-71252",
1641 "cloud-zone": "example-cloud-zone-val-27112",
1642 "complex-name": "example-complex-name-val-85283",
1643 "sriov-automation": True,
1644 "cloud-extra-info": "example-cloud-extra-info-val-90854",
1645 "cloud-epa-caps": "example-cloud-epa-caps-val-2409",
1646 "resource-version": "example-resource-version-val-42094",
1647 "esr-system-info-list": {
1648 "esr-system-info": [
1650 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1651 "system-name": "example-system-name-val-19801",
1652 "type": "example-type-val-24477",
1653 "vendor": "example-vendor-val-50079",
1654 "version": "example-version-val-93146",
1655 "service-url": "example-service-url-val-68090",
1656 "user-name": "example-user-name-val-14470",
1657 "password": "example-password-val-84190",
1658 "system-type": "example-system-type-val-42773",
1659 "protocal": "example-protocal-val-85736",
1660 "ssl-cacert": "example-ssl-cacert-val-33989",
1661 "ssl-insecure": True,
1662 "ip-address": "example-ip-address-val-99038",
1663 "port": "example-port-val-27323",
1664 "cloud-domain": "example-cloud-domain-val-55163",
1665 "default-tenant": "admin",
1666 "resource-version": "example-resource-version-val-15424"
1673 "csarId": "zte_vbras",
1676 "vnfPackageId": "zte_vbras",
1677 "vnfdProvider": "1",
1681 "vnfdModel": vnfd_model_dict,
1687 vnf_place_request = {
1688 "requestId": "1234",
1689 "transactionId": "1234",
1690 "statusMessage": "xx",
1691 "requestStatus": "completed",
1693 "placementSolutions": [
1696 "resourceModuleName": "vG",
1697 "serviceResourceId": "1234",
1699 "identifierType": "serviceInstanceId",
1703 "cloudOwner": "CloudOwner1"
1709 {"key": "locationId",
1712 {"key": "locationType",
1713 "value": "openstack-cloud"
1716 "value": "CloudOwner1_DLLSTX1A"
1718 {"key": "physicalLocationId",
1719 "value": "DLLSTX1223"
1721 {"key": "oof_directives",
1726 "type": "tocsa.nodes.nfv.Vdu.Compute",
1729 "type": "flavor_directives",
1732 "attribute_name": "flavor_name",
1733 "attribute_value": "HPA.flavor.1"
1746 "attribute_name": " ",
1747 "attribute_value": " "
1760 "licenseSolutions": [
1762 "resourceModuleName": "string",
1763 "serviceResourceId": "string",
1764 "entitlementPoolUUID": [
1767 "licenseKeyGroupUUID": [
1770 "entitlementPoolInvariantUUID": [
1773 "licenseKeyGroupInvariantUUID": [