Skip to content

Commit 4b96bd7

Browse files
cytsao1yxieca
authored andcommitted
Update pcieutil error message on loading common pcie module (#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
1 parent 77b725c commit 4b96bd7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pcieutil/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def load_platform_pcieutil():
5454
from sonic_platform.pcie import Pcie
5555
platform_pcieutil = Pcie(platform_path)
5656
except ImportError as e:
57-
log.log_warning("Failed to load platform Pcie module. Error : {}, fallback to load Pcie common utility.".format(str(e)), True)
57+
log.log_warning("Failed to load platform Pcie module. Warning : {}, fallback to load Pcie common utility.".format(str(e)))
5858
try:
5959
from sonic_platform_base.sonic_pcie.pcie_common import PcieUtil
6060
platform_pcieutil = PcieUtil(platform_path)

tests/pcieutil_test.py

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest import mock
44

55
from click.testing import CliRunner
6+
from io import StringIO
67

78
test_path = os.path.dirname(os.path.abspath(__file__))
89
modules_path = os.path.dirname(test_path)
@@ -156,6 +157,8 @@
156157
+---------------------+-----------+
157158
"""
158159

160+
pcieutil_load_module_warning_msg = "Failed to load platform Pcie module. Warning : No module named 'sonic_platform.pcie', fallback to load Pcie common utility."
161+
159162
class TestPcieUtil(object):
160163
@classmethod
161164
def setup_class(cls):
@@ -199,6 +202,16 @@ def test_aer_option_device(self):
199202
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], ["-d", "0:1.0"])
200203
assert result.output == pcieutil_pcie_aer_correctable_dev_output
201204

205+
def test_load_pcie_module_warning(self):
206+
stdout = sys.stdout
207+
sys.stdout = result = StringIO()
208+
try:
209+
pcieutil.load_platform_pcieutil()
210+
except ImportError:
211+
pass
212+
sys.stdout = stdout
213+
assert pcieutil_load_module_warning_msg not in result.getvalue()
214+
202215
@classmethod
203216
def teardown_class(cls):
204217
print("TEARDOWN")

0 commit comments

Comments
 (0)