Browse Source

eswitchd: improve error handling

This patch improve the error handling by adding try except.
It also make sure that the response will send as json.
This also fix ugly error when delete port failed because
it doesn't not exist.

Change-Id: I975c768926ecbafa8a608c0e1fff49d12c021e30
changes/22/743822/5
Moshe Levi 1 week ago
parent
commit
43681d3574
3 changed files with 39 additions and 28 deletions
  1. +2
    -4
      networking_mlnx/eswitchd/cli/ebrctl.py
  2. +1
    -1
      networking_mlnx/eswitchd/eswitch_daemon.py
  3. +36
    -23
      networking_mlnx/eswitchd/msg_handler.py

+ 2
- 4
networking_mlnx/eswitchd/cli/ebrctl.py View File

@@ -62,8 +62,7 @@ def add_port(args):
args.vnic_type, args.dev_name)

except exceptions.MlxException as e:
sys.stderr.write("Error in add-port command")
sys.stderr.write(e.message)
sys.stderr.write("Error in add-port command " + e.message)
sys.exit(1)
sys.stdout.write(dev)
sys.exit(0)
@@ -73,8 +72,7 @@ def del_port(args):
try:
client.deallocate_nic(args.vnic_mac, args.fabric)
except exceptions.MlxException as e:
sys.stderr.write("Error in del-port command")
sys.stderr.write(e.message)
sys.stderr.write("Error in del-port command " + e.message)
sys.exit(1)
sys.exit(0)



+ 1
- 1
networking_mlnx/eswitchd/eswitch_daemon.py View File

@@ -87,7 +87,7 @@ class MlxEswitchDaemon(object):
msg = jsonutils.dumps(result)
except Exception as e:
LOG.exception("Exception during message handling - %s", e)
msg = str(e)
msg = jsonutils.dumps(str(e))
sender.send_string(msg)

def daemon_loop(self):


+ 36
- 23
networking_mlnx/eswitchd/msg_handler.py View File

@@ -40,9 +40,7 @@ class BasicMessageHandler(object):
return ret

def validate_vnic_type(self, vnic_type):
if vnic_type in (constants.VIF_TYPE_HOSTDEV, ):
return True
return False
return vnic_type == constants.VIF_TYPE_HOSTDEV

def build_response(self, status, reason=None, response=None):
if status:
@@ -65,11 +63,14 @@ class PlugVnic(BasicMessageHandler):
vnic_mac = (self.msg['vnic_mac']).lower()
dev_name = self.msg['dev_name']

dev = eswitch_handler.plug_nic(fabric, device_id, vnic_mac, dev_name)
if dev:
return self.build_response(True, response={'dev': dev})
else:
return self.build_response(False, reason='Plug vnic failed')
try:
dev = eswitch_handler.plug_nic(
fabric, device_id, vnic_mac, dev_name)
if dev:
return self.build_response(True, response={'dev': dev})
except Exception as e:
LOG.error("Plug vnic failed - %s", str(e))
return self.build_response(False, reason='Plug vnic failed')


class DetachVnic(BasicMessageHandler):
@@ -81,11 +82,13 @@ class DetachVnic(BasicMessageHandler):
def execute(self, eswitch_handler):
fabric = self.msg['fabric']
vnic_mac = (self.msg['vnic_mac']).lower()
dev = eswitch_handler.delete_port(fabric, vnic_mac)
if dev:
return self.build_response(True, response={'dev': dev})
else:
return self.build_response(True, response={})
try:
dev = eswitch_handler.delete_port(fabric, vnic_mac)
if dev:
return self.build_response(True, response={'dev': dev})
except Exception as e:
LOG.warning("Detach vnic failed - %s", str(e))
return self.build_response(True, response={})


class SetVLAN(BasicMessageHandler):
@@ -98,13 +101,14 @@ class SetVLAN(BasicMessageHandler):
fabric = self.msg['fabric']
pci_slot = self.msg['pci_slot']
vlan = int(self.msg['vlan'])
ret = eswitch_handler.set_vlan(fabric, pci_slot, vlan)
reason = None
if not ret:
reason = 'Set VLAN Failed'
if reason:
return self.build_response(False, reason=reason)
return self.build_response(True, response={})
try:
ret = eswitch_handler.set_vlan(fabric, pci_slot, vlan)
if ret:
return self.build_response(True, response={})
except Exception as e:
LOG.error("Set Vlan failed - %s", str(e))
reason = 'Set VLAN Failed'
return self.build_response(False, reason=reason)


class GetVnics(BasicMessageHandler):
@@ -119,7 +123,10 @@ class GetVnics(BasicMessageHandler):
fabrics = None
else:
fabrics = [fabric]
vnics = eswitch_handler.get_vnics(fabrics)
try:
vnics = eswitch_handler.get_vnics(fabrics)
except Exception as e:
LOG.warning("GetVnics failed - %s", str(e))
return self.build_response(True, response=vnics)


@@ -170,7 +177,10 @@ class PortUp(BasicMessageHandler):
def execute(self, eswitch_handler):
fabric = self.msg['fabric']
pci_slot = self.msg['pci_slot']
eswitch_handler.port_up(fabric, pci_slot)
try:
eswitch_handler.port_up(fabric, pci_slot)
except Exception as e:
LOG.warning("Port up - %s", str(e))
return self.build_response(True, response={})


@@ -183,7 +193,10 @@ class PortDown(BasicMessageHandler):
def execute(self, eswitch_handler):
fabric = self.msg['fabric']
pci_slot = self.msg['pci_slot']
eswitch_handler.port_down(fabric, pci_slot)
try:
eswitch_handler.port_down(fabric, pci_slot)
except Exception as e:
LOG.warning("Port down failed - %s", str(e))
return self.build_response(True, response={})




Loading…
Cancel
Save