Update python2 to python3
[vfc/nfvo/lcm.git] / lcm / ns_sfcs / tests / test_sfc.py
1 # Copyright 2018 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
15 import json
16 import mock
17 from django.test import Client
18 from django.test import TestCase
19 from rest_framework import status
20
21 from lcm.pub.database.models import FPInstModel, CPInstModel, PortInstModel, NfInstModel
22 from lcm.pub.database.models import VNFFGInstModel
23 from lcm.pub.msapi import extsys
24 from lcm.pub.msapi import sdncdriver
25 from lcm.pub.utils import restcall
26
27
28 class TestSfc(TestCase):
29     def setUp(self):
30         self.client = Client()
31         FPInstModel.objects.filter().delete()
32         VNFFGInstModel.objects.filter().delete()
33         CPInstModel.objects.filter().delete()
34         PortInstModel.objects.filter().delete()
35         NfInstModel.objects.filter().delete()
36
37         self.save_vnffg_inst_data()
38         self.save_vnf_inst_data()
39         self.save_cp_inst_data()
40         self.save_port_inst_data()
41         self.save_fp_inst_data()
42
43     def tearDown(self):
44         pass
45
46     @mock.patch.object(restcall, 'call_req')
47     def test_sfc_instanciate(self, mock_call_req):
48         pass
49         # data = {
50         #     "nsInstanceId": "ns_inst_1",
51         #     "context": nsd_model,
52         #     "fpindex": "fpd_1",
53         #     "sdnControllerId": "sdnControllerId_1"
54         # }
55         # resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", data, format='json')
56         # self.assertEqual(resp.status_code, status.HTTP_200_OK, resp.data)
57
58     @mock.patch.object(extsys, "get_sdn_controller_by_id")
59     @mock.patch.object(sdncdriver, "create_flow_classfier")
60     @mock.patch.object(restcall, 'call_req')
61     def test_create_flow_classfier(self, mock_call_req, mock_create_flow_classfier, mock_get_sdn_controller_by_id):
62         data = {
63             "fpinstid": "fp_inst_1",
64             "context": json.dumps(nsd_model)
65         }
66         mock_create_flow_classfier.return_value = [0, json.dumps({'id': '1'})]
67         mock_get_sdn_controller_by_id.return_value = json.loads('{"test":"test_name","url":"url_add"}')
68         resp = self.client.post("/api/nslcm/v1/ns/create_flow_classifier", data)
69         self.assertEqual(resp.status_code, status.HTTP_200_OK)
70
71     @mock.patch.object(extsys, "get_sdn_controller_by_id")
72     @mock.patch.object(sdncdriver, 'create_port_pair_group')
73     @mock.patch.object(sdncdriver, 'create_port_pair')
74     @mock.patch.object(restcall, 'call_req')
75     def test_create_port_pair_group(self, mock_call_req, mock_create_port_pair,
76                                     mock_create_port_pair_group, mock_get_sdn_controller_by_id):
77         data = {
78             "nsinstanceid": "ns_inst_1",
79             "fpinstid": "fp_inst_1",
80             "context": json.dumps(nsd_model)
81         }
82         mock_create_port_pair.return_value = [0, json.dumps({'id': '1'})]
83         mock_create_port_pair_group.return_value = [0, json.dumps({'id': '1'})]
84         mock_get_sdn_controller_by_id.return_value = json.loads('{"test":"test_name","url":"url_add"}')
85         resp = self.client.post("/api/nslcm/v1/ns/create_port_pair_group", data)
86         self.assertEqual(resp.status_code, status.HTTP_200_OK)
87
88     @mock.patch.object(extsys, "get_sdn_controller_by_id")
89     @mock.patch.object(sdncdriver, 'create_port_chain')
90     @mock.patch.object(restcall, 'call_req')
91     def test_create_port_chain(self, mock_call_req, mock_create_port_chain, mock_get_sdn_controller_by_id):
92         data = {
93             "nsinstanceid": "ns_inst_1",
94             "fpinstid": "fp_inst_1",
95             "context": json.dumps(nsd_model)
96         }
97         self.update_fp_inst_data()
98         mock_create_port_chain.return_value = [0, json.dumps({'id': '1'})]
99         mock_get_sdn_controller_by_id.return_value = json.loads('{"test":"test_name","url":"url_add"}')
100         resp = self.client.post("/api/nslcm/v1/ns/create_port_chain", data)
101         self.assertEqual(resp.status_code, status.HTTP_200_OK)
102
103     @mock.patch.object(restcall, 'call_req')
104     def test_create_sfc(self, mock_call_req):
105         pass
106         # data = {
107         #     "nsInstanceId": "ns_inst_1",
108         #     "context": json.dumps(nsd_model),
109         #     "fpindex": "1",
110         #     'fpinstid': str(uuid.uuid4()),
111         #     "sdnControllerId": "sdnControllerId_1"
112         # }
113         # resp = self.client.post("/api/nslcm/v1/ns/ns_sfcs", data, format='json')
114         # self.assertEqual(resp.status_code, status.HTTP_200_OK, resp.data)
115
116     def update_fp_inst_data(self):
117         FPInstModel.objects.filter(fpinstid="fp_inst_1").update(flowclassifiers="1",
118                                                                 portpairgroups=json.JSONEncoder().encode([{
119                                                                     "groupid": "1",
120                                                                     "portpair": ["2"]
121                                                                 }]))
122
123     def save_vnffg_inst_data(self):
124         VNFFGInstModel(
125             vnffgdid="vnffg_id1",
126             vnffginstid="vnffg_inst_1",
127             nsinstid="ns_inst_1",
128             endpointnumber=2,
129             vllist="vlinst1",
130             cplist="cp1",
131             vnflist="vnf1,vnf2"
132         ).save()
133
134     def save_cp_inst_data(self):
135         CPInstModel(
136             cpinstanceid="cp_inst_1",
137             cpdid="cpd_1",
138             ownertype=0,
139             ownerid="vnf_inst_1",
140             relatedtype=1,
141             relatedport="port_inst_1"
142         ).save()
143
144         CPInstModel(
145             cpinstanceid="cp_inst_2",
146             cpdid="cpd_2",
147             ownertype=0,
148             ownerid="vnf_inst_2",
149             relatedtype=1,
150             relatedport="port_inst_2"
151         ).save()
152
153     def save_fp_inst_data(self):
154         FPInstModel(
155             fpid="fpd_1",
156             fpinstid="fp_inst_1",
157             nsinstid="ns_inst_1",
158             vnffginstid="vnffg_inst_1",
159             policyinfo=[{
160                 "type": "ACL",
161                 "criteria": {
162                     "dest_port_range": [80, 1024],
163                     "source_port_range": [80, 1024],
164                     "ip_protocol": "tcp",
165                     "dest_ip_range": ["192.168.1.2", "192.168.1.100"],
166                     "source_ip_range": ["192.168.1.2", "192.168.1.100"],
167                     "dscp": 100,
168                 }
169             }],
170             status="enabled",
171             sdncontrollerid="sdn_controller_1"
172
173         ).save()
174
175         FPInstModel(
176             fpid="fpd_2",
177             fpinstid="fp_inst_2",
178             nsinstid="ns_inst_1",
179             vnffginstid="vnffg_inst_1",
180             policyinfo=[{
181                 "type": "ACL",
182                 "criteria": {
183                     "dest_port_range": [80, 1024],
184                     "source_port_range": [80, 1024],
185                     "ip_protocol": "tcp",
186                     "dest_ip_range": ["192.168.1.2", "192.168.1.100"],
187                     "source_ip_range": ["192.168.1.2", "192.168.1.100"],
188                     "dscp": 100,
189                 }
190             }],
191             status="enabled",
192             sdncontrollerid="sdn_controller_1"
193         ).save()
194
195     def save_sdnc_inst_data(self):
196         pass
197         # SDNCModel(
198         #     uuid="uuid_111",
199         #     sdncontrollerid="sdn_controller_1",
200         #     name="111",
201         #     type="vnf",
202         #     url="192.168.0.1:8080",
203         #     username="admin",
204         #     pwd="admin",
205         #     ver="ver",
206         #     longitude="longitude",
207         #     latitude="latitude"
208         # ).save()
209
210     def save_port_inst_data(self):
211         PortInstModel(
212             portid="port_inst_1",
213             networkid="network_inst_1",
214             subnetworkid="subnetwork_inst_1",
215             vimid="vim_1",
216             resourceid="res_1",
217             ipaddress="10.43.25.2",
218             macaddress="EC-F4-BB-20-43-F1"
219         ).save()
220
221         PortInstModel(
222             portid="port_inst_2",
223             networkid="network_inst_1",
224             subnetworkid="subnetwork_inst_1",
225             vimid="vim_1",
226             resourceid="res_1",
227             ipaddress="10.43.25.3",
228             macaddress="EC-F4-BB-20-43-F2"
229         ).save()
230
231     def save_vnf_inst_data(self):
232         NfInstModel(
233             nfinstid="vnf_inst_1",
234             ns_inst_id="ns_inst_1",
235             vnf_id="vnf_1",
236             vnfd_model=json.dumps(vnfd_model_dict1)
237
238         ).save()
239
240         NfInstModel(
241             nfinstid="vnf_inst_2",
242             vnf_id="vnf_2",
243             ns_inst_id="ns_inst_1",
244             vnfd_model=json.dumps(vnfd_model_dict2)
245
246         ).save()
247
248
249 vnfd_model_dict1 = {
250     'vdus': [
251         {
252             'volumn_storages': [
253
254             ],
255             'nfv_compute': {
256                 'mem_size': '',
257                 'num_cpus': '2'
258             },
259             'local_storages': [
260
261             ],
262             'vdu_id': 'vdu_omm.001',
263             'image_file': 'opencos_sss_omm_img_release_20150723-1-disk1',
264             'dependencies': [
265
266             ],
267             'vls': [
268
269             ],
270             'cps': [
271
272             ],
273             'properties': {
274                 'key_vdu': '',
275                 'support_scaling': False,
276                 'vdu_type': '',
277                 'name': '',
278                 'storage_policy': '',
279                 'location_info': {
280                     'vimId': '',
281                     'availability_zone': '',
282                     'region': '',
283                     'dc': '',
284                     'host': '',
285                     'tenant': ''
286                 },
287                 'inject_data_list': [
288
289                 ],
290                 'watchdog': {
291                     'action': '',
292                     'enabledelay': ''
293                 },
294                 'local_affinity_antiaffinity_rule': {
295
296                 },
297                 'template_id': 'omm.001',
298                 'manual_scale_select_vim': False
299             },
300             'description': 'singleommvm'
301         },
302         {
303             'volumn_storages': [
304
305             ],
306             'nfv_compute': {
307                 'mem_size': '',
308                 'num_cpus': '4'
309             },
310             'local_storages': [
311
312             ],
313             'vdu_id': 'vdu_1',
314             'image_file': 'sss',
315             'dependencies': [
316
317             ],
318             'vls': [
319
320             ],
321             'cps': [
322
323             ],
324             'properties': {
325                 'key_vdu': '',
326                 'support_scaling': False,
327                 'vdu_type': '',
328                 'name': '',
329                 'storage_policy': '',
330                 'location_info': {
331                     'vimId': '',
332                     'availability_zone': '',
333                     'region': '',
334                     'dc': '',
335                     'host': '',
336                     'tenant': ''
337                 },
338                 'inject_data_list': [
339
340                 ],
341                 'watchdog': {
342                     'action': '',
343                     'enabledelay': ''
344                 },
345                 'local_affinity_antiaffinity_rule': {
346
347                 },
348                 'template_id': '1',
349                 'manual_scale_select_vim': False
350             },
351             'description': 'ompvm'
352         },
353         {
354             'volumn_storages': [
355
356             ],
357             'nfv_compute': {
358                 'mem_size': '',
359                 'num_cpus': '14'
360             },
361             'local_storages': [
362
363             ],
364             'vdu_id': 'vdu_2',
365             'image_file': 'sss',
366             'dependencies': [
367
368             ],
369             'vls': [
370
371             ],
372             'cps': [
373
374             ],
375             'properties': {
376                 'key_vdu': '',
377                 'support_scaling': False,
378                 'vdu_type': '',
379                 'name': '',
380                 'storage_policy': '',
381                 'location_info': {
382                     'vimId': '',
383                     'availability_zone': '',
384                     'region': '',
385                     'dc': '',
386                     'host': '',
387                     'tenant': ''
388                 },
389                 'inject_data_list': [
390
391                 ],
392                 'watchdog': {
393                     'action': '',
394                     'enabledelay': ''
395                 },
396                 'local_affinity_antiaffinity_rule': {
397
398                 },
399                 'template_id': '2',
400                 'manual_scale_select_vim': False
401             },
402             'description': 'ompvm'
403         },
404         {
405             'volumn_storages': [
406
407             ],
408             'nfv_compute': {
409                 'mem_size': '',
410                 'num_cpus': '14'
411             },
412             'local_storages': [
413
414             ],
415             'vdu_id': 'vdu_3',
416             'image_file': 'sss',
417             'dependencies': [
418
419             ],
420             'vls': [
421
422             ],
423             'cps': [
424
425             ],
426             'properties': {
427                 'key_vdu': '',
428                 'support_scaling': False,
429                 'vdu_type': '',
430                 'name': '',
431                 'storage_policy': '',
432                 'location_info': {
433                     'vimId': '',
434                     'availability_zone': '',
435                     'region': '',
436                     'dc': '',
437                     'host': '',
438                     'tenant': ''
439                 },
440                 'inject_data_list': [
441
442                 ],
443                 'watchdog': {
444                     'action': '',
445                     'enabledelay': ''
446                 },
447                 'local_affinity_antiaffinity_rule': {
448
449                 },
450                 'template_id': '3',
451                 'manual_scale_select_vim': False
452             },
453             'description': 'ompvm'
454         },
455         {
456             'volumn_storages': [
457
458             ],
459             'nfv_compute': {
460                 'mem_size': '',
461                 'num_cpus': '4'
462             },
463             'local_storages': [
464
465             ],
466             'vdu_id': 'vdu_10',
467             'image_file': 'sss',
468             'dependencies': [
469
470             ],
471             'vls': [
472
473             ],
474             'cps': [
475
476             ],
477             'properties': {
478                 'key_vdu': '',
479                 'support_scaling': False,
480                 'vdu_type': '',
481                 'name': '',
482                 'storage_policy': '',
483                 'location_info': {
484                     'vimId': '',
485                     'availability_zone': '',
486                     'region': '',
487                     'dc': '',
488                     'host': '',
489                     'tenant': ''
490                 },
491                 'inject_data_list': [
492
493                 ],
494                 'watchdog': {
495                     'action': '',
496                     'enabledelay': ''
497                 },
498                 'local_affinity_antiaffinity_rule': {
499
500                 },
501                 'template_id': '10',
502                 'manual_scale_select_vim': False
503             },
504             'description': 'ppvm'
505         },
506         {
507             'volumn_storages': [
508
509             ],
510             'nfv_compute': {
511                 'mem_size': '',
512                 'num_cpus': '14'
513             },
514             'local_storages': [
515
516             ],
517             'vdu_id': 'vdu_11',
518             'image_file': 'sss',
519             'dependencies': [
520
521             ],
522             'vls': [
523
524             ],
525             'cps': [
526
527             ],
528             'properties': {
529                 'key_vdu': '',
530                 'support_scaling': False,
531                 'vdu_type': '',
532                 'name': '',
533                 'storage_policy': '',
534                 'location_info': {
535                     'vimId': '',
536                     'availability_zone': '',
537                     'region': '',
538                     'dc': '',
539                     'host': '',
540                     'tenant': ''
541                 },
542                 'inject_data_list': [
543
544                 ],
545                 'watchdog': {
546                     'action': '',
547                     'enabledelay': ''
548                 },
549                 'local_affinity_antiaffinity_rule': {
550
551                 },
552                 'template_id': '11',
553                 'manual_scale_select_vim': False
554             },
555             'description': 'ppvm'
556         },
557         {
558             'volumn_storages': [
559
560             ],
561             'nfv_compute': {
562                 'mem_size': '',
563                 'num_cpus': '14'
564             },
565             'local_storages': [
566
567             ],
568             'vdu_id': 'vdu_12',
569             'image_file': 'sss',
570             'dependencies': [
571
572             ],
573             'vls': [
574
575             ],
576             'cps': [
577
578             ],
579             'properties': {
580                 'key_vdu': '',
581                 'support_scaling': False,
582                 'vdu_type': '',
583                 'name': '',
584                 'storage_policy': '',
585                 'location_info': {
586                     'vimId': '',
587                     'availability_zone': '',
588                     'region': '',
589                     'dc': '',
590                     'host': '',
591                     'tenant': ''
592                 },
593                 'inject_data_list': [
594
595                 ],
596                 'watchdog': {
597                     'action': '',
598                     'enabledelay': ''
599                 },
600                 'local_affinity_antiaffinity_rule': {
601
602                 },
603                 'template_id': '12',
604                 'manual_scale_select_vim': False
605             },
606             'description': 'ppvm'
607         }
608     ],
609     'volumn_storages': [
610
611     ],
612     'policies': {
613         'scaling': {
614             'targets': {
615
616             },
617             'policy_id': 'policy_scale_sss-vnf-template',
618             'properties': {
619                 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'
620             },
621             'description': ''
622         }
623     },
624     'image_files': [
625         {
626             'description': '',
627             'properties': {
628                 'name': 'opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
629                 'checksum': '',
630                 'disk_format': 'VMDK',
631                 'file_url': './zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
632                 'container_type': 'vm',
633                 'version': '',
634                 'hypervisor_type': 'kvm'
635             },
636             'image_file_id': 'opencos_sss_omm_img_release_20150723-1-disk1'
637         },
638         {
639             'description': '',
640             'properties': {
641                 'name': 'sss.vmdk',
642                 'checksum': '',
643                 'disk_format': 'VMDK',
644                 'file_url': './zte-cn-sss-main-image/NE/sss.vmdk',
645                 'container_type': 'vm',
646                 'version': '',
647                 'hypervisor_type': 'kvm'
648             },
649             'image_file_id': 'sss'
650         }
651     ],
652     'vls': [
653
654     ],
655     'cps': [
656         {'cp_id': 'cpd_1',
657          "description": "",
658          "properties": {
659              "mac_address": "00:d9:00:82:11:e1",
660              "ip_address": "10.43.25.2",
661              "ip_range_start": "192.168.1.20",
662              "ip_range_end": "192.168.1.29",
663              "sfc_encapsulation": ""
664          }
665          },
666     ],
667     'metadata': {
668         'vendor': 'zte',
669         'is_shared': False,
670         'description': '',
671         'domain_type': 'CN',
672         'version': 'v4.14.10',
673         'vmnumber_overquota_alarm': False,
674         'cross_dc': False,
675         'vnf_type': 'SSS',
676         'vnfd_version': 'V00000001',
677         'id': 'vnfd_2',
678         'name': 'sss-vnf-template'
679     },
680
681     'vnf_exposed': {
682         "external_cps": [
683             {
684                 "key_name": "virtualLink1",
685                 "cp_id": "cp1",
686             },
687         ],
688         "forward_cps": [
689             {
690                 "key_name": "forwarder1",
691                 "cp_id": "cpd_1",
692             },
693             {
694                 "key_name": "forwarder2",
695                 "cp_id": "cpd_2",
696             },
697         ],
698     }
699 }
700
701 vnfd_model_dict2 = {
702     'local_storages': [
703
704     ],
705     'vdus': [
706         {
707             'volumn_storages': [
708
709             ],
710             'nfv_compute': {
711                 'mem_size': '',
712                 'num_cpus': '2'
713             },
714             'local_storages': [
715
716             ],
717             'vdu_id': 'vdu_omm.001',
718             'image_file': 'opencos_sss_omm_img_release_20150723-1-disk1',
719             'dependencies': [
720
721             ],
722             'vls': [
723
724             ],
725             'cps': [
726
727             ],
728             'properties': {
729                 'key_vdu': '',
730                 'support_scaling': False,
731                 'vdu_type': '',
732                 'name': '',
733                 'storage_policy': '',
734                 'location_info': {
735                     'vimId': '',
736                     'availability_zone': '',
737                     'region': '',
738                     'dc': '',
739                     'host': '',
740                     'tenant': ''
741                 },
742                 'inject_data_list': [
743
744                 ],
745                 'watchdog': {
746                     'action': '',
747                     'enabledelay': ''
748                 },
749                 'local_affinity_antiaffinity_rule': {
750
751                 },
752                 'template_id': 'omm.001',
753                 'manual_scale_select_vim': False
754             },
755             'description': 'singleommvm'
756         },
757         {
758             'volumn_storages': [
759
760             ],
761             'nfv_compute': {
762                 'mem_size': '',
763                 'num_cpus': '4'
764             },
765             'local_storages': [
766
767             ],
768             'vdu_id': 'vdu_1',
769             'image_file': 'sss',
770             'dependencies': [
771
772             ],
773             'vls': [
774
775             ],
776             'cps': [
777
778             ],
779             'properties': {
780                 'key_vdu': '',
781                 'support_scaling': False,
782                 'vdu_type': '',
783                 'name': '',
784                 'storage_policy': '',
785                 'location_info': {
786                     'vimId': '',
787                     'availability_zone': '',
788                     'region': '',
789                     'dc': '',
790                     'host': '',
791                     'tenant': ''
792                 },
793                 'inject_data_list': [
794
795                 ],
796                 'watchdog': {
797                     'action': '',
798                     'enabledelay': ''
799                 },
800                 'local_affinity_antiaffinity_rule': {
801
802                 },
803                 'template_id': '1',
804                 'manual_scale_select_vim': False
805             },
806             'description': 'ompvm'
807         },
808         {
809             'volumn_storages': [
810
811             ],
812             'nfv_compute': {
813                 'mem_size': '',
814                 'num_cpus': '14'
815             },
816             'local_storages': [
817
818             ],
819             'vdu_id': 'vdu_2',
820             'image_file': 'sss',
821             'dependencies': [
822
823             ],
824             'vls': [
825
826             ],
827             'cps': [
828
829             ],
830             'properties': {
831                 'key_vdu': '',
832                 'support_scaling': False,
833                 'vdu_type': '',
834                 'name': '',
835                 'storage_policy': '',
836                 'location_info': {
837                     'vimId': '',
838                     'availability_zone': '',
839                     'region': '',
840                     'dc': '',
841                     'host': '',
842                     'tenant': ''
843                 },
844                 'inject_data_list': [
845
846                 ],
847                 'watchdog': {
848                     'action': '',
849                     'enabledelay': ''
850                 },
851                 'local_affinity_antiaffinity_rule': {
852
853                 },
854                 'template_id': '2',
855                 'manual_scale_select_vim': False
856             },
857             'description': 'ompvm'
858         },
859         {
860             'volumn_storages': [
861
862             ],
863             'nfv_compute': {
864                 'mem_size': '',
865                 'num_cpus': '14'
866             },
867             'local_storages': [
868
869             ],
870             'vdu_id': 'vdu_3',
871             'image_file': 'sss',
872             'dependencies': [
873
874             ],
875             'vls': [
876
877             ],
878             'cps': [
879
880             ],
881             'properties': {
882                 'key_vdu': '',
883                 'support_scaling': False,
884                 'vdu_type': '',
885                 'name': '',
886                 'storage_policy': '',
887                 'location_info': {
888                     'vimId': '',
889                     'availability_zone': '',
890                     'region': '',
891                     'dc': '',
892                     'host': '',
893                     'tenant': ''
894                 },
895                 'inject_data_list': [
896
897                 ],
898                 'watchdog': {
899                     'action': '',
900                     'enabledelay': ''
901                 },
902                 'local_affinity_antiaffinity_rule': {
903
904                 },
905                 'template_id': '3',
906                 'manual_scale_select_vim': False
907             },
908             'description': 'ompvm'
909         },
910         {
911             'volumn_storages': [
912
913             ],
914             'nfv_compute': {
915                 'mem_size': '',
916                 'num_cpus': '4'
917             },
918             'local_storages': [
919
920             ],
921             'vdu_id': 'vdu_10',
922             'image_file': 'sss',
923             'dependencies': [
924
925             ],
926             'vls': [
927
928             ],
929             'cps': [
930
931             ],
932             'properties': {
933                 'key_vdu': '',
934                 'support_scaling': False,
935                 'vdu_type': '',
936                 'name': '',
937                 'storage_policy': '',
938                 'location_info': {
939                     'vimId': '',
940                     'availability_zone': '',
941                     'region': '',
942                     'dc': '',
943                     'host': '',
944                     'tenant': ''
945                 },
946                 'inject_data_list': [
947
948                 ],
949                 'watchdog': {
950                     'action': '',
951                     'enabledelay': ''
952                 },
953                 'local_affinity_antiaffinity_rule': {
954
955                 },
956                 'template_id': '10',
957                 'manual_scale_select_vim': False
958             },
959             'description': 'ppvm'
960         },
961         {
962             'volumn_storages': [
963
964             ],
965             'nfv_compute': {
966                 'mem_size': '',
967                 'num_cpus': '14'
968             },
969             'local_storages': [
970
971             ],
972             'vdu_id': 'vdu_11',
973             'image_file': 'sss',
974             'dependencies': [
975
976             ],
977             'vls': [
978
979             ],
980             'cps': [
981
982             ],
983             'properties': {
984                 'key_vdu': '',
985                 'support_scaling': False,
986                 'vdu_type': '',
987                 'name': '',
988                 'storage_policy': '',
989                 'location_info': {
990                     'vimId': '',
991                     'availability_zone': '',
992                     'region': '',
993                     'dc': '',
994                     'host': '',
995                     'tenant': ''
996                 },
997                 'inject_data_list': [
998
999                 ],
1000                 'watchdog': {
1001                     'action': '',
1002                     'enabledelay': ''
1003                 },
1004                 'local_affinity_antiaffinity_rule': {
1005
1006                 },
1007                 'template_id': '11',
1008                 'manual_scale_select_vim': False
1009             },
1010             'description': 'ppvm'
1011         },
1012         {
1013             'volumn_storages': [
1014
1015             ],
1016             'nfv_compute': {
1017                 'mem_size': '',
1018                 'num_cpus': '14'
1019             },
1020             'local_storages': [
1021
1022             ],
1023             'vdu_id': 'vdu_12',
1024             'image_file': 'sss',
1025             'dependencies': [
1026
1027             ],
1028             'vls': [
1029
1030             ],
1031             'cps': [
1032
1033             ],
1034             'properties': {
1035                 'key_vdu': '',
1036                 'support_scaling': False,
1037                 'vdu_type': '',
1038                 'name': '',
1039                 'storage_policy': '',
1040                 'location_info': {
1041                     'vimId': '',
1042                     'availability_zone': '',
1043                     'region': '',
1044                     'dc': '',
1045                     'host': '',
1046                     'tenant': ''
1047                 },
1048                 'inject_data_list': [
1049
1050                 ],
1051                 'watchdog': {
1052                     'action': '',
1053                     'enabledelay': ''
1054                 },
1055                 'local_affinity_antiaffinity_rule': {
1056
1057                 },
1058                 'template_id': '12',
1059                 'manual_scale_select_vim': False
1060             },
1061             'description': 'ppvm'
1062         }
1063     ],
1064     'volumn_storages': [
1065
1066     ],
1067     'policies': {
1068         'scaling': {
1069             'targets': {
1070
1071             },
1072             'policy_id': 'policy_scale_sss-vnf-template',
1073             'properties': {
1074                 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'
1075             },
1076             'description': ''
1077         }
1078     },
1079     'image_files': [
1080         {
1081             'description': '',
1082             'properties': {
1083                 'name': 'opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1084                 'checksum': '',
1085                 'disk_format': 'VMDK',
1086                 'file_url': './zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk',
1087                 'container_type': 'vm',
1088                 'version': '',
1089                 'hypervisor_type': 'kvm'
1090             },
1091             'image_file_id': 'opencos_sss_omm_img_release_20150723-1-disk1'
1092         },
1093         {
1094             'description': '',
1095             'properties': {
1096                 'name': 'sss.vmdk',
1097                 'checksum': '',
1098                 'disk_format': 'VMDK',
1099                 'file_url': './zte-cn-sss-main-image/NE/sss.vmdk',
1100                 'container_type': 'vm',
1101                 'version': '',
1102                 'hypervisor_type': 'kvm'
1103             },
1104             'image_file_id': 'sss'
1105         }
1106     ],
1107     'vls': [
1108
1109     ],
1110     'cps': [
1111         {'cp_id': 'cpd_2',
1112          "description": "",
1113          "properties": {
1114              "mac_address": "00:d9:00:82:11:e2",
1115              "ip_address": "10.43.25.3",
1116              "ip_range_start": "192.168.1.20",
1117              "ip_range_end": "192.168.1.29",
1118              "sfc_encapsulation": ""
1119          }
1120          },
1121     ],
1122     'metadata': {
1123         'vendor': 'zte',
1124         'is_shared': False,
1125         'description': '',
1126         'domain_type': 'CN',
1127         'version': 'v4.14.10',
1128         'vmnumber_overquota_alarm': False,
1129         'cross_dc': False,
1130         'vnf_type': 'SSS',
1131         'vnfd_version': 'V00000001',
1132         'id': 'sss-vnf-template',
1133         'name': 'vnfd_2'
1134     },
1135     'vnf_exposed': {
1136         "external_cps": [
1137             {
1138                 "key_name": "virtualLink1",
1139                 "cp_id": "cp1",
1140             },
1141         ],
1142         "forward_cps": [
1143             {
1144                 "key_name": "forwarder2",
1145                 "cp_id": "cpd_2",
1146             },
1147             {
1148                 "key_name": "forwarder3",
1149                 "cp_id": "cpd_2",
1150             },
1151         ],
1152     }
1153 }
1154
1155 nsd_model = {
1156     "metadata": {
1157         "id": "nsd_demo",
1158         "vendor": "zte",
1159         "version": "1.1.0",
1160         "name": "testNSD",
1161         "description": "demo nsd",
1162     },
1163
1164     "inputs": {
1165         "param1": "11",
1166         "param2": "22",
1167     },
1168
1169     "vnfs": [
1170         {
1171             "type": "tosca.nodes.nfv.ext.VNF.FireWall",
1172             "vnf_id": "vnf_1",
1173             "description": "",
1174             "properties": {
1175                 "id": "vnfd_1",
1176                 "vendor": "zte",
1177                 "version": "1.2.0",
1178                 "vnfd_version": "1.1.0",
1179                 "vnf_type": "vnf1",
1180                 "domain_type": "CN",
1181                 "name": "vnf1",
1182                 "is_shared": False,
1183                 "cross_dc": False,
1184                 "request_reclassification": False,
1185                 "nsh_aware": False,
1186                 "custom_properties": {
1187                     "key1": "value1",
1188                     "keyN": "valueN",
1189                 },
1190             },
1191             "dependencies": [
1192                 "vnf_id1", "vnf_id2"
1193             ],
1194             "networks": [
1195                 {
1196                     "key_name": "virtualLink1",
1197                     "vl_id": "vl_id1",
1198                 },
1199             ],
1200         },
1201         {
1202             "type": "tosca.nodes.nfv.ext.VNF.FireWall",
1203             "vnf_id": "vnf_2",
1204             "description": "",
1205             "properties": {
1206                 "id": "vnfd_2",
1207                 "vendor": "zte",
1208                 "version": "1.2.0",
1209                 "vnfd_version": "1.1.0",
1210                 "vnf_type": "vnf2",
1211                 "domain_type": "CN",
1212                 "name": "vnf1",
1213                 "is_shared": False,
1214                 "cross_dc": False,
1215                 "request_reclassification": False,
1216                 "nsh_aware": False,
1217                 "custom_properties": {
1218                     "key1": "value1",
1219                     "keyN": "valueN",
1220                 },
1221             },
1222             "dependencies": [
1223                 "vnf_id1", "vnf_id2"
1224             ],
1225             "networks": [
1226                 {
1227                     "key_name": "virtualLink1",
1228                     "vl_id": "vl_id1",
1229                 },
1230             ],
1231         }
1232     ],
1233
1234     "pnfs": [
1235         {
1236             "pnf_id": "pnf1",
1237             "description": "",
1238             "properties": {
1239                 "id": "pnf1",
1240                 "vendor": "zte",
1241                 "version": "1.1.0",
1242                 "pnf_type": "TTGW",
1243                 "request_reclassification": False,
1244                 "nsh_aware": False,
1245                 "management_address": "10.44.56.78"
1246             },
1247             "cps": [
1248                 "cpd_1", "cpd_22",
1249             ]
1250         }
1251     ],
1252
1253     "nested_ns": [
1254         {
1255             "ns_id": "ns2",
1256             "description": "",
1257             "properties": {
1258                 "id": "ns2_demo",
1259                 "vendor": "zte",
1260                 "version": "1.1.0",
1261                 "name": "NSD2",
1262             },
1263             "networks": [
1264                 {
1265                     "key_name": "virtualLink1",
1266                     "vl_id": "vl_id1",
1267                 },
1268             ],
1269         }
1270     ],
1271
1272     "vls": [
1273         {
1274             "vl_id": "vldId1",
1275             "description": "",
1276             "properties": {
1277                 "name": "umac_241_control",
1278                 "network_id": "fgdhsj434hfjdfd",
1279                 "network_name": "umac_control",
1280                 "vendor": "zte",
1281                 "mtu": 1500,
1282                 "network_type": "vlan",
1283                 "physical_network": "phynet01",
1284                 "segmentation_id": "30",
1285                 "vlan_transparent": False,
1286                 "vds_name": "vds1",
1287                 "cidr": "192.168.199.0/24",
1288                 "ip_version": 4,
1289                 "gateway_ip": "192.168.199.1",
1290                 "dhcp_enabled": False,
1291                 "dns_nameservers": ["192.168.0.4", "192.168.0.10"],
1292                 "start_ip": "192.168.199.2",
1293                 "end_ip": "192.168.199.254",
1294                 "host_routes": [
1295                     {
1296                         "destination": "10.43.26.0/24",
1297                         "nexthop": "10.41.23.1",
1298                     },
1299                 ],
1300                 "location_info": {
1301                     "vimId": "vimid",
1302                     "tenant": "tenantname",
1303                 },
1304                 "vlan_transparent": False,
1305             },
1306         },
1307     ],
1308
1309     "cps": [
1310         {
1311             "cp_id": "cpd_1",
1312             "description": "",
1313             "properties": {
1314                 "mac_address": "00:d9:00:82:11:e1",
1315                 "ip_address": "192.168.1.21",
1316                 "ip_range_start": "192.168.1.20",
1317                 "ip_range_end": "192.168.1.29",
1318                 "floating_ip_address": {
1319                     "external_network": "extnet01",
1320                     "ip_address": "10.43.53.23",
1321                 },
1322                 "service_ip_address": "192.168.1.23",
1323                 "order": 1,
1324                 "bandwidth": 1000,
1325                 "vnic_type": "normal",
1326                 "allowed_address_pairs": [
1327                     {
1328                         "ip": "192.168.1.13",
1329                         "mac": "00:f3:43:20:a2:a3"
1330                     },
1331                 ],
1332                 "bond": "none",
1333                 "macbond": "00:d9:00:82:11:d1",
1334                 "sfc_encapsulation": "",
1335                 "direction": "",
1336             },
1337             "vl_id": "vlid1",
1338             "pnf_id": "pnf1",
1339         },
1340
1341         {
1342             "cp_id": "forwarder_brasDP_dcPort",
1343             "description": "",
1344             "properties": {
1345                 "mac_address": "00:d9:00:82:14:e1",
1346                 "ip_address": "192.168.1.24",
1347                 "ip_range_start": "192.168.1.20",
1348                 "ip_range_end": "192.168.1.29",
1349                 "floating_ip_address": {
1350                     "external_network": "extnet01",
1351                     "ip_address": "10.43.53.23",
1352                 },
1353                 "service_ip_address": "192.168.1.23",
1354                 "order": 1,
1355                 "bandwidth": 1000,
1356                 "vnic_type": "normal",
1357                 "allowed_address_pairs": [
1358                     {
1359                         "ip": "192.168.1.13",
1360                         "mac": "00:f3:43:20:a2:a3"
1361                     },
1362                 ],
1363                 "bond": "none",
1364                 "macbond": "00:d9:00:82:11:d1",
1365                 "sfc_encapsulation": "",
1366                 "direction": "",
1367             },
1368             "vl_id": "vlid1",
1369             "pnf_id": "pnf1",
1370         },
1371         {
1372             "cp_id": "forwarder_brasDP_internetPort",
1373             "description": "",
1374             "properties": {
1375                 "mac_address": "00:d9:00:82:15:e1",
1376                 "ip_address": "192.168.1.25",
1377                 "ip_range_start": "192.168.1.20",
1378                 "ip_range_end": "192.168.1.29",
1379                 "floating_ip_address": {
1380                     "external_network": "extnet01",
1381                     "ip_address": "10.43.53.23",
1382                 },
1383                 "service_ip_address": "192.168.1.23",
1384                 "order": 1,
1385                 "bandwidth": 1000,
1386                 "vnic_type": "normal",
1387                 "allowed_address_pairs": [
1388                     {
1389                         "ip": "192.168.1.13",
1390                         "mac": "00:f3:43:20:a2:a3"
1391                     },
1392                 ],
1393                 "bond": "none",
1394                 "macbond": "00:d9:00:82:11:d1",
1395                 "sfc_encapsulation": "",
1396                 "direction": "",
1397             },
1398             "vl_id": "vlid1",
1399             "pnf_id": "pnf1",
1400         },
1401
1402     ],
1403
1404     "fps": [
1405         {
1406             "fp_id": "fpd_1",
1407             "description": "",
1408             "properties": {
1409                 "policy": {
1410                     "type": "ACL",
1411                     "criteria": {
1412                         "dest_port_range": [80, 1024],
1413                         "source_port_range": [80, 1024],
1414                         "ip_protocol": "tcp",
1415                         "dest_ip_range": ["192.168.1.2", "192.168.1.100"],
1416                         "source_ip_range": ["192.168.1.2", "192.168.1.100"],
1417                         "dscp": 100,
1418                     },
1419                 },
1420                 "symmetric": True,
1421             },
1422             "forwarder_list": [
1423                 {
1424                     "type": "cp",
1425                     "node_name": "cpd_1",
1426                     "capability": "",
1427                 },
1428                 {
1429                     "type": "cp",
1430                     "node_name": "forwarder_brasDP_dcPort",
1431                     "capability": "",
1432                 },
1433                 {
1434                     "type": "vnf",
1435                     "node_name": "vnf_1",
1436                     "capability": "forwarder1",
1437                 },
1438                 {
1439                     "type": "vnf",
1440                     "node_name": "vnf_2",
1441                     "capability": "forwarder2",
1442                 },
1443                 {
1444                     "type": "cp",
1445                     "node_name": "forwarder_brasDP_dcPort",
1446                     "capability": "",
1447                 },
1448                 {
1449                     "type": "cp",
1450                     "node_name": "forwarder_brasDP_internetPort",
1451                     "capability": "",
1452                 },
1453             ],
1454         },
1455
1456         {
1457             "fp_id": "fpd_2",
1458             "description": "",
1459             "properties": {
1460                 "policy": {
1461                     "type": "ACL",
1462                     "criteria": {
1463                         "dest_port_range": [80, 1024],
1464                         "source_port_range": [80, 1024],
1465                         "ip_protocol": "tcp",
1466                         "dest_ip_range": ["192.168.1.2", "192.168.1.100"],
1467                         "source_ip_range": ["192.168.1.2", "192.168.1.100"],
1468                         "dscp": 100,
1469                     },
1470                 },
1471                 "symmetric": True,
1472             },
1473             "forwarder_list": [
1474
1475                 {
1476                     "type": "cp",
1477                     "node_name": "forwarder_brasDP_internetPort",
1478                     "capability": "",
1479                 },
1480                 {
1481                     "type": "cp",
1482                     "node_name": "forwarder_brasDP_dcPort",
1483                     "capability": "",
1484                 },
1485                 {
1486                     "type": "vnf",
1487                     "node_name": "vnf_2",
1488                     "capability": "forwarder2",
1489                 },
1490
1491             ],
1492         },
1493     ],
1494
1495     "vnffgs": [
1496         {
1497             "vnffg_id": "vnffg_id1",
1498             "description": "",
1499             "properties": {
1500                 "vendor": "zte",
1501                 "version": "1.1.2",
1502                 "number_of_endpoints": 7,
1503                 "dependent_virtual_link": ["vldId1"],
1504                 "connection_point": ["CP01", "CP02"],
1505                 "constituent_vnfs": ["vnf_id1", "vnf_id2"],
1506                 "constituent_pnfs": ["pnf1", "pnf2"],
1507             },
1508             "members": ["fpd_1", "fpd_2"],
1509         }
1510     ],
1511
1512     "server_groups": [
1513         {
1514             "group_id": "",
1515             "description": "",
1516             "properties": {
1517                 "name": "server_group1",
1518                 "affinity_antiaffinity": "anti-affinity",
1519                 "scope": "host",
1520             },
1521             "members": ["vnf1", "vnf2"],
1522         },
1523     ],
1524
1525     "ns_exposed": {
1526         "external_cps": [
1527             {
1528                 "key_name": "virtualLink1",
1529                 "cp_id": "cp1",
1530             },
1531         ],
1532         "forward_cps": [
1533             {
1534                 "key_name": "forwarder_brasDP_userPort",
1535                 "cp_id": "cpd_1",
1536             },
1537             {
1538                 "key_name": "forwarder_brasDP_internetPort",
1539                 "cp_id": "cpd_4",
1540             },
1541             {
1542                 "key_name": "forwarder_brasDP_dcPort",
1543                 "cp_id": "cpd_5",
1544             },
1545
1546         ],
1547     },
1548
1549     "policies": [
1550         {
1551             "scaling": [
1552                 {
1553                     "policy_id": "id1",
1554                     "description": "",
1555                     "properties": {
1556                         "policy_file": "Policies/ns1-policy.xml",
1557                     },
1558                     "targets": ['pfu_vm'],
1559                 },
1560             ],
1561         },
1562     ],
1563
1564     "ns_flavours": [
1565         {
1566             "flavour_id": "flavour1",
1567             "description": "",
1568             "vnf_profiles": [
1569                 {
1570                     "vnf_id": "vnf1",
1571                     "flavour_id": "flavour1",
1572                     "instances_minimum_number": 1,
1573                     "instances_maximum_number": 4,
1574                     "local_affinity_antiaffinity_rule": [
1575                         {
1576                             "affinity_antiaffinity": "affinity",
1577                             "scope": "node",
1578                         }
1579                     ]
1580                 },
1581             ],
1582             "pnf_profiles": [
1583                 {
1584                     "pnf_id": "pnf1",
1585                 },
1586             ],
1587             "vl_profiles": [
1588                 {
1589                     "vl_id": "vlid1",
1590                     "bitrate_requirements": {
1591                         "root": 1000,
1592                         "leaf": 100
1593                     },
1594                     "qos": {
1595                         "maximum_latency": "1 ms",
1596                         "maximum_jitter": "10 ms",
1597                         "maximum_packet_loss_ratio": 0.5
1598                     },
1599                 }
1600             ],
1601             "instantiation_levels": [
1602                 {
1603                     "id": "instLevel1",
1604                     "description": "",
1605                     "vnf_levels": [
1606                         {
1607                             "vnf_id": "",
1608                             "vnf_instantiation_level": "small",
1609                             "instances_number": 1
1610                         },
1611                     ],
1612                     "scale_level_id": "scaleLevel1",
1613                 }
1614             ],
1615             "default_instantiation_level": "instLevel1",
1616             "scale_levels": [
1617                 {
1618                     "id": "scaleLevel1",
1619                     "order": 1,
1620                     "vnf_levels": [
1621                         {
1622                             "vnf_id": "",
1623                             "vnf_instantiation_level": "small",
1624                             "instances_number": 1
1625                         },
1626                     ],
1627                 },
1628             ],
1629             "supported_operations": ["Scale", "Heal"],
1630             "affinity_antiaffinity_groups": [
1631                 {
1632                     "group_id": "group1Id",
1633                     "name": "groupName",
1634                     "affinity_antiaffinity": "affinity",
1635                     "scope": "node",
1636                     "members": [
1637                         "vnfId1", "vnfIdN",
1638                     ],
1639                 },
1640             ],
1641         },
1642     ],
1643 }