Skip to content

Commit 19b8545

Browse files
authored
[sonic_y_cable] fix the unpacking (#135)
Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent b316f8d commit 19b8545

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

sonic_y_cable/y_cable.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
Y_CABLE_ACTIVE_TOR_INDICATOR = 645
2626
Y_CABLE_MANUAL_SWITCH_COUNT = 669
2727

28+
SYSLOG_IDENTIFIER = "sonic_y_cable"
29+
2830
# Global logger instance for helper functions and classes to log
2931
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)
3032

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

148-
regval_read = struct.unpack(">i", result)
150+
regval_read = struct.unpack(">B", result)
149151

150-
if ((regval_read >> 2) & 0x01):
152+
if ((regval_read[0] >> 2) & 0x01):
151153
helper_logger.log_info("Reading from TOR A")
152154
return 1
153-
elif ((regval_read >> 1) & 0x01):
155+
elif ((regval_read[0] >> 1) & 0x01):
154156
helper_logger.log_info("Reading from TOR B")
155157
return 2
156-
elif (regval_read & 0x01):
158+
elif (regval_read[0] & 0x01):
157159
helper_logger.log_info("Reading from NIC side")
158160
return 0
159161
else:
@@ -196,15 +198,15 @@ def check_active_linked_tor_side(physical_port):
196198
helper_logger.log_error("platform_chassis is not loaded, failed to check Active Linked and routing TOR side")
197199
return -1
198200

199-
regval_read = struct.unpack(">i", result)
201+
regval_read = struct.unpack(">B", result)
200202

201-
if ((regval_read >> 1) & 0x01):
203+
if ((regval_read[0] >> 1) & 0x01):
202204
helper_logger.log_info("TOR B active linked and actively routing")
203205
return 2
204-
elif ((regval_read) & 0x01):
206+
elif ((regval_read[0]) & 0x01):
205207
helper_logger.log_info("TOR A standby linked and actively routing")
206208
return 1
207-
elif regval_read == 0:
209+
elif regval_read[0] == 0:
208210
helper_logger.log_info("Nothing linked for routing")
209211
return 0
210212
else:
@@ -245,9 +247,9 @@ def check_if_link_is_active_for_NIC(physical_port):
245247
helper_logger.log_error("platform_chassis is not loaded, failed to check if link is Active on NIC side")
246248
return -1
247249

248-
regval_read = struct.unpack(">i", result)
250+
regval_read = struct.unpack(">B", result)
249251

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

288-
regval_read = struct.unpack(">i", result)
290+
regval_read = struct.unpack(">B", result)
289291

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

328-
regval_read = struct.unpack(">i", result)
330+
regval_read = struct.unpack(">B", result)
329331

330-
if ((regval_read >> 1) & 0x01):
332+
if ((regval_read[0] >> 1) & 0x01):
331333
helper_logger.log_info("TOR B link is up")
332334
return True
333335
else:

0 commit comments

Comments
 (0)