Skip to content

Commit

Permalink
Fix the issue that sonic_platform is not installed on vs image (#2300)
Browse files Browse the repository at this point in the history
Method is_rj45_port references sonic_platform which has not been implemented on vs platform
However, the method is referenced by show interface status which is widely used in kvm test in azure pipeline checkers

- What I did

- How I did it
True is returned in is_rj45_port if sonic_platform can not be imported

- How to verify it
Run vs tests

Signed-off-by: Stephen Sun <[email protected]>
  • Loading branch information
stephenxs authored and yxieca committed Aug 13, 2022
1 parent 19a3540 commit fbf82b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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

0 comments on commit fbf82b9

Please sign in to comment.