Skip to content

Commit 5b01ffb

Browse files
committed
Reboot device after L 1 tests
Signed-off-by: Stepan Vovk <stepan.vovk@plvision.eu>
1 parent c5090e7 commit 5b01ffb

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • DentOS_Framework/DentOsTestbed/src/dent_os_testbed/test

DentOS_Framework/DentOsTestbed/src/dent_os_testbed/test/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
tgen_utils_get_dent_devices_with_tgen,
2727
tgen_utils_stop_traffic,
2828
)
29+
reboot_after_test = None
2930

3031
# Add python files for defining per folder fixtures here
3132
# And depending on the scope of fixtures, they can be used
@@ -76,6 +77,15 @@ def pytest_unconfigure(config):
7677
# Save and parameters for each suite run
7778

7879

80+
def pytest_collection_finish(session):
81+
global reboot_after_test
82+
for item in session.items:
83+
# Save the name of the last L1 test in session
84+
if 'test_l1' in item.name:
85+
reboot_after_test = session.items[-1]
86+
break
87+
88+
7989
def pytest_runtest_setup(item):
8090
logger = AppLogger(DEFAULT_LOGGER)
8191
if logger:
@@ -87,6 +97,11 @@ def pytest_runtest_setup(item):
8797
)
8898
logger.info('=================================================================')
8999

100+
if reboot_after_test:
101+
if reboot_after_test.name == item.name:
102+
# Add `reboot_device` fixture to last L1 test
103+
item.fixturenames.append('reboot_device')
104+
90105

91106
def pytest_runtest_teardown(item, nextitem):
92107
logger = AppLogger(DEFAULT_LOGGER)
@@ -125,6 +140,12 @@ def pytest_collection_modifyitems(session, config, items):
125140
if mark and mark.name.startswith('feature'):
126141
if logger:
127142
logger.info('pytest %s has feature markers:%s' % (item.name, item.own_markers))
143+
144+
for item in items:
145+
# Move l1 tests to the end of the list
146+
if 'test_l1' in item.name:
147+
items.sort(key=lambda item: 'test_l1' in item.name)
148+
break
128149
return False
129150

130151

@@ -148,6 +169,16 @@ async def _get_dent_devs_from_testbed(testbed):
148169
return devs
149170

150171

172+
@pytest_asyncio.fixture()
173+
async def reboot_device(testbed):
174+
yield
175+
devices = await _get_dent_devs_from_testbed(testbed)
176+
to_reboot = [dev.reboot() for dev in devices]
177+
up_ports = [dev.run_cmd('onlpd') for dev in devices]
178+
await asyncio.gather(*to_reboot)
179+
await asyncio.gather(*up_ports)
180+
181+
151182
@pytest_asyncio.fixture()
152183
async def cleanup_qdiscs(testbed):
153184
yield

0 commit comments

Comments
 (0)