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