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