Skip to content

Commit

Permalink
Update pcieutil error message on loading common pcie module (sonic-ne…
Browse files Browse the repository at this point in the history
…t#2786)

* Update pcieutil load module error message

* Add pcieutil test for load module warning to not print to output

* Update pcieutil import test

* Update pcieutil import test

* Fix pcieutil import test
  • Loading branch information
cytsao1 authored May 20, 2023
1 parent e6aacd3 commit 3d89589
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pcieutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def load_platform_pcieutil():
from sonic_platform.pcie import Pcie
platform_pcieutil = Pcie(platform_path)
except ImportError as e:
log.log_warning("Failed to load platform Pcie module. Error : {}, fallback to load Pcie common utility.".format(str(e)), True)
log.log_warning("Failed to load platform Pcie module. Warning : {}, fallback to load Pcie common utility.".format(str(e)))
try:
from sonic_platform_base.sonic_pcie.pcie_common import PcieUtil
platform_pcieutil = PcieUtil(platform_path)
Expand Down
13 changes: 13 additions & 0 deletions tests/pcieutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import mock

from click.testing import CliRunner
from io import StringIO

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand Down Expand Up @@ -156,6 +157,8 @@
+---------------------+-----------+
"""

pcieutil_load_module_warning_msg = "Failed to load platform Pcie module. Warning : No module named 'sonic_platform.pcie', fallback to load Pcie common utility."

class TestPcieUtil(object):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -199,6 +202,16 @@ def test_aer_option_device(self):
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], ["-d", "0:1.0"])
assert result.output == pcieutil_pcie_aer_correctable_dev_output

def test_load_pcie_module_warning(self):
stdout = sys.stdout
sys.stdout = result = StringIO()
try:
pcieutil.load_platform_pcieutil()
except ImportError:
pass
sys.stdout = stdout
assert pcieutil_load_module_warning_msg not in result.getvalue()

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down

0 comments on commit 3d89589

Please sign in to comment.