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