Skip to content

Commit

Permalink
[sonic_y_cable] fix the unpacking (sonic-net#135)
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya <[email protected]>
  • Loading branch information
vdahiya12 authored Oct 17, 2020
1 parent b316f8d commit 19b8545
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions sonic_y_cable/y_cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
Y_CABLE_ACTIVE_TOR_INDICATOR = 645
Y_CABLE_MANUAL_SWITCH_COUNT = 669

SYSLOG_IDENTIFIER = "sonic_y_cable"

# Global logger instance for helper functions and classes to log
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)

Expand Down Expand Up @@ -145,15 +147,15 @@ def check_read_side(physical_port):
helper_logger.log_error("platform_chassis is not loaded, failed to check read side")
return -1

regval_read = struct.unpack(">i", result)
regval_read = struct.unpack(">B", result)

if ((regval_read >> 2) & 0x01):
if ((regval_read[0] >> 2) & 0x01):
helper_logger.log_info("Reading from TOR A")
return 1
elif ((regval_read >> 1) & 0x01):
elif ((regval_read[0] >> 1) & 0x01):
helper_logger.log_info("Reading from TOR B")
return 2
elif (regval_read & 0x01):
elif (regval_read[0] & 0x01):
helper_logger.log_info("Reading from NIC side")
return 0
else:
Expand Down Expand Up @@ -196,15 +198,15 @@ def check_active_linked_tor_side(physical_port):
helper_logger.log_error("platform_chassis is not loaded, failed to check Active Linked and routing TOR side")
return -1

regval_read = struct.unpack(">i", result)
regval_read = struct.unpack(">B", result)

if ((regval_read >> 1) & 0x01):
if ((regval_read[0] >> 1) & 0x01):
helper_logger.log_info("TOR B active linked and actively routing")
return 2
elif ((regval_read) & 0x01):
elif ((regval_read[0]) & 0x01):
helper_logger.log_info("TOR A standby linked and actively routing")
return 1
elif regval_read == 0:
elif regval_read[0] == 0:
helper_logger.log_info("Nothing linked for routing")
return 0
else:
Expand Down Expand Up @@ -245,9 +247,9 @@ def check_if_link_is_active_for_NIC(physical_port):
helper_logger.log_error("platform_chassis is not loaded, failed to check if link is Active on NIC side")
return -1

regval_read = struct.unpack(">i", result)
regval_read = struct.unpack(">B", result)

if (regval_read & 0x01):
if (regval_read[0] & 0x01):
helper_logger.log_info("NIC link is up")
return True
else:
Expand Down Expand Up @@ -285,9 +287,9 @@ def check_if_link_is_active_for_torA(physical_port):
helper_logger.log_error("platform_chassis is not loaded, failed to check if link is Active on TOR A side")
return -1

regval_read = struct.unpack(">i", result)
regval_read = struct.unpack(">B", result)

if ((regval_read >> 2) & 0x01):
if ((regval_read[0] >> 2) & 0x01):
helper_logger.log_info("TOR A link is up")
return True
else:
Expand Down Expand Up @@ -325,9 +327,9 @@ def check_if_link_is_active_for_torB(physical_port):
helper_logger.log_error("platform_chassis is not loaded, failed to check if link is Active on TOR B side")
return -1

regval_read = struct.unpack(">i", result)
regval_read = struct.unpack(">B", result)

if ((regval_read >> 1) & 0x01):
if ((regval_read[0] >> 1) & 0x01):
helper_logger.log_info("TOR B link is up")
return True
else:
Expand Down

0 comments on commit 19b8545

Please sign in to comment.