blob: cf616c7fde378baaebc40c1b1189f7f2c365ea4d [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
A R Karthick35495c32017-05-11 14:58:32 -070017import requests
18import json
19import time
A.R Karthick57fa9372017-05-24 12:47:03 -070020import os
21import signal
A.R Karthick4c4d0492017-05-26 19:23:05 -070022from CordTestUtils import log_test as log, getstatusoutput, get_controller
A R Karthickbf1e4b02017-07-11 20:17:14 -070023from CordContainer import Container, Onos
A.R Karthick4c4d0492017-05-26 19:23:05 -070024from OnosCtrl import OnosCtrl
A.R Karthick4f583842017-06-09 17:15:47 -070025from OltConfig import OltConfig
A.R Karthick57fa9372017-05-24 12:47:03 -070026
27class VolthaService(object):
28 services = ('consul', 'kafka', 'zookeeper', 'registrator', 'fluentd')
A R Karthick168e2342017-08-15 16:13:10 -070029 standalone_services = ('chameleon', 'voltha', 'ofagent', 'vcli')
A.R Karthick57fa9372017-05-24 12:47:03 -070030 compose_file = 'docker-compose-system-test.yml'
31 service_map = {}
A R Karthick168e2342017-08-15 16:13:10 -070032 PROJECT = 'cordtester'
33 NETWORK = '{}_default'.format(PROJECT)
34 CONTAINER_MODE = False
35 REST_SERVICE = 'chameleon'
36 DOCKER_HOST_IP = '172.17.0.1'
37 PONSIM_HOST = '172.17.0.1'
A.R Karthick57fa9372017-05-24 12:47:03 -070038
A R Karthick168e2342017-08-15 16:13:10 -070039 def __init__(self, voltha_loc, controller, interface = 'eth0', olt_config = None, container_mode = False):
A.R Karthick57fa9372017-05-24 12:47:03 -070040 if not os.access(voltha_loc, os.F_OK):
41 raise Exception('Voltha location %s not found' %voltha_loc)
42 compose_file_loc = os.path.join(voltha_loc, 'compose', self.compose_file)
43 if not os.access(compose_file_loc, os.F_OK):
44 raise Exception('Voltha compose file %s not found' %compose_file_loc)
45 self.voltha_loc = voltha_loc
46 self.controller = controller
47 self.interface = interface
48 self.compose_file_loc = compose_file_loc
A R Karthick168e2342017-08-15 16:13:10 -070049 VolthaService.CONTAINER_MODE = container_mode
A.R Karthick4f583842017-06-09 17:15:47 -070050 num_onus = 1
51 if olt_config is not None:
52 port_map, _ = OltConfig(olt_config).olt_port_map()
53 if port_map['ponsim'] is True:
54 num_onus = max(1, len(port_map['ports']))
55 self.num_onus = num_onus
A.R Karthick57fa9372017-05-24 12:47:03 -070056
A R Karthick168e2342017-08-15 16:13:10 -070057 def start_services(self, *services):
58 services_fmt = ' {}' * len(services)
59 services_cmd_fmt = 'DOCKER_HOST_IP={} docker-compose -p {} -f {} up -d {}'.format(self.DOCKER_HOST_IP,
60 self.PROJECT,
61 self.compose_file_loc,
62 services_fmt)
63 start_cmd = services_cmd_fmt.format(*services)
A.R Karthick57fa9372017-05-24 12:47:03 -070064 ret = os.system(start_cmd)
65 if ret != 0:
66 raise Exception('Failed to start voltha services. Failed with code %d' %ret)
67
A R Karthick168e2342017-08-15 16:13:10 -070068 for service in services:
69 name = '{}_{}_1'.format(self.PROJECT, service)
A.R Karthick57fa9372017-05-24 12:47:03 -070070 cnt = Container(name, name)
A R Karthick168e2342017-08-15 16:13:10 -070071 ip = cnt.ip(network = self.NETWORK)
A.R Karthick57fa9372017-05-24 12:47:03 -070072 if not ip:
73 raise Exception('IP not found for container %s' %name)
74 print('IP %s for service %s' %(ip, service))
A R Karthick168e2342017-08-15 16:13:10 -070075 self.service_map[service] = dict(name = name, network = self.NETWORK, ip = ip)
A.R Karthick57fa9372017-05-24 12:47:03 -070076
A R Karthick168e2342017-08-15 16:13:10 -070077 def ponmgmt_enable(self):
78 cmds = ('echo 8 | tee /sys/class/net/ponmgmt/bridge/group_fwd_mask',
79 'brctl addif ponmgmt {} >/dev/null 2>&1'.format(self.interface),
80 )
81 for cmd in cmds:
82 try:
83 os.system(cmd)
84 except:
85 pass
86
87 def start(self):
88 self.start_services(*self.services)
89 if self.CONTAINER_MODE is True:
90 self.start_services(*self.standalone_services)
91 #enable multicast mac forwarding:
92 self.ponmgmt_enable()
A R Karthickd69d5702017-07-25 11:31:47 -070093 time.sleep(10)
A.R Karthickc2697a12017-05-24 14:01:15 -070094 else:
A R Karthick168e2342017-08-15 16:13:10 -070095 #first start chameleon
96 chameleon_start_cmd = "cd {} && sh -c '. ./env.sh && \
97 nohup python chameleon/main.py -v --consul=localhost:8500 \
98 --fluentd={}:24224 --grpc-endpoint=localhost:50555 \
99 >/tmp/chameleon.log 2>&1 &'".format(self.voltha_loc,
100 self.service_map['fluentd']['ip'])
101 if not self.service_running('python chameleon/main.py'):
102 ret = os.system(chameleon_start_cmd)
103 if ret != 0:
104 raise Exception('VOLTHA chameleon service not started. Failed with return code %d' %ret)
105 time.sleep(10)
106 else:
107 print('Chameleon voltha sevice is already running. Skipped start')
A.R Karthick57fa9372017-05-24 12:47:03 -0700108
A R Karthick168e2342017-08-15 16:13:10 -0700109 #now start voltha and ofagent
110 voltha_setup_cmd = "cd {} && sh -c '. ./env.sh && make rebuild-venv && make protos'".format(self.voltha_loc)
111 voltha_start_cmd = "cd {} && sh -c '. ./env.sh && \
112 nohup python voltha/main.py -v --consul=localhost:8500 --kafka={}:9092 -I {} \
113 --fluentd={}:24224 --rest-port=8880 --grpc-port=50555 \
114 >/tmp/voltha.log 2>&1 &'".format(self.voltha_loc,
115 self.service_map['kafka']['ip'],
116 self.interface,
117 self.service_map['fluentd']['ip'])
118 pki_dir = '{}/pki'.format(self.voltha_loc)
119 if not self.service_running('python voltha/main.py'):
120 voltha_pki_dir = '/voltha'
121 if os.access(pki_dir, os.F_OK):
122 pki_xfer_cmd = 'mkdir -p {} && cp -rv {}/pki {}'.format(voltha_pki_dir,
123 self.voltha_loc,
124 voltha_pki_dir)
125 os.system(pki_xfer_cmd)
126 #os.system(voltha_setup_cmd)
127 ret = os.system(voltha_start_cmd)
128 if ret != 0:
129 raise Exception('Failed to start VOLTHA. Return code %d' %ret)
130 time.sleep(10)
131 else:
132 print('VOLTHA core is already running. Skipped start')
A.R Karthick57fa9372017-05-24 12:47:03 -0700133
A R Karthick168e2342017-08-15 16:13:10 -0700134 ofagent_start_cmd = "cd {} && sh -c '. ./env.sh && \
135 nohup python ofagent/main.py -v --consul=localhost:8500 \
136 --fluentd={}:24224 --controller={}:6653 --grpc-endpoint=localhost:50555 \
137 >/tmp/ofagent.log 2>&1 &'".format(self.voltha_loc,
138 self.service_map['fluentd']['ip'],
139 self.controller)
140 if not self.service_running('python ofagent/main.py'):
141 ofagent_pki_dir = '/ofagent'
142 if os.access(pki_dir, os.F_OK):
143 pki_xfer_cmd = 'mkdir -p {} && cp -rv {}/pki {}'.format(ofagent_pki_dir,
144 self.voltha_loc,
145 ofagent_pki_dir)
146 os.system(pki_xfer_cmd)
147 ret = os.system(ofagent_start_cmd)
148 if ret != 0:
149 raise Exception('VOLTHA ofagent not started. Failed with return code %d' %ret)
150 time.sleep(10)
151 else:
152 print('VOLTHA ofagent is already running. Skipped start')
A.R Karthickc2697a12017-05-24 14:01:15 -0700153
A.R Karthick12e08c32017-05-30 17:09:26 -0700154 ponsim_start_cmd = "cd {} && sh -c '. ./env.sh && \
A.R Karthick4f583842017-06-09 17:15:47 -0700155 nohup python ponsim/main.py -o {} -v >/tmp/ponsim.log 2>&1 &'".format(self.voltha_loc, self.num_onus)
A.R Karthick12e08c32017-05-30 17:09:26 -0700156 if not self.service_running('python ponsim/main.py'):
157 ret = os.system(ponsim_start_cmd)
158 if ret != 0:
159 raise Exception('PONSIM not started. Failed with return code %d' %ret)
160 time.sleep(3)
161 else:
162 print('PONSIM already running. Skipped start')
163
A.R Karthickc2697a12017-05-24 14:01:15 -0700164 def service_running(self, pattern):
165 st, _ = getstatusoutput('pgrep -f "{}"'.format(pattern))
166 return True if st == 0 else False
A.R Karthick57fa9372017-05-24 12:47:03 -0700167
168 def kill_service(self, pattern):
169 st, output = getstatusoutput('pgrep -f "{}"'.format(pattern))
170 if st == 0 and output:
171 pids = output.strip().splitlines()
172 for pid in pids:
173 try:
174 os.kill(int(pid), signal.SIGKILL)
175 except:
176 pass
177
178 def stop(self):
A R Karthick168e2342017-08-15 16:13:10 -0700179 if self.CONTAINER_MODE is False:
180 self.kill_service('python voltha/main.py')
181 self.kill_service('python ofagent/main.py')
182 self.kill_service('python chameleon/main.py')
183 self.kill_service('python ponsim/main.py')
184 service_stop_cmd = 'DOCKER_HOST_IP={} docker-compose -p {} -f {} down'.format(self.DOCKER_HOST_IP,
185 self.PROJECT,
186 self.compose_file_loc)
A.R Karthick57fa9372017-05-24 12:47:03 -0700187 os.system(service_stop_cmd)
A R Karthick35495c32017-05-11 14:58:32 -0700188
A R Karthick168e2342017-08-15 16:13:10 -0700189 @classmethod
190 def get_ip(cls, service):
191 if service in cls.service_map:
192 return cls.service_map[service]['ip']
193 if service == cls.REST_SERVICE:
194 return os.getenv('VOLTHA_HOST', None)
195 return None
196
197 @classmethod
198 def get_network(cls, service):
199 if service in cls.service_map:
200 return cls.service_map[service]['network']
201 return None
202
A R Karthick35495c32017-05-11 14:58:32 -0700203class VolthaCtrl(object):
A R Karthick53442712017-07-27 12:23:30 -0700204 UPLINK_VLAN_START = 333
A.R Karthick4c4d0492017-05-26 19:23:05 -0700205 UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
A R Karthickbf1e4b02017-07-11 20:17:14 -0700206 REST_PORT = 8881
A R Karthick53442712017-07-27 12:23:30 -0700207 HOST = '172.17.0.1'
A R Karthick6e70e142017-07-28 15:25:38 -0700208 ONOS_APPS = ('org.onosproject.dhcp', 'org.onosproject.dhcp-relay', 'org.ciena.cordigmp')
A.R Karthick4c4d0492017-05-26 19:23:05 -0700209
A R Karthick53442712017-07-27 12:23:30 -0700210 def __init__(self, host = HOST, rest_port = REST_PORT, uplink_vlan_map = UPLINK_VLAN_MAP, uplink_vlan_start = UPLINK_VLAN_START):
A R Karthick35495c32017-05-11 14:58:32 -0700211 self.host = host
212 self.rest_port = rest_port
213 self.rest_url = 'http://{}:{}/api/v1'.format(host, rest_port)
A.R Karthick4c4d0492017-05-26 19:23:05 -0700214 self.uplink_vlan_map = uplink_vlan_map
A R Karthick53442712017-07-27 12:23:30 -0700215 VolthaCtrl.UPLINK_VLAN_START = uplink_vlan_start
A.R Karthick4c4d0492017-05-26 19:23:05 -0700216 self.switches = []
217 self.switch_map = {}
218
219 def config(self, fake = False):
220 devices = OnosCtrl.get_devices()
221 if not devices:
222 return self.switch_map
223 voltha_devices = filter(lambda d: not d['mfr'].startswith('Nicira'), devices)
224 self.switches = voltha_devices
225 device_config = { 'devices' : { } }
226 device_id = None
227 for device in voltha_devices:
228 device_id = device['id']
229 ports = OnosCtrl.get_ports_device(device_id)
230 nni_ports = filter(lambda p: p['isEnabled'] and 'annotations' in p and p['annotations']['portName'].startswith('nni'), ports)
231 uni_ports = filter(lambda p: p['isEnabled'] and 'annotations' in p and p['annotations']['portName'].startswith('uni'), ports)
232 if device_id not in self.uplink_vlan_map:
A R Karthick53442712017-07-27 12:23:30 -0700233 uplink_vlan = VolthaCtrl.UPLINK_VLAN_START
234 VolthaCtrl.UPLINK_VLAN_START += 1
235 log.info('Voltha device %s not in map. Using uplink vlan %d' %(device_id, uplink_vlan))
236 else:
237 uplink_vlan = self.uplink_vlan_map[device_id]
A.R Karthick4c4d0492017-05-26 19:23:05 -0700238 if not nni_ports:
239 log.info('Voltha device %s has no NNI ports' %device_id)
240 if fake is True:
241 log.info('Faking NNI port 0')
242 nni_ports = [ {'port': '0'} ]
243 else:
244 log.info('Skip configuring device %s' %device_id)
245 continue
246 if not uni_ports:
247 log.info('Voltha device %s has no UNI ports' %device_id)
248 if fake is True:
249 log.info('Faking UNI port 252')
250 uni_ports = [ {'port': '252'} ]
251 else:
252 log.info('Skip configuring device %s' %device_id)
253 continue
A.R Karthick4c4d0492017-05-26 19:23:05 -0700254 onu_ports = map(lambda uni: uni['port'], uni_ports)
255 self.switch_map[device_id] = dict(uplink_vlan = uplink_vlan, ports = onu_ports)
256 device_config['devices'][device_id] = {}
257 device_config['devices'][device_id]['basic'] = dict(driver='pmc-olt')
258 device_config['devices'][device_id]['accessDevice'] = dict(uplink=nni_ports[0]['port'],
259 vlan = uplink_vlan,
260 defaultVlan='0'
261 )
262 if device_id:
263 #toggle drivers/openflow base before reconfiguring the driver and olt config data
264 OnosCtrl('org.onosproject.drivers').deactivate()
265 OnosCtrl('org.onosproject.openflow-base').deactivate()
266 OnosCtrl.config(device_config)
A R Karthick6e70e142017-07-28 15:25:38 -0700267 time.sleep(10)
A.R Karthick4c4d0492017-05-26 19:23:05 -0700268 OnosCtrl('org.onosproject.drivers').activate()
269 OnosCtrl('org.onosproject.openflow-base').activate()
270 time.sleep(5)
A R Karthick6e70e142017-07-28 15:25:38 -0700271 log.info('Reactivating CORD and ONOS apps')
272 Onos.activate_cord_apps(deactivate = True)
273 Onos.activate_apps(self.ONOS_APPS, deactivate = True)
A.R Karthick4c4d0492017-05-26 19:23:05 -0700274
275 return self.switch_map
A R Karthick35495c32017-05-11 14:58:32 -0700276
277 def get_devices(self):
278 url = '{}/local/devices'.format(self.rest_url)
279 resp = requests.get(url)
280 if resp.ok is not True or resp.status_code != 200:
281 return None
282 return resp.json()
283
A.R Karthick8b9c5f12017-05-30 17:47:08 -0700284 def enable_device(self, olt_type, olt_mac = None, address = None):
A R Karthick35495c32017-05-11 14:58:32 -0700285 url = '{}/local/devices'.format(self.rest_url)
A.R Karthick8b9c5f12017-05-30 17:47:08 -0700286 if olt_mac is None and address is None:
287 log.error('Either olt mac or address needs to be specified')
A.R Karthick8a507cf2017-06-02 18:44:49 -0700288 return None, False
A.R Karthick8b9c5f12017-05-30 17:47:08 -0700289 if olt_mac is not None:
290 device_config = { 'type' : olt_type, 'mac_address' : olt_mac }
291 else:
A R Karthick31a40172017-08-14 12:06:09 -0700292 if len(address.split(':')) > 1:
293 device_config = { 'type' : olt_type, 'host_and_port' : address }
294 else:
295 device_config = { 'type' : olt_type, 'ipv4_address' : address }
A R Karthick35495c32017-05-11 14:58:32 -0700296 #pre-provision
A.R Karthick8b9c5f12017-05-30 17:47:08 -0700297 if olt_mac is not None:
298 log.info('Pre-provisioning %s with mac %s' %(olt_type, olt_mac))
299 else:
A R Karthick168e2342017-08-15 16:13:10 -0700300 log.info('Pre-provisioning %s with address %s, url %s' %(olt_type, address, url))
A R Karthick35495c32017-05-11 14:58:32 -0700301 resp = requests.post(url, data = json.dumps(device_config))
302 if resp.ok is not True or resp.status_code != 200:
A.R Karthick8a507cf2017-06-02 18:44:49 -0700303 return None, False
A R Karthick35495c32017-05-11 14:58:32 -0700304 device_id = resp.json()['id']
305 log.info('Enabling device %s' %(device_id))
306 enable_url = '{}/{}/enable'.format(url, device_id)
307 resp = requests.post(enable_url)
308 if resp.ok is not True or resp.status_code != 200:
A.R Karthick8a507cf2017-06-02 18:44:49 -0700309 return None, False
A R Karthick35495c32017-05-11 14:58:32 -0700310 #get operational status
A R Karthick090631b2017-07-25 16:05:05 -0700311 time.sleep(10)
A R Karthick35495c32017-05-11 14:58:32 -0700312 log.info('Checking operational status for device %s' %(device_id))
313 resp = requests.get('{}/{}'.format(url, device_id))
314 if resp.ok is not True or resp.status_code != 200:
A.R Karthick8a507cf2017-06-02 18:44:49 -0700315 return device_id, False
A R Karthick35495c32017-05-11 14:58:32 -0700316 device_info = resp.json()
317 if device_info['oper_status'] != 'ACTIVE' or \
318 device_info['admin_state'] != 'ENABLED' or \
319 device_info['connect_status'] != 'REACHABLE':
A.R Karthick8a507cf2017-06-02 18:44:49 -0700320 return device_id, False
A R Karthick35495c32017-05-11 14:58:32 -0700321
A.R Karthick8a507cf2017-06-02 18:44:49 -0700322 return device_id, True
323
324 def disable_device(self, device_id, delete = True):
325 log.info('Disabling device %s' %(device_id))
326 disable_url = '{}/local/devices/{}/disable'.format(self.rest_url, device_id)
327 resp = requests.post(disable_url)
328 if resp.ok is not True or resp.status_code != 200:
329 return False
330 if delete is True:
A R Karthickd69d5702017-07-25 11:31:47 -0700331 #rest for disable completion
332 time.sleep(10)
A.R Karthick8a507cf2017-06-02 18:44:49 -0700333 log.info('Deleting device %s' %(device_id))
334 delete_url = '{}/local/devices/{}/delete'.format(self.rest_url, device_id)
335 resp = requests.delete(delete_url)
336 if resp.status_code not in [204, 202, 200]:
337 return False
A R Karthick35495c32017-05-11 14:58:32 -0700338 return True
Chetan Gaonker3620a112017-05-23 06:10:15 +0000339
Thangavelu K Se6c77c72017-06-23 21:28:48 +0000340 def restart_device(self, device_id):
341 log.info('Restarting olt or onu device %s' %(device_id))
342 disable_url = '{}/local/devices/{}/restart'.format(self.rest_url, device_id)
343 resp = requests.post(disable_url)
344 if resp.ok is not True or resp.status_code != 200:
345 return False
346 return True
347
348 def pause_device(self, device_id):
349 log.info('Restarting olt or onu device %s' %(device_id))
350 disable_url = '{}/local/devices/{}/pause'.format(self.rest_url, device_id)
351 resp = requests.post(disable_url)
352 if resp.ok is not True or resp.status_code != 200:
353 return False
354 return True
355
Chetan Gaonker3620a112017-05-23 06:10:15 +0000356 def get_operational_status(self, device_id):
357 url = '{}/local/devices'.format(self.rest_url)
358 log.info('Checking operational status for device %s' %(device_id))
359 resp = requests.get('{}/{}'.format(url, device_id))
360 if resp.ok is not True or resp.status_code != 200:
361 return False
362 device_info = resp.json()
363 if device_info['oper_status'] != 'ACTIVE' or \
364 device_info['admin_state'] != 'ENABLED' or \
365 device_info['connect_status'] != 'REACHABLE':
366 return False
367 return True
368
369 def check_preprovision_status(self, device_id):
370 url = '{}/local/devices'.format(self.rest_url)
371 log.info('Check if device %s is in Preprovisioning state'%(device_id))
372 resp = requests.get('{}/{}'.format(url, device_id))
373 if resp.ok is not True or resp.status_code != 200:
374 return False
375 device_info = resp.json()
376 if device_info['admin_status'] == 'PREPROVISIONED':
377 return True
378 return False
A R Karthickbf1e4b02017-07-11 20:17:14 -0700379
380def get_olt_app():
381 our_path = os.path.dirname(os.path.realpath(__file__))
382 version = Onos.getVersion()
383 major = int(version.split('.')[0])
384 minor = int(version.split('.')[1])
385 olt_app_version = '1.2-SNAPSHOT'
386 if major > 1:
387 olt_app_version = '2.0-SNAPSHOT'
388 elif major == 1:
389 if minor > 10:
390 olt_app_version = '2.0-SNAPSHOT'
391 elif minor <= 8:
392 olt_app_version = '1.1-SNAPSHOT'
393 olt_app_file = os.path.join(our_path, '..', 'apps/olt-app-{}.oar'.format(olt_app_version))
394 return olt_app_file
395
A R Karthick168e2342017-08-15 16:13:10 -0700396def voltha_setup(host = '172.17.0.1', ponsim_host = VolthaService.PONSIM_HOST, olt_ip = None, rest_port = VolthaCtrl.REST_PORT,
A R Karthick9dc6e922017-07-12 14:40:16 -0700397 olt_type = 'ponsim_olt', olt_mac = '00:0c:e2:31:12:00',
A R Karthickbf1e4b02017-07-11 20:17:14 -0700398 uplink_vlan_map = VolthaCtrl.UPLINK_VLAN_MAP,
A R Karthick53442712017-07-27 12:23:30 -0700399 uplink_vlan_start = VolthaCtrl.UPLINK_VLAN_START,
A R Karthickbf1e4b02017-07-11 20:17:14 -0700400 config_fake = False, olt_app = None):
401
A R Karthick53442712017-07-27 12:23:30 -0700402 voltha = VolthaCtrl(host, rest_port = rest_port,
403 uplink_vlan_map = uplink_vlan_map,
404 uplink_vlan_start = uplink_vlan_start)
A R Karthickbf1e4b02017-07-11 20:17:14 -0700405 if olt_type.startswith('ponsim'):
A R Karthick168e2342017-08-15 16:13:10 -0700406 ponsim_address = '{}:50060'.format(ponsim_host)
A R Karthickbf1e4b02017-07-11 20:17:14 -0700407 log.info('Enabling ponsim olt')
408 device_id, status = voltha.enable_device(olt_type, address = ponsim_address)
409 else:
A R Karthick31a40172017-08-14 12:06:09 -0700410 if olt_type.startswith('maple'):
411 if olt_ip:
412 log.info('Enabling %s' %olt_type)
413 device_id, status = voltha.enable_device(olt_type, address = olt_ip)
414 else:
415 log.info('OLT IP needs to be specified for maple olt')
416 else:
417 log.info('Enabling OLT instance for %s with mac %s' %(olt_type, olt_mac))
418 device_id, status = voltha.enable_device(olt_type, olt_mac)
A R Karthickbf1e4b02017-07-11 20:17:14 -0700419
420 if device_id is None or status is False:
A R Karthick9dc6e922017-07-12 14:40:16 -0700421 if device_id:
422 voltha.disable_device(device_id)
A R Karthickbf1e4b02017-07-11 20:17:14 -0700423 return None
424
425 switch_map = None
426 olt_installed = False
427 if olt_app is None:
428 olt_app = get_olt_app()
429 try:
A R Karthick090631b2017-07-25 16:05:05 -0700430 time.sleep(5)
A R Karthickbf1e4b02017-07-11 20:17:14 -0700431 switch_map = voltha.config(fake = config_fake)
432 if switch_map is None:
433 voltha.disable_device(device_id)
434 return None
435 log.info('Installing OLT app %s' %olt_app)
436 OnosCtrl.install_app(olt_app)
437 olt_installed = True
438 time.sleep(5)
439 return voltha, device_id, switch_map
440 except:
441 voltha.disable_device(device_id)
442 time.sleep(10)
443 if olt_installed is True:
444 log.info('Uninstalling OLT app %s' %olt_app)
445 OnosCtrl.uninstall_app(olt_app)
446
447 return None
448
449def voltha_teardown(voltha_ctrl, device_id, switch_map, olt_app = None):
450 voltha_ctrl.disable_device(device_id)
451 time.sleep(10)
452 if olt_app is None:
453 olt_app = get_olt_app()
A R Karthickdd064632017-07-12 13:02:17 -0700454 log.info('Uninstalling OLT app %s' %olt_app)
A R Karthickbf1e4b02017-07-11 20:17:14 -0700455 OnosCtrl.uninstall_app(olt_app)