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

Graceful integration test 2 #5926

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

holmanb
Copy link
Member

@holmanb holmanb commented Dec 12, 2024

Proposed Commit Message

test: disambiguate resource cleanup from test failure

Add a background thread which is responsible for instance cleanup
in integration tests.

Additional Context

blocked by #5920

I'm happy to reorganize the module as a class to reduce use of globals. This is very much work in progress.

Test log

Search for the keyword "reaper" in the following example log.

tox -e integration-tests -- tests/integration_tests/test_defaults.py
integration-tests: commands[0]> .tox/integration-tests/bin/python -m pytest --log-cli-level=INFO tests/integration_tests/test_defaults.py

--------------------------------------------------------------------------- live log sessionstart ---------------------------------------------------------------------------
2024-12-11 18:49:36 INFO      integration_testing:clouds.py:75 Settings:
CLOUD_INIT_PKG=cloud-init
CLOUD_INIT_SOURCE=NONE
COLLECT_LOGS=ON_ERROR
EXISTING_INSTANCE_ID=None
INCLUDE_COVERAGE=False
INCLUDE_PROFILE=False
INSTANCE_TYPE=None
KEEP_IMAGE=False
KEEP_INSTANCE=False
LOCAL_LOG_PATH=/tmp/cloud_init_test_logs
OS_IMAGE=focal
OS_IMAGE_TYPE=generic
PLATFORM=lxd_container
RUN_UNSTABLE=False
2024-12-11 18:49:36 INFO      root:reaper.py:50 Starting reaper
2024-12-11 18:49:36 INFO      root:reaper.py:84 [reaper] exhalted in life, to assist others in death
============================================================================ test session starts ============================================================================
platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
cachedir: .tox/integration-tests/.pytest_cache
rootdir: /home/holmanb/ci-a
configfile: tox.ini
collected 3 items                                                                                                                                                           

