def rollback(db, port, fwfile): """Config muxcable firmware rollback""" port = platform_sfputil_helper.get_interface_alias(port, db) delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP") delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD") if port is not None and port != "all": res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "rollback_firmware", "status", "0", "XCVRD_ROLL_FW_CMD", "XCVRD_ROLL_FW_RSP", port, 60, fwfile) delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP") delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD") rc = res_dict[0] if rc == 0: click.echo("Success in rollback firmware port {} fwfile {}".format( port, fwfile)) else: click.echo( "ERR: Unable to rollback firmware port {} fwfile {}".format( port, fwfile)) sys.exit(CONFIG_FAIL) elif port == "all": logical_port_list = platform_sfputil_helper.get_logical_list() rc_exit = True for port in logical_port_list: if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list( port) if not isinstance(physical_port_list, list): continue if len(physical_port_list) != 1: continue physical_port = physical_port_list[0] logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical( ) logical_port_list_per_port = logical_port_list_for_physical_port.get( physical_port, None) """ This check is required for checking whether or not this logical port is the one which is actually mapped to physical port and by convention it is always the first port. TODO: this should be removed with more logic to check which logical port maps to actual physical port being used""" if port != logical_port_list_per_port[0]: continue res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "rollback_firmware", "status", "0", "XCVRD_ROLL_FW_CMD", "XCVRD_ROLL_FW_RSP", port, 60, fwfile) delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP") delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD") rc = res_dict[0] if rc == 0: click.echo( "Success in rollback firmware port {} fwfile {}".format( port, fwfile)) else: click.echo( "ERR: Unable to rollback firmware port {} fwfile {}". format(port, fwfile)) rc_exit = CONFIG_FAIL sys.exit(rc_exit)
def setswitchmode(db, state, port): """Configure the muxcable mux switching mode {auto/manual}""" port = platform_sfputil_helper.get_interface_alias(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP") if port is not None and port != "all": click.confirm(( 'Muxcable at port {} will be changed to {} switching mode. Continue?' .format(port, state)), abort=True) res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "config", "result", "True", "XCVRD_CONFIG_HWMODE_SWMODE_CMD", "XCVRD_CONFIG_HWMODE_SWMODE_RSP", port, 1, state) rc = res_dict[0] delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP") if rc == 0: click.echo("Success in switch muxcable mode port {} to {}".format( port, state)) else: click.echo( "ERR: Unable to switch muxcable mode port {} to {}".format( port, state)) sys.exit(CONFIG_FAIL) elif port == "all": click.confirm(( 'Muxcable at all ports will be changed to {} switching mode. Continue?' .format(state)), abort=True) logical_port_list = platform_sfputil_helper.get_logical_list() rc_exit = 0 for port in logical_port_list: if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list( port) if not isinstance(physical_port_list, list): continue if len(physical_port_list) != 1: continue physical_port = physical_port_list[0] logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical( ) logical_port_list_per_port = logical_port_list_for_physical_port.get( physical_port, None) """ This check is required for checking whether or not this logical port is the one which is actually mapped to physical port and by convention it is always the first port. TODO: this should be removed with more logic to check which logical port maps to actual physical port being used""" if port != logical_port_list_per_port[0]: continue res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "config", "result", "True", "XCVRD_CONFIG_HWMODE_SWMODE_CMD", "XCVRD_CONFIG_HWMODE_SWMODE_RSP", port, 1, state) rc = res_dict[0] delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP") if rc == 0: click.echo("Success in toggling port {} to {}".format( port, state)) else: click.echo("ERR: Unable to toggle port {} to {}".format( port, state)) rc_exit = CONFIG_FAIL sys.exit(rc_exit)
def muxdirection(port): """Shows the current direction of the muxcable {active/standy}""" per_npu_statedb = {} transceiver_table_keys = {} transceiver_dict = {} # Getting all front asic namespace and correspding config and state DB connector namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB) transceiver_table_keys[asic_id] = per_npu_statedb[asic_id].keys( per_npu_statedb[asic_id].STATE_DB, 'TRANSCEIVER_INFO|*') if port is not None: logical_port_list = platform_sfputil_helper.get_logical_list() if port not in logical_port_list: click.echo( "ERR: This is not a valid port, valid ports ({})".format( ", ".join(logical_port_list))) sys.exit(EXIT_FAIL) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.get_asic_id_for_logical_port( port) if asic_index is None: # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base # is fully mocked import sonic_platform_base.sonic_sfp.sfputilhelper asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper( ).get_asic_id_for_logical_port(port) if asic_index is None: click.echo( "Got invalid asic index for port {}, cant retreive mux status" .format(port)) sys.exit(CONFIG_FAIL) transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "manufacturer", "TRANSCEIVER_INFO") model_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "model", "TRANSCEIVER_INFO") """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL: click.echo( "ERR: Got invalid vendor value and model for port {}".format( port)) sys.exit(EXIT_FAIL) if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list( port) if not isinstance(physical_port_list, list): click.echo( ("ERR: Unable to locate physical port information for {}". format(port))) sys.exit(EXIT_FAIL) if len(physical_port_list) != 1: click.echo( "ERR: Found multiple physical ports ({}) associated with {}". format(", ".join(physical_port_list), port)) sys.exit(EXIT_FAIL) physical_port = physical_port_list[0] logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical( ) logical_port_list_per_port = logical_port_list_for_physical_port.get( physical_port, None) """ This check is required for checking whether or not this logical port is the one which is actually mapped to physical port and by convention it is always the first port. TODO: this should be removed with more logic to check which logical port maps to actual physical port being used""" if port != logical_port_list_per_port[0]: click.echo( "ERR: This logical Port {} is not on a muxcable".format(port)) sys.exit(EXIT_FAIL) import sonic_y_cable.y_cable read_side = sonic_y_cable.y_cable.check_read_side(physical_port) if read_side == False or read_side == -1: click.echo( ("ERR: Unable to get read_side for the cable port {}".format( port))) sys.exit(EXIT_FAIL) mux_direction = sonic_y_cable.y_cable.check_mux_direction( physical_port) if mux_direction == False or mux_direction == -1: click.echo( ("ERR: Unable to get mux direction for the cable port {}". format(port))) sys.exit(EXIT_FAIL) if int(read_side) == 1: if mux_direction == 1: state = "active" elif mux_direction == 2: state = "standby" elif int(read_side) == 2: if mux_direction == 1: state = "standby" elif mux_direction == 2: state = "active" else: click.echo( ("ERR: Unable to get mux direction, port {}".format(port))) state = "unknown" headers = ['Port', 'Direction'] body = [[port, state]] click.echo(tabulate(body, headers=headers)) else: logical_port_list = platform_sfputil_helper.get_logical_list() rc = True body = [] for port in logical_port_list: temp_list = [] if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list( port) if not isinstance(physical_port_list, list): continue if len(physical_port_list) != 1: continue asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.get_asic_id_for_logical_port( port) if asic_index is None: # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base # is fully mocked import sonic_platform_base.sonic_sfp.sfputilhelper asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper( ).get_asic_id_for_logical_port(port) if asic_index is None: continue transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = transceiver_dict[asic_index].get( "manufacturer", None) model_value = transceiver_dict[asic_index].get("model", None) """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL: continue physical_port = physical_port_list[0] logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical( ) logical_port_list_per_port = logical_port_list_for_physical_port.get( physical_port, None) """ This check is required for checking whether or not this logical port is the one which is actually mapped to physical port and by convention it is always the first port. TODO: this should be removed with more logic to check which logical port maps to actual physical port being used""" if port != logical_port_list_per_port[0]: continue import sonic_y_cable.y_cable read_side = sonic_y_cable.y_cable.check_read_side(physical_port) if read_side == False or read_side == -1: rc = False temp_list.append(port) temp_list.append("unknown") body.append(temp_list) continue mux_direction = sonic_y_cable.y_cable.check_mux_direction( physical_port) if mux_direction == False or mux_direction == -1: rc = False temp_list.append(port) temp_list.append("unknown") body.append(temp_list) continue if int(read_side) == 1: if mux_direction == 1: state = "active" elif mux_direction == 2: state = "standby" elif int(read_side) == 2: if mux_direction == 1: state = "standby" elif mux_direction == 2: state = "active" else: rc = False temp_list.append(port) temp_list.append("unknown") body.append(temp_list) continue temp_list.append(port) temp_list.append(state) body.append(temp_list) headers = ['Port', 'Direction'] click.echo(tabulate(body, headers=headers)) if rc == False: sys.exit(EXIT_FAIL)
def setswitchmode(state, port): """Configure the muxcable mux switching mode {auto/manual}""" per_npu_statedb = {} transceiver_dict = {} # Getting all front asic namespace and correspding config and state DB connector namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB) if port is not None and port != "all": click.confirm(( 'Muxcable at port {} will be changed to {} switching mode. Continue?' .format(port, state)), abort=True) logical_port_list = platform_sfputil_helper.get_logical_list() if port not in logical_port_list: click.echo( "ERR: This is not a valid port, valid ports ({})".format( ", ".join(logical_port_list))) sys.exit(CONFIG_FAIL) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.get_asic_id_for_logical_port( port) if asic_index is None: # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base # is fully mocked import sonic_platform_base.sonic_sfp.sfputilhelper asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper( ).get_asic_id_for_logical_port(port) if asic_index is None: click.echo( "Got invalid asic index for port {}, cant retreive mux status" .format(port)) sys.exit(CONFIG_FAIL) if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list( port) if not isinstance(physical_port_list, list): click.echo( ("ERR: Unable to locate physical port information for {}". format(port))) sys.exit(CONFIG_FAIL) if len(physical_port_list) != 1: click.echo( "ERR: Found multiple physical ports ({}) associated with {}". format(", ".join(physical_port_list), port)) sys.exit(CONFIG_FAIL) transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "manufacturer", "TRANSCEIVER_INFO") model_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "model", "TRANSCEIVER_INFO") """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value): click.echo( "ERR: Got invalid vendor value and model for port {}".format( port)) sys.exit(CONFIG_FAIL) physical_port = physical_port_list[0] logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical( ) logical_port_list_per_port = logical_port_list_for_physical_port.get( physical_port, None) """ This check is required for checking whether or not this logical port is the one which is actually mapped to physical port and by convention it is always the first port. TODO: this should be removed with more logic to check which logical port maps to actual physical port being used""" if port != logical_port_list_per_port[0]: click.echo( "ERR: This logical Port {} is not on a muxcable".format(port)) sys.exit(CONFIG_FAIL) if state == "auto": mode = sonic_y_cable.y_cable.SWITCHING_MODE_AUTO elif state == "manual": mode = sonic_y_cable.y_cable.SWITCHING_MODE_MANUAL import sonic_y_cable.y_cable result = sonic_y_cable.y_cable.set_switching_mode(physical_port, mode) if result == False: click.echo( ("ERR: Unable to set switching mode for the cable port {}". format(port))) sys.exit(CONFIG_FAIL) click.echo("Success in switching mode on port {} to {}".format( port, state)) elif port == "all" and port is not None: click.confirm(( 'Muxcable at port {} will be changed to {} switching mode. Continue?' .format(port, state)), abort=True) logical_port_list = platform_sfputil_helper.get_logical_list() rc = True for port in logical_port_list: if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list( port) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.get_asic_id_for_logical_port( port) if asic_index is None: # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base # is fully mocked import sonic_platform_base.sonic_sfp.sfputilhelper asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper( ).get_asic_id_for_logical_port(port) if asic_index is None: click.echo( "Got invalid asic index for port {}, cant retreive mux status" .format(port)) if not isinstance(physical_port_list, list): click.echo( ("ERR: Unable to locate physical port information for {}". format(port))) continue if len(physical_port_list) != 1: click.echo( "ERR: Found multiple physical ports ({}) associated with {}" .format(", ".join(physical_port_list), port)) continue transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = transceiver_dict[asic_index].get( "manufacturer", None) model_value = transceiver_dict[asic_index].get("model", None) """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or not re.match( VENDOR_MODEL_REGEX, model_value): continue physical_port = physical_port_list[0] logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical( ) logical_port_list_per_port = logical_port_list_for_physical_port.get( physical_port, None) """ This check is required for checking whether or not this logical port is the one which is actually mapped to physical port and by convention it is always the first port. TODO: this should be removed with more logic to check which logical port maps to actual physical port being used""" if port != logical_port_list_per_port[0]: continue if state == "auto": mode = sonic_y_cable.y_cable.SWITCHING_MODE_AUTO elif state == "manual": mode = sonic_y_cable.y_cable.SWITCHING_MODE_MANUAL import sonic_y_cable.y_cable result = sonic_y_cable.y_cable.set_switching_mode( physical_port, mode) if result == False: rc = False click.echo( "ERR: Unable to set switching mode on port {} to {}". format(port, state)) click.echo("Success in switching mode on port {} to {}".format( port, state)) if rc == False: click.echo( "ERR: Unable to set switching mode one or more ports to {}". format(state)) sys.exit(CONFIG_FAIL)
def switchmode(db, port): """Shows the current switching mode of the muxcable {auto/manual}""" port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP") if port is not None: res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", "XCVRD_SHOW_HWMODE_SWMODE_RSP", port, 1, "probe") body = [] temp_list = [] headers = ['Port', 'Switching'] port = platform_sfputil_helper.get_interface_alias(port, db) temp_list.append(port) temp_list.append(res_dict[1]) body.append(temp_list) rc = res_dict[0] click.echo(tabulate(body, headers=headers)) delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP") return rc else: logical_port_list = platform_sfputil_helper.get_logical_list() rc_exit = True body = [] for port in logical_port_list: if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port) if not isinstance(physical_port_list, list): continue if len(physical_port_list) != 1: continue physical_port = physical_port_list[0] logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical() logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None) """ This check is required for checking whether or not this logical port is the one which is actually mapped to physical port and by convention it is always the first port. TODO: this should be removed with more logic to check which logical port maps to actual physical port being used""" if port != logical_port_list_per_port[0]: continue temp_list = [] res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", "XCVRD_SHOW_HWMODE_SWMODE_RSP", port, 1, "probe") port = platform_sfputil_helper.get_interface_alias(port, db) temp_list.append(port) temp_list.append(res_dict[1]) rc = res_dict[1] if rc != 0: rc_exit = False body.append(temp_list) delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP") headers = ['Port', 'Switching'] click.echo(tabulate(body, headers=headers)) if rc_exit == False: sys.exit(EXIT_FAIL)