Fix vfc lcm vnf operations unit tests
[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
23 from lcm.ns.vnfs.create_vnfs import CreateVnfs
24 from lcm.pub.database.models import NfInstModel, JobModel, NfPackageModel, NSInstModel
25 from lcm.pub.utils import restcall
26 from lcm.pub.utils.jobutil import JOB_MODEL_STATUS
27 from lcm.pub.utils.timeutil import now_time
28 from lcm.pub.utils.values import ignore_case_get
29 from lcm.ns.vnfs.terminate_nfs import TerminateVnfs
30 from lcm.ns.vnfs.scale_vnfs import NFManualScaleService
31 from lcm.ns.vnfs.heal_vnfs import NFHealService
32 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
33 from lcm.pub.exceptions import NSLCMException
34
35 vnfm_info = {
36     "vnfm-id": "example-vnfm-id-val-97336",
37     "vim-id": "example-vim-id-val-35532",
38     "certificate-url": "example-certificate-url-val-18046",
39     "resource-version": "example-resource-version-val-42094",
40     "esr-system-info-list": {
41         "esr-system-info": [
42             {
43                 "esr-system-info-id": "example-esr-system-info-id-val-7713",
44                 "system-name": "example-system-name-val-19801",
45                 "type": "ztevmanagerdriver",
46                 "vendor": "example-vendor-val-50079",
47                 "version": "example-version-val-93146",
48                 "service-url": "example-service-url-val-68090",
49                 "user-name": "example-user-name-val-14470",
50                 "password": "example-password-val-84190",
51                 "system-type": "example-system-type-val-42773",
52                 "protocal": "example-protocal-val-85736",
53                 "ssl-cacert": "example-ssl-cacert-val-33989",
54                 "ssl-insecure": True,
55                 "ip-address": "example-ip-address-val-99038",
56                 "port": "example-port-val-27323",
57                 "cloud-domain": "example-cloud-domain-val-55163",
58                 "default-tenant": "example-default-tenant-val-99383",
59                 "resource-version": "example-resource-version-val-15424"
60             }
61         ]
62     }
63 }
64
65 class TestGetVnfViews(TestCase):
66     def setUp(self):
67         self.client = Client()
68         self.nf_inst_id = str(uuid.uuid4())
69         NfInstModel(nfinstid=self.nf_inst_id, nf_name='vnf1', vnfm_inst_id='1', vnf_id='vnf_id1',
70                     status=VNF_STATUS.ACTIVE, create_time=now_time(), lastuptime=now_time()).save()
71
72     def tearDown(self):
73         NfInstModel.objects.all().delete()
74
75     def test_get_vnf(self):
76         response = self.client.get("/api/nslcm/v1/ns/vnfs/%s" % self.nf_inst_id)
77         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
78         context = json.loads(response.content)
79         self.failUnlessEqual(self.nf_inst_id, context['vnfInstId'])
80
81
82 class TestCreateVnfViews(TestCase):
83     def setUp(self):
84         self.ns_inst_id = str(uuid.uuid4())
85         self.job_id = str(uuid.uuid4())
86         self.data = {
87             'nsInstanceId': self.ns_inst_id,
88             'additionalParamForNs': {"inputs": json.dumps({})},
89             'additionalParamForVnf': [{
90                 'vnfprofileid': 'VBras',
91                 'additionalparam': {
92                     'inputs': json.dumps({'vnf_param1': '11', 'vnf_param2': '22'}),
93                     'vnfminstanceid': "1"}}],
94             'vnfIndex': '1'}
95         self.client = Client()
96         NfPackageModel(uuid=str(uuid.uuid4()), nfpackageid='package_id1', vnfdid='zte_vbras', vendor='zte',
97                        vnfdversion='1.0.0', vnfversion='1.0.0', vnfdmodel=json.dumps(vnfd_model_dict)).save()
98         NSInstModel(id=self.ns_inst_id, name='ns', nspackage_id='1', nsd_id='nsd_id', description='description',
99                     status='instantiating', nsd_model=json.dumps(nsd_model_dict), create_time=now_time(),
100                     lastuptime=now_time()).save()
101
102     def tearDown(self):
103         NfInstModel.objects.all().delete()
104         JobModel.objects.all().delete()
105
106     @mock.patch.object(CreateVnfs, 'run')
107     def test_create_vnf(self, mock_run):
108         response = self.client.post("/api/nslcm/v1/ns/vnfs", data=self.data)
109         self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
110         context = json.loads(response.content)
111         self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstId']).exists())
112
113     @mock.patch.object(restcall, 'call_req')
114     def test_create_vnf_thread(self, mock_call_req):
115         mock_vals = {
116             "/api/ztevmanagerdriver/v1/1/vnfs":
117                 [0, json.JSONEncoder().encode({"jobId": self.job_id, "vnfInstanceId": 3}), '200'],
118             "/external-system/esr-vnfm-list/esr-vnfm/1":
119                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
120             "/api/resmgr/v1/vnf":
121                 [0, json.JSONEncoder().encode({}), '200'],
122             "/api/resmgr/v1/vnfinfo":
123                 [0, json.JSONEncoder().encode({}), '200'],
124             "/api/ztevmanagerdriver/v1/jobs/" + self.job_id + "&responseId=0":
125                 [0, json.JSONEncoder().encode({"jobid": self.job_id,
126                                                "responsedescriptor": {"progress": "100",
127                                                                       "status": JOB_MODEL_STATUS.FINISHED,
128                                                                       "responseid": "3",
129                                                                       "statusdescription": "creating",
130                                                                       "errorcode": "0",
131                                                                       "responsehistorylist": [
132                                                                           {"progress": "0",
133                                                                            "status": JOB_MODEL_STATUS.PROCESSING,
134                                                                            "responseid": "2",
135                                                                            "statusdescription": "creating",
136                                                                            "errorcode": "0"}]}}), '200']}
137
138         def side_effect(*args):
139             return mock_vals[args[4]]
140         mock_call_req.side_effect = side_effect
141         data = {'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
142                 'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
143                 'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
144                 'vnf_index': ignore_case_get(self.data, 'vnfIndex')}
145         nf_inst_id, job_id = create_vnfs.prepare_create_params()
146         CreateVnfs(data, nf_inst_id, job_id).run()
147         self.assertTrue(NfInstModel.objects.get(nfinstid=nf_inst_id).status, VNF_STATUS.ACTIVE)
148
149
150 class TestTerminateVnfViews(TestCase):
151     def setUp(self):
152         self.client = Client()
153         self.ns_inst_id = str(uuid.uuid4())
154         self.nf_inst_id = '1'
155         self.vnffg_id = str(uuid.uuid4())
156         self.vim_id = str(uuid.uuid4())
157         self.job_id = str(uuid.uuid4())
158         self.nf_uuid = '111'
159         self.tenant = "tenantname"
160         NSInstModel.objects.all().delete()
161         NfInstModel.objects.all().delete()
162         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
163         NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
164                                    vnfm_inst_id='1', ns_inst_id='111,2-2-2',
165                                    max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
166                                    status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
167                                    vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
168                                               '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
169                                               '"productType": "CN","vnfType": "PGW",'
170                                               '"description": "PGW VNFD description",'
171                                               '"isShared":true,"vnfExtendType":"driver"}}')
172
173     def tearDown(self):
174         NSInstModel.objects.all().delete()
175         NfInstModel.objects.all().delete()
176
177     @mock.patch.object(TerminateVnfs, 'run')
178     def test_terminate_vnf_url(self, mock_run):
179         req_data = {
180             "terminationType": "forceful",
181             "gracefulTerminationTimeout": "600"}
182
183         response = self.client.post("/api/nslcm/v1/ns/vnfs/%s" % self.nf_inst_id, data=req_data)
184         self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
185
186
187     @mock.patch.object(restcall, 'call_req')
188     def test_terminate_vnf(self, mock_call_req):
189         job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
190
191         nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
192         if nfinst:
193             self.failUnlessEqual(1, 1)
194         else:
195             self.failUnlessEqual(1, 0)
196
197         vnf_info = {
198             "vnf-id": "vnf-id-test111",
199             "vnf-name": "vnf-name-test111",
200             "vnf-type": "vnf-type-test111",
201             "in-maint": True,
202             "is-closed-loop-disabled": False,
203             "resource-version": "1505465356262"
204         }
205         job_info = {
206             "jobId": job_id,
207             "responsedescriptor": {
208                 "progress": "100",
209                 "status": JOB_MODEL_STATUS.FINISHED,
210                 "responseid": "3",
211                 "statusdescription": "creating",
212                 "errorcode": "0",
213                 "responsehistorylist": [
214                     {
215                         "progress": "0",
216                         "status": JOB_MODEL_STATUS.PROCESSING,
217                         "responseid": "2",
218                         "statusdescription": "creating",
219                         "errorcode": "0"
220                     }
221                 ]
222             }
223         }
224
225         mock_vals = {
226             "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all":
227                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
228             "/api/ztevmanagerdriver/v1/1/vnfs/111/terminate":
229                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
230             "/api/resmgr/v1/vnf/1":
231                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
232             "/api/ztevmanagerdriver/v1/1/jobs/" + job_id + "?responseId=0":
233                 [0, json.JSONEncoder().encode(job_info), '200'],
234             "/network/generic-vnfs/generic-vnf/111?depth=all":
235             [0, json.JSONEncoder().encode(vnf_info), '200'],
236             "/network/generic-vnfs/generic-vnf/111?resource-version=1505465356262":
237             [0, json.JSONEncoder().encode({}), '200']
238         }
239
240         def side_effect(*args):
241             return mock_vals[args[4]]
242         mock_call_req.side_effect = side_effect
243
244         req_data = {
245             "terminationType": "forceful",
246             "gracefulTerminationTimeout": "600"}
247
248         TerminateVnfs(req_data, self.nf_inst_id, job_id).run()
249         nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
250         if nfinst:
251             self.failUnlessEqual(1, 0)
252         else:
253             self.failUnlessEqual(1, 1)
254
255 class TestScaleVnfViews(TestCase):
256     def setUp(self):
257         self.client = Client()
258         self.ns_inst_id = str(uuid.uuid4())
259         self.nf_inst_id = str(uuid.uuid4())
260         self.vnffg_id = str(uuid.uuid4())
261         self.vim_id = str(uuid.uuid4())
262         self.job_id = str(uuid.uuid4())
263         self.nf_uuid = '111'
264         self.tenant = "tenantname"
265         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
266         NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
267                                    vnfm_inst_id='1', ns_inst_id='111,2-2-2',
268                                    max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
269                                    status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
270                                    vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
271                                               '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
272                                               '"productType": "CN","vnfType": "PGW",'
273                                               '"description": "PGW VNFD description",'
274                                               '"isShared":true,"vnfExtendType":"driver"}}')
275
276     def tearDown(self):
277         NSInstModel.objects.all().delete()
278         NfInstModel.objects.all().delete()
279
280     @mock.patch.object(restcall, "call_req")
281     def test_scale_vnf(self, mock_call_req):
282         job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
283
284         vnfd_info = {
285             "vnf_flavours":[
286                 {
287                     "flavour_id":"flavour1",
288                     "description":"",
289                     "vdu_profiles":[
290                         {
291                             "vdu_id":"vdu1Id",
292                             "instances_minimum_number": 1,
293                             "instances_maximum_number": 4,
294                             "local_affinity_antiaffinity_rule":[
295                                 {
296                                     "affinity_antiaffinity":"affinity",
297                                     "scope":"node",
298                                 }
299                             ]
300                         }
301                     ],
302                     "scaling_aspects":[
303                         {
304                             "id": "demo_aspect",
305                             "name": "demo_aspect",
306                             "description": "demo_aspect",
307                             "associated_group": "elementGroup1",
308                             "max_scale_level": 5
309                         }
310                     ]
311                 }
312             ],
313             "element_groups": [
314                   {
315                       "group_id": "elementGroup1",
316                       "description": "",
317                       "properties":{
318                           "name": "elementGroup1",
319                       },
320                       "members": ["gsu_vm","pfu_vm"],
321                   }
322             ]
323         }
324
325         req_data = {
326             "scaleVnfData": [
327                 {
328                     "type":"SCALE_OUT",
329                     "aspectId":"demo_aspect1",
330                     "numberOfSteps":1,
331                     "additionalParam":vnfd_info
332                 },
333                 {
334                     "type":"SCALE_OUT",
335                     "aspectId":"demo_aspect2",
336                     "numberOfSteps":1,
337                     "additionalParam":vnfd_info
338                 }
339             ]
340         }
341
342
343         mock_vals = {
344             "/api/ztevmanagerdriver/v1/1/vnfs/111/terminate":
345                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200'],
346             "/api/ztevmanagerdriver/v1/1/vnfs/111/terminate":
347                 [0, json.JSONEncoder().encode({"jobId": job_id}), '200']
348         }
349         def side_effect(*args):
350             return mock_vals[args[4]]
351         mock_call_req.side_effect = side_effect
352
353         NFManualScaleService(self.nf_inst_id, req_data).run()
354         nsIns = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
355         if nsIns:
356             self.failUnlessEqual(1, 1)
357         else:
358             self.failUnlessEqual(1, 0)
359
360
361 class TestHealVnfViews(TestCase):
362     def setUp(self):
363         self.client = Client()
364         self.ns_inst_id = str(uuid.uuid4())
365         self.nf_inst_id = str(uuid.uuid4())
366         self.nf_uuid = '111'
367
368         self.job_id = JobUtil.create_job("VNF", JOB_TYPE.HEAL_VNF, self.nf_inst_id)
369
370         NSInstModel(id=self.ns_inst_id, name="ns_name").save()
371         NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
372                                    vnfm_inst_id='1', ns_inst_id='111,2-2-2',
373                                    max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
374                                    status='active', mnfinstid=self.nf_uuid, package_id='pkg1',
375                                    vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
376                                               '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
377                                               '"productType": "CN","vnfType": "PGW",'
378                                               '"description": "PGW VNFD description",'
379                                               '"isShared":true,"vnfExtendType":"driver"}}')
380
381     def tearDown(self):
382         NSInstModel.objects.all().delete()
383         NfInstModel.objects.all().delete()
384
385     @mock.patch.object(restcall, "call_req")
386     def test_heal_vnf(self, mock_call_req):
387
388
389         mock_vals = {
390             "/api/ztevmanagerdriver/v1/1/vnfs/111/heal":
391                 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
392             "/external-system/esr-vnfm-list/esr-vnfm/1":
393                 [0, json.JSONEncoder().encode(vnfm_info), '200'],
394             "/api/resmgr/v1/vnf/1":
395                 [0, json.JSONEncoder().encode({"jobId": self.job_id}), '200'],
396             "/api/ztevmanagerdriver/v1/1/jobs/" + self.job_id + "?responseId=0":
397                 [0, json.JSONEncoder().encode({"jobId": self.job_id,
398                                                "responsedescriptor": {"progress": "100",
399                                                                       "status": JOB_MODEL_STATUS.FINISHED,
400                                                                       "responseid": "3",
401                                                                       "statusdescription": "creating",
402                                                                       "errorcode": "0",
403                                                                       "responsehistorylist": [
404                                                                           {"progress": "0",
405                                                                            "status": JOB_MODEL_STATUS.PROCESSING,
406                                                                            "responseid": "2",
407                                                                            "statusdescription": "creating",
408                                                                            "errorcode": "0"}]}}), '200']}
409
410         def side_effect(*args):
411             return mock_vals[args[4]]
412
413         mock_call_req.side_effect = side_effect
414
415         req_data = {
416             "action": "vmReset",
417             "affectedvm": {
418                 "vmid": "1",
419                 "vduid": "1",
420                 "vmname": "name",
421             }
422         }
423
424         NFHealService(self.nf_inst_id, req_data).run()
425
426         self.assertEqual(NfInstModel.objects.get(nfinstid=self.nf_inst_id).status, VNF_STATUS.ACTIVE)
427
428     @mock.patch.object(NFHealService, "run")
429     def test_heal_vnf_non_existing_vnf(self, mock_biz):
430         mock_biz.side_effect = NSLCMException("VNF Not Found")
431
432         nf_inst_id = "1"
433
434         req_data = {
435             "action": "vmReset",
436             "affectedvm": {
437                 "vmid": "1",
438                 "vduid": "1",
439                 "vmname": "name",
440             }
441         }
442
443         self.assertRaises(NSLCMException, NFHealService(nf_inst_id, req_data).run)
444         self.assertEqual(len(NfInstModel.objects.filter(nfinstid=nf_inst_id)), 0)
445
446 class TestGetVnfmInfoViews(TestCase):
447     def setUp(self):
448         self.client = Client()
449         self.vnfm_id = str(uuid.uuid4())
450
451     def tearDown(self):
452         pass
453
454     @mock.patch.object(restcall, "call_req")
455     def test_get_vnfm_info(self, mock_call_req):
456         vnfm_info_aai = \
457             {
458                 "vnfm-id": "example-vnfm-id-val-62576",
459                 "vim-id": "example-vim-id-val-35114",
460                 "certificate-url": "example-certificate-url-val-90242",
461                 "esr-system-info-list": {
462                     "esr-system-info": [
463                         {
464                             "esr-system-info-id": "example-esr-system-info-id-val-78484",
465                             "system-name": "example-system-name-val-23790",
466                             "type": "example-type-val-52596",
467                             "vendor": "example-vendor-val-47399",
468                             "version": "example-version-val-42051",
469                             "service-url": "example-service-url-val-10731",
470                             "user-name": "example-user-name-val-65946",
471                             "password": "example-password-val-22505",
472                             "system-type": "example-system-type-val-27221",
473                             "protocal": "example-protocal-val-54632",
474                             "ssl-cacert": "example-ssl-cacert-val-45965",
475                             "ssl-insecure": True,
476                             "ip-address": "example-ip-address-val-19212",
477                             "port": "example-port-val-57641",
478                             "cloud-domain": "example-cloud-domain-val-26296",
479                             "default-tenant": "example-default-tenant-val-87724"
480                         }
481                     ]
482                 }
483             }
484         r1 = [0, json.JSONEncoder().encode(vnfm_info_aai), '200']
485         mock_call_req.side_effect = [r1]
486         esr_system_info = ignore_case_get(ignore_case_get(vnfm_info_aai, "esr-system-info-list"), "esr-system-info")
487         expect_data = \
488             {
489                 "vnfmId": vnfm_info_aai["vnfm-id"],
490                 "name": vnfm_info_aai["vnfm-id"],
491                 "type": ignore_case_get(esr_system_info[0], "type"),
492                 "vimId": vnfm_info_aai["vim-id"],
493                 "vendor": ignore_case_get(esr_system_info[0], "vendor"),
494                 "version": ignore_case_get(esr_system_info[0], "version"),
495                 "description": "vnfm",
496                 "certificateUrl": vnfm_info_aai["certificate-url"],
497                 "url": ignore_case_get(esr_system_info[0], "service-url"),
498                 "userName": ignore_case_get(esr_system_info[0], "user-name"),
499                 "password": ignore_case_get(esr_system_info[0], "password"),
500                 "createTime": "2016-07-06 15:33:18"
501             }
502
503         response = self.client.get("/api/nslcm/v1/vnfms/%s" % self.vnfm_id)
504         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
505         context = json.loads(response.content)
506         self.assertEqual(expect_data, context)
507
508 class TestGetVimInfoViews(TestCase):
509     def setUp(self):
510         self.client = Client()
511         self.vim_id = "zte_test"
512
513     def tearDown(self):
514         pass
515
516     @mock.patch.object(restcall, "call_req")
517     def test_get_vim_info(self, mock_call_req):
518         r1 = [0, json.JSONEncoder().encode(vim_info_aai), '200']
519         mock_call_req.side_effect = [r1]
520         esr_system_info = ignore_case_get(ignore_case_get(vim_info_aai, "esr-system-info-list"), "esr-system-info")
521         expect_data = \
522             {
523                 "vimId": self.vim_id,
524                 "name": self.vim_id,
525                 "url": ignore_case_get(esr_system_info[0], "service-url"),
526                 "userName": ignore_case_get(esr_system_info[0], "user-name"),
527                 "password": ignore_case_get(esr_system_info[0], "password"),
528                 # "tenant": ignore_case_get(tenants[0], "tenant-id"),
529                 "tenant": ignore_case_get(esr_system_info[0], "default-tenant"),
530                 "vendor": ignore_case_get(esr_system_info[0], "vendor"),
531                 "version": ignore_case_get(esr_system_info[0], "version"),
532                 "description": "vim",
533                 "domain": "",
534                 "type": ignore_case_get(esr_system_info[0], "type"),
535                 "createTime": "2016-07-18 12:22:53"
536             }
537
538         response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id)
539         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
540         context = json.loads(response.content)
541         self.assertEqual(expect_data["url"], context["url"])
542
543 vnfd_model_dict = {
544     'local_storages': [],
545     'vdus': [
546         {
547             'volumn_storages': [],
548             'nfv_compute': {
549                 'mem_size': '',
550                 'num_cpus': u'2'},
551             'local_storages': [],
552             'vdu_id': u'vdu_omm.001',
553             'image_file': u'opencos_sss_omm_img_release_20150723-1-disk1',
554             'dependencies': [],
555             'vls': [],
556             'cps': [],
557             'properties': {
558                 'key_vdu': '',
559                 'support_scaling': False,
560                 'vdu_type': '',
561                 'name': '',
562                 'storage_policy': '',
563                 'location_info': {
564                     'vimId': '',
565                     'availability_zone': '',
566                     'region': '',
567                     'dc': '',
568                     'host': '',
569                     'tenant': ''},
570                 'inject_data_list': [],
571                 'watchdog': {
572                     'action': '',
573                     'enabledelay': ''},
574                 'local_affinity_antiaffinity_rule': {},
575                 'template_id': u'omm.001',
576                 'manual_scale_select_vim': False},
577             'description': u'singleommvm'},
578         {
579             'volumn_storages': [],
580             'nfv_compute': {
581                 'mem_size': '',
582                 'num_cpus': u'4'},
583             'local_storages': [],
584             'vdu_id': u'vdu_1',
585             'image_file': u'sss',
586             'dependencies': [],
587             'vls': [],
588             'cps': [],
589             'properties': {
590                 'key_vdu': '',
591                 'support_scaling': False,
592                 'vdu_type': '',
593                 'name': '',
594                 'storage_policy': '',
595                 'location_info': {
596                     'vimId': '',
597                     'availability_zone': '',
598                     'region': '',
599                     'dc': '',
600                     'host': '',
601                     'tenant': ''},
602                 'inject_data_list': [],
603                 'watchdog': {
604                     'action': '',
605                     'enabledelay': ''},
606                 'local_affinity_antiaffinity_rule': {},
607                 'template_id': u'1',
608                 'manual_scale_select_vim': False},
609             'description': u'ompvm'},
610         {
611             'volumn_storages': [],
612             'nfv_compute': {
613                 'mem_size': '',
614                 'num_cpus': u'14'},
615             'local_storages': [],
616             'vdu_id': u'vdu_2',
617             'image_file': u'sss',
618             'dependencies': [],
619             'vls': [],
620             'cps': [],
621             'properties': {
622                 'key_vdu': '',
623                 'support_scaling': False,
624                 'vdu_type': '',
625                 'name': '',
626                 'storage_policy': '',
627                 'location_info': {
628                     'vimId': '',
629                     'availability_zone': '',
630                     'region': '',
631                     'dc': '',
632                     'host': '',
633                     'tenant': ''},
634                 'inject_data_list': [],
635                 'watchdog': {
636                     'action': '',
637                     'enabledelay': ''},
638                 'local_affinity_antiaffinity_rule': {},
639                 'template_id': u'2',
640                 'manual_scale_select_vim': False},
641             'description': u'ompvm'},
642         {
643             'volumn_storages': [],
644             'nfv_compute': {
645                 'mem_size': '',
646                 'num_cpus': u'14'},
647             'local_storages': [],
648             'vdu_id': u'vdu_3',
649             'image_file': u'sss',
650             'dependencies': [],
651             'vls': [],
652             'cps': [],
653             'properties': {
654                 'key_vdu': '',
655                 'support_scaling': False,
656                 'vdu_type': '',
657                 'name': '',
658                 'storage_policy': '',
659                 'location_info': {
660                     'vimId': '',
661                     'availability_zone': '',
662                     'region': '',
663                     'dc': '',
664                     'host': '',
665                     'tenant': ''},
666                 'inject_data_list': [],
667                 'watchdog': {
668                     'action': '',
669                     'enabledelay': ''},
670                 'local_affinity_antiaffinity_rule': {},
671                 'template_id': u'3',
672                 'manual_scale_select_vim': False},
673             'description': u'ompvm'},
674         {
675             'volumn_storages': [],
676             'nfv_compute': {
677                 'mem_size': '',
678                 'num_cpus': u'4'},
679             'local_storages': [],
680             'vdu_id': u'vdu_10',
681             'image_file': u'sss',
682             'dependencies': [],
683             'vls': [],
684             'cps': [],
685             'properties': {
686                 'key_vdu': '',
687                 'support_scaling': False,
688                 'vdu_type': '',
689                 'name': '',
690                 'storage_policy': '',
691                 'location_info': {
692                     'vimId': '',
693                     'availability_zone': '',
694                     'region': '',
695                     'dc': '',
696                     'host': '',
697                     'tenant': ''},
698                 'inject_data_list': [],
699                 'watchdog': {
700                     'action': '',
701                     'enabledelay': ''},
702                 'local_affinity_antiaffinity_rule': {},
703                 'template_id': u'10',
704                 'manual_scale_select_vim': False},
705             'description': u'ppvm'},
706         {
707             'volumn_storages': [],
708             'nfv_compute': {
709                 'mem_size': '',
710                 'num_cpus': u'14'},
711             'local_storages': [],
712             'vdu_id': u'vdu_11',
713             'image_file': u'sss',
714             'dependencies': [],
715             'vls': [],
716             'cps': [],
717             'properties': {
718                 'key_vdu': '',
719                 'support_scaling': False,
720                 'vdu_type': '',
721                 'name': '',
722                 'storage_policy': '',
723                 'location_info': {
724                     'vimId': '',
725                     'availability_zone': '',
726                     'region': '',
727                     'dc': '',
728                     'host': '',
729                     'tenant': ''},
730                 'inject_data_list': [],
731                 'watchdog': {
732                     'action': '',
733                     'enabledelay': ''},
734                 'local_affinity_antiaffinity_rule': {},
735                 'template_id': u'11',
736                 'manual_scale_select_vim': False},
737             'description': u'ppvm'},
738         {
739             'volumn_storages': [],
740             'nfv_compute': {
741                 'mem_size': '',
742                 'num_cpus': u'14'},
743             'local_storages': [],
744             'vdu_id': u'vdu_12',
745             'image_file': u'sss',
746             'dependencies': [],
747             'vls': [],
748             'cps': [],
749             'properties': {
750                 'key_vdu': '',
751                 'support_scaling': False,
752                 'vdu_type': '',
753                 'name': '',
754                 'storage_policy': '',
755                 'location_info': {
756                     'vimId': '',
757                     'availability_zone': '',
758                     'region': '',
759                     'dc': '',
760                     'host': '',
761                     'tenant': ''},
762                 'inject_data_list': [],
763                 'watchdog': {
764                     'action': '',
765                     'enabledelay': ''},
766                 'local_affinity_antiaffinity_rule': {},
767                 'template_id': u'12',
768                 'manual_scale_select_vim': False},
769             'description': u'ppvm'}],
770     'volumn_storages': [],
771     'policies': {
772         'scaling': {
773             'targets': {},
774             'policy_id': u'policy_scale_sss-vnf-template',
775             'properties': {
776                 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'},
777             'description': ''}},
778     'image_files': [
779         {
780             'description': '',
781             'properties': {
782                 'name': u'opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
783                 'checksum': '',
784                 'disk_format': u'VMDK',
785                 'file_url': u'./zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
786                 'container_type': 'vm',
787                 'version': '',
788                 'hypervisor_type': 'kvm'},
789             'image_file_id': u'opencos_sss_omm_img_release_20150723-1-disk1'},
790         {
791             'description': '',
792             'properties': {
793                 'name': u'sss.vmdk',
794                 'checksum': '',
795                 'disk_format': u'VMDK',
796                 'file_url': u'./zte-cn-sss-main-image/NE/sss.vmdk',
797                 'container_type': 'vm',
798                 'version': '',
799                 'hypervisor_type': 'kvm'},
800             'image_file_id': u'sss'}],
801     'vls': [],
802     'cps': [],
803     'metadata': {
804         'vendor': u'zte',
805         'is_shared': False,
806         'description': '',
807         'domain_type': u'CN',
808         'version': u'v4.14.10',
809         'vmnumber_overquota_alarm': False,
810         'cross_dc': False,
811         'vnf_type': u'SSS',
812         'vnfd_version': u'V00000001',
813         'id': u'sss-vnf-template',
814         'name': u'sss-vnf-template'}}
815
816 nsd_model_dict = {
817     "vnffgs": [],
818     "inputs": {
819         "externalDataNetworkName": {
820             "default": "",
821             "type": "string",
822             "description": ""}},
823     "pnfs": [],
824     "fps": [],
825     "server_groups": [],
826     "ns_flavours": [],
827     "vnfs": [
828         {
829             "dependency": [],
830             "properties": {
831                 "plugin_info": "vbrasplugin_1.0",
832                 "vendor": "zte",
833                 "is_shared": "False",
834                 "request_reclassification": "False",
835                 "vnfd_version": "1.0.0",
836                 "version": "1.0",
837                 "nsh_aware": "True",
838                 "cross_dc": "False",
839                 "externalDataNetworkName": {
840                     "get_input": "externalDataNetworkName"},
841                 "id": "zte_vbras",
842                 "name": "vbras"},
843             "vnf_id": "VBras",
844             "networks": [],
845             "description": ""}],
846     "ns_exposed": {
847         "external_cps": [],
848         "forward_cps": []},
849     "vls": [
850         {
851             "vl_id": "ext_mnet_network",
852             "description": "",
853             "properties": {
854                 "network_type": "vlan",
855                 "name": "externalMNetworkName",
856                 "dhcp_enabled": False,
857                 "location_info": {
858                     "host": True,
859                     "vimid": 2,
860                     "region": True,
861                     "tenant": "admin",
862                     "dc": ""},
863                 "end_ip": "190.168.100.100",
864                 "gateway_ip": "190.168.100.1",
865                 "start_ip": "190.168.100.2",
866                 "cidr": "190.168.100.0/24",
867                 "mtu": 1500,
868                 "network_name": "sub_mnet",
869                 "ip_version": 4}}],
870     "cps": [],
871     "policies": [],
872     "metadata": {
873         "invariant_id": "vbras_ns",
874         "description": "vbras_ns",
875         "version": 1,
876         "vendor": "zte",
877         "id": "vbras_ns",
878         "name": "vbras_ns"}}
879
880
881 vim_info_aai = {
882     "cloud-owner": "example-cloud-owner-val-1140",
883     "cloud-region-id": "example-cloud-region-id-val-73665",
884     "cloud-type": "example-cloud-type-val-14605",
885     "owner-defined-type": "example-owner-defined-type-val-84308",
886     "cloud-region-version": "example-cloud-region-version-val-67581",
887     "identity-url": "example-identity-url-val-98779",
888     "cloud-zone": "example-cloud-zone-val-67799",
889     "complex-name": "example-complex-name-val-62313",
890     "sriov-automation": True,
891     "cloud-extra-info": "example-cloud-extra-info-val-72366",
892     "cloud-epa-caps": "example-cloud-epa-caps-val-6090",
893     "volume-groups": {
894         "volume-group": [
895             {
896                 "volume-group-id": "example-volume-group-id-val-22419",
897                 "volume-group-name": "example-volume-group-name-val-41986",
898                 "heat-stack-id": "example-heat-stack-id-val-53241",
899                 "vnf-type": "example-vnf-type-val-19402",
900                 "orchestration-status": "example-orchestration-status-val-61478",
901                 "model-customization-id": "example-model-customization-id-val-82523",
902                 "vf-module-model-customization-id": "example-vf-module-model-customization-id-val-49214"
903             }
904         ]
905     },
906     "tenants": {
907         "tenant": [
908             {
909                 "tenant-id": "example-tenant-id-val-28032",
910                 "tenant-name": "example-tenant-name-val-65072",
911                 "tenant-context": "example-tenant-context-val-81984",
912                 "vservers": {
913                     "vserver": [
914                         {
915                             "vserver-id": "example-vserver-id-val-25067",
916                             "vserver-name": "example-vserver-name-val-16505",
917                             "vserver-name2": "example-vserver-name2-val-84664",
918                             "prov-status": "example-prov-status-val-1789",
919                             "vserver-selflink": "example-vserver-selflink-val-6858",
920                             "in-maint": True,
921                             "is-closed-loop-disabled": True,
922                             "volumes": {
923                                 "volume": [
924                                     {
925                                         "volume-id": "example-volume-id-val-69135",
926                                         "volume-selflink": "example-volume-selflink-val-96457"
927                                     }
928                                 ]
929                             },
930                             "l-interfaces": {
931                                 "l-interface": [
932                                     {
933                                         "interface-name": "example-interface-name-val-57532",
934                                         "interface-role": "example-interface-role-val-10218",
935                                         "v6-wan-link-ip": "example-v6-wan-link-ip-val-64941",
936                                         "selflink": "example-selflink-val-80427",
937                                         "interface-id": "example-interface-id-val-53136",
938                                         "macaddr": "example-macaddr-val-35417",
939                                         "network-name": "example-network-name-val-77107",
940                                         "management-option": "example-management-option-val-19752",
941                                         "interface-description": "example-interface-description-val-34461",
942                                         "is-port-mirrored": True,
943                                         "in-maint": True,
944                                         "prov-status": "example-prov-status-val-39824",
945                                         "is-ip-unnumbered": True,
946                                         "allowed-address-pairs": "example-allowed-address-pairs-val-76052",
947                                         "vlans": {
948                                             "vlan": [
949                                                 {
950                                                     "vlan-interface": "example-vlan-interface-val-81272",
951                                                     "vlan-id-inner": 70939085,
952                                                     "vlan-id-outer": 80445097,
953                                                     "speed-value": "example-speed-value-val-47939",
954                                                     "speed-units": "example-speed-units-val-90989",
955                                                     "vlan-description": "example-vlan-description-val-96792",
956                                                     "backdoor-connection": "example-backdoor-connection-val-74707",
957                                                     "vpn-key": "example-vpn-key-val-73677",
958                                                     "orchestration-status": "example-orchestration-status-val-93544",
959                                                     "in-maint": True,
960                                                     "prov-status": "example-prov-status-val-18854",
961                                                     "is-ip-unnumbered": True,
962                                                     "l3-interface-ipv4-address-list": [
963                                                         {
964                                                             "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-46993",
965                                                             "l3-interface-ipv4-prefix-length": 28216731,
966                                                             "vlan-id-inner": 8589169,
967                                                             "vlan-id-outer": 22167953,
968                                                             "is-floating": True,
969                                                             "neutron-network-id": "example-neutron-network-id-val-45028",
970                                                             "neutron-subnet-id": "example-neutron-subnet-id-val-99844"
971                                                         }
972                                                     ],
973                                                     "l3-interface-ipv6-address-list": [
974                                                         {
975                                                             "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-8414",
976                                                             "l3-interface-ipv6-prefix-length": 6761190,
977                                                             "vlan-id-inner": 88349266,
978                                                             "vlan-id-outer": 87459050,
979                                                             "is-floating": True,
980                                                             "neutron-network-id": "example-neutron-network-id-val-23050",
981                                                             "neutron-subnet-id": "example-neutron-subnet-id-val-49448"
982                                                         }
983                                                     ]
984                                                 }
985                                             ]
986                                         },
987                                         "sriov-vfs": {
988                                             "sriov-vf": [
989                                                 {
990                                                     "pci-id": "example-pci-id-val-9702",
991                                                     "vf-vlan-filter": "example-vf-vlan-filter-val-94893",
992                                                     "vf-mac-filter": "example-vf-mac-filter-val-40257",
993                                                     "vf-vlan-strip": True,
994                                                     "vf-vlan-anti-spoof-check": True,
995                                                     "vf-mac-anti-spoof-check": True,
996                                                     "vf-mirrors": "example-vf-mirrors-val-86932",
997                                                     "vf-broadcast-allow": True,
998                                                     "vf-unknown-multicast-allow": True,
999                                                     "vf-unknown-unicast-allow": True,
1000                                                     "vf-insert-stag": True,
1001                                                     "vf-link-status": "example-vf-link-status-val-94678",
1002                                                     "neutron-network-id": "example-neutron-network-id-val-18823"
1003                                                 }
1004                                             ]
1005                                         },
1006                                         "l-interfaces": {
1007                                             "l-interface": [
1008                                                 {
1009                                                     "interface-name": "example-interface-name-val-42153",
1010                                                     "interface-role": "example-interface-role-val-38539",
1011                                                     "v6-wan-link-ip": "example-v6-wan-link-ip-val-12452",
1012                                                     "selflink": "example-selflink-val-38250",
1013                                                     "interface-id": "example-interface-id-val-68366",
1014                                                     "macaddr": "example-macaddr-val-76392",
1015                                                     "network-name": "example-network-name-val-58136",
1016                                                     "management-option": "example-management-option-val-88555",
1017                                                     "interface-description": "example-interface-description-val-66875",
1018                                                     "is-port-mirrored": True,
1019                                                     "in-maint": True,
1020                                                     "prov-status": "example-prov-status-val-9493",
1021                                                     "is-ip-unnumbered": True,
1022                                                     "allowed-address-pairs": "example-allowed-address-pairs-val-80407"
1023                                                 }
1024                                             ]
1025                                         },
1026                                         "l3-interface-ipv4-address-list": [
1027                                             {
1028                                                 "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-57596",
1029                                                 "l3-interface-ipv4-prefix-length": 90030728,
1030                                                 "vlan-id-inner": 43361064,
1031                                                 "vlan-id-outer": 18962103,
1032                                                 "is-floating": True,
1033                                                 "neutron-network-id": "example-neutron-network-id-val-55667",
1034                                                 "neutron-subnet-id": "example-neutron-subnet-id-val-46585"
1035                                             }
1036                                         ],
1037                                         "l3-interface-ipv6-address-list": [
1038                                             {
1039                                                 "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-74591",
1040                                                 "l3-interface-ipv6-prefix-length": 38739444,
1041                                                 "vlan-id-inner": 65048885,
1042                                                 "vlan-id-outer": 94802338,
1043                                                 "is-floating": True,
1044                                                 "neutron-network-id": "example-neutron-network-id-val-64105",
1045                                                 "neutron-subnet-id": "example-neutron-subnet-id-val-65190"
1046                                             }
1047                                         ]
1048                                     }
1049                                 ]
1050                             }
1051                         }
1052                     ]
1053                 }
1054             }
1055         ]
1056     },
1057     "flavors": {
1058         "flavor": [
1059             {
1060                 "flavor-id": "example-flavor-id-val-92555",
1061                 "flavor-name": "example-flavor-name-val-35938",
1062                 "flavor-vcpus": 88056,
1063                 "flavor-ram": 18804,
1064                 "flavor-disk": 2575,
1065                 "flavor-ephemeral": 28190,
1066                 "flavor-swap": "example-flavor-swap-val-76888",
1067                 "flavor-is-public": True,
1068                 "flavor-selflink": "example-flavor-selflink-val-33816",
1069                 "flavor-disabled": True
1070             }
1071         ]
1072     },
1073     "group-assignments": {
1074         "group-assignment": [
1075             {
1076                 "group-id": "example-group-id-val-6872",
1077                 "group-type": "example-group-type-val-64490",
1078                 "group-name": "example-group-name-val-67702",
1079                 "group-description": "example-group-description-val-99149"
1080             }
1081         ]
1082     },
1083     "snapshots": {
1084         "snapshot": [
1085             {
1086                 "snapshot-id": "example-snapshot-id-val-32009",
1087                 "snapshot-name": "example-snapshot-name-val-47165",
1088                 "snapshot-architecture": "example-snapshot-architecture-val-84769",
1089                 "snapshot-os-distro": "example-snapshot-os-distro-val-70763",
1090                 "snapshot-os-version": "example-snapshot-os-version-val-4220",
1091                 "application": "example-application-val-12453",
1092                 "application-vendor": "example-application-vendor-val-95617",
1093                 "application-version": "example-application-version-val-77699",
1094                 "snapshot-selflink": "example-snapshot-selflink-val-90202",
1095                 "prev-snapshot-id": "example-prev-snapshot-id-val-10951"
1096             }
1097         ]
1098     },
1099     "images": {
1100         "image": [
1101             {
1102                 "image-id": "example-image-id-val-17245",
1103                 "image-name": "example-image-name-val-93251",
1104                 "image-architecture": "example-image-architecture-val-21934",
1105                 "image-os-distro": "example-image-os-distro-val-51699",
1106                 "image-os-version": "example-image-os-version-val-92745",
1107                 "application": "example-application-val-47760",
1108                 "application-vendor": "example-application-vendor-val-67650",
1109                 "application-version": "example-application-version-val-4499",
1110                 "image-selflink": "example-image-selflink-val-70348",
1111                 "metadata": {
1112                     "metadatum": [
1113                         {
1114                             "metaname": "example-metaname-val-57218",
1115                             "metaval": "example-metaval-val-39269"
1116                         }
1117                     ]
1118                 }
1119             }
1120         ]
1121     },
1122     "dvs-switches": {
1123         "dvs-switch": [
1124             {
1125                 "switch-name": "example-switch-name-val-31508",
1126                 "vcenter-url": "example-vcenter-url-val-57139"
1127             }
1128         ]
1129     },
1130     "oam-networks": {
1131         "oam-network": [
1132             {
1133                 "network-uuid": "example-network-uuid-val-93435",
1134                 "network-name": "example-network-name-val-66722",
1135                 "cvlan-tag": 54019733,
1136                 "ipv4-oam-gateway-address": "example-ipv4-oam-gateway-address-val-3261",
1137                 "ipv4-oam-gateway-address-prefix-length": 53725
1138             }
1139         ]
1140     },
1141     "availability-zones": {
1142         "availability-zone": [
1143             {
1144                 "availability-zone-name": "example-availability-zone-name-val-71842",
1145                 "hypervisor-type": "example-hypervisor-type-val-21339",
1146                 "operational-status": "example-operational-status-val-18872"
1147             }
1148         ]
1149     },
1150     "esr-system-info-list": {
1151         "esr-system-info": [
1152             {
1153                 "esr-system-info-id": "example-esr-system-info-id-val-42986",
1154                 "system-name": "example-system-name-val-1117",
1155                 "type": "example-type-val-28567",
1156                 "vendor": "example-vendor-val-99666",
1157                 "version": "example-version-val-9880",
1158                 "service-url": "example-service-url-val-95838",
1159                 "user-name": "example-user-name-val-88013",
1160                 "password": "example-password-val-51483",
1161                 "system-type": "example-system-type-val-24554",
1162                 "protocal": "example-protocal-val-92250",
1163                 "ssl-cacert": "example-ssl-cacert-val-80275",
1164                 "ssl-insecure": True,
1165                 "ip-address": "example-ip-address-val-49558",
1166                 "port": "example-port-val-55636",
1167                 "cloud-domain": "example-cloud-domain-val-77975",
1168                 "default-tenant": "example-default-tenant-val-85499"
1169             }
1170         ]
1171     }
1172 }