Skip to content

Commit fe531c5

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

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
@@ -28,6 +28,7 @@
2828
tgen_utils_get_dent_devices_with_tgen,
2929
tgen_utils_stop_traffic,
3030
)
31+
reboot_after_test = None
3132

3233
# Add python files for defining per folder fixtures here
3334
# And depending on the scope of fixtures, they can be used
@@ -78,6 +79,15 @@ def pytest_unconfigure(config):
7879
# Save and parameters for each suite run
7980

8081

82+
def pytest_collection_finish(session):
83+
global reboot_after_test
84+
for item in session.items:
85+
# Save the name of the last L1 test in session
86+
if 'test_l1' in item.name:
87+
reboot_after_test = session.items[-1]
88+
break
89+
90+
8191
def pytest_runtest_setup(item):
8292
logger = AppLogger(DEFAULT_LOGGER)
8393
if logger:
@@ -89,6 +99,11 @@ def pytest_runtest_setup(item):
8999
)
90100
logger.info('=================================================================')
91101

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

93108
def pytest_runtest_teardown(item, nextitem):
94109
logger = AppLogger(DEFAULT_LOGGER)
@@ -127,6 +142,12 @@ def pytest_collection_modifyitems(session, config, items):
127142
if mark and mark.name.startswith('feature'):
128143
if logger:
129144
logger.info('pytest %s has feature markers:%s' % (item.name, item.own_markers))
145+
146+
for item in items:
147+
# Move l1 tests to the end of the list
148+
if 'test_l1' in item.name:
149+
items.sort(key=lambda item: 'test_l1' in item.name)
150+
break
130151
return False
131152

132153

@@ -150,6 +171,16 @@ async def _get_dent_devs_from_testbed(testbed):
150171
return devs
151172

152173

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

0 commit comments

Comments
 (0)