[ 3195 ] Remove duplicate method add_port
Update to the device operations as follows:
1) Add a few test scenarios to test the device state transitions
2) Check whether there is a callback before removing it from the queue
3) Fix a port reference issue when disabling an ONU
4) Update the CLI to handle exceptions from the grpc server
Change-Id: Ic7f41e80279f41d9a4575da5dd49de11294a22d5
diff --git a/cli/main.py b/cli/main.py
index 05cee3b..f125634 100755
--- a/cli/main.py
+++ b/cli/main.py
@@ -285,23 +285,26 @@
"""
device_id = line or self.default_device_id
self.poutput('enabling {}'.format(device_id))
- stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
- stub.EnableDevice(voltha_pb2.ID(id=device_id))
+ try:
+ stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
+ stub.EnableDevice(voltha_pb2.ID(id=device_id))
- while True:
- device = stub.GetDevice(voltha_pb2.ID(id=device_id))
- # If this is an OLT then acquire logical device id
- if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
- if device.type.endswith('_olt'):
- assert device.parent_id
- self.default_logical_device_id = device.parent_id
- self.poutput('success (logical device id = {})'.format(
- self.default_logical_device_id))
- else:
- self.poutput('success (device id = {})'.format(device.id))
- break
- self.poutput('waiting for device to be enabled...')
- sleep(.5)
+ while True:
+ device = stub.GetDevice(voltha_pb2.ID(id=device_id))
+ # If this is an OLT then acquire logical device id
+ if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
+ if device.type.endswith('_olt'):
+ assert device.parent_id
+ self.default_logical_device_id = device.parent_id
+ self.poutput('success (logical device id = {})'.format(
+ self.default_logical_device_id))
+ else:
+ self.poutput('success (device id = {})'.format(device.id))
+ break
+ self.poutput('waiting for device to be enabled...')
+ sleep(.5)
+ except Exception, e:
+ self.poutput('Error enabling {}. Error:{}'.format(device_id, e))
complete_activate_olt = complete_device
@@ -311,9 +314,12 @@
"""
device_id = line or self.default_device_id
self.poutput('rebooting {}'.format(device_id))
- stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
- stub.RebootDevice(voltha_pb2.ID(id=device_id))
- self.poutput('rebooted {}'.format(device_id))
+ try:
+ stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
+ stub.RebootDevice(voltha_pb2.ID(id=device_id))
+ self.poutput('rebooted {}'.format(device_id))
+ except Exception, e:
+ self.poutput('Error rebooting {}. Error:{}'.format(device_id, e))
def do_delete(self, line):
"""
@@ -321,9 +327,12 @@
"""
device_id = line or self.default_device_id
self.poutput('deleting {}'.format(device_id))
- stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
- stub.DeleteDevice(voltha_pb2.ID(id=device_id))
- self.poutput('deleted {}'.format(device_id))
+ try:
+ stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
+ stub.DeleteDevice(voltha_pb2.ID(id=device_id))
+ self.poutput('deleted {}'.format(device_id))
+ except Exception, e:
+ self.poutput('Error deleting {}. Error:{}'.format(device_id, e))
def do_disable(self, line):
"""
@@ -331,20 +340,23 @@
"""
device_id = line
self.poutput('disabling {}'.format(device_id))
- stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
- stub.DisableDevice(voltha_pb2.ID(id=device_id))
+ try:
+ stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
+ stub.DisableDevice(voltha_pb2.ID(id=device_id))
- # Do device query and verify that the device admin status is
- # DISABLED and Operational Status is unknown
- device = stub.GetDevice(voltha_pb2.ID(id=device_id))
- if device.oper_status == voltha_pb2.OperStatus.UNKNOWN and \
- device.admin_state == voltha_pb2.AdminState.DISABLED:
- self.poutput('disabled successfully {}'.format(device_id))
- else:
- self.poutput('disabling failed {}. Admin State:{} '
- 'Operation State: {}'.format(device_id,
- device.admin_state,
- device.oper_status))
+ # Do device query and verify that the device admin status is
+ # DISABLED and Operational Status is unknown
+ device = stub.GetDevice(voltha_pb2.ID(id=device_id))
+ if device.oper_status == voltha_pb2.OperStatus.UNKNOWN and \
+ device.admin_state == voltha_pb2.AdminState.DISABLED:
+ self.poutput('disabled successfully {}'.format(device_id))
+ else:
+ self.poutput('disabling failed {}. Admin State:{} '
+ 'Operation State: {}'.format(device_id,
+ device.admin_state,
+ device.oper_status))
+ except Exception, e:
+ self.poutput('Error disabling {}. Error:{}'.format(device_id, e))
def do_test(self, line):
"""Enter test mode, which makes a bunch on new commands available"""
diff --git a/cli/utils.py b/cli/utils.py
index f4111e3..5ca0da5 100644
--- a/cli/utils.py
+++ b/cli/utils.py
@@ -153,7 +153,7 @@
table.print_table(header, printfn)
# see CORD-817 (https://jira.opencord.org/browse/CORD-817)
- assert len(groups) == 0
+ # assert len(groups) == 0
def dict2line(d):