tests/integration_tests/test_defaults.py::TestDefaults::test_clean_log 
------------------------------------------------------------------------------ live log setup -------------------------------------------------------------------------------
2024-12-11 18:49:36 INFO      integration_testing:clouds.py:142 Launching instance with launch_kwargs:
image_id=ubuntu-daily:b7ad14ea0a26617cf6d834a6b925dcb5270e459a865c97c9ecf426fe69db55bb
user_data=None
username=ubuntu
2024-12-11 18:49:37 INFO      pycloudlib.cloud.LXDContainer:cloud.py:245 ['lxc', 'init', 'ubuntu-daily:b7ad14ea0a26617cf6d834a6b925dcb5270e459a865c97c9ecf426fe69db55bb', 'cloudinit-1212-0149365iw2ltnr', '--config', 'user.meta-data=public-keys: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqpCozNyoIR4yR5UGrjUg4HzfDs0voCchtGzRcYc1HO83rgPJGHMSFi5WuiLCZtWMtLShnZBxwouXo03mnYPe1dC1QBas2QZIEgJ9Piq+c3kS/YxIf0R2UNg/laYeRNpNtz5zuC+gBQpz5BWLGL39PUHyW6eBtIdpl2CrOASN56pK6Hk285ZphFVWDc+GyxqM1s1E1qH8NmtX2RKl9/LV/LWcPqwkwWMaV9PmdoiwKekJb9xNJiE0HEwdgE55FCSVzMMxJtGZaSHfva8qDamW/IK5JB7RM5u2aC71yWZI8DOXEPHFxKBWBJO4eMQPLQp4ACq8fEWqzci3Ieu9AzmGBa4PCiWA70flPoU09U8daqoYjZei/az1H0CAObaWeDo/pU8bN4CUX8ap3+RU3UzD5JMcZs9jy2VG1nbrM5CYM9EO4Mt6yT+/vQQbXd9Qvg3KkLM8IUVNUf0yPRb/yqJ3QknQ11LVdhJI8GPFzxC5JxbaqngAoqqE5Da2lHb+60vVXIJdwPgKQCXnD9E40Ej8XwmE3DJciZN8zFl1eNsAQF/wJIdoR7+uKnayMu6DcoOBwNwc2MjPJochkicLz7slpzslAE78XM2AzTZg5z8t4bAN+IWeOdiqlyvBFOVEBuzyVmhbkedvzj/SKciU8RFHup6STEH++ujOgIkBdqJYLPQ== holmanb@arc\n']
2024-12-11 18:49:43 INFO      pycloudlib.instance:instance.py:493 _wait_for_execute to complete
2024-12-11 18:49:49 INFO      paramiko.transport:transport.py:1944 Connected (version 2.0, client OpenSSH_8.2p1)
2024-12-11 18:49:49 INFO      paramiko.transport:transport.py:1944 Authentication (publickey) successful!
2024-12-11 18:51:50 INFO      pycloudlib.instance:instance.py:515 _wait_for_cloudinit to complete
2024-12-11 18:51:50 INFO      pycloudlib.instance:instance.py:266 executing: sh -c 'command -v systemctl'
2024-12-11 18:51:50 INFO      pycloudlib.instance:instance.py:266 executing: cloud-init status --wait --long
2024-12-11 18:51:50 INFO      integration_testing:clouds.py:153 Launched instance: LXDInstance(name=cloudinit-1212-0149365iw2ltnr)
2024-12-11 18:51:50 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'cloud-init --version'
2024-12-11 18:51:51 INFO      integration_testing:clouds.py:157 cloud-init version: /usr/bin/cloud-init 24.3.1-0ubuntu0~20.04.1
2024-12-11 18:51:51 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'grep serial /etc/cloud/build.info'
2024-12-11 18:51:51 INFO      integration_testing:clouds.py:163 image serial: 20241127
------------------------------------------------------------------------------- live log call -------------------------------------------------------------------------------
2024-12-11 18:51:51 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'cat /var/log/cloud-init.log'
2024-12-11 18:51:51 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'cloud-init status --format=json'
2024-12-11 18:51:51 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'grep --count Traceback /var/log/cloud-init.log'
2024-12-11 18:51:51 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'cloud-init status --long'
2024-12-11 18:51:52 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'cloud-init schema --system --annotate'
PASSED                                                                                                                                                                [ 33%]
tests/integration_tests/test_defaults.py::TestDefaults::test_inactive_modules 
------------------------------------------------------------------------------- live log call -------------------------------------------------------------------------------
2024-12-11 18:51:52 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'cat /var/log/cloud-init.log'
PASSED                                                                                                                                                                [ 66%]
tests/integration_tests/test_defaults.py::TestDefaults::test_var_log_cloud_init_output_not_world_readable 
------------------------------------------------------------------------------- live log call -------------------------------------------------------------------------------
2024-12-11 18:51:52 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'test -f /var/log/cloud-init-output.log'
2024-12-11 18:51:52 INFO      pycloudlib.instance:instance.py:266 executing: sudo -- sh -c 'stat -c %a:%U:%G /var/log/cloud-init-output.log'
PASSED                                                                                                                                                                [100%]
----------------------------------------------------------------------------- live log teardown -----------------------------------------------------------------------------
2024-12-11 18:51:52 INFO      root:reaper.py:41 Instance cloudinit-1212-0149365iw2ltnr submitted to reaper.
2024-12-11 18:51:52 INFO      root:reaper.py:69 Destroying instance cloudinit-1212-0149365iw2ltnr
-------------------------------------------------------------------------- live log sessionfinish ---------------------------------------------------------------------------
2024-12-11 18:51:52 INFO      root:reaper.py:57 Instructing reaper to stop
2024-12-11 18:51:55 INFO      root:reaper.py:109 Reaper destroyed instance cloudinit-1212-0149365iw2ltnr.
2024-12-11 18:51:55 INFO      root:reaper.py:119 Exiting reaper
2024-12-11 18:51:55 INFO      root:reaper.py:131 [reaper] duties complete, my turn to rest
2024-12-11 18:51:55 INFO      root:reaper.py:63 Reaper stopped


============================================================================= warnings summary ==============================================================================
tests/integration_tests/test_defaults.py::TestDefaults::test_clean_log
tests/integration_tests/test_defaults.py::TestDefaults::test_clean_log
tests/integration_tests/test_defaults.py::TestDefaults::test_clean_log
tests/integration_tests/test_defaults.py::TestDefaults::test_clean_log
tests/integration_tests/reaper.py:114
  /home/holmanb/ci-a/tests/integration_tests/reaper.py:114: DeprecationWarning: isSet() is deprecated, use is_set() instead
    if EXIT_REAPER.isSet():

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================= 3 passed, 5 warnings in 139.14s (0:02:19) =================================================================
  integration-tests: OK (143.73=setup[0.06]+cmd[143.68] seconds)
  congratulations :) (143.84 seconds)

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

For more correct clean-up. A quote from the docs[1]:

    We have to be careful though, because pytest will run that finalizer once
    it’s been added, even if that fixture raises an exception after adding the
    finalizer. So to make sure we don’t run the finalizer code when we wouldn’t
    need to, we would only add the finalizer once the fixture would have done
    something that we’d need to teardown.

[1] https://docs.pytest.org/en/stable/how-to/fixtures.html
@holmanb holmanb force-pushed the holmanb/graceful_integration_test_2 branch 2 times, most recently from 08f311d to df5b25e Compare December 12, 2024 01:56
@holmanb holmanb force-pushed the holmanb/graceful_integration_test_2 branch from df5b25e to 1a58d0f Compare December 12, 2024 01:57
@holmanb holmanb changed the title Holmanb/graceful integration test 2 Graceful integration test 2 Dec 14, 2024
@holmanb holmanb marked this pull request as ready for review December 14, 2024 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant