Skip to content

Commit

Permalink
conftest reboot l1 device add
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Vovk <[email protected]>
  • Loading branch information
StepanVovkPLV committed Mar 23, 2023
1 parent 2967dc7 commit bde955a
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
tgen_utils_get_dent_devices_with_tgen,
tgen_utils_stop_protocols,
)
reboot_after_test = None

# Add python files for defining per folder fixtures here
# And depending on the scope of fixtures, they can be used
Expand Down Expand Up @@ -74,6 +75,14 @@ def pytest_unconfigure(config):
# Save and parameters for each suite run


def pytest_collection_finish(session):
global reboot_after_test
for item in session.items:
if "test_l1" in item.name:
reboot_after_test = session.items[-1]
break


def pytest_runtest_setup(item):
logger = AppLogger(DEFAULT_LOGGER)
if logger:
Expand All @@ -85,6 +94,10 @@ def pytest_runtest_setup(item):
)
logger.info("=================================================================")

if reboot_after_test:
if reboot_after_test.name == item.name:
item.fixturenames.append("reboot_device")


def pytest_runtest_teardown(item, nextitem):
logger = AppLogger(DEFAULT_LOGGER)
Expand Down Expand Up @@ -123,9 +136,15 @@ def pytest_collection_modifyitems(session, config, items):
if mark and mark.name.startswith("feature"):
if logger:
logger.info("pytest %s has feature markers:%s" % (item.name, item.own_markers))

for item in items:
if "test_l1" in item.name:
items.sort(key=lambda item: "test_l1" in item.name)
break
return False



@pytest.fixture(scope="session")
def testbed():
return pytest.testbed
Expand All @@ -146,6 +165,16 @@ async def _get_dent_devs_from_testbed(testbed):
return devs


@pytest_asyncio.fixture()
async def reboot_device(testbed):
yield
devices = await _get_dent_devs_from_testbed(testbed)
to_reboot = [dev.reboot() for dev in devices]
# up_ports = [dev.run_cmd("sudo onlpdump -S") for dev in devices]
await asyncio.gather(*to_reboot)
# await asyncio.gather(*up_ports)


@pytest_asyncio.fixture()
async def cleanup_qdiscs(testbed):
yield
Expand Down

0 comments on commit bde955a

Please sign in to comment.