Update python2 to python3
[vfc/nfvo/lcm.git] / lcm / ns_vnfs / tests / tests.py
1 # Copyright 2016-2017 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 import json
15 import uuid
16
17 import mock
18 from django.test import TestCase, Client
19 from rest_framework import status
20
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.enum import JOB_MODEL_STATUS, JOB_TYPE
25 from lcm.pub.utils.jobutil import JobUtil
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.grant_vnf import GrantVnf
30 from lcm.ns_vnfs.biz.heal_vnfs import NFHealService
31 from lcm.ns_vnfs.biz.scale_vnfs import NFManualScaleService
32 from lcm.ns_vnfs.biz.subscribe import SubscriptionDeletion
33 from lcm.ns_vnfs.biz.terminate_nfs import TerminateVnfs
34 from lcm.ns_vnfs.enum import VNF_STATUS, INST_TYPE
35 from lcm.ns_vnfs.biz import create_vnfs
36 from lcm.ns_vnfs.biz.place_vnfs import PlaceVnfs
37 from lcm.pub.msapi import resmgr
38
39
40 class TestGetVnfViews(TestCase):
41     def setUp(self):
42         self.client = Client()
43         self.nf_inst_id = str(uuid.uuid4())
44         NfInstModel(nfinstid=self.nf_inst_id, nf_name='vnf1', vnfm_inst_id='1', vnf_id='vnf_id1',
45                     status=VNF_STATUS.ACTIVE, create_time=now_time(), lastuptime=now_time()).save()
46
47     def tearDown(self):
48         NfInstModel.objects.all().delete()
49
50     def test_get_vnf(self):
51         response = self.client.get("/api/nslcm/v1/ns/vnfs/%s" % self.nf_inst_id)
52         self.assertEqual(status.HTTP_200_OK, response.status_code)
53         context = json.loads(response.content)
54         self.assertEqual(self.nf_inst_id, context['vnfInstId'])
55
56
57 class TestCreateVnfViews(TestCase):
58     def setUp(self):
59         self.ns_inst_id = str(uuid.uuid4())
60         self.job_id = str(uuid.uuid4())
61         self.data = {
62             "nsInstanceId": self.ns_inst_id,
63             "additionalParamForNs": {
64                 "inputs": json.dumps({
65
66                 })
67             },
68             "additionalParamForVnf": [
69                 {
70                     "vnfprofileid": "VBras",
71                     "additionalparam": {
72                         "inputs": json.dumps({
73                             "vnf_param1": "11",
74                             "vnf_param2": "22"
75                         }),
76                         "vnfminstanceid": "1",
77                         # "vimId": "zte_test"
78                         "vimId": '{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}'
79                     }
80                 }
81             ],
82             "vnfIndex": "1"
83         }
84         self.client = Client()
85         NSInstModel(id=self.ns_inst_id, name='ns', nspackage_id='1', nsd_id='nsd_id', description='description',
86                     status='instantiating', nsd_model=json.dumps(nsd_model_dict), create_time=now_time(),
87                     lastuptime=now_time()).save()
88
89     def tearDown(self):
90         NfInstModel.objects.all().delete()
91         JobModel.objects.all().delete()
92
93     @mock.patch.object(CreateVnfs, 'run')
94     def test_create_vnf(self, mock_run):
95         response = self.client.post("/api/nslcm/v1/ns/vnfs", data=self.data)
96         self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
97         context = json.loads(response.content)
98         self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstId']).exists())
99
100     @mock.patch.object(restcall, 'call_req')
101     def test_create_vnf_thread(self, mock_call_req):
102         nf_inst_id, job_id = create_vnfs.prepare_create_params()
103         mock_vals = {
104             "/api/ztevnfmdriver/v1/1/vnfs":
105                 [0, json.JSONEncoder().encode({"jobId": self.job_id, "vnfInstanceId": 3}), '200'],
106             "/api/catalog/v1/vnfpackages/zte_vbras":
107                 [0, json.JSONEncoder().encode(nf_package_info), '200'],
108             "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
109                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
110             "/api/resmgr/v1/vnf":
111                 [0, json.JSONEncoder().encode({}), '200'],
112             "/api/resmgr/v1/vnfinfo":
113                 [0, json.JSONEncoder().encode({}), '200'],
114             "/network/generic-vnfs/generic-vnf/%s" % nf_inst_id:
115                 [0, json.JSONEncoder().encode({}), '201'],
116             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
117                 [0, json.JSONEncoder().encode(vim_info), '201'],
118             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1":
119                 [0, json.JSONEncoder().encode({}), '201'],
120             "/api/ztevnfmdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
121                 [0, json.JSONEncoder().encode({"jobid": self.job_id,
122                                                "responsedescriptor": {"progress": "100",
123                                                                       "status": JOB_MODEL_STATUS.FINISHED,
124                                                                       "responseid": "3",
125                                                                       "statusdescription": "creating",
126                                                                       "errorcode": "0",
127                                                                       "responsehistorylist": [
128                                                                           {"progress": "0",
129                                                                            "status": JOB_MODEL_STATUS.PROCESSING,
130                                                                            "responseid": "2",
131                                                                            "statusdescription": "creating",
132                                                                            "errorcode": "0"}]}}), '200']}
133
134         def side_effect(*args):
135             return mock_vals[args[4]]
136         mock_call_req.side_effect = side_effect
137         data = {
138             'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
139             'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
140             'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
141             'vnf_index': ignore_case_get(self.data, 'vnfIndex')
142         }
143         CreateVnfs(data, nf_inst_id, job_id).run()
144         self.assertTrue(NfInstModel.objects.get(nfinstid=nf_inst_id).status, VNF_STATUS.ACTIVE)
145
146     @mock.patch.object(restcall, 'call_req')
147     @mock.patch.object(CreateVnfs, 'build_homing_request')
148     def test_send_homing_request(self, mock_build_req, mock_call_req):
149         nf_inst_id, job_id = create_vnfs.prepare_create_params()
150         OOFDataModel.objects.all().delete()
151         resp = {
152             "requestId": "1234",
153             "transactionId": "1234",
154             "requestStatus": "accepted"
155         }
156         mock_build_req.return_value = {
157             "requestInfo": {
158                 "transactionId": "1234",
159                 "requestId": "1234",
160                 "callbackUrl": "xx",
161                 "sourceId": "vfc",
162                 "requestType": "create",
163                 "numSolutions": 1,
164                 "optimizers": ["placement"],
165                 "timeout": 600
166             },
167             "placementInfo": {
168                 "placementDemands": [
169                     {
170                         "resourceModuleName": "vG",
171                         "serviceResourceId": "1234",
172                         "resourceModelInfo": {
173                             "modelInvariantId": "1234",
174                             "modelVersionId": "1234"
175                         }
176                     }
177                 ]
178             },
179             "serviceInfo": {
180                 "serviceInstanceId": "1234",
181                 "serviceName": "1234",
182                 "modelInfo": {
183                     "modelInvariantId": "5678",
184                     "modelVersionId": "7890"
185                 }
186             }
187         }
188         mock_call_req.return_value = [0, json.JSONEncoder().encode(resp), '202']
189         data = {
190             'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
191             'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
192             'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
193             'vnf_index': ignore_case_get(self.data, 'vnfIndex')
194         }
195         CreateVnfs(data, nf_inst_id, job_id).send_homing_request_to_OOF()
196         ret = OOFDataModel.objects.filter(request_id="1234", transaction_id="1234")
197         self.assertIsNotNone(ret)
198
199
200 class TestTerminateVnfViews(TestCase):
201     def setUp(self):
202         self.client = Client()
203         self.ns_inst_id = str(uuid.uuid4())
204         self.nf_inst_id = '1'
205         self.vnffg_id = str(uuid.uuid4())
206         self.vim_id = str(uuid.uuid4())
207         self.job_id = str(uuid.uuid4())
208         self.nf_uuid = '111'
209         self.tenant = "tenantname"
210         self.vnfd_model = {
211             "metadata": {
212                 "vnfdId": "1",
213                 "vnfdName": "PGW001",
214                 "vnfProvider": "zte",
215                 "vnfdVersion": "V00001",
216                 "vnfVersion": "V5.10.20",
217                 "productType": "CN",
218                 "vnfType": "PGW",
219                 "description": "PGW VNFD description",
220                 "isShared": True,
221                 "vnfExtendType": "driver"
222             }
223         }
224         NSInstModel.objects.all().delete()
225         NfInstModel.objects.all().delete()
226         VmInstModel.objects.all().delete()
227         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
228         NfInstModel.objects.create(nfinstid=self.nf_inst_id,
229                                    nf_name='name_1',
230                                    vnf_id='1',
231                                    vnfm_inst_id='1',
232                                    ns_inst_id='111,2-2-2',
233                                    max_cpu='14',
234                                    max_ram='12296',
235                                    max_hd='101',
236                                    max_shd="20",
237                                    max_net=10,
238                                    status='active',
239                                    mnfinstid=self.nf_uuid,
240                                    package_id='pkg1',
241                                    vnfd_model=self.vnfd_model)
242         VmInstModel.objects.create(vmid="1",
243                                    # vimid="zte_test",
244                                    vimid='{"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}',
245                                    resouceid="1",
246                                    insttype=INST_TYPE.VNF,
247                                    instid=self.nf_inst_id,
248                                    vmname="test",
249                                    hostid='1')
250
251     def tearDown(self):
252         NSInstModel.objects.all().delete()
253         NfInstModel.objects.all().delete()
254
255     @mock.patch.object(TerminateVnfs, 'run')
256     def test_terminate_vnf_url(self, mock_run):
257         req_data = {
258             "terminationType": "forceful",
259             "gracefulTerminationTimeout": "600"}
260
261         response = self.client.post("/api/nslcm/v1/ns/terminatevnf/%s" % self.nf_inst_id, data=req_data)
262         self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
263
264     @mock.patch.object(restcall, 'call_req')
265     @mock.patch.object(SubscriptionDeletion, 'send_subscription_deletion_request')
266     def test_terminate_vnf(self, mock_send_subscription_deletion_request, mock_call_req):
267         job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
268
269         nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
270         if nfinst:
271             self.assertEqual(1, 1)
272         else:
273             self.assertEqual(1, 0)
274
275         notification_types = ["VnfLcmOperationOccurrenceNotification"],
276         operation_types = [
277             "INSTANTIATE",
278             "SCALE",
279             "SCALE_TO_LEVEL",
280             "CHANGE_FLAVOUR",
281             "TERMINATE",
282             "HEAL",
283             "OPERATE",
284             "CHANGE_EXT_CONN",
285             "MODIFY_INFO"
286         ],
287         operation_states = [
288             "STARTING",
289             "PROCESSING",
290             "COMPLETED",
291             "FAILED_TEMP",
292             "FAILED",
293             "ROLLING_BACK",
294             "ROLLED_BACK"
295         ],
296         vnf_instance_subscription_filter = {
297             "vnfdIds": [],
298             "vnfInstanceIds": '1',
299             "vnfInstanceNames": [],
300             "vnfProductsFromProviders": {}
301         }
302         SubscriptionModel.objects.create(
303             subscription_id='1',
304             notification_types=json.dumps(notification_types),
305             operation_types=json.dumps(operation_types),
306             operation_states=json.dumps(operation_states),
307             vnf_instance_filter=json.dumps(vnf_instance_subscription_filter),
308             # callback_uri,
309             # links=json.dumps(...)
310         )
311
312         vnf_info = {
313             "vnf-id": "vnf-id-test111",
314             "vnf-name": "vnf-name-test111",
315             "vnf-type": "vnf-type-test111",
316             "in-maint": True,
317             "is-closed-loop-disabled": False,
318             "resource-version": "1505465356262"
319         }
320         job_info = {
321             "jobId": job_id,
322             "responsedescriptor": {
323                 "progress": "100",
324                 "status": JOB_MODEL_STATUS.FINISHED,
325                 "responseid": "3",
326                 "statusdescription": "creating",
327                 "errorcode": "0",
328                 "responsehistorylist": [
329                     {
330                         "progress": "0",
331                         "status": JOB_MODEL_STATUS.PROCESSING,
332                         "responseid": "2",
333                         "statusdescription": "creating",
334                         "errorcode": "0"
335                     }
336                 ]
337             }
338         }
339
340         mock_vals = {
341             "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
342                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
343             "/api/ztevnfmdriver/v1/1/vnfs/111/terminate":
344                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
345             "/api/resmgr/v1/vnf/1":
346                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
347             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
348                 [0, json.JSONEncoder().encode(vim_info), '201'],
349             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?depth=all":
350                 [0, json.JSONEncoder().encode(vserver_info), '201'],
351             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?resource-version=1505465356263":
352                 [0, json.JSONEncoder().encode({}), '200'],
353             "/api/ztevnfmdriver/v1/1/jobs/" + job_id + "?responseId=0":
354                 [0, json.JSONEncoder().encode(job_info), '200'],
355             "/network/generic-vnfs/generic-vnf/1?depth=all":
356             [0, json.JSONEncoder().encode(vnf_info), '200'],
357             "/network/generic-vnfs/generic-vnf/1?resource-version=1505465356262":
358             [0, json.JSONEncoder().encode({}), '200']
359         }
360
361         def side_effect(*args):
362             return mock_vals[args[4]]
363
364         mock_call_req.side_effect = side_effect
365
366         req_data = {
367             "terminationType": "forceful",
368             "gracefulTerminationTimeout": "600"
369         }
370
371         TerminateVnfs(req_data, self.nf_inst_id, job_id).run()
372         nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
373         if nfinst:
374             self.assertEqual(1, 0)
375         else:
376             self.assertEqual(1, 1)
377
378
379 class TestScaleVnfViews(TestCase):
380     def setUp(self):
381         self.client = Client()
382         self.ns_inst_id = str(uuid.uuid4())
383         self.nf_inst_id = str(uuid.uuid4())
384         self.vnffg_id = str(uuid.uuid4())
385         self.vim_id = str(uuid.uuid4())
386         self.job_id = str(uuid.uuid4())
387         self.nf_uuid = '111'
388         self.tenant = "tenantname"
389         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
390         NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
391                                    vnfm_inst_id='1', ns_inst_id='111,2-2-2',
392                                    max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
393                                    status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
394                                    vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
395                                               '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
396                                               '"productType": "CN","vnfType": "PGW",'
397                                               '"description": "PGW VNFD description",'
398                                               '"isShared":true,"vnfExtendType":"driver"}}')
399
400     def tearDown(self):
401         NSInstModel.objects.all().delete()
402         NfInstModel.objects.all().delete()
403
404     def test_scale_vnf(self):
405         vnfd_info = {
406             "vnf_flavours": [{
407                 "flavour_id": "flavour1",
408                 "description": "",
409                 "vdu_profiles": [
410                     {
411                         "vdu_id": "vdu1Id",
412                         "instances_minimum_number": 1,
413                         "instances_maximum_number": 4,
414                         "local_affinity_antiaffinity_rule": [
415                             {
416                                 "affinity_antiaffinity": "affinity",
417                                 "scope": "node",
418                             }
419                         ]
420                     }
421                 ],
422                 "scaling_aspects": [
423                     {
424                         "id": "demo_aspect",
425                         "name": "demo_aspect",
426                         "description": "demo_aspect",
427                         "associated_group": "elementGroup1",
428                         "max_scale_level": 5
429                     }
430                 ]
431             }],
432             "element_groups": [{
433                 "group_id": "elementGroup1",
434                 "description": "",
435                 "properties": {
436                     "name": "elementGroup1",
437                 },
438                 "members": ["gsu_vm", "pfu_vm"]
439             }]
440         }
441
442         req_data = {
443             "scaleVnfData": [
444                 {
445                     "type": "SCALE_OUT",
446                     "aspectId": "demo_aspect1",
447                     "numberOfSteps": 1,
448                     "additionalParam": vnfd_info
449                 },
450                 {
451                     "type": "SCALE_OUT",
452                     "aspectId": "demo_aspect2",
453                     "numberOfSteps": 1,
454                     "additionalParam": vnfd_info
455                 }
456             ]
457         }
458
459         NFManualScaleService(self.nf_inst_id, req_data).run()
460         nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
461         self.assertIsNotNone(nsIns)
462
463     @mock.patch.object(NFManualScaleService, "send_nf_scaling_request")
464     def test_scale_vnf_success(self, mock_send_nf_scaling_request):
465         vnfd_info = {
466             "vnf_flavours": [{
467                 "flavour_id": "flavour1",
468                 "description": "",
469                 "vdu_profiles": [
470                     {
471                         "vdu_id": "vdu1Id",
472                         "instances_minimum_number": 1,
473                         "instances_maximum_number": 4,
474                         "local_affinity_antiaffinity_rule": [
475                             {
476                                 "affinity_antiaffinity": "affinity",
477                                 "scope": "node",
478                             }
479                         ]
480                     }
481                 ],
482                 "scaling_aspects": [
483                     {
484                         "id": "demo_aspect",
485                         "name": "demo_aspect",
486                         "description": "demo_aspect",
487                         "associated_group": "elementGroup1",
488                         "max_scale_level": 5
489                     }
490                 ]
491             }],
492             "element_groups": [{
493                 "group_id": "elementGroup1",
494                 "description": "",
495                 "properties": {
496                     "name": "elementGroup1",
497                 },
498                 "members": ["gsu_vm", "pfu_vm"]
499             }]
500         }
501
502         req_data = {
503             "scaleVnfData": [
504                 {
505                     "type": "SCALE_OUT",
506                     "aspectId": "demo_aspect1",
507                     "numberOfSteps": 1,
508                     "additionalParam": vnfd_info
509                 },
510                 {
511                     "type": "SCALE_OUT",
512                     "aspectId": "demo_aspect2",
513                     "numberOfSteps": 1,
514                     "additionalParam": vnfd_info
515                 }
516             ]
517         }
518         scale_service = NFManualScaleService(self.nf_inst_id, req_data)
519         scale_service.run()
520         nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
521         self.assertIsNotNone(nsIns)
522
523         jobs = JobModel.objects.filter(jobid=scale_service.job_id)
524         self.assertIsNotNone(100, jobs[0].progress)
525
526
527 class TestHealVnfViews(TestCase):
528     def setUp(self):
529         self.client = Client()
530         self.ns_inst_id = str(uuid.uuid4())
531         self.nf_inst_id = str(uuid.uuid4())
532         self.nf_uuid = '111'
533
534         self.job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, self.nf_inst_id)
535
536         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
537         NfInstModel.objects.create(nfinstid=self.nf_inst_id,
538                                    nf_name='name_1',
539                                    vnf_id='1',
540                                    vnfm_inst_id='1',
541                                    ns_inst_id='111,2-2-2',
542                                    max_cpu='14',
543                                    max_ram='12296',
544                                    max_hd='101',
545                                    max_shd="20",
546                                    max_net=10,
547                                    status='active',
548                                    mnfinstid=self.nf_uuid,
549                                    package_id='pkg1',
550                                    vnfd_model=json.dumps({
551                                        "metadata": {
552                                            "vnfdId": "1",
553                                            "vnfdName": "PGW001",
554                                            "vnfProvider": "zte",
555                                            "vnfdVersion": "V00001",
556                                            "vnfVersion": "V5.10.20",
557                                            "productType": "CN",
558                                            "vnfType": "PGW",
559                                            "description": "PGW VNFD description",
560                                            "isShared": True,
561                                            "vnfExtendType": "driver"
562                                        }
563                                    }))
564
565     def tearDown(self):
566         NSInstModel.objects.all().delete()
567         NfInstModel.objects.all().delete()
568
569     @mock.patch.object(restcall, "call_req")
570     def test_heal_vnf(self, mock_call_req):
571
572         mock_vals = {
573             "/api/ztevnfmdriver/v1/1/vnfs/111/heal":
574                 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
575             "/external-system/esr-vnfm-list/esr-vnfm/1":
576                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
577             "/api/resmgr/v1/vnf/1":
578                 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
579             "/api/ztevnfmdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
580                 [0, json.JSONEncoder().encode({
581                     "jobId": self.job_id,
582                     "responsedescriptor": {
583                         "progress": "100",
584                         "status": JOB_MODEL_STATUS.FINISHED,
585                         "responseid": "3",
586                         "statusdescription": "creating",
587                         "errorcode": "0",
588                         "responsehistorylist": [{
589                             "progress": "0",
590                             "status": JOB_MODEL_STATUS.PROCESSING,
591                             "responseid": "2",
592                             "statusdescription": "creating",
593                             "errorcode": "0"
594                         }]
595                     }
596                 }), '200']}
597
598         def side_effect(*args):
599             return mock_vals[args[4]]
600
601         mock_call_req.side_effect = side_effect
602
603         req_data = {
604             "action": "vmReset",
605             "affectedvm": {
606                 "vmid": "1",
607                 "vduid": "1",
608                 "vmname": "name",
609             }
610         }
611
612         NFHealService(self.nf_inst_id, req_data).run()
613
614         self.assertEqual(NfInstModel.objects.get(nfinstid=self.nf_inst_id).status, VNF_STATUS.ACTIVE)
615
616     @mock.patch.object(NFHealService, "run")
617     def test_heal_vnf_non_existing_vnf(self, mock_biz):
618         mock_biz.side_effect = NSLCMException("VNF Not Found")
619
620         nf_inst_id = "1"
621
622         req_data = {
623             "action": "vmReset",
624             "affectedvm": {
625                 "vmid": "1",
626                 "vduid": "1",
627                 "vmname": "name",
628             }
629         }
630
631         self.assertRaises(NSLCMException, NFHealService(nf_inst_id, req_data).run)
632         self.assertEqual(len(NfInstModel.objects.filter(nfinstid=nf_inst_id)), 0)
633
634
635 class TestGetVnfmInfoViews(TestCase):
636     def setUp(self):
637         self.client = Client()
638         self.vnfm_id = str(uuid.uuid4())
639
640     def tearDown(self):
641         pass
642
643     @mock.patch.object(restcall, "call_req")
644     def test_get_vnfm_info(self, mock_call_req):
645         vnfm_info_aai = {
646             "vnfm-id": "example-vnfm-id-val-62576",
647             "vim-id": "example-vim-id-val-35114",
648             "certificate-url": "example-certificate-url-val-90242",
649             "esr-system-info-list": {
650                 "esr-system-info": [
651                     {
652                         "esr-system-info-id": "example-esr-system-info-id-val-78484",
653                         "system-name": "example-system-name-val-23790",
654                         "type": "example-type-val-52596",
655                         "vendor": "example-vendor-val-47399",
656                         "version": "example-version-val-42051",
657                         "service-url": "example-service-url-val-10731",
658                         "user-name": "example-user-name-val-65946",
659                         "password": "example-password-val-22505",
660                         "system-type": "example-system-type-val-27221",
661                         "protocal": "example-protocal-val-54632",
662                         "ssl-cacert": "example-ssl-cacert-val-45965",
663                         "ssl-insecure": True,
664                         "ip-address": "example-ip-address-val-19212",
665                         "port": "example-port-val-57641",
666                         "cloud-domain": "example-cloud-domain-val-26296",
667                         "default-tenant": "example-default-tenant-val-87724"
668                     }
669                 ]
670             }
671         }
672         r1 = [0, json.JSONEncoder().encode(vnfm_info_aai), '200']
673         mock_call_req.side_effect = [r1]
674         esr_system_info = ignore_case_get(ignore_case_get(vnfm_info_aai, "esr-system-info-list"), "esr-system-info")
675         expect_data = {
676             "vnfmId": vnfm_info_aai["vnfm-id"],
677             "name": vnfm_info_aai["vnfm-id"],
678             "type": ignore_case_get(esr_system_info[0], "type"),
679             "vimId": vnfm_info_aai["vim-id"],
680             "vendor": ignore_case_get(esr_system_info[0], "vendor"),
681             "version": ignore_case_get(esr_system_info[0], "version"),
682             "description": "vnfm",
683             "certificateUrl": vnfm_info_aai["certificate-url"],
684             "url": ignore_case_get(esr_system_info[0], "service-url"),
685             "userName": ignore_case_get(esr_system_info[0], "user-name"),
686             "password": ignore_case_get(esr_system_info[0], "password"),
687             "createTime": ""
688         }
689
690         response = self.client.get("/api/nslcm/v1/vnfms/%s" % self.vnfm_id)
691         self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
692         context = json.loads(response.content)
693         self.assertEqual(expect_data, context)
694
695
696 class TestGetVimInfoViews(TestCase):
697     def setUp(self):
698         self.client = Client()
699         self.vim_id = {"cloud_owner": "VCPE", "cloud_regionid": "RegionOne"}
700
701     def tearDown(self):
702         pass
703
704     @mock.patch.object(restcall, "call_req")
705     def test_get_vim_info(self, mock_call_req):
706         r1 = [0, json.JSONEncoder().encode(vim_info), '200']
707         mock_call_req.side_effect = [r1]
708         esr_system_info = ignore_case_get(ignore_case_get(vim_info, "esr-system-info-list"), "esr-system-info")
709         expect_data = {
710             "vimId": self.vim_id,
711             "name": self.vim_id,
712             "url": ignore_case_get(esr_system_info[0], "service-url"),
713             "userName": ignore_case_get(esr_system_info[0], "user-name"),
714             "password": ignore_case_get(esr_system_info[0], "password"),
715             # "tenant": ignore_case_get(tenants[0], "tenant-id"),
716             "tenant": ignore_case_get(esr_system_info[0], "default-tenant"),
717             "vendor": ignore_case_get(esr_system_info[0], "vendor"),
718             "version": ignore_case_get(esr_system_info[0], "version"),
719             "description": "vim",
720             "domain": "",
721             "type": ignore_case_get(esr_system_info[0], "type"),
722             "createTime": ""
723         }
724
725         # response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
726         response = self.client.get("/api/nslcm/v1/vims/%s/%s" % (self.vim_id['cloud_owner'], self.vim_id['cloud_regionid']))
727         self.assertEqual(status.HTTP_200_OK, response.status_code)
728         context = json.loads(response.content)
729         self.assertEqual(expect_data["url"], context["url"])
730
731
732 class TestPlaceVnfViews(TestCase):
733     def setUp(self):
734         self.vnf_inst_id = "1234"
735         self.vnf_id = "vG"
736         self.client = Client()
737         OOFDataModel.objects.all().delete()
738         OOFDataModel.objects.create(
739             request_id="1234",
740             transaction_id="1234",
741             request_status="init",
742             request_module_name=self.vnf_id,
743             service_resource_id=self.vnf_inst_id,
744             vim_id="",
745             cloud_owner="",
746             cloud_region_id="",
747             vdu_info="",
748         )
749
750     def tearDown(self):
751         OOFDataModel.objects.all().delete()
752
753     @mock.patch.object(restcall, 'call_req')
754     def test_place_vnf(self, mock_call_req):
755         vdu_info_json = [{
756             "vduName": "vG_0",
757             "flavorName": "HPA.flavor.1",
758             "flavorId": "12345",
759             "directive": []
760         }]
761         PlaceVnfs(vnf_place_request).extract()
762         db_info = OOFDataModel.objects.filter(request_id=vnf_place_request.get("requestId"), transaction_id=vnf_place_request.get("transactionId"))
763         self.assertEqual(db_info[0].request_status, "completed")
764         self.assertEqual(db_info[0].vim_id, "CloudOwner1_DLLSTX1A")
765         self.assertEqual(db_info[0].cloud_owner, "CloudOwner1")
766         self.assertEqual(db_info[0].cloud_region_id, "DLLSTX1A")
767         self.assertEqual(db_info[0].vdu_info, json.dumps(vdu_info_json))
768
769     def test_place_vnf_with_invalid_response(self):
770         resp = {
771             "requestId": "1234",
772             "transactionId": "1234",
773             "statusMessage": "xx",
774             "requestStatus": "pending",
775             "solutions": {
776                 "placementSolutions": [
777                     [
778                         {
779                             "resourceModuleName": self.vnf_id,
780                             "serviceResourceId": self.vnf_inst_id,
781                             "solution": {
782                                 "identifierType": "serviceInstanceId",
783                                 "identifiers": [
784                                     "xx"
785                                 ],
786                                 "cloudOwner": "CloudOwner1 "
787                             },
788                             "assignmentInfo": []
789                         }
790                     ]
791                 ],
792                 "licenseSolutions": [
793                     {
794                         "resourceModuleName": "string",
795                         "serviceResourceId": "string",
796                         "entitlementPoolUUID": [
797                             "string"
798                         ],
799                         "licenseKeyGroupUUID": [
800                             "string"
801                         ],
802                         "entitlementPoolInvariantUUID": [
803                             "string"
804                         ],
805                         "licenseKeyGroupInvariantUUID": [
806                             "string"
807                         ]
808                     }
809                 ]
810             }
811         }
812         PlaceVnfs(resp).extract()
813         db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
814         self.assertEqual(db_info[0].request_status, "pending")
815         self.assertEqual(db_info[0].vim_id, "none")
816         self.assertEqual(db_info[0].cloud_owner, "none")
817         self.assertEqual(db_info[0].cloud_region_id, "none")
818         self.assertEqual(db_info[0].vdu_info, "none")
819
820     def test_place_vnf_with_no_assignment_info(self):
821         resp = {
822             "requestId": "1234",
823             "transactionId": "1234",
824             "statusMessage": "xx",
825             "requestStatus": "completed",
826             "solutions": {
827                 "placementSolutions": [
828                     [
829                         {
830                             "resourceModuleName": self.vnf_id,
831                             "serviceResourceId": self.vnf_inst_id,
832                             "solution": {
833                                 "identifierType": "serviceInstanceId",
834                                 "identifiers": [
835                                     "xx"
836                                 ],
837                                 "cloudOwner": "CloudOwner1 "
838                             }
839                         }
840                     ]
841                 ],
842                 "licenseSolutions": [
843                     {
844                         "resourceModuleName": "string",
845                         "serviceResourceId": "string",
846                         "entitlementPoolUUID": [
847                             "string"
848                         ],
849                         "licenseKeyGroupUUID": [
850                             "string"
851                         ],
852                         "entitlementPoolInvariantUUID": [
853                             "string"
854                         ],
855                         "licenseKeyGroupInvariantUUID": [
856                             "string"
857                         ]
858                     }
859                 ]
860             }
861         }
862         PlaceVnfs(resp).extract()
863         db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
864         self.assertEqual(db_info[0].request_status, "completed")
865         self.assertEqual(db_info[0].vim_id, "none")
866         self.assertEqual(db_info[0].cloud_owner, "none")
867         self.assertEqual(db_info[0].cloud_region_id, "none")
868         self.assertEqual(db_info[0].vdu_info, "none")
869
870     def test_place_vnf_no_directives(self):
871         resp = {
872             "requestId": "1234",
873             "transactionId": "1234",
874             "statusMessage": "xx",
875             "requestStatus": "completed",
876             "solutions": {
877                 "placementSolutions": [
878                     [
879                         {
880                             "resourceModuleName": self.vnf_id,
881                             "serviceResourceId": self.vnf_inst_id,
882                             "solution": {
883                                 "identifierType": "serviceInstanceId",
884                                 "identifiers": [
885                                     "xx"
886                                 ],
887                                 "cloudOwner": "CloudOwner1 "
888                             },
889                             "assignmentInfo": [
890                                 {"key": "locationId",
891                                  "value": "DLLSTX1A"
892                                  }
893                             ]
894                         }
895                     ]
896                 ],
897                 "licenseSoutions": [
898                     {
899                         "resourceModuleName": "string",
900                         "serviceResourceId": "string",
901                         "entitlementPoolUUID": [
902                             "string"
903                         ],
904                         "licenseKeyGroupUUID": [
905                             "string"
906                         ],
907                         "entitlementPoolInvariantUUID": [
908                             "string"
909                         ],
910                         "licenseKeyGroupInvariantUUID": [
911                             "string"
912                         ]
913                     }
914                 ]
915             }
916         }
917         PlaceVnfs(resp).extract()
918         db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
919         self.assertEqual(db_info[0].request_status, "completed")
920         self.assertEqual(db_info[0].vim_id, "none")
921         self.assertEqual(db_info[0].cloud_owner, "none")
922         self.assertEqual(db_info[0].cloud_region_id, "none")
923         self.assertEqual(db_info[0].vdu_info, "none")
924
925     def test_place_vnf_with_no_solution(self):
926         resp = {
927             "requestId": "1234",
928             "transactionId": "1234",
929             "statusMessage": "xx",
930             "requestStatus": "completed",
931             "solutions": {
932                 "placementSolutions": [],
933                 "licenseSoutions": []
934             }
935         }
936         PlaceVnfs(resp).extract()
937         db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
938         self.assertEqual(db_info[0].request_status, "completed")
939         self.assertEqual(db_info[0].vim_id, "none")
940         self.assertEqual(db_info[0].cloud_owner, "none")
941         self.assertEqual(db_info[0].cloud_region_id, "none")
942         self.assertEqual(db_info[0].vdu_info, "none")
943
944
945 class TestGrantVnfViews(TestCase):
946     def setUp(self):
947         self.vnf_inst_id = str(uuid.uuid4())
948         self.data = {
949             "vnfInstanceId": self.vnf_inst_id,
950             "vnfLcmOpOccId": "1234",
951             "operation": "INSTANTIATE"
952         }
953         vdu_info_dict = [{"vduName": "vg", "flavorName": "flavor_1", "flavorId": "12345", "directive": []}]
954         OOFDataModel(request_id='1234', transaction_id='1234', request_status='done', request_module_name='vg',
955                      service_resource_id=self.vnf_inst_id, vim_id='cloudOwner_casa', cloud_owner='cloudOwner',
956                      cloud_region_id='casa', vdu_info=json.dumps(vdu_info_dict)).save()
957
958     def tearDown(self):
959         OOFDataModel.objects.all().delete()
960
961     @mock.patch.object(resmgr, "grant_vnf")
962     def test_exec_grant(self, mock_grant):
963         resmgr_grant_resp = {
964             "vim": {
965                 "vimId": "cloudOwner_casa",
966                 "accessInfo": {
967                     "tenant": "tenantA"
968                 }
969             }
970         }
971         mock_grant.return_value = resmgr_grant_resp
972         resp = GrantVnf(self.data).exec_grant()
973         self.assertEqual(resp['vimAssets']['computeResourceFlavours'][0]['vimConnectionId'], 'cloudOwner_casa')
974         self.assertEqual(resp['vimAssets']['computeResourceFlavours'][0]['resourceProviderId'], 'vg')
975         self.assertEqual(resp['vimAssets']['computeResourceFlavours'][0]['vimFlavourId'], '12345')
976
977
978 vnfd_model_dict = {
979     'local_storages': [],
980     'vdus': [
981         {
982             'volumn_storages': [
983
984             ],
985             'nfv_compute': {
986                 'mem_size': '',
987                 'num_cpus': '2'
988             },
989             'local_storages': [
990
991             ],
992             'vdu_id': 'vdu_omm.001',
993             'image_file': 'opencos_sss_omm_img_release_20150723-1-disk1',
994             'dependencies': [
995
996             ],
997             'vls': [
998
999             ],
1000             'cps': [
1001
1002             ],
1003             'properties': {
1004                 'key_vdu': '',
1005                 'support_scaling': False,
1006                 'vdu_type': '',
1007                 'name': '',
1008                 'storage_policy': '',
1009                 'location_info': {
1010                     'vimId': '',
1011                     'availability_zone': '',
1012                     'region': '',
1013                     'dc': '',
1014                     'host': '',
1015                     'tenant': ''
1016                 },
1017                 'inject_data_list': [
1018
1019                 ],
1020                 'watchdog': {
1021                     'action': '',
1022                     'enabledelay': ''
1023                 },
1024                 'local_affinity_antiaffinity_rule': {
1025
1026                 },
1027                 'template_id': 'omm.001',
1028                 'manual_scale_select_vim': False
1029             },
1030             'description': 'singleommvm'
1031         },
1032         {
1033             'volumn_storages': [
1034
1035             ],
1036             'nfv_compute': {
1037                 'mem_size': '',
1038                 'num_cpus': '4'
1039             },
1040             'local_storages': [
1041
1042             ],
1043             'vdu_id': 'vdu_1',
1044             'image_file': 'sss',
1045             'dependencies': [
1046
1047             ],
1048             'vls': [
1049
1050             ],
1051             'cps': [
1052
1053             ],
1054             'properties': {
1055                 'key_vdu': '',
1056                 'support_scaling': False,
1057                 'vdu_type': '',
1058                 'name': '',
1059                 'storage_policy': '',
1060                 'location_info': {
1061                     'vimId': '',
1062                     'availability_zone': '',
1063                     'region': '',
1064                     'dc': '',
1065                     'host': '',
1066                     'tenant': ''
1067                 },
1068                 'inject_data_list': [
1069
1070                 ],
1071                 'watchdog': {
1072                     'action': '',
1073                     'enabledelay': ''
1074                 },
1075                 'local_affinity_antiaffinity_rule': {
1076
1077                 },
1078                 'template_id': '1',
1079                 'manual_scale_select_vim': False
1080             },
1081             'description': 'ompvm'
1082         },
1083         {
1084             'volumn_storages': [
1085
1086             ],
1087             'nfv_compute': {
1088                 'mem_size': '',
1089                 'num_cpus': '14'
1090             },
1091             'local_storages': [
1092
1093             ],
1094             'vdu_id': 'vdu_2',
1095             'image_file': 'sss',
1096             'dependencies': [
1097
1098             ],
1099             'vls': [
1100
1101             ],
1102             'cps': [
1103
1104             ],
1105             'properties': {
1106                 'key_vdu': '',
1107                 'support_scaling': False,
1108                 'vdu_type': '',
1109                 'name': '',
1110                 'storage_policy': '',
1111                 'location_info': {
1112                     'vimId': '',
1113                     'availability_zone': '',
1114                     'region': '',
1115                     'dc': '',
1116                     'host': '',
1117                     'tenant': ''
1118                 },
1119                 'inject_data_list': [
1120
1121                 ],
1122                 'watchdog': {
1123                     'action': '',
1124                     'enabledelay': ''
1125                 },
1126                 'local_affinity_antiaffinity_rule': {
1127
1128                 },
1129                 'template_id': '2',
1130                 'manual_scale_select_vim': False
1131             },
1132             'description': 'ompvm'
1133         },
1134         {
1135             'volumn_storages': [
1136
1137             ],
1138             'nfv_compute': {
1139                 'mem_size': '',
1140                 'num_cpus': '14'
1141             },
1142             'local_storages': [
1143
1144             ],
1145             'vdu_id': 'vdu_3',
1146             'image_file': 'sss',
1147             'dependencies': [
1148
1149             ],
1150             'vls': [
1151
1152             ],
1153             'cps': [
1154
1155             ],
1156             'properties': {
1157                 'key_vdu': '',
1158                 'support_scaling': False,
1159                 'vdu_type': '',
1160                 'name': '',
1161                 'storage_policy': '',
1162                 'location_info': {
1163                     'vimId': '',
1164                     'availability_zone': '',
1165                     'region': '',
1166                     'dc': '',
1167                     'host': '',
1168                     'tenant': ''
1169                 },
1170                 'inject_data_list': [
1171
1172                 ],
1173                 'watchdog': {
1174                     'action': '',
1175                     'enabledelay': ''
1176                 },
1177                 'local_affinity_antiaffinity_rule': {
1178
1179                 },
1180                 'template_id': '3',
1181                 'manual_scale_select_vim': False
1182             },
1183             'description': 'ompvm'
1184         },
1185         {
1186             'volumn_storages': [
1187
1188             ],
1189             'nfv_compute': {
1190                 'mem_size': '',
1191                 'num_cpus': '4'
1192             },
1193             'local_storages': [
1194
1195             ],
1196             'vdu_id': 'vdu_10',
1197             'image_file': 'sss',
1198             'dependencies': [
1199
1200             ],
1201             'vls': [
1202
1203             ],
1204             'cps': [
1205
1206             ],
1207             'properties': {
1208                 'key_vdu': '',
1209                 'support_scaling': False,
1210                 'vdu_type': '',
1211                 'name': '',
1212                 'storage_policy': '',
1213                 'location_info': {
1214                     'vimId': '',
1215                     'availability_zone': '',
1216                     'region': '',
1217                     'dc': '',
1218                     'host': '',
1219                     'tenant': ''
1220                 },
1221                 'inject_data_list': [
1222
1223                 ],
1224                 'watchdog': {
1225                     'action': '',
1226                     'enabledelay': ''
1227                 },
1228                 'local_affinity_antiaffinity_rule': {
1229
1230                 },
1231                 'template_id': '10',
1232                 'manual_scale_select_vim': False
1233             },
1234             'description': 'ppvm'
1235         },
1236         {
1237             'volumn_storages': [
1238
1239             ],
1240             'nfv_compute': {
1241                 'mem_size': '',
1242                 'num_cpus': '14'
1243             },
1244             'local_storages': [
1245
1246             ],
1247             'vdu_id': 'vdu_11',
1248             'image_file': 'sss',
1249             'dependencies': [
1250
1251             ],
1252             'vls': [
1253
1254             ],
1255             'cps': [
1256
1257             ],
1258             'properties': {
1259                 'key_vdu': '',
1260                 'support_scaling': False,
1261                 'vdu_type': '',
1262                 'name': '',
1263                 'storage_policy': '',
1264                 'location_info': {
1265                     'vimId': '',
1266                     'availability_zone': '',
1267                     'region': '',
1268                     'dc': '',
1269                     'host': '',
1270                     'tenant': ''
1271                 },
1272                 'inject_data_list': [
1273
1274                 ],
1275                 'watchdog': {
1276                     'action': '',
1277                     'enabledelay': ''
1278                 },
1279                 'local_affinity_antiaffinity_rule': {
1280
1281                 },
1282                 'template_id': '11',
1283                 'manual_scale_select_vim': False
1284             },
1285             'description': 'ppvm'
1286         },
1287         {
1288             'volumn_storages': [
1289
1290             ],
1291             'nfv_compute': {
1292                 'mem_size': '',
1293                 'num_cpus': '14'
1294             },
1295             'local_storages': [
1296
1297             ],
1298             'vdu_id': 'vdu_12',
1299             'image_file': 'sss',
1300             'dependencies': [
1301
1302             ],
1303             'vls': [
1304
1305             ],
1306             'cps': [
1307
1308             ],
1309             'properties': {
1310                 'key_vdu': '',
1311                 'support_scaling': False,
1312                 'vdu_type': '',
1313                 'name': '',
1314                 'storage_policy': '',
1315                 'location_info': {
1316                     'vimId': '',
1317                     'availability_zone': '',
1318                     'region': '',
1319                     'dc': '',
1320                     'host': '',
1321                     'tenant': ''
1322                 },
1323                 'inject_data_list': [
1324
1325                 ],
1326                 'watchdog': {
1327                     'action': '',
1328                     'enabledelay': ''
1329                 },
1330                 'local_affinity_antiaffinity_rule': {
1331
1332                 },
1333                 'template_id': '12',
1334                 'manual_scale_select_vim': False
1335             },
1336             'description': 'ppvm'
1337         }
1338     ],
1339     'volumn_storages': [
1340
1341     ],
1342     'policies': {
1343         'scaling': {
1344             'targets': {
1345
1346             },
1347             'policy_id': 'policy_scale_sss-vnf-template',
1348             'properties': {
1349                 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'
1350             },
1351             'description': ''
1352         }
1353     },
1354     'image_files': [
1355         {
1356             'description': '',
1357             'properties': {
1358                 'name': 'opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1359                 'checksum': '',
1360                 'disk_format': 'VMDK',
1361                 'file_url': './zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1362                 'container_type': 'vm',
1363                 'version': '',
1364                 'hypervisor_type': 'kvm'
1365             },
1366             'image_file_id': 'opencos_sss_omm_img_release_20150723-1-disk1'
1367         },
1368         {
1369             'description': '',
1370             'properties': {
1371                 'name': 'sss.vmdk',
1372                 'checksum': '',
1373                 'disk_format': 'VMDK',
1374                 'file_url': './zte-cn-sss-main-image/NE/sss.vmdk',
1375                 'container_type': 'vm',
1376                 'version': '',
1377                 'hypervisor_type': 'kvm'
1378             },
1379             'image_file_id': 'sss'
1380         }
1381     ],
1382     'vls': [
1383
1384     ],
1385     'cps': [
1386
1387     ],
1388     'metadata': {
1389         'vendor': 'zte',
1390         'is_shared': False,
1391         'description': '',
1392         'domain_type': 'CN',
1393         'version': 'v4.14.10',
1394         'vmnumber_overquota_alarm': False,
1395         'cross_dc': False,
1396         'vnf_type': 'SSS',
1397         'vnfd_version': 'V00000001',
1398         'id': 'sss-vnf-template',
1399         'name': 'sss-vnf-template'
1400     }
1401 }
1402
1403 nsd_model_dict = {
1404     "vnffgs": [
1405
1406     ],
1407     "inputs": {
1408         "externalDataNetworkName": {
1409             "default": "",
1410             "type": "string",
1411             "description": ""
1412         }
1413     },
1414     "pnfs": [
1415
1416     ],
1417     "fps": [
1418
1419     ],
1420     "server_groups": [
1421
1422     ],
1423     "ns_flavours": [
1424
1425     ],
1426     "vnfs": [
1427         {
1428             "dependency": [
1429
1430             ],
1431             "properties": {
1432                 "plugin_info": "vbrasplugin_1.0",
1433                 "vendor": "zte",
1434                 "is_shared": "False",
1435                 "request_reclassification": "False",
1436                 "vnfd_version": "1.0.0",
1437                 "version": "1.0",
1438                 "nsh_aware": "True",
1439                 "cross_dc": "False",
1440                 "externalDataNetworkName": {
1441                     "get_input": "externalDataNetworkName"
1442                 },
1443                 "id": "zte_vbras",
1444                 "name": "vbras"
1445             },
1446             "vnf_id": "VBras",
1447             "networks": [
1448
1449             ],
1450             "description": ""
1451         }
1452     ],
1453     "ns_exposed": {
1454         "external_cps": [
1455
1456         ],
1457         "forward_cps": [
1458
1459         ]
1460     },
1461     "vls": [
1462         {
1463             "vl_id": "ext_mnet_network",
1464             "description": "",
1465             "properties": {
1466                 "network_type": "vlan",
1467                 "name": "externalMNetworkName",
1468                 "dhcp_enabled": False,
1469                 "location_info": {
1470                     "host": True,
1471                     "vimid": 2,
1472                     "region": True,
1473                     "tenant": "admin",
1474                     "dc": ""
1475                 },
1476                 "end_ip": "190.168.100.100",
1477                 "gateway_ip": "190.168.100.1",
1478                 "start_ip": "190.168.100.2",
1479                 "cidr": "190.168.100.0/24",
1480                 "mtu": 1500,
1481                 "network_name": "sub_mnet",
1482                 "ip_version": 4
1483             }
1484         }
1485     ],
1486     "cps": [
1487
1488     ],
1489     "policies": [
1490
1491     ],
1492     "metadata": {
1493         "invariant_id": "vbras_ns",
1494         "description": "vbras_ns",
1495         "version": 1,
1496         "vendor": "zte",
1497         "id": "vbras_ns",
1498         "name": "vbras_ns"
1499     }
1500 }
1501
1502 vserver_info = {
1503     "vserver-id": "example-vserver-id-val-70924",
1504     "vserver-name": "example-vserver-name-val-61674",
1505     "vserver-name2": "example-vserver-name2-val-19234",
1506     "prov-status": "example-prov-status-val-94916",
1507     "vserver-selflink": "example-vserver-selflink-val-26562",
1508     "in-maint": True,
1509     "is-closed-loop-disabled": True,
1510     "resource-version": "1505465356263",
1511     "volumes": {
1512         "volume": [
1513             {
1514                 "volume-id": "example-volume-id-val-71854",
1515                 "volume-selflink": "example-volume-selflink-val-22433"
1516             }
1517         ]
1518     },
1519     "l-interfaces": {
1520         "l-interface": [
1521             {
1522                 "interface-name": "example-interface-name-val-24351",
1523                 "interface-role": "example-interface-role-val-43242",
1524                 "v6-wan-link-ip": "example-v6-wan-link-ip-val-4196",
1525                 "selflink": "example-selflink-val-61295",
1526                 "interface-id": "example-interface-id-val-95879",
1527                 "macaddr": "example-macaddr-val-37302",
1528                 "network-name": "example-network-name-val-44254",
1529                 "management-option": "example-management-option-val-49009",
1530                 "interface-description": "example-interface-description-val-99923",
1531                 "is-port-mirrored": True,
1532                 "in-maint": True,
1533                 "prov-status": "example-prov-status-val-4698",
1534                 "is-ip-unnumbered": True,
1535                 "allowed-address-pairs": "example-allowed-address-pairs-val-5762",
1536                 "vlans": {
1537                     "vlan": [
1538                         {
1539                             "vlan-interface": "example-vlan-interface-val-58193",
1540                             "vlan-id-inner": 54452151,
1541                             "vlan-id-outer": 70239293,
1542                             "speed-value": "example-speed-value-val-18677",
1543                             "speed-units": "example-speed-units-val-46185",
1544                             "vlan-description": "example-vlan-description-val-81675",
1545                             "backdoor-connection": "example-backdoor-connection-val-44608",
1546                             "vpn-key": "example-vpn-key-val-7946",
1547                             "orchestration-status": "example-orchestration-status-val-33611",
1548                             "in-maint": True,
1549                             "prov-status": "example-prov-status-val-8288",
1550                             "is-ip-unnumbered": True,
1551                             "l3-interface-ipv4-address-list": [
1552                                 {
1553                                     "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-25520",
1554                                     "l3-interface-ipv4-prefix-length": 69931928,
1555                                     "vlan-id-inner": 86628520,
1556                                     "vlan-id-outer": 62729236,
1557                                     "is-floating": True,
1558                                     "neutron-network-id": "example-neutron-network-id-val-64021",
1559                                     "neutron-subnet-id": "example-neutron-subnet-id-val-95049"
1560                                 }
1561                             ],
1562                             "l3-interface-ipv6-address-list": [
1563                                 {
1564                                     "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-64310",
1565                                     "l3-interface-ipv6-prefix-length": 57919834,
1566                                     "vlan-id-inner": 79150122,
1567                                     "vlan-id-outer": 59789973,
1568                                     "is-floating": True,
1569                                     "neutron-network-id": "example-neutron-network-id-val-31713",
1570                                     "neutron-subnet-id": "example-neutron-subnet-id-val-89568"
1571                                 }
1572                             ]
1573                         }
1574                     ]
1575                 },
1576                 "sriov-vfs": {
1577                     "sriov-vf": [
1578                         {
1579                             "pci-id": "example-pci-id-val-16747",
1580                             "vf-vlan-filter": "example-vf-vlan-filter-val-4613",
1581                             "vf-mac-filter": "example-vf-mac-filter-val-68168",
1582                             "vf-vlan-strip": True,
1583                             "vf-vlan-anti-spoof-check": True,
1584                             "vf-mac-anti-spoof-check": True,
1585                             "vf-mirrors": "example-vf-mirrors-val-6270",
1586                             "vf-broadcast-allow": True,
1587                             "vf-unknown-multicast-allow": True,
1588                             "vf-unknown-unicast-allow": True,
1589                             "vf-insert-stag": True,
1590                             "vf-link-status": "example-vf-link-status-val-49266",
1591                             "neutron-network-id": "example-neutron-network-id-val-29493"
1592                         }
1593                     ]
1594                 },
1595                 "l-interfaces": {
1596                     "l-interface": [
1597                         {
1598                             "interface-name": "example-interface-name-val-98222",
1599                             "interface-role": "example-interface-role-val-78360",
1600                             "v6-wan-link-ip": "example-v6-wan-link-ip-val-76921",
1601                             "selflink": "example-selflink-val-27117",
1602                             "interface-id": "example-interface-id-val-11260",
1603                             "macaddr": "example-macaddr-val-60378",
1604                             "network-name": "example-network-name-val-16258",
1605                             "management-option": "example-management-option-val-35097",
1606                             "interface-description": "example-interface-description-val-10475",
1607                             "is-port-mirrored": True,
1608                             "in-maint": True,
1609                             "prov-status": "example-prov-status-val-65203",
1610                             "is-ip-unnumbered": True,
1611                             "allowed-address-pairs": "example-allowed-address-pairs-val-65028"
1612                         }
1613                     ]
1614                 },
1615                 "l3-interface-ipv4-address-list": [
1616                     {
1617                         "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-72779",
1618                         "l3-interface-ipv4-prefix-length": 55956636,
1619                         "vlan-id-inner": 98174431,
1620                         "vlan-id-outer": 20372128,
1621                         "is-floating": True,
1622                         "neutron-network-id": "example-neutron-network-id-val-39596",
1623                         "neutron-subnet-id": "example-neutron-subnet-id-val-51109"
1624                     }
1625                 ],
1626                 "l3-interface-ipv6-address-list": [
1627                     {
1628                         "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-95203",
1629                         "l3-interface-ipv6-prefix-length": 57454747,
1630                         "vlan-id-inner": 53421060,
1631                         "vlan-id-outer": 16006050,
1632                         "is-floating": True,
1633                         "neutron-network-id": "example-neutron-network-id-val-54216",
1634                         "neutron-subnet-id": "example-neutron-subnet-id-val-1841"
1635                     }
1636                 ]
1637             }
1638         ]
1639     }
1640 }
1641
1642
1643 vnfm_info = {
1644     "vnfm-id": "example-vnfm-id-val-97336",
1645     "vim-id": "zte_test",
1646     "certificate-url": "example-certificate-url-val-18046",
1647     "resource-version": "example-resource-version-val-42094",
1648     "esr-system-info-list": {
1649         "esr-system-info": [
1650             {
1651                 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1652                 "system-name": "example-system-name-val-19801",
1653                 "type": "ztevnfmdriver",
1654                 "vendor": "example-vendor-val-50079",
1655                 "version": "example-version-val-93146",
1656                 "service-url": "example-service-url-val-68090",
1657                 "user-name": "example-user-name-val-14470",
1658                 "password": "example-password-val-84190",
1659                 "system-type": "example-system-type-val-42773",
1660                 "protocal": "example-protocal-val-85736",
1661                 "ssl-cacert": "example-ssl-cacert-val-33989",
1662                 "ssl-insecure": True,
1663                 "ip-address": "example-ip-address-val-99038",
1664                 "port": "example-port-val-27323",
1665                 "cloud-domain": "example-cloud-domain-val-55163",
1666                 "default-tenant": "example-default-tenant-val-99383",
1667                 "resource-version": "example-resource-version-val-15424"
1668             }
1669         ]
1670     }
1671 }
1672
1673 vim_info = {
1674     "cloud-owner": "example-cloud-owner-val-97336",
1675     "cloud-region-id": "example-cloud-region-id-val-35532",
1676     "cloud-type": "example-cloud-type-val-18046",
1677     "owner-defined-type": "example-owner-defined-type-val-9413",
1678     "cloud-region-version": "example-cloud-region-version-val-85706",
1679     "identity-url": "example-identity-url-val-71252",
1680     "cloud-zone": "example-cloud-zone-val-27112",
1681     "complex-name": "example-complex-name-val-85283",
1682     "sriov-automation": True,
1683     "cloud-extra-info": "example-cloud-extra-info-val-90854",
1684     "cloud-epa-caps": "example-cloud-epa-caps-val-2409",
1685     "resource-version": "example-resource-version-val-42094",
1686     "esr-system-info-list": {
1687         "esr-system-info": [
1688             {
1689                 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1690                 "system-name": "example-system-name-val-19801",
1691                 "type": "example-type-val-24477",
1692                 "vendor": "example-vendor-val-50079",
1693                 "version": "example-version-val-93146",
1694                 "service-url": "example-service-url-val-68090",
1695                 "user-name": "example-user-name-val-14470",
1696                 "password": "example-password-val-84190",
1697                 "system-type": "example-system-type-val-42773",
1698                 "protocal": "example-protocal-val-85736",
1699                 "ssl-cacert": "example-ssl-cacert-val-33989",
1700                 "ssl-insecure": True,
1701                 "ip-address": "example-ip-address-val-99038",
1702                 "port": "example-port-val-27323",
1703                 "cloud-domain": "example-cloud-domain-val-55163",
1704                 "default-tenant": "admin",
1705                 "resource-version": "example-resource-version-val-15424"
1706             }
1707         ]
1708     }
1709 }
1710
1711 nf_package_info = {
1712     "csarId": "zte_vbras",
1713     "packageInfo": {
1714         "vnfdId": "1",
1715         "vnfPackageId": "zte_vbras",
1716         "vnfdProvider": "1",
1717         "vnfdVersion": "1",
1718         "vnfVersion": "1",
1719         "csarName": "1",
1720         "vnfdModel": vnfd_model_dict,
1721         "downloadUrl": "1"
1722     },
1723     "imageInfo": []
1724 }
1725
1726 vnf_place_request = {
1727     "requestId": "1234",
1728     "transactionId": "1234",
1729     "statusMessage": "xx",
1730     "requestStatus": "completed",
1731     "solutions": {
1732         "placementSolutions": [
1733             [
1734                 {
1735                     "resourceModuleName": "vG",
1736                     "serviceResourceId": "1234",
1737                     "solution": {
1738                         "identifierType": "serviceInstanceId",
1739                         "identifiers": [
1740                             "xx"
1741                         ],
1742                         "cloudOwner": "CloudOwner1"
1743                     },
1744                     "assignmentInfo": [
1745                         {"key": "isRehome",
1746                          "value": "false"
1747                          },
1748                         {"key": "locationId",
1749                          "value": "DLLSTX1A"
1750                          },
1751                         {"key": "locationType",
1752                          "value": "openstack-cloud"
1753                          },
1754                         {"key": "vimId",
1755                          "value": "CloudOwner1_DLLSTX1A"
1756                          },
1757                         {"key": "physicalLocationId",
1758                          "value": "DLLSTX1223"
1759                          },
1760                         {"key": "oof_directives",
1761                          "value": {
1762                              "directives": [
1763                                  {
1764                                      "id": "vG_0",
1765                                      "type": "tosca.nodes.nfv.Vdu.Compute",
1766                                      "directives": [
1767                                          {
1768                                              "type": "flavor_directives",
1769                                              "attributes": [
1770                                                  {
1771                                                      "attribute_name": "flavorName",
1772                                                      "attribute_value": "HPA.flavor.1"
1773                                                  },
1774                                                  {
1775                                                      "attribute_name": "flavorId",
1776                                                      "attribute_value": "12345"
1777                                                  },
1778                                              ]
1779                                          }
1780                                      ]
1781                                  },
1782                                  {
1783                                      "id": "",
1784                                      "type": "vnf",
1785                                      "directives": [
1786                                          {"type": " ",
1787                                           "attributes": [
1788                                               {
1789                                                   "attribute_name": " ",
1790                                                   "attribute_value": " "
1791                                               }
1792                                           ]
1793                                           }
1794                                      ]
1795                                  }
1796                              ]
1797                          }
1798                          }
1799                     ]
1800                 }
1801             ]
1802         ],
1803         "licenseSolutions": [
1804             {
1805                 "resourceModuleName": "string",
1806                 "serviceResourceId": "string",
1807                 "entitlementPoolUUID": [
1808                     "string"
1809                 ],
1810                 "licenseKeyGroupUUID": [
1811                     "string"
1812                 ],
1813                 "entitlementPoolInvariantUUID": [
1814                     "string"
1815                 ],
1816                 "licenseKeyGroupInvariantUUID": [
1817                     "string"
1818                 ]
1819             }
1820         ]
1821     }
1822 }