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.
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
23 class TestScaleAspect(TestCase):
26 self.init_scaling_map_json()
29 self.init_scale_ns_data()
31 self.vnf_scale_info_list = [
33 "vnfd_id": "nf_zte_cscf",
34 "vnf_scaleAspectId": "mpu",
38 "vnfd_id": "nf_zte_hss",
39 "vnf_scaleAspectId": "gsu",
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"
49 "scaleNsByStepsData": [
51 "aspectId": self.ns_scale_aspect,
52 "numberOfSteps": self.ns_scale_steps,
53 "scalingDirection": self.ns_scale_direction
58 self.ns_scale_aspect2 = "TIC_EDGE_HW"
59 self.ns_scale_steps2 = "4"
60 self.scaleNsData2 = [{
61 "scaleNsByStepsData": [
63 "aspectId": self.ns_scale_aspect2,
64 "numberOfSteps": self.ns_scale_steps2,
65 "scalingDirection": self.ns_scale_direction
70 def init_scaling_map_json(self):
71 curdir_path = 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)
78 def initInstModel(self):
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"
87 NSInstModel(id=self.ns_inst_id,
89 nspackage_id=self.ns_package_id,
91 description=self.description,
93 lastuptime=now_time(),
94 global_customer_id=self.global_customer_id,
95 service_type=self.service_type).save()
97 self.nf_inst_id = "231"
99 self.nf_name = "name_1"
101 self.vnfm_inst_id = "1"
102 self.package_id = "nf_zte_cscf"
103 self.nf_uuid = "abc34-345a-de13-ab85-ijs9"
105 NfInstModel.objects.create(
106 nfinstid=self.nf_inst_id,
107 nf_name=self.nf_name,
109 vnfm_inst_id=self.vnfm_inst_id,
110 ns_inst_id=self.ns_inst_id,
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"}}')
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"
130 NfInstModel.objects.create(
131 nfinstid=self.nf_inst_id,
132 nf_name=self.nf_name,
134 vnfm_inst_id=self.vnfm_inst_id,
135 ns_inst_id=self.ns_inst_id,
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"}}')
150 def add_another_nf_instance(self):
151 # Create a third vnf instance
153 package_id = "nf_zte_hss"
154 nf_uuid = "ab34-3g5j-de13-ab85-ij93"
156 NfInstModel.objects.create(
158 nf_name=self.nf_name,
160 vnfm_inst_id=self.vnfm_inst_id,
161 ns_inst_id=self.ns_inst_id,
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"}}')
176 def add_new_vnf_instance(self):
177 # Create a third vnf instance
179 package_id = "nf_hw_cscf"
180 nf_uuid = "ab34-3g5j-de13-aa85-ij93"
182 NfInstModel.objects.create(
184 nf_name=self.nf_name,
186 vnfm_inst_id=self.vnfm_inst_id,
187 ns_inst_id=self.ns_inst_id,
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"}}')
202 # Create a third vnf instance
204 package_id = "nf_hw_hss"
205 nf_uuid = "ab34-3g5j-de13-aa85-id93"
207 NfInstModel.objects.create(
209 nf_name=self.nf_name,
211 vnfm_inst_id=self.vnfm_inst_id,
212 ns_inst_id=self.ns_inst_id,
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"}}')
228 NSInstModel().clean()
229 NfInstModel().clean()