-
Notifications
You must be signed in to change notification settings - Fork 740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[multi_asic_host]: Add __repr__ method #3090
[multi_asic_host]: Add __repr__ method #3090
Conversation
Signed-off-by: Lawrence Lee <[email protected]>
tests/common/devices/multi_asic.py
Outdated
@@ -43,6 +43,9 @@ def __init__(self, ansible_adhoc, hostname): | |||
|
|||
self.critical_services_tracking_list() | |||
|
|||
def __repr__(self): | |||
return self.hostname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to return something like '<MultiAsicSonicHost {}>'.format(self.hostname)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, will change
tests/common/devices/multi_asic.py
Outdated
@@ -43,6 +43,9 @@ def __init__(self, ansible_adhoc, hostname): | |||
|
|||
self.critical_services_tracking_list() | |||
|
|||
def __repr__(self): | |||
return '<MultiAsicSonicHost> {}'.format(self.hostname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you fix the alignment?
Signed-off-by: Lawrence Lee [email protected]
Description of PR
Summary:
Fixes # (issue)
Type of change
Approach
What is the motivation for this PR?
When viewing stack traces for failed tests, any
duthost
objects are displayed using the default Python representation which simply gives the object's location in memory. On single DUT testbeds this is not an issue, but on dual ToR systems it is difficult to tell which DUT is relevant to the failure.How did you do it?
Add the
__repr__
method to theMultiAsicSonicHost
class, which makes the class readable by using the device hostname as the representation.This also gives the added benefit of returning the hostname when the duthost object is cast to a string (for example when formatting a string)
How did you verify/test it?
Run a test that failed. Confirm in the stack trace that the device hostname is shown instead of the host object's memory location.
Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation