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