e41796171c32a98c9770e7ebbad2e934d7344e32
[vfc/nfvo/lcm.git] / lcm / ns / tests / vnfs / 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.ns.vnfs import create_vnfs
22 from lcm.ns.vnfs.const import VNF_STATUS, INST_TYPE
23 from lcm.ns.vnfs.create_vnfs import CreateVnfs
24 from lcm.ns.vnfs.heal_vnfs import NFHealService
25 from lcm.ns.vnfs.scale_vnfs import NFManualScaleService
26 from lcm.ns.vnfs.terminate_nfs import TerminateVnfs
27 from lcm.pub.database.models import NfInstModel, JobModel, NfPackageModel, NSInstModel, VmInstModel
28 from lcm.pub.exceptions import NSLCMException
29 from lcm.pub.utils import restcall
30 from lcm.pub.utils.jobutil import JOB_MODEL_STATUS
31 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
32 from lcm.pub.utils.timeutil import now_time
33 from lcm.pub.utils.values import ignore_case_get
34
35
36 class TestGetVnfViews(TestCase):
37     def setUp(self):
38         self.client = Client()
39         self.nf_inst_id = str(uuid.uuid4())
40         NfInstModel(nfinstid=self.nf_inst_id, nf_name='vnf1', vnfm_inst_id='1', vnf_id='vnf_id1',
41                     status=VNF_STATUS.ACTIVE, create_time=now_time(), lastuptime=now_time()).save()
42
43     def tearDown(self):
44         NfInstModel.objects.all().delete()
45
46     def test_get_vnf(self):
47         response = self.client.get("/api/nslcm/v1/ns/vnfs/%s" % self.nf_inst_id)
48         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
49         context = json.loads(response.content)
50         self.failUnlessEqual(self.nf_inst_id, context['vnfInstId'])
51
52
53 class TestCreateVnfViews(TestCase):
54     def setUp(self):
55         self.ns_inst_id = str(uuid.uuid4())
56         self.job_id = str(uuid.uuid4())
57         self.data = {
58             "nsInstanceId": self.ns_inst_id,
59             "additionalParamForNs": {
60                 "inputs": json.dumps({
61
62                 })
63             },
64             "additionalParamForVnf": [
65                 {
66                     "vnfprofileid": "VBras",
67                     "additionalparam": {
68                         "inputs": json.dumps({
69                             "vnf_param1": "11",
70                             "vnf_param2": "22"
71                         }),
72                         "vnfminstanceid": "1",
73                         "vimId": "zte_test"
74                     }
75                 }
76             ],
77             "vnfIndex": "1"
78         }
79         self.client = Client()
80         NfPackageModel(uuid=str(uuid.uuid4()), nfpackageid='package_id1', vnfdid='zte_vbras', vendor='zte',
81                        vnfdversion='1.0.0', vnfversion='1.0.0', vnfdmodel=json.dumps(vnfd_model_dict)).save()
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         nf_package_info = {
101             "csarId": "zte_vbras",
102             "packageInfo": {
103                 "vnfdId": "1",
104                 "vnfPackageId": "zte_vbras",
105                 "vnfdProvider": "1",
106                 "vnfdVersion": "1",
107                 "vnfVersion": "1",
108                 "csarName": "1",
109                 "vnfdModel": vnfd_model_dict,
110                 "downloadUrl": "1"
111             },
112             "imageInfo": []
113         }
114         mock_vals = {
115             "/api/ztevmanagerdriver/v1/1/vnfs":
116                 [0, json.JSONEncoder().encode({"jobId": self.job_id, "vnfInstanceId": 3}), '200'],
117             "/api/catalog/v1/vnfpackages/zte_vbras":
118                 [0, json.JSONEncoder().encode(nf_package_info), '200'],
119             "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
120                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
121             "/api/resmgr/v1/vnf":
122                 [0, json.JSONEncoder().encode({}), '200'],
123             "/api/resmgr/v1/vnfinfo":
124                 [0, json.JSONEncoder().encode({}), '200'],
125             "/network/generic-vnfs/generic-vnf/%s" % nf_inst_id:
126                 [0, json.JSONEncoder().encode({}), '201'],
127             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
128                 [0, json.JSONEncoder().encode(vim_info), '201'],
129             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1":
130                 [0, json.JSONEncoder().encode({}), '201'],
131             "/api/ztevmanagerdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
132                 [0, json.JSONEncoder().encode({"jobid": self.job_id,
133                                                "responsedescriptor": {"progress": "100",
134                                                                       "status": JOB_MODEL_STATUS.FINISHED,
135                                                                       "responseid": "3",
136                                                                       "statusdescription": "creating",
137                                                                       "errorcode": "0",
138                                                                       "responsehistorylist": [
139                                                                           {"progress": "0",
140                                                                            "status": JOB_MODEL_STATUS.PROCESSING,
141                                                                            "responseid": "2",
142                                                                            "statusdescription": "creating",
143                                                                            "errorcode": "0"}]}}), '200']}
144
145         def side_effect(*args):
146             return mock_vals[args[4]]
147         mock_call_req.side_effect = side_effect
148         data = {
149             'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
150             'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
151             'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
152             'vnf_index': ignore_case_get(self.data, 'vnfIndex')
153         }
154         CreateVnfs(data, nf_inst_id, job_id).run()
155         self.assertTrue(NfInstModel.objects.get(nfinstid=nf_inst_id).status, VNF_STATUS.ACTIVE)
156
157
158 class TestTerminateVnfViews(TestCase):
159     def setUp(self):
160         self.client = Client()
161         self.ns_inst_id = str(uuid.uuid4())
162         self.nf_inst_id = '1'
163         self.vnffg_id = str(uuid.uuid4())
164         self.vim_id = str(uuid.uuid4())
165         self.job_id = str(uuid.uuid4())
166         self.nf_uuid = '111'
167         self.tenant = "tenantname"
168         self.vnfd_model = {
169             "metadata": {
170                 "vnfdId": "1",
171                 "vnfdName": "PGW001",
172                 "vnfProvider": "zte",
173                 "vnfdVersion": "V00001",
174                 "vnfVersion": "V5.10.20",
175                 "productType": "CN",
176                 "vnfType": "PGW",
177                 "description": "PGW VNFD description",
178                 "isShared": True,
179                 "vnfExtendType": "driver"
180             }
181         }
182         NSInstModel.objects.all().delete()
183         NfInstModel.objects.all().delete()
184         VmInstModel.objects.all().delete()
185         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
186         NfInstModel.objects.create(nfinstid=self.nf_inst_id,
187                                    nf_name='name_1',
188                                    vnf_id='1',
189                                    vnfm_inst_id='1',
190                                    ns_inst_id='111,2-2-2',
191                                    max_cpu='14',
192                                    max_ram='12296',
193                                    max_hd='101',
194                                    max_shd="20",
195                                    max_net=10,
196                                    status='active',
197                                    mnfinstid=self.nf_uuid,
198                                    package_id='pkg1',
199                                    vnfd_model=self.vnfd_model)
200         VmInstModel.objects.create(vmid="1",
201                                    vimid="zte_test",
202                                    resouceid="1",
203                                    insttype=INST_TYPE.VNF,
204                                    instid=self.nf_inst_id,
205                                    vmname="test",
206                                    hostid='1')
207
208     def tearDown(self):
209         NSInstModel.objects.all().delete()
210         NfInstModel.objects.all().delete()
211
212     @mock.patch.object(TerminateVnfs, 'run')
213     def test_terminate_vnf_url(self, mock_run):
214         req_data = {
215             "terminationType": "forceful",
216             "gracefulTerminationTimeout": "600"}
217
218         response = self.client.post("/api/nslcm/v1/ns/vnfs/%s" % self.nf_inst_id, data=req_data)
219         self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
220
221     @mock.patch.object(restcall, 'call_req')
222     def test_terminate_vnf(self, mock_call_req):
223         job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
224
225         nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
226         if nfinst:
227             self.failUnlessEqual(1, 1)
228         else:
229             self.failUnlessEqual(1, 0)
230
231         vnf_info = {
232             "vnf-id": "vnf-id-test111",
233             "vnf-name": "vnf-name-test111",
234             "vnf-type": "vnf-type-test111",
235             "in-maint": True,
236             "is-closed-loop-disabled": False,
237             "resource-version": "1505465356262"
238         }
239         job_info = {
240             "jobId": job_id,
241             "responsedescriptor": {
242                 "progress": "100",
243                 "status": JOB_MODEL_STATUS.FINISHED,
244                 "responseid": "3",
245                 "statusdescription": "creating",
246                 "errorcode": "0",
247                 "responsehistorylist": [
248                     {
249                         "progress": "0",
250                         "status": JOB_MODEL_STATUS.PROCESSING,
251                         "responseid": "2",
252                         "statusdescription": "creating",
253                         "errorcode": "0"
254                     }
255                 ]
256             }
257         }
258
259         mock_vals = {
260             "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
261                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
262             "/api/ztevmanagerdriver/v1/1/vnfs/111/terminate":
263                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
264             "/api/resmgr/v1/vnf/1":
265                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
266             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all":
267                 [0, json.JSONEncoder().encode(vim_info), '201'],
268             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?depth=all":
269                 [0, json.JSONEncoder().encode(vserver_info), '201'],
270             "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1?resource-version=1505465356263":
271                 [0, json.JSONEncoder().encode({}), '200'],
272             "/api/ztevmanagerdriver/v1/1/jobs/" + job_id + "?responseId=0":
273                 [0, json.JSONEncoder().encode(job_info), '200'],
274             "/network/generic-vnfs/generic-vnf/1?depth=all":
275             [0, json.JSONEncoder().encode(vnf_info), '200'],
276             "/network/generic-vnfs/generic-vnf/1?resource-version=1505465356262":
277             [0, json.JSONEncoder().encode({}), '200']
278         }
279
280         def side_effect(*args):
281             return mock_vals[args[4]]
282         mock_call_req.side_effect = side_effect
283
284         req_data = {
285             "terminationType": "forceful",
286             "gracefulTerminationTimeout": "600"
287         }
288
289         TerminateVnfs(req_data, self.nf_inst_id, job_id).run()
290         nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
291         if nfinst:
292             self.failUnlessEqual(1, 0)
293         else:
294             self.failUnlessEqual(1, 1)
295
296
297 class TestScaleVnfViews(TestCase):
298     def setUp(self):
299         self.client = Client()
300         self.ns_inst_id = str(uuid.uuid4())
301         self.nf_inst_id = str(uuid.uuid4())
302         self.vnffg_id = str(uuid.uuid4())
303         self.vim_id = str(uuid.uuid4())
304         self.job_id = str(uuid.uuid4())
305         self.nf_uuid = '111'
306         self.tenant = "tenantname"
307         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
308         NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
309                                    vnfm_inst_id='1', ns_inst_id='111,2-2-2',
310                                    max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
311                                    status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
312                                    vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
313                                               '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
314                                               '"productType": "CN","vnfType": "PGW",'
315                                               '"description": "PGW VNFD description",'
316                                               '"isShared":true,"vnfExtendType":"driver"}}')
317
318     def tearDown(self):
319         NSInstModel.objects.all().delete()
320         NfInstModel.objects.all().delete()
321
322     @mock.patch.object(restcall, "call_req")
323     def test_scale_vnf(self, mock_call_req):
324         job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
325
326         vnfd_info = {
327             "vnf_flavours": [{
328                 "flavour_id": "flavour1",
329                 "description": "",
330                 "vdu_profiles": [
331                     {
332                         "vdu_id": "vdu1Id",
333                         "instances_minimum_number": 1,
334                         "instances_maximum_number": 4,
335                         "local_affinity_antiaffinity_rule": [
336                             {
337                                 "affinity_antiaffinity": "affinity",
338                                 "scope": "node",
339                             }
340                         ]
341                     }
342                 ],
343                 "scaling_aspects": [
344                     {
345                         "id": "demo_aspect",
346                         "name": "demo_aspect",
347                         "description": "demo_aspect",
348                         "associated_group": "elementGroup1",
349                         "max_scale_level": 5
350                     }
351                 ]
352             }],
353             "element_groups": [{
354                 "group_id": "elementGroup1",
355                 "description": "",
356                 "properties": {
357                     "name": "elementGroup1",
358                 },
359                 "members": ["gsu_vm","pfu_vm"]
360             }]
361         }
362
363         req_data = {
364             "scaleVnfData": [
365                 {
366                     "type":"SCALE_OUT",
367                     "aspectId":"demo_aspect1",
368                     "numberOfSteps":1,
369                     "additionalParam":vnfd_info
370                 },
371                 {
372                     "type":"SCALE_OUT",
373                     "aspectId":"demo_aspect2",
374                     "numberOfSteps":1,
375                     "additionalParam":vnfd_info
376                 }
377             ]
378         }
379
380         mock_vals = {
381             "/api/ztevmanagerdriver/v1/1/vnfs/111/terminate":
382                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200']
383         }
384
385         def side_effect(*args):
386             return mock_vals[args[4]]
387
388         mock_call_req.side_effect = side_effect
389
390         NFManualScaleService(self.nf_inst_id, req_data).run()
391         nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
392         if nsIns:
393             self.failUnlessEqual(1, 1)
394         else:
395             self.failUnlessEqual(1, 0)
396
397
398 class TestHealVnfViews(TestCase):
399     def setUp(self):
400         self.client = Client()
401         self.ns_inst_id = str(uuid.uuid4())
402         self.nf_inst_id = str(uuid.uuid4())
403         self.nf_uuid = '111'
404
405         self.job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, self.nf_inst_id)
406
407         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
408         NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
409                                    vnfm_inst_id='1', ns_inst_id='111,2-2-2',
410                                    max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
411                                    status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
412                                    vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
413                                               '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
414                                               '"productType": "CN","vnfType": "PGW",'
415                                               '"description": "PGW VNFD description",'
416                                               '"isShared":true,"vnfExtendType":"driver"}}')
417
418     def tearDown(self):
419         NSInstModel.objects.all().delete()
420         NfInstModel.objects.all().delete()
421
422     @mock.patch.object(restcall, "call_req")
423     def test_heal_vnf(self, mock_call_req):
424
425         mock_vals = {
426             "/api/ztevmanagerdriver/v1/1/vnfs/111/heal":
427                 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
428             "/external-system/esr-vnfm-list/esr-vnfm/1":
429                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
430             "/api/resmgr/v1/vnf/1":
431                 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
432             "/api/ztevmanagerdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
433                 [0, json.JSONEncoder().encode({"jobId": self.job_id,
434                                                "responsedescriptor": {"progress": "100",
435                                                                       "status": JOB_MODEL_STATUS.FINISHED,
436                                                                       "responseid": "3",
437                                                                       "statusdescription": "creating",
438                                                                       "errorcode": "0",
439                                                                       "responsehistorylist": [
440                                                                           {"progress": "0",
441                                                                            "status": JOB_MODEL_STATUS.PROCESSING,
442                                                                            "responseid": "2",
443                                                                            "statusdescription": "creating",
444                                                                            "errorcode": "0"}]}}), '200']}
445
446         def side_effect(*args):
447             return mock_vals[args[4]]
448
449         mock_call_req.side_effect = side_effect
450
451         req_data = {
452             "action": "vmReset",
453             "affectedvm": {
454                 "vmid": "1",
455                 "vduid": "1",
456                 "vmname": "name",
457             }
458         }
459
460         NFHealService(self.nf_inst_id, req_data).run()
461
462         self.assertEqual(NfInstModel.objects.get(nfinstid=self.nf_inst_id).status, VNF_STATUS.ACTIVE)
463
464     @mock.patch.object(NFHealService, "run")
465     def test_heal_vnf_non_existing_vnf(self, mock_biz):
466         mock_biz.side_effect = NSLCMException("VNF Not Found")
467
468         nf_inst_id = "1"
469
470         req_data = {
471             "action": "vmReset",
472             "affectedvm": {
473                 "vmid": "1",
474                 "vduid": "1",
475                 "vmname": "name",
476             }
477         }
478
479         self.assertRaises(NSLCMException, NFHealService(nf_inst_id, req_data).run)
480         self.assertEqual(len(NfInstModel.objects.filter(nfinstid=nf_inst_id)), 0)
481
482
483 class TestGetVnfmInfoViews(TestCase):
484     def setUp(self):
485         self.client = Client()
486         self.vnfm_id = str(uuid.uuid4())
487
488     def tearDown(self):
489         pass
490
491     @mock.patch.object(restcall, "call_req")
492     def test_get_vnfm_info(self, mock_call_req):
493         vnfm_info_aai = {
494             "vnfm-id": "example-vnfm-id-val-62576",
495             "vim-id": "example-vim-id-val-35114",
496             "certificate-url": "example-certificate-url-val-90242",
497             "esr-system-info-list": {
498                 "esr-system-info": [
499                     {
500                         "esr-system-info-id": "example-esr-system-info-id-val-78484",
501                         "system-name": "example-system-name-val-23790",
502                         "type": "example-type-val-52596",
503                         "vendor": "example-vendor-val-47399",
504                         "version": "example-version-val-42051",
505                         "service-url": "example-service-url-val-10731",
506                         "user-name": "example-user-name-val-65946",
507                         "password": "example-password-val-22505",
508                         "system-type": "example-system-type-val-27221",
509                         "protocal": "example-protocal-val-54632",
510                         "ssl-cacert": "example-ssl-cacert-val-45965",
511                         "ssl-insecure": True,
512                         "ip-address": "example-ip-address-val-19212",
513                         "port": "example-port-val-57641",
514                         "cloud-domain": "example-cloud-domain-val-26296",
515                         "default-tenant": "example-default-tenant-val-87724"
516                     }
517                 ]
518             }
519         }
520         r1 = [0, json.JSONEncoder().encode(vnfm_info_aai), '200']
521         mock_call_req.side_effect = [r1]
522         esr_system_info = ignore_case_get(ignore_case_get(vnfm_info_aai, "esr-system-info-list"), "esr-system-info")
523         expect_data = {
524             "vnfmId": vnfm_info_aai["vnfm-id"],
525             "name": vnfm_info_aai["vnfm-id"],
526             "type": ignore_case_get(esr_system_info[0], "type"),
527             "vimId": vnfm_info_aai["vim-id"],
528             "vendor": ignore_case_get(esr_system_info[0], "vendor"),
529             "version": ignore_case_get(esr_system_info[0], "version"),
530             "description": "vnfm",
531             "certificateUrl": vnfm_info_aai["certificate-url"],
532             "url": ignore_case_get(esr_system_info[0], "service-url"),
533             "userName": ignore_case_get(esr_system_info[0], "user-name"),
534             "password": ignore_case_get(esr_system_info[0], "password"),
535             "createTime": "2016-07-06 15:33:18"
536         }
537
538         response = self.client.get("/api/nslcm/v1/vnfms/%s" % self.vnfm_id)
539         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
540         context = json.loads(response.content)
541         self.assertEqual(expect_data, context)
542
543
544 class TestGetVimInfoViews(TestCase):
545     def setUp(self):
546         self.client = Client()
547         self.vim_id = "zte_test"
548
549     def tearDown(self):
550         pass
551
552     @mock.patch.object(restcall, "call_req")
553     def test_get_vim_info(self, mock_call_req):
554         r1 = [0, json.JSONEncoder().encode(vim_info), '200']
555         mock_call_req.side_effect = [r1]
556         esr_system_info = ignore_case_get(ignore_case_get(vim_info, "esr-system-info-list"), "esr-system-info")
557         expect_data = {
558             "vimId": self.vim_id,
559             "name": self.vim_id,
560             "url": ignore_case_get(esr_system_info[0], "service-url"),
561             "userName": ignore_case_get(esr_system_info[0], "user-name"),
562             "password": ignore_case_get(esr_system_info[0], "password"),
563             # "tenant": ignore_case_get(tenants[0], "tenant-id"),
564             "tenant": ignore_case_get(esr_system_info[0], "default-tenant"),
565             "vendor": ignore_case_get(esr_system_info[0], "vendor"),
566             "version": ignore_case_get(esr_system_info[0], "version"),
567             "description": "vim",
568             "domain": "",
569             "type": ignore_case_get(esr_system_info[0], "type"),
570             "createTime": "2016-07-18 12:22:53"
571         }
572
573         response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
574         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
575         context = json.loads(response.content)
576         self.assertEqual(expect_data["url"], context["url"])
577
578
579 vnfd_model_dict = {
580     'local_storages': [],
581     'vdus': [
582         {
583             'volumn_storages': [
584
585             ],
586             'nfv_compute': {
587                 'mem_size': '',
588                 'num_cpus': u'2'
589             },
590             'local_storages': [
591
592             ],
593             'vdu_id': u'vdu_omm.001',
594             'image_file': u'opencos_sss_omm_img_release_20150723-1-disk1',
595             'dependencies': [
596
597             ],
598             'vls': [
599
600             ],
601             'cps': [
602
603             ],
604             'properties': {
605                 'key_vdu': '',
606                 'support_scaling': False,
607                 'vdu_type': '',
608                 'name': '',
609                 'storage_policy': '',
610                 'location_info': {
611                     'vimId': '',
612                     'availability_zone': '',
613                     'region': '',
614                     'dc': '',
615                     'host': '',
616                     'tenant': ''
617                 },
618                 'inject_data_list': [
619
620                 ],
621                 'watchdog': {
622                     'action': '',
623                     'enabledelay': ''
624                 },
625                 'local_affinity_antiaffinity_rule': {
626
627                 },
628                 'template_id': u'omm.001',
629                 'manual_scale_select_vim': False
630             },
631             'description': u'singleommvm'
632         },
633         {
634             'volumn_storages': [
635
636             ],
637             'nfv_compute': {
638                 'mem_size': '',
639                 'num_cpus': u'4'
640             },
641             'local_storages': [
642
643             ],
644             'vdu_id': u'vdu_1',
645             'image_file': u'sss',
646             'dependencies': [
647
648             ],
649             'vls': [
650
651             ],
652             'cps': [
653
654             ],
655             'properties': {
656                 'key_vdu': '',
657                 'support_scaling': False,
658                 'vdu_type': '',
659                 'name': '',
660                 'storage_policy': '',
661                 'location_info': {
662                     'vimId': '',
663                     'availability_zone': '',
664                     'region': '',
665                     'dc': '',
666                     'host': '',
667                     'tenant': ''
668                 },
669                 'inject_data_list': [
670
671                 ],
672                 'watchdog': {
673                     'action': '',
674                     'enabledelay': ''
675                 },
676                 'local_affinity_antiaffinity_rule': {
677
678                 },
679                 'template_id': u'1',
680                 'manual_scale_select_vim': False
681             },
682             'description': u'ompvm'
683         },
684         {
685             'volumn_storages': [
686
687             ],
688             'nfv_compute': {
689                 'mem_size': '',
690                 'num_cpus': u'14'
691             },
692             'local_storages': [
693
694             ],
695             'vdu_id': u'vdu_2',
696             'image_file': u'sss',
697             'dependencies': [
698
699             ],
700             'vls': [
701
702             ],
703             'cps': [
704
705             ],
706             'properties': {
707                 'key_vdu': '',
708                 'support_scaling': False,
709                 'vdu_type': '',
710                 'name': '',
711                 'storage_policy': '',
712                 'location_info': {
713                     'vimId': '',
714                     'availability_zone': '',
715                     'region': '',
716                     'dc': '',
717                     'host': '',
718                     'tenant': ''
719                 },
720                 'inject_data_list': [
721
722                 ],
723                 'watchdog': {
724                     'action': '',
725                     'enabledelay': ''
726                 },
727                 'local_affinity_antiaffinity_rule': {
728
729                 },
730                 'template_id': u'2',
731                 'manual_scale_select_vim': False
732             },
733             'description': u'ompvm'
734         },
735         {
736             'volumn_storages': [
737
738             ],
739             'nfv_compute': {
740                 'mem_size': '',
741                 'num_cpus': u'14'
742             },
743             'local_storages': [
744
745             ],
746             'vdu_id': u'vdu_3',
747             'image_file': u'sss',
748             'dependencies': [
749
750             ],
751             'vls': [
752
753             ],
754             'cps': [
755
756             ],
757             'properties': {
758                 'key_vdu': '',
759                 'support_scaling': False,
760                 'vdu_type': '',
761                 'name': '',
762                 'storage_policy': '',
763                 'location_info': {
764                     'vimId': '',
765                     'availability_zone': '',
766                     'region': '',
767                     'dc': '',
768                     'host': '',
769                     'tenant': ''
770                 },
771                 'inject_data_list': [
772
773                 ],
774                 'watchdog': {
775                     'action': '',
776                     'enabledelay': ''
777                 },
778                 'local_affinity_antiaffinity_rule': {
779
780                 },
781                 'template_id': u'3',
782                 'manual_scale_select_vim': False
783             },
784             'description': u'ompvm'
785         },
786         {
787             'volumn_storages': [
788
789             ],
790             'nfv_compute': {
791                 'mem_size': '',
792                 'num_cpus': u'4'
793             },
794             'local_storages': [
795
796             ],
797             'vdu_id': u'vdu_10',
798             'image_file': u'sss',
799             'dependencies': [
800
801             ],
802             'vls': [
803
804             ],
805             'cps': [
806
807             ],
808             'properties': {
809                 'key_vdu': '',
810                 'support_scaling': False,
811                 'vdu_type': '',
812                 'name': '',
813                 'storage_policy': '',
814                 'location_info': {
815                     'vimId': '',
816                     'availability_zone': '',
817                     'region': '',
818                     'dc': '',
819                     'host': '',
820                     'tenant': ''
821                 },
822                 'inject_data_list': [
823
824                 ],
825                 'watchdog': {
826                     'action': '',
827                     'enabledelay': ''
828                 },
829                 'local_affinity_antiaffinity_rule': {
830
831                 },
832                 'template_id': u'10',
833                 'manual_scale_select_vim': False
834             },
835             'description': u'ppvm'
836         },
837         {
838             'volumn_storages': [
839
840             ],
841             'nfv_compute': {
842                 'mem_size': '',
843                 'num_cpus': u'14'
844             },
845             'local_storages': [
846
847             ],
848             'vdu_id': u'vdu_11',
849             'image_file': u'sss',
850             'dependencies': [
851
852             ],
853             'vls': [
854
855             ],
856             'cps': [
857
858             ],
859             'properties': {
860                 'key_vdu': '',
861                 'support_scaling': False,
862                 'vdu_type': '',
863                 'name': '',
864                 'storage_policy': '',
865                 'location_info': {
866                     'vimId': '',
867                     'availability_zone': '',
868                     'region': '',
869                     'dc': '',
870                     'host': '',
871                     'tenant': ''
872                 },
873                 'inject_data_list': [
874
875                 ],
876                 'watchdog': {
877                     'action': '',
878                     'enabledelay': ''
879                 },
880                 'local_affinity_antiaffinity_rule': {
881
882                 },
883                 'template_id': u'11',
884                 'manual_scale_select_vim': False
885             },
886             'description': u'ppvm'
887         },
888         {
889             'volumn_storages': [
890
891             ],
892             'nfv_compute': {
893                 'mem_size': '',
894                 'num_cpus': u'14'
895             },
896             'local_storages': [
897
898             ],
899             'vdu_id': u'vdu_12',
900             'image_file': u'sss',
901             'dependencies': [
902
903             ],
904             'vls': [
905
906             ],
907             'cps': [
908
909             ],
910             'properties': {
911                 'key_vdu': '',
912                 'support_scaling': False,
913                 'vdu_type': '',
914                 'name': '',
915                 'storage_policy': '',
916                 'location_info': {
917                     'vimId': '',
918                     'availability_zone': '',
919                     'region': '',
920                     'dc': '',
921                     'host': '',
922                     'tenant': ''
923                 },
924                 'inject_data_list': [
925
926                 ],
927                 'watchdog': {
928                     'action': '',
929                     'enabledelay': ''
930                 },
931                 'local_affinity_antiaffinity_rule': {
932
933                 },
934                 'template_id': u'12',
935                 'manual_scale_select_vim': False
936             },
937             'description': u'ppvm'
938         }
939     ],
940     'volumn_storages': [
941
942     ],
943     'policies': {
944         'scaling': {
945             'targets': {
946
947             },
948             'policy_id': u'policy_scale_sss-vnf-template',
949             'properties': {
950                 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'
951             },
952             'description': ''
953         }
954     },
955     'image_files': [
956         {
957             'description': '',
958             'properties': {
959                 'name': u'opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
960                 'checksum': '',
961                 'disk_format': u'VMDK',
962                 'file_url': u'./zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
963                 'container_type': 'vm',
964                 'version': '',
965                 'hypervisor_type': 'kvm'
966             },
967             'image_file_id': u'opencos_sss_omm_img_release_20150723-1-disk1'
968         },
969         {
970             'description': '',
971             'properties': {
972                 'name': u'sss.vmdk',
973                 'checksum': '',
974                 'disk_format': u'VMDK',
975                 'file_url': u'./zte-cn-sss-main-image/NE/sss.vmdk',
976                 'container_type': 'vm',
977                 'version': '',
978                 'hypervisor_type': 'kvm'
979             },
980             'image_file_id': u'sss'
981         }
982     ],
983     'vls': [
984
985     ],
986     'cps': [
987
988     ],
989     'metadata': {
990         'vendor': u'zte',
991         'is_shared': False,
992         'description': '',
993         'domain_type': u'CN',
994         'version': u'v4.14.10',
995         'vmnumber_overquota_alarm': False,
996         'cross_dc': False,
997         'vnf_type': u'SSS',
998         'vnfd_version': u'V00000001',
999         'id': u'sss-vnf-template',
1000         'name': u'sss-vnf-template'
1001     }
1002 }
1003
1004 nsd_model_dict = {
1005     "vnffgs": [
1006
1007     ],
1008     "inputs": {
1009         "externalDataNetworkName": {
1010             "default": "",
1011             "type": "string",
1012             "description": ""
1013         }
1014     },
1015     "pnfs": [
1016
1017     ],
1018     "fps": [
1019
1020     ],
1021     "server_groups": [
1022
1023     ],
1024     "ns_flavours": [
1025
1026     ],
1027     "vnfs": [
1028         {
1029             "dependency": [
1030
1031             ],
1032             "properties": {
1033                 "plugin_info": "vbrasplugin_1.0",
1034                 "vendor": "zte",
1035                 "is_shared": "False",
1036                 "request_reclassification": "False",
1037                 "vnfd_version": "1.0.0",
1038                 "version": "1.0",
1039                 "nsh_aware": "True",
1040                 "cross_dc": "False",
1041                 "externalDataNetworkName": {
1042                     "get_input": "externalDataNetworkName"
1043                 },
1044                 "id": "zte_vbras",
1045                 "name": "vbras"
1046             },
1047             "vnf_id": "VBras",
1048             "networks": [
1049
1050             ],
1051             "description": ""
1052         }
1053     ],
1054     "ns_exposed": {
1055         "external_cps": [
1056
1057         ],
1058         "forward_cps": [
1059
1060         ]
1061     },
1062     "vls": [
1063         {
1064             "vl_id": "ext_mnet_network",
1065             "description": "",
1066             "properties": {
1067                 "network_type": "vlan",
1068                 "name": "externalMNetworkName",
1069                 "dhcp_enabled": False,
1070                 "location_info": {
1071                     "host": True,
1072                     "vimid": 2,
1073                     "region": True,
1074                     "tenant": "admin",
1075                     "dc": ""
1076                 },
1077                 "end_ip": "190.168.100.100",
1078                 "gateway_ip": "190.168.100.1",
1079                 "start_ip": "190.168.100.2",
1080                 "cidr": "190.168.100.0/24",
1081                 "mtu": 1500,
1082                 "network_name": "sub_mnet",
1083                 "ip_version": 4
1084             }
1085         }
1086     ],
1087     "cps": [
1088
1089     ],
1090     "policies": [
1091
1092     ],
1093     "metadata": {
1094         "invariant_id": "vbras_ns",
1095         "description": "vbras_ns",
1096         "version": 1,
1097         "vendor": "zte",
1098         "id": "vbras_ns",
1099         "name": "vbras_ns"
1100     }
1101 }
1102
1103 vserver_info = {
1104     "vserver-id": "example-vserver-id-val-70924",
1105     "vserver-name": "example-vserver-name-val-61674",
1106     "vserver-name2": "example-vserver-name2-val-19234",
1107     "prov-status": "example-prov-status-val-94916",
1108     "vserver-selflink": "example-vserver-selflink-val-26562",
1109     "in-maint": True,
1110     "is-closed-loop-disabled": True,
1111     "resource-version": "1505465356263",
1112     "volumes": {
1113         "volume": [
1114             {
1115                 "volume-id": "example-volume-id-val-71854",
1116                 "volume-selflink": "example-volume-selflink-val-22433"
1117             }
1118         ]
1119     },
1120     "l-interfaces": {
1121         "l-interface": [
1122             {
1123                 "interface-name": "example-interface-name-val-24351",
1124                 "interface-role": "example-interface-role-val-43242",
1125                 "v6-wan-link-ip": "example-v6-wan-link-ip-val-4196",
1126                 "selflink": "example-selflink-val-61295",
1127                 "interface-id": "example-interface-id-val-95879",
1128                 "macaddr": "example-macaddr-val-37302",
1129                 "network-name": "example-network-name-val-44254",
1130                 "management-option": "example-management-option-val-49009",
1131                 "interface-description": "example-interface-description-val-99923",
1132                 "is-port-mirrored": True,
1133                 "in-maint": True,
1134                 "prov-status": "example-prov-status-val-4698",
1135                 "is-ip-unnumbered": True,
1136                 "allowed-address-pairs": "example-allowed-address-pairs-val-5762",
1137                 "vlans": {
1138                     "vlan": [
1139                         {
1140                             "vlan-interface": "example-vlan-interface-val-58193",
1141                             "vlan-id-inner": 54452151,
1142                             "vlan-id-outer": 70239293,
1143                             "speed-value": "example-speed-value-val-18677",
1144                             "speed-units": "example-speed-units-val-46185",
1145                             "vlan-description": "example-vlan-description-val-81675",
1146                             "backdoor-connection": "example-backdoor-connection-val-44608",
1147                             "vpn-key": "example-vpn-key-val-7946",
1148                             "orchestration-status": "example-orchestration-status-val-33611",
1149                             "in-maint": True,
1150                             "prov-status": "example-prov-status-val-8288",
1151                             "is-ip-unnumbered": True,
1152                             "l3-interface-ipv4-address-list": [
1153                                 {
1154                                     "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-25520",
1155                                     "l3-interface-ipv4-prefix-length": 69931928,
1156                                     "vlan-id-inner": 86628520,
1157                                     "vlan-id-outer": 62729236,
1158                                     "is-floating": True,
1159                                     "neutron-network-id": "example-neutron-network-id-val-64021",
1160                                     "neutron-subnet-id": "example-neutron-subnet-id-val-95049"
1161                                 }
1162                             ],
1163                             "l3-interface-ipv6-address-list": [
1164                                 {
1165                                     "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-64310",
1166                                     "l3-interface-ipv6-prefix-length": 57919834,
1167                                     "vlan-id-inner": 79150122,
1168                                     "vlan-id-outer": 59789973,
1169                                     "is-floating": True,
1170                                     "neutron-network-id": "example-neutron-network-id-val-31713",
1171                                     "neutron-subnet-id": "example-neutron-subnet-id-val-89568"
1172                                 }
1173                             ]
1174                         }
1175                     ]
1176                 },
1177                 "sriov-vfs": {
1178                     "sriov-vf": [
1179                         {
1180                             "pci-id": "example-pci-id-val-16747",
1181                             "vf-vlan-filter": "example-vf-vlan-filter-val-4613",
1182                             "vf-mac-filter": "example-vf-mac-filter-val-68168",
1183                             "vf-vlan-strip": True,
1184                             "vf-vlan-anti-spoof-check": True,
1185                             "vf-mac-anti-spoof-check": True,
1186                             "vf-mirrors": "example-vf-mirrors-val-6270",
1187                             "vf-broadcast-allow": True,
1188                             "vf-unknown-multicast-allow": True,
1189                             "vf-unknown-unicast-allow": True,
1190                             "vf-insert-stag": True,
1191                             "vf-link-status": "example-vf-link-status-val-49266",
1192                             "neutron-network-id": "example-neutron-network-id-val-29493"
1193                         }
1194                     ]
1195                 },
1196                 "l-interfaces": {
1197                     "l-interface": [
1198                         {
1199                             "interface-name": "example-interface-name-val-98222",
1200                             "interface-role": "example-interface-role-val-78360",
1201                             "v6-wan-link-ip": "example-v6-wan-link-ip-val-76921",
1202                             "selflink": "example-selflink-val-27117",
1203                             "interface-id": "example-interface-id-val-11260",
1204                             "macaddr": "example-macaddr-val-60378",
1205                             "network-name": "example-network-name-val-16258",
1206                             "management-option": "example-management-option-val-35097",
1207                             "interface-description": "example-interface-description-val-10475",
1208                             "is-port-mirrored": True,
1209                             "in-maint": True,
1210                             "prov-status": "example-prov-status-val-65203",
1211                             "is-ip-unnumbered": True,
1212                             "allowed-address-pairs": "example-allowed-address-pairs-val-65028"
1213                         }
1214                     ]
1215                 },
1216                 "l3-interface-ipv4-address-list": [
1217                     {
1218                         "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-72779",
1219                         "l3-interface-ipv4-prefix-length": 55956636,
1220                         "vlan-id-inner": 98174431,
1221                         "vlan-id-outer": 20372128,
1222                         "is-floating": True,
1223                         "neutron-network-id": "example-neutron-network-id-val-39596",
1224                         "neutron-subnet-id": "example-neutron-subnet-id-val-51109"
1225                     }
1226                 ],
1227                 "l3-interface-ipv6-address-list": [
1228                     {
1229                         "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-95203",
1230                         "l3-interface-ipv6-prefix-length": 57454747,
1231                         "vlan-id-inner": 53421060,
1232                         "vlan-id-outer": 16006050,
1233                         "is-floating": True,
1234                         "neutron-network-id": "example-neutron-network-id-val-54216",
1235                         "neutron-subnet-id": "example-neutron-subnet-id-val-1841"
1236                     }
1237                 ]
1238             }
1239         ]
1240     }
1241 }
1242
1243
1244 vnfm_info = {
1245     "vnfm-id": "example-vnfm-id-val-97336",
1246     "vim-id": "zte_test",
1247     "certificate-url": "example-certificate-url-val-18046",
1248     "resource-version": "example-resource-version-val-42094",
1249     "esr-system-info-list": {
1250         "esr-system-info": [
1251             {
1252                 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1253                 "system-name": "example-system-name-val-19801",
1254                 "type": "ztevmanagerdriver",
1255                 "vendor": "example-vendor-val-50079",
1256                 "version": "example-version-val-93146",
1257                 "service-url": "example-service-url-val-68090",
1258                 "user-name": "example-user-name-val-14470",
1259                 "password": "example-password-val-84190",
1260                 "system-type": "example-system-type-val-42773",
1261                 "protocal": "example-protocal-val-85736",
1262                 "ssl-cacert": "example-ssl-cacert-val-33989",
1263                 "ssl-insecure": True,
1264                 "ip-address": "example-ip-address-val-99038",
1265                 "port": "example-port-val-27323",
1266                 "cloud-domain": "example-cloud-domain-val-55163",
1267                 "default-tenant": "example-default-tenant-val-99383",
1268                 "resource-version": "example-resource-version-val-15424"
1269             }
1270         ]
1271     }
1272 }
1273
1274 vim_info = {
1275     "cloud-owner": "example-cloud-owner-val-97336",
1276     "cloud-region-id": "example-cloud-region-id-val-35532",
1277     "cloud-type": "example-cloud-type-val-18046",
1278     "owner-defined-type": "example-owner-defined-type-val-9413",
1279     "cloud-region-version": "example-cloud-region-version-val-85706",
1280     "identity-url": "example-identity-url-val-71252",
1281     "cloud-zone": "example-cloud-zone-val-27112",
1282     "complex-name": "example-complex-name-val-85283",
1283     "sriov-automation": True,
1284     "cloud-extra-info": "example-cloud-extra-info-val-90854",
1285     "cloud-epa-caps": "example-cloud-epa-caps-val-2409",
1286     "resource-version": "example-resource-version-val-42094",
1287     "esr-system-info-list": {
1288         "esr-system-info": [
1289             {
1290                 "esr-system-info-id": "example-esr-system-info-id-val-7713",
1291                 "system-name": "example-system-name-val-19801",
1292                 "type": "example-type-val-24477",
1293                 "vendor": "example-vendor-val-50079",
1294                 "version": "example-version-val-93146",
1295                 "service-url": "example-service-url-val-68090",
1296                 "user-name": "example-user-name-val-14470",
1297                 "password": "example-password-val-84190",
1298                 "system-type": "example-system-type-val-42773",
1299                 "protocal": "example-protocal-val-85736",
1300                 "ssl-cacert": "example-ssl-cacert-val-33989",
1301                 "ssl-insecure": True,
1302                 "ip-address": "example-ip-address-val-99038",
1303                 "port": "example-port-val-27323",
1304                 "cloud-domain": "example-cloud-domain-val-55163",
1305                 "default-tenant": "admin",
1306                 "resource-version": "example-resource-version-val-15424"
1307             }
1308         ]
1309     }
1310 }