Browse Source

Merge "eswitchd: improve error handling" into stable/train

stable/train
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
9a85e1c67b
3 changed files with 30 additions and 26 deletions
  1. +2
    -4
      networking_mlnx/eswitchd/cli/ebrctl.py
  2. +1
    -1
      networking_mlnx/eswitchd/eswitch_daemon.py
  3. +27
    -21
      networking_mlnx/eswitchd/msg_handler.py

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

@@ -67,8 +67,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)
@@ -78,8 +77,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):


+ 27
- 21
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,13 @@ class SetVLAN(BasicMessageHandler):
fabric = self.msg['fabric']
vnic_mac = (self.msg['port_mac']).lower()
vlan = self.msg['vlan']
ret = eswitch_handler.set_vlan(fabric, vnic_mac, 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, vnic_mac, vlan)
if ret:
return self.build_response(True, response={})
except Exception as e:
LOG.error("Set Vlan failed - %s", str(e))
return self.build_response(False, reason='Set Vlan Failed')


class GetVnics(BasicMessageHandler):
@@ -120,7 +123,10 @@ class GetVnics(BasicMessageHandler):
LOG.info("fabrics = %s", fabrics)
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)




Loading…
Cancel
Save