diff options
author | Robert Schweikert <rjschwei@suse.com> | 2021-07-01 12:35:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-01 10:35:40 -0600 |
commit | 78e89b03ecb29e7df3181b1219a0b5f44b9d7532 (patch) | |
tree | c75f1c25fd386fd5bf8a287ddf1d9932fcad8980 /tests/integration_tests | |
parent | 6e0aa175513d0d5f64a3684f6840621cb9759b27 (diff) | |
download | vyos-cloud-init-78e89b03ecb29e7df3181b1219a0b5f44b9d7532.tar.gz vyos-cloud-init-78e89b03ecb29e7df3181b1219a0b5f44b9d7532.zip |
- Detect a Python version change and clear the cache (#857)
summary: Clear cache when a Python version change is detected
When a distribution gets updated it is possible that the Python version
changes. Python makes no guarantee that pickle is consistent across
versions as such we need to purge the cache and start over.
Co-authored-by: James Falcon <therealfalcon@gmail.com>
Diffstat (limited to 'tests/integration_tests')
-rw-r--r-- | tests/integration_tests/assets/test_version_change.pkl | bin | 0 -> 21 bytes | |||
-rw-r--r-- | tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py | 2 | ||||
-rw-r--r-- | tests/integration_tests/modules/test_version_change.py | 56 | ||||
-rw-r--r-- | tests/integration_tests/util.py | 4 |
4 files changed, 61 insertions, 1 deletions
diff --git a/tests/integration_tests/assets/test_version_change.pkl b/tests/integration_tests/assets/test_version_change.pkl Binary files differnew file mode 100644 index 00000000..65ae93e5 --- /dev/null +++ b/tests/integration_tests/assets/test_version_change.pkl diff --git a/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py b/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py index b9b0d85e..e1946cb1 100644 --- a/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py +++ b/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py @@ -18,7 +18,7 @@ USER_DATA_SSH_AUTHKEY_DISABLE = """\ no_ssh_fingerprints: true """ -USER_DATA_SSH_AUTHKEY_ENABLE="""\ +USER_DATA_SSH_AUTHKEY_ENABLE = """\ #cloud-config ssh_genkeytypes: - ecdsa diff --git a/tests/integration_tests/modules/test_version_change.py b/tests/integration_tests/modules/test_version_change.py new file mode 100644 index 00000000..4e9ab63f --- /dev/null +++ b/tests/integration_tests/modules/test_version_change.py @@ -0,0 +1,56 @@ +from pathlib import Path + +from tests.integration_tests.instances import IntegrationInstance +from tests.integration_tests.util import ASSETS_DIR + + +PICKLE_PATH = Path('/var/lib/cloud/instance/obj.pkl') +TEST_PICKLE = ASSETS_DIR / 'test_version_change.pkl' + + +def _assert_no_pickle_problems(log): + assert 'Failed loading pickled blob' not in log + assert 'Traceback' not in log + assert 'WARN' not in log + + +def test_reboot_without_version_change(client: IntegrationInstance): + log = client.read_from_file('/var/log/cloud-init.log') + assert 'Python version change detected' not in log + assert 'Cache compatibility status is currently unknown.' not in log + _assert_no_pickle_problems(log) + + client.restart() + log = client.read_from_file('/var/log/cloud-init.log') + assert 'Python version change detected' not in log + assert 'Could not determine Python version used to write cache' not in log + _assert_no_pickle_problems(log) + + # Now ensure that loading a bad pickle gives us problems + client.push_file(TEST_PICKLE, PICKLE_PATH) + client.restart() + log = client.read_from_file('/var/log/cloud-init.log') + assert 'Failed loading pickled blob from {}'.format(PICKLE_PATH) in log + + +def test_cache_purged_on_version_change(client: IntegrationInstance): + # Start by pushing the invalid pickle so we'll hit an error if the + # cache didn't actually get purged + client.push_file(TEST_PICKLE, PICKLE_PATH) + client.execute("echo '1.0' > /var/lib/cloud/data/python-version") + client.restart() + log = client.read_from_file('/var/log/cloud-init.log') + assert 'Python version change detected. Purging cache' in log + _assert_no_pickle_problems(log) + + +def test_log_message_on_missing_version_file(client: IntegrationInstance): + # Start by pushing a pickle so we can see the log message + client.push_file(TEST_PICKLE, PICKLE_PATH) + client.execute("rm /var/lib/cloud/data/python-version") + client.restart() + log = client.read_from_file('/var/log/cloud-init.log') + assert ( + 'Writing python-version file. ' + 'Cache compatibility status is currently unknown.' + ) in log diff --git a/tests/integration_tests/util.py b/tests/integration_tests/util.py index 3ef12358..8d726bb2 100644 --- a/tests/integration_tests/util.py +++ b/tests/integration_tests/util.py @@ -3,10 +3,14 @@ import multiprocessing import os import time from contextlib import contextmanager +from pathlib import Path log = logging.getLogger('integration_testing') +ASSETS_DIR = Path('tests/integration_tests/assets') + + def verify_ordered_items_in_text(to_verify: list, text: str): """Assert all items in list appear in order in text. |