Skip to content
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

Fix the issue that sonic_platform is not installed on vs image #2300

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/sfp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ def test_sfp_eeprom_dom_all(self):
assert result.exit_code == 0
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_sfp_eeprom_dom_all_output

def test_is_rj45_port(self):
import utilities_common.platform_sfputil_helper as platform_sfputil_helper
platform_sfputil_helper.platform_chassis = None
if 'sonic_platform' in sys.modules:
sys.modules.pop('sonic_platform')
assert platform_sfputil_helper.is_rj45_port("Ethernet0") == False

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down
18 changes: 12 additions & 6 deletions utilities_common/platform_sfputil_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ def is_rj45_port(port_name):
global platform_sfp_base
global platform_sfputil_loaded

if not platform_chassis:
import sonic_platform
platform_chassis = sonic_platform.platform.Platform().get_chassis()
if not platform_sfp_base:
import sonic_platform_base
platform_sfp_base = sonic_platform_base.sfp_base.SfpBase
try:
if not platform_chassis:
import sonic_platform
platform_chassis = sonic_platform.platform.Platform().get_chassis()
if not platform_sfp_base:
import sonic_platform_base
platform_sfp_base = sonic_platform_base.sfp_base.SfpBase
except ModuleNotFoundError as e:
# This method is referenced by intfutil which is called on vs image
# However, there is no platform API supported on vs image
# So False is returned in such case
return False

if platform_chassis and platform_sfp_base:
if not platform_sfputil:
Expand Down