SOL003 API Align
[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 import os
16
17 from django.test import TestCase
18
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
23
24
25 class TestScaleAspect(TestCase):
26
27     def setUp(self):
28         self.init_scaling_map_json()
29         self.initInstModel()
30
31         self.init_scale_ns_data()
32
33         self.vnf_scale_info_list = [
34             {
35                 "vnfd_id": "nf_zte_cscf",
36                 "vnf_scaleAspectId": "mpu",
37                 "numberOfSteps": "1"
38             },
39             {
40                 "vnfd_id": "nf_zte_hss",
41                 "vnf_scaleAspectId": "gsu",
42                 "numberOfSteps": "2"
43             }
44         ]
45
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"
50         self.scaleNsData = [{
51             "scaleNsByStepsData": [
52                 {
53                     "aspectId": self.ns_scale_aspect,
54                     "numberOfSteps": self.ns_scale_steps,
55                     "scalingDirection": self.ns_scale_direction
56                 }
57             ]
58         }]
59
60         self.ns_scale_aspect2 = "TIC_EDGE_HW"
61         self.ns_scale_steps2 = "4"
62         self.scaleNsData2 = [{
63             "scaleNsByStepsData": [
64                 {
65                     "aspectId": self.ns_scale_aspect2,
66                     "numberOfSteps": self.ns_scale_steps2,
67                     "scalingDirection": self.ns_scale_direction
68                 }
69             ]
70         }]
71
72     def init_scaling_map_json(self):
73         curdir_path = os.path.dirname(
74             os.path.dirname(
75                 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)
79
80     def initInstModel(self):
81         self.nsd_id = "23"
82         self.ns_inst_id = "1"
83         self.ns_name = "ns_1"
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"
88
89         NSInstModel(id=self.ns_inst_id,
90                     name=self.ns_name,
91                     nspackage_id=self.ns_package_id,
92                     nsd_id=self.nsd_id,
93                     description=self.description,
94                     status='empty',
95                     lastuptime=now_time(),
96                     global_customer_id=self.global_customer_id,
97                     service_type=self.service_type).save()
98
99         self.nf_inst_id = "231"
100         self.ns_inst_id = "1"
101         self.nf_name = "name_1"
102         self.vnf_id = "1"
103         self.vnfm_inst_id = "1"
104         self.package_id = "nf_zte_cscf"
105         self.nf_uuid = "abc34-345a-de13-ab85-ijs9"
106
107         NfInstModel.objects.create(
108             nfinstid=self.nf_inst_id,
109             nf_name=self.nf_name,
110             vnf_id=self.vnf_id,
111             vnfm_inst_id=self.vnfm_inst_id,
112             ns_inst_id=self.ns_inst_id,
113             max_cpu='14',
114             max_ram='12296',
115             max_hd='101',
116             max_shd="20",
117             max_net=10,
118             status='active',
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"}}')
126
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"
131
132         NfInstModel.objects.create(
133             nfinstid=self.nf_inst_id,
134             nf_name=self.nf_name,
135             vnf_id=self.vnf_id,
136             vnfm_inst_id=self.vnfm_inst_id,
137             ns_inst_id=self.ns_inst_id,
138             max_cpu='14',
139             max_ram='12296',
140             max_hd='101',
141             max_shd="20",
142             max_net=10,
143             status='active',
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"}}')
151
152     def add_another_nf_instance(self):
153         # Create a third vnf instance
154         nf_inst_id = "233"
155         package_id = "nf_zte_hss"
156         nf_uuid = "ab34-3g5j-de13-ab85-ij93"
157
158         NfInstModel.objects.create(
159             nfinstid=nf_inst_id,
160             nf_name=self.nf_name,
161             vnf_id=self.vnf_id,
162             vnfm_inst_id=self.vnfm_inst_id,
163             ns_inst_id=self.ns_inst_id,
164             max_cpu='14',
165             max_ram='12296',
166             max_hd='101',
167             max_shd="20",
168             max_net=10,
169             status='active',
170             mnfinstid=nf_uuid,
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"}}')
177
178     def add_new_vnf_instance(self):
179         # Create a third vnf instance
180         nf_inst_id = "241"
181         package_id = "nf_hw_cscf"
182         nf_uuid = "ab34-3g5j-de13-aa85-ij93"
183
184         NfInstModel.objects.create(
185             nfinstid=nf_inst_id,
186             nf_name=self.nf_name,
187             vnf_id=self.vnf_id,
188             vnfm_inst_id=self.vnfm_inst_id,
189             ns_inst_id=self.ns_inst_id,
190             max_cpu='14',
191             max_ram='12296',
192             max_hd='101',
193             max_shd="20",
194             max_net=10,
195             status='active',
196             mnfinstid=nf_uuid,
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"}}')
203
204         # Create a third vnf instance
205         nf_inst_id = "242"
206         package_id = "nf_hw_hss"
207         nf_uuid = "ab34-3g5j-de13-aa85-id93"
208
209         NfInstModel.objects.create(
210             nfinstid=nf_inst_id,
211             nf_name=self.nf_name,
212             vnf_id=self.vnf_id,
213             vnfm_inst_id=self.vnfm_inst_id,
214             ns_inst_id=self.ns_inst_id,
215             max_cpu='14',
216             max_ram='12296',
217             max_hd='101',
218             max_shd="20",
219             max_net=10,
220             status='active',
221             mnfinstid=nf_uuid,
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"}}')
228
229     def tearDown(self):
230         NSInstModel().clean()
231         NfInstModel().clean()