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