Delete useless codes of ns scale
[vfc/nfvo/lcm.git] / lcm / ns / tests / test_scaleaspect.py
1 # Copyright 2016-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 from django.test import TestCase
16 from lcm.ns.scaleaspect import get_json_data
17 from lcm.pub.database.models import NfInstModel
18 from lcm.pub.database.models import NSInstModel
19 from lcm.pub.utils.timeutil import now_time
20 import os
21
22
23 class TestScaleAspect(TestCase):
24
25     def setUp(self):
26         self.init_scaling_map_json()
27         self.initInstModel()
28
29         self.init_scale_ns_data()
30
31         self.vnf_scale_info_list = [
32             {
33                 "vnfd_id": "nf_zte_cscf",
34                 "vnf_scaleAspectId": "mpu",
35                 "numberOfSteps": "1"
36             },
37             {
38                 "vnfd_id": "nf_zte_hss",
39                 "vnf_scaleAspectId": "gsu",
40                 "numberOfSteps": "2"
41             }
42         ]
43
44     def init_scale_ns_data(self):
45         self.ns_scale_aspect = "TIC_EDGE_IMS"
46         self.ns_scale_steps = "1"
47         self.ns_scale_direction = "SCALE_IN"
48         self.scaleNsData = [{
49             "scaleNsByStepsData": [
50                 {
51                     "aspectId": self.ns_scale_aspect,
52                     "numberOfSteps": self.ns_scale_steps,
53                     "scalingDirection": self.ns_scale_direction
54                 }
55             ]
56         }]
57
58         self.ns_scale_aspect2 = "TIC_EDGE_HW"
59         self.ns_scale_steps2 = "4"
60         self.scaleNsData2 = [{
61             "scaleNsByStepsData": [
62                 {
63                     "aspectId": self.ns_scale_aspect2,
64                     "numberOfSteps": self.ns_scale_steps2,
65                     "scalingDirection": self.ns_scale_direction
66                 }
67             ]
68         }]
69
70     def init_scaling_map_json(self):
71         curdir_path = os.path.dirname(
72             os.path.dirname(
73                 os.path.dirname(
74                     os.path.abspath(__file__))))
75         filename = curdir_path + "/ns/data/scalemapping.json"
76         self.scaling_map_json = get_json_data(filename)
77
78     def initInstModel(self):
79         self.nsd_id = "23"
80         self.ns_inst_id = "1"
81         self.ns_name = "ns_1"
82         self.ns_package_id = "ns_zte"
83         self.description = "ns_zte"
84         self.global_customer_id = "global_customer_id"
85         self.service_type = "service_role"
86
87         NSInstModel(id=self.ns_inst_id,
88                     name=self.ns_name,
89                     nspackage_id=self.ns_package_id,
90                     nsd_id=self.nsd_id,
91                     description=self.description,
92                     status='empty',
93                     lastuptime=now_time(),
94                     global_customer_id=self.global_customer_id,
95                     service_type=self.service_type).save()
96
97         self.nf_inst_id = "231"
98         self.ns_inst_id = "1"
99         self.nf_name = "name_1"
100         self.vnf_id = "1"
101         self.vnfm_inst_id = "1"
102         self.package_id = "nf_zte_cscf"
103         self.nf_uuid = "abc34-345a-de13-ab85-ijs9"
104
105         NfInstModel.objects.create(
106             nfinstid=self.nf_inst_id,
107             nf_name=self.nf_name,
108             vnf_id=self.vnf_id,
109             vnfm_inst_id=self.vnfm_inst_id,
110             ns_inst_id=self.ns_inst_id,
111             max_cpu='14',
112             max_ram='12296',
113             max_hd='101',
114             max_shd="20",
115             max_net=10,
116             status='active',
117             mnfinstid=self.nf_uuid,
118             package_id=self.package_id,
119             vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
120             '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
121             '"productType": "CN","vnfType": "PGW",'
122             '"description": "PGW VNFD description",'
123             '"isShared":true,"vnfExtendType":"driver"}}')
124
125         # Create a second vnf instance
126         self.nf_inst_id = "232"
127         self.package_id = "nf_zte_hss"
128         self.nf_uuid = "abc34-3g5a-de13-ab85-ijs3"
129
130         NfInstModel.objects.create(
131             nfinstid=self.nf_inst_id,
132             nf_name=self.nf_name,
133             vnf_id=self.vnf_id,
134             vnfm_inst_id=self.vnfm_inst_id,
135             ns_inst_id=self.ns_inst_id,
136             max_cpu='14',
137             max_ram='12296',
138             max_hd='101',
139             max_shd="20",
140             max_net=10,
141             status='active',
142             mnfinstid=self.nf_uuid,
143             package_id=self.package_id,
144             vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
145                        '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
146                        '"productType": "CN","vnfType": "PGW",'
147                        '"description": "PGW VNFD description",'
148                        '"isShared":true,"vnfExtendType":"driver"}}')
149
150     def add_another_nf_instance(self):
151         # Create a third vnf instance
152         nf_inst_id = "233"
153         package_id = "nf_zte_hss"
154         nf_uuid = "ab34-3g5j-de13-ab85-ij93"
155
156         NfInstModel.objects.create(
157             nfinstid=nf_inst_id,
158             nf_name=self.nf_name,
159             vnf_id=self.vnf_id,
160             vnfm_inst_id=self.vnfm_inst_id,
161             ns_inst_id=self.ns_inst_id,
162             max_cpu='14',
163             max_ram='12296',
164             max_hd='101',
165             max_shd="20",
166             max_net=10,
167             status='active',
168             mnfinstid=nf_uuid,
169             package_id=package_id,
170             vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
171                        '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
172                        '"productType": "CN","vnfType": "PGW",'
173                        '"description": "PGW VNFD description",'
174                        '"isShared":true,"vnfExtendType":"driver"}}')
175
176     def add_new_vnf_instance(self):
177         # Create a third vnf instance
178         nf_inst_id = "241"
179         package_id = "nf_hw_cscf"
180         nf_uuid = "ab34-3g5j-de13-aa85-ij93"
181
182         NfInstModel.objects.create(
183             nfinstid=nf_inst_id,
184             nf_name=self.nf_name,
185             vnf_id=self.vnf_id,
186             vnfm_inst_id=self.vnfm_inst_id,
187             ns_inst_id=self.ns_inst_id,
188             max_cpu='14',
189             max_ram='12296',
190             max_hd='101',
191             max_shd="20",
192             max_net=10,
193             status='active',
194             mnfinstid=nf_uuid,
195             package_id=package_id,
196             vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
197                        '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
198                        '"productType": "CN","vnfType": "PGW",'
199                        '"description": "PGW VNFD description",'
200                        '"isShared":true,"vnfExtendType":"driver"}}')
201
202         # Create a third vnf instance
203         nf_inst_id = "242"
204         package_id = "nf_hw_hss"
205         nf_uuid = "ab34-3g5j-de13-aa85-id93"
206
207         NfInstModel.objects.create(
208             nfinstid=nf_inst_id,
209             nf_name=self.nf_name,
210             vnf_id=self.vnf_id,
211             vnfm_inst_id=self.vnfm_inst_id,
212             ns_inst_id=self.ns_inst_id,
213             max_cpu='14',
214             max_ram='12296',
215             max_hd='101',
216             max_shd="20",
217             max_net=10,
218             status='active',
219             mnfinstid=nf_uuid,
220             package_id=package_id,
221             vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
222                        '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
223                        '"productType": "CN","vnfType": "PGW",'
224                        '"description": "PGW VNFD description",'
225                        '"isShared":true,"vnfExtendType":"driver"}}')
226
227     def tearDown(self):
228         NSInstModel().clean()
229         NfInstModel().clean()