Skip to content

Commit 649e487

Browse files
Issue 21314: Remove --enable_sflow_feature from sflow tests (#21319)
Summary: Currently, sflow/test_sflow.py accepts a flag --enable_sflow_feature which will start the sflow feature when it is passed in. This is not necessary; if the feature is compiled in and available, then the test should enable it automatically when run, and if it was enabled by the test, we should disable it when it is finished. Note that the test calls config reload at the end of the test anyways, so in practice it's not necessary to disable the feature after the test completes. * remove --enable_sflow_feature from options * unconditionally start sflow feature at start of test * disable sflow feature at end of test if it was not enabled before
1 parent dde98b7 commit 649e487

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

tests/sflow/conftest.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
11
"""
22
Pytest configuration used by the sFlow tests.
33
"""
4-
5-
6-
def pytest_addoption(parser):
7-
"""
8-
Adds options to pytest that are used by the sFlow tests.
9-
"""
10-
parser.addoption(
11-
"--enable_sflow_feature",
12-
action="store_true",
13-
default=False,
14-
help="Enable sFlow feature on DUT",
15-
)

tests/sflow/test_sflow.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,22 @@ def config_sflow(duthost, sflow_status='enable'):
195195

196196
@pytest.fixture(scope='module')
197197
def config_sflow_feature(request, duthost):
198-
# Enable sFlow feature on DUT if enable_sflow_feature argument was passed
199-
if request.config.getoption("--enable_sflow_feature"):
200-
feature_status, _ = duthost.get_feature_status()
201-
if feature_status['sflow'] == 'disabled':
202-
duthost.shell("sudo config feature state sflow enabled")
203-
time.sleep(2)
198+
feature_status, _ = duthost.get_feature_status()
199+
200+
if 'sflow' not in feature_status:
201+
pytest.skip("sflow feature is not supported")
202+
203+
sflow_disabled_by_default = feature_status['sflow'] == 'disabled'
204+
if sflow_disabled_by_default:
205+
logger.info("sflow feature is disabled by default, enabling it for this test run")
206+
duthost.shell("sudo config feature state sflow enabled")
207+
time.sleep(2)
208+
209+
yield
210+
211+
if sflow_disabled_by_default:
212+
logger.info("Disabling sflow feature")
213+
duthost.shell("sudo config feature state sflow disabled")
204214
# ----------------------------------------------------------------------------------
205215

206216

0 commit comments

Comments
 (0)