blob: d94655f0a284b6129aa19b06e67ac32aae36e89d [file] [log] [blame]
Chetan Gaonker357f4892017-06-19 19:38:27 +00001#copyright 2016-present Ciena 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#
15import time
16import os
17import sys
18import json
19import requests
20from nose.tools import *
21from twisted.internet import defer
22from nose.twistedtools import reactor, deferred
23from CordTestUtils import *
24from OltConfig import OltConfig
25from onosclidriver import OnosCliDriver
26from SSHTestAgent import SSHTestAgent
27from CordLogger import CordLogger
28from VSGAccess import VSGAccess
29from CordTestUtils import log_test as log
30from CordTestConfig import setup_module, running_on_ciab
31from OnosCtrl import OnosCtrl
32from CordContainer import Onos
33log.setLevel('INFO')
34
35class scale_exchange(CordLogger):
36 HOST = "10.1.0.1"
37 USER = "vagrant"
38 PASS = "vagrant"
39 head_node = os.getenv('HEAD_NODE', 'prod')
40 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
41 test_path = os.path.dirname(os.path.realpath(__file__))
42 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
43 restApiXos = None
44 subscriber_account_num = 100
45 subscriber_s_tag = 500
46 subscriber_c_tag = 500
47 subscribers_per_s_tag = 8
48 subscriber_map = {}
49 subscriber_info = []
50 volt_subscriber_info = []
51 restore_methods = []
52 TIMEOUT=120
53 NUM_SUBSCRIBERS = 100
54
55 @classmethod
56 def getSubscriberCredentials(cls, subId):
57 """Generate our own account num, s_tag and c_tags"""
58 if subId in cls.subscriber_map:
59 return cls.subscriber_map[subId]
60 account_num = cls.subscriber_account_num
61 cls.subscriber_account_num += 1
62 s_tag, c_tag = cls.subscriber_s_tag, cls.subscriber_c_tag
63 cls.subscriber_c_tag += 1
64 if cls.subscriber_c_tag % cls.subscribers_per_s_tag == 0:
65 cls.subscriber_s_tag += 1
66 cls.subscriber_map[subId] = account_num, s_tag, c_tag
67 return cls.subscriber_map[subId]
68
69 @classmethod
70 def getXosCredentials(cls):
71 onos_cfg = OnosCtrl.get_config()
72 if onos_cfg is None:
73 return None
74 if 'apps' in onos_cfg and \
75 'org.opencord.vtn' in onos_cfg['apps'] and \
76 'cordvtn' in onos_cfg['apps']['org.opencord.vtn'] and \
77 'xos' in onos_cfg['apps']['org.opencord.vtn']['cordvtn']:
78 xos_cfg = onos_cfg['apps']['org.opencord.vtn']['cordvtn']['xos']
79 endpoint = xos_cfg['endpoint']
80 user = xos_cfg['user']
81 password = xos_cfg['password']
82 xos_endpoints = endpoint.split(':')
83 xos_host = xos_endpoints[1][len('//'):]
84 xos_port = xos_endpoints[2][:-1]
85 #log.info('xos_host: %s, port: %s, user: %s, password: %s' %(xos_host, xos_port, user, password))
86 return dict(host = xos_host, port = xos_port, user = user, password = password)
87
88 return None
89
90 @classmethod
91 def getSubscriberConfig(cls, num_subscribers):
92 features = {
93 'cdn': True,
94 'uplink_speed': 1000000000,
95 'downlink_speed': 1000000000,
96 'uverse': True,
97 'status': 'enabled'
98 }
99 subscriber_map = []
100 for i in xrange(num_subscribers):
101 subId = 'sub{}'.format(i)
102 account_num, _, _ = cls.getSubscriberCredentials(subId)
103 identity = { 'account_num' : str(account_num),
104 'name' : 'My House {}'.format(i)
105 }
106 sub_info = { 'features' : features,
107 'identity' : identity
108 }
109 subscriber_map.append(sub_info)
110
111 return subscriber_map
112
113 @classmethod
114 def getVoltSubscriberConfig(cls, num_subscribers):
115 voltSubscriberMap = []
116 for i in xrange(num_subscribers):
117 subId = 'sub{}'.format(i)
118 account_num, s_tag, c_tag = cls.getSubscriberCredentials(subId)
119 voltSubscriberInfo = {}
120 voltSubscriberInfo['voltTenant'] = dict(s_tag = str(s_tag),
121 c_tag = str(c_tag),
122 subscriber = '')
123 voltSubscriberInfo['account_num'] = account_num
124 voltSubscriberMap.append(voltSubscriberInfo)
125
126 return voltSubscriberMap
127
128 @classmethod
129 def setUpCordApi(cls):
130 our_path = os.path.dirname(os.path.realpath(__file__))
131 cord_api_path = os.path.join(our_path, '..', 'cord-api')
132 framework_path = os.path.join(cord_api_path, 'Framework')
133 utils_path = os.path.join(framework_path, 'utils')
134 data_path = os.path.join(cord_api_path, 'Tests', 'data')
135 subscriber_cfg = os.path.join(data_path, 'Subscriber.json')
136 volt_tenant_cfg = os.path.join(data_path, 'VoltTenant.json')
137 num_subscribers = max(cls.NUM_SUBSCRIBERS, 10)
138 cls.subscriber_info = cls.getSubscriberConfig(num_subscribers)
139 cls.volt_subscriber_info = cls.getVoltSubscriberConfig(num_subscribers)
140
141 sys.path.append(utils_path)
142 sys.path.append(framework_path)
143 from restApi import restApi
144 restApiXos = restApi()
145 xos_credentials = cls.getXosCredentials()
146 if xos_credentials is None:
147 restApiXos.controllerIP = cls.HEAD_NODE
148 restApiXos.controllerPort = '9000'
149 else:
150 restApiXos.controllerIP = xos_credentials['host']
151 restApiXos.controllerPort = xos_credentials['port']
152 restApiXos.user = xos_credentials['user']
153 restApiXos.password = xos_credentials['password']
154 cls.restApiXos = restApiXos
155
156 @classmethod
157 def getVoltId(cls, result, subId):
158 if type(result) is not type([]):
159 return None
160 for tenant in result:
161 if str(tenant['subscriber']) == str(subId):
162 return str(tenant['id'])
163 return None
164
165 @classmethod
166 def setUpClass(cls):
167 cls.controllers = get_controllers()
168 cls.controller = cls.controllers[0]
169 cls.cli = None
170 cls.on_pod = running_on_pod()
171 cls.on_ciab = running_on_ciab()
172 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
173 cls.vcpes = cls.olt.get_vcpes()
174 cls.vcpes_dhcp = cls.olt.get_vcpes_by_type('dhcp')
175 cls.vcpes_reserved = cls.olt.get_vcpes_by_type('reserved')
176 cls.dhcp_vcpes_reserved = [ 'vcpe{}.{}.{}'.format(i, cls.vcpes_reserved[i]['s_tag'], cls.vcpes_reserved[i]['c_tag'])
177 for i in xrange(len(cls.vcpes_reserved)) ]
178 cls.untagged_dhcp_vcpes_reserved = [ 'vcpe{}'.format(i) for i in xrange(len(cls.vcpes_reserved)) ]
179 cls.container_vcpes_reserved = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_reserved ]
180 vcpe_dhcp_reserved = None
181 vcpe_container_reserved = None
182 if cls.vcpes_reserved:
183 vcpe_dhcp_reserved = cls.dhcp_vcpes_reserved[0]
184 if cls.on_pod is False:
185 vcpe_dhcp_reserved = cls.untagged_dhcp_vcpes_reserved[0]
186 vcpe_container_reserved = cls.container_vcpes_reserved[0]
187
188 cls.vcpe_dhcp_reserved = vcpe_dhcp_reserved
189 cls.vcpe_container_reserved = vcpe_container_reserved
190 dhcp_vcpe_offset = len(cls.vcpes_reserved)
191 cls.dhcp_vcpes = [ 'vcpe{}.{}.{}'.format(i+dhcp_vcpe_offset, cls.vcpes_dhcp[i]['s_tag'], cls.vcpes_dhcp[i]['c_tag'])
192 for i in xrange(len(cls.vcpes_dhcp)) ]
193 cls.untagged_dhcp_vcpes = [ 'vcpe{}'.format(i+dhcp_vcpe_offset) for i in xrange(len(cls.vcpes_dhcp)) ]
194 cls.container_vcpes = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_dhcp ]
195 vcpe_dhcp = None
196 vcpe_container = None
197 #cache the first dhcp vcpe in the class for quick testing
198 if cls.vcpes_dhcp:
199 vcpe_container = cls.container_vcpes[0]
200 vcpe_dhcp = cls.dhcp_vcpes[0]
201 if cls.on_pod is False:
202 vcpe_dhcp = cls.untagged_dhcp_vcpes[0]
203 cls.vcpe_container = vcpe_container_reserved or vcpe_container
204 cls.vcpe_dhcp = vcpe_dhcp_reserved or vcpe_dhcp
205 VSGAccess.setUp()
206 cls.setUpCordApi()
207 if cls.on_pod is True:
208 cls.openVCPEAccess(cls.volt_subscriber_info)
209
210 @classmethod
211 def tearDownClass(cls):
212 VSGAccess.tearDown()
213 if cls.on_pod is True:
214 cls.closeVCPEAccess(cls.volt_subscriber_info)
215
216 def log_set(self, level = None, app = 'org.onosproject'):
217 CordLogger.logSet(level = level, app = app, controllers = self.controllers, forced = True)
218
219 @classmethod
220 def config_restore(cls):
221 """Restore the vsg test configuration on test case failures"""
222 for restore_method in cls.restore_methods:
223 restore_method()
224
225 def vsg_xos_subscriber_id(self, index):
226 log.info('index and its type are %s, %s'%(index, type(index)))
227 volt_subscriber_info = self.volt_subscriber_info[index]
228 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
229 assert_not_equal(result, None)
230 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
231 return subId
232
233 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
234 if self.on_pod is False:
235 return ''
236 if subscriber_info is None:
237 subscriber_info = self.subscriber_info[index]
238 if volt_subscriber_info is None:
239 volt_subscriber_info = self.volt_subscriber_info[index]
240 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
241 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
242 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
243 log.info('Creating tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
244 subId = ''
245 try:
246 result = self.restApiXos.ApiPost('TENANT_SUBSCRIBER', subscriber_info)
247 assert_equal(result, True)
248 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
249 assert_not_equal(result, None)
250 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
251 assert_not_equal(subId, '0')
252 log.info('Subscriber ID for account num %s = %s' %(str(volt_subscriber_info['account_num']), subId))
253 volt_tenant = volt_subscriber_info['voltTenant']
254 #update the subscriber id in the tenant info before making the rest
255 volt_tenant['subscriber'] = subId
256 result = self.restApiXos.ApiPost('TENANT_VOLT', volt_tenant)
257 assert_equal(result, True)
258 #if the vsg instance was already instantiated, then reduce delay
259 if c_tag % self.subscribers_per_s_tag == 0:
260 delay = 350
261 else:
262 delay = 90
263 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
264 time.sleep(delay)
265 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
266 self.vsg_for_external_connectivity(index)
267 finally:
268 return subId
269
270 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None):
271 if self.on_pod is False:
272 return
273 if subscriber_info is None:
274 subscriber_info = self.subscriber_info[index]
275 if volt_subscriber_info is None:
276 volt_subscriber_info = self.volt_subscriber_info[index]
277 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
278 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
279 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
280 log.info('Deleting tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
281 if not subId:
282 #get the subscriber id first
283 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
284 assert_not_equal(result, None)
285 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
286 assert_not_equal(subId, '0')
287 if not voltId:
288 #get the volt id for the subscriber
289 result = self.restApiXos.ApiGet('TENANT_VOLT')
290 assert_not_equal(result, None)
291 voltId = self.getVoltId(result, subId)
292 assert_not_equal(voltId, None)
293 log.info('Deleting subscriber ID %s for account num %s' %(subId, str(volt_subscriber_info['account_num'])))
294 status = self.restApiXos.ApiDelete('TENANT_SUBSCRIBER', subId)
295 assert_equal(status, True)
296 #Delete the tenant
297 log.info('Deleting VOLT Tenant ID %s for subscriber %s' %(voltId, subId))
298 self.restApiXos.ApiDelete('TENANT_VOLT', voltId)
299
300 def test_scale_for_vsg_vm_creations(self):
301 for index in xrange(len(self.subscriber_info)):
302 #check if the index exists
303 subId = self.vsg_xos_subscriber_id(index)
304 log.info('test_vsg_xos_subscriber_creation')
305 if subId and subId != '0':
306 self.vsg_xos_subscriber_delete(index, subId = subId)
307 subId = self.vsg_xos_subscriber_create(index)
308 log.info('Created Subscriber %s' %(subId))
309
310 def test_scale_for_vcpe_creations(self):
311 for index in xrange(len(self.subscriber_info)):
312 #check if the index exists
313 subId = self.vsg_xos_subscriber_id(index)
314 log.info('test_vsg_xos_subscriber_creation')
315 if subId and subId != '0':
316 self.vsg_xos_subscriber_delete(index, subId = subId)
317 subId = self.vsg_xos_subscriber_create(index)
318 log.info('Created Subscriber %s' %(subId))
319
320 def test_scale_of_subcriber_vcpe_creations_in_single_vsg_vm(self):
321 subId = self.vsg_xos_subscriber_create(100)
322 if subId and subId != '0':
323 self.vsg_xos_subscriber_delete(100, subId)
324
325 def test_scale_for_cord_subscriber_creation_and_deletion(self):
326 subId = self.vsg_xos_subscriber_create(100)
327 if subId and subId != '0':
328 self.vsg_xos_subscriber_delete(100, subId)
329
330 def test_cord_for_scale_of_subscriber_containers_per_compute_node(self):
331 pass
332