Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L1 tests reboot device #84

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
tgen_utils_get_dent_devices_with_tgen,
tgen_utils_stop_traffic,
)
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 @@ -78,6 +79,15 @@ 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:
# Save the name of the last L1 test in session
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 @@ -89,6 +99,11 @@ def pytest_runtest_setup(item):
)
logger.info('=================================================================')

if reboot_after_test:
if reboot_after_test.name == item.name:
Comment on lines +102 to +103
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if reboot_after_test:
if reboot_after_test.name == item.name:
if reboot_after_test and reboot_after_test.name == item.name:

# Add `reboot_device` fixture to last L1 test
item.fixturenames.append('reboot_device')


def pytest_runtest_teardown(item, nextitem):
logger = AppLogger(DEFAULT_LOGGER)
Expand Down Expand Up @@ -127,6 +142,12 @@ 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:
# Move l1 tests to the end of the list
if 'test_l1' in item.name:
items.sort(key=lambda item: 'test_l1' in item.name)
break
return False


Expand All @@ -150,6 +171,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('onlpd') for dev in devices]
await asyncio.gather(*to_reboot)
await asyncio.gather(*up_ports)
Comment on lines +178 to +181
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to_reboot = [dev.reboot() for dev in devices]
up_ports = [dev.run_cmd('onlpd') for dev in devices]
await asyncio.gather(*to_reboot)
await asyncio.gather(*up_ports)
await asyncio.gather(*[dev.reboot() for dev in devices])
# https://github.com/dentproject/dentOS/issues/152#issuecomment-973264204
await asyncio.gather(*[dev.run_cmd('onlpd') for dev in devices])



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