1 # Copyright 2016-2018 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 from django.test import TestCase
19 from lcm.ns.biz.scaleaspect import get_json_data
20 from lcm.pub.database.models import NSInstModel
21 from lcm.pub.database.models import NfInstModel
22 from lcm.pub.utils.timeutil import now_time
25 class TestScaleAspect(TestCase):
28 self.init_scaling_map_json()
31 self.init_scale_ns_data()
33 self.vnf_scale_info_list = [
35 "vnfd_id": "nf_zte_cscf",
36 "vnf_scaleAspectId": "mpu",
40 "vnfd_id": "nf_zte_hss",
41 "vnf_scaleAspectId": "gsu",
46 def init_scale_ns_data(self):
47 self.ns_scale_aspect = "TIC_EDGE_IMS"
48 self.ns_scale_steps = "1"
49 self.ns_scale_direction = "SCALE_IN"
51 "scaleNsByStepsData": [
53 "aspectId": self.ns_scale_aspect,
54 "numberOfSteps": self.ns_scale_steps,
55 "scalingDirection": self.ns_scale_direction
60 self.ns_scale_aspect2 = "TIC_EDGE_HW"
61 self.ns_scale_steps2 = "4"
62 self.scaleNsData2 = [{
63 "scaleNsByStepsData": [
65 "aspectId": self.ns_scale_aspect2,
66 "numberOfSteps": self.ns_scale_steps2,
67 "scalingDirection": self.ns_scale_direction
72 def init_scaling_map_json(self):
73 curdir_path = os.path.dirname(
76 os.path.abspath(__file__))))
77 filename = curdir_path + "/ns/data/scalemapping.json"
78 self.scaling_map_json = get_json_data(filename)
80 def initInstModel(self):
84 self.ns_package_id = "ns_zte"
85 self.description = "ns_zte"
86 self.global_customer_id = "global_customer_id"
87 self.service_type = "service_role"
89 NSInstModel(id=self.ns_inst_id,
91 nspackage_id=self.ns_package_id,
93 description=self.description,
95 lastuptime=now_time(),
96 global_customer_id=self.global_customer_id,
97 service_type=self.service_type).save()
99 self.nf_inst_id = "231"
100 self.ns_inst_id = "1"
101 self.nf_name = "name_1"
103 self.vnfm_inst_id = "1"
104 self.package_id = "nf_zte_cscf"
105 self.nf_uuid = "abc34-345a-de13-ab85-ijs9"
107 NfInstModel.objects.create(
108 nfinstid=self.nf_inst_id,
109 nf_name=self.nf_name,
111 vnfm_inst_id=self.vnfm_inst_id,
112 ns_inst_id=self.ns_inst_id,
119 mnfinstid=self.nf_uuid,
120 package_id=self.package_id,
121 vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
122 '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
123 '"productType": "CN","vnfType": "PGW",'
124 '"description": "PGW VNFD description",'
125 '"isShared":true,"vnfExtendType":"driver"}}')
127 # Create a second vnf instance
128 self.nf_inst_id = "232"
129 self.package_id = "nf_zte_hss"
130 self.nf_uuid = "abc34-3g5a-de13-ab85-ijs3"
132 NfInstModel.objects.create(
133 nfinstid=self.nf_inst_id,
134 nf_name=self.nf_name,
136 vnfm_inst_id=self.vnfm_inst_id,
137 ns_inst_id=self.ns_inst_id,
144 mnfinstid=self.nf_uuid,
145 package_id=self.package_id,
146 vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
147 '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
148 '"productType": "CN","vnfType": "PGW",'
149 '"description": "PGW VNFD description",'
150 '"isShared":true,"vnfExtendType":"driver"}}')
152 def add_another_nf_instance(self):
153 # Create a third vnf instance
155 package_id = "nf_zte_hss"
156 nf_uuid = "ab34-3g5j-de13-ab85-ij93"
158 NfInstModel.objects.create(
160 nf_name=self.nf_name,
162 vnfm_inst_id=self.vnfm_inst_id,
163 ns_inst_id=self.ns_inst_id,
171 package_id=package_id,
172 vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
173 '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
174 '"productType": "CN","vnfType": "PGW",'
175 '"description": "PGW VNFD description",'
176 '"isShared":true,"vnfExtendType":"driver"}}')
178 def add_new_vnf_instance(self):
179 # Create a third vnf instance
181 package_id = "nf_hw_cscf"
182 nf_uuid = "ab34-3g5j-de13-aa85-ij93"
184 NfInstModel.objects.create(
186 nf_name=self.nf_name,
188 vnfm_inst_id=self.vnfm_inst_id,
189 ns_inst_id=self.ns_inst_id,
197 package_id=package_id,
198 vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
199 '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
200 '"productType": "CN","vnfType": "PGW",'
201 '"description": "PGW VNFD description",'
202 '"isShared":true,"vnfExtendType":"driver"}}')
204 # Create a third vnf instance
206 package_id = "nf_hw_hss"
207 nf_uuid = "ab34-3g5j-de13-aa85-id93"
209 NfInstModel.objects.create(
211 nf_name=self.nf_name,
213 vnfm_inst_id=self.vnfm_inst_id,
214 ns_inst_id=self.ns_inst_id,
222 package_id=package_id,
223 vnfd_model='{"metadata": {"vnfdId": "1","vnfdName": "PGW001",'
224 '"vnfProvider": "zte","vnfdVersion": "V00001","vnfVersion": "V5.10.20",'
225 '"productType": "CN","vnfType": "PGW",'
226 '"description": "PGW VNFD description",'
227 '"isShared":true,"vnfExtendType":"driver"}}')
230 NSInstModel().clean()
231 NfInstModel().clean()