From 11fa714f3a7b031657b642d0c2f0155854d5ee0e Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 2 Oct 2020 15:13:19 -0400 Subject: add integration test for LP: #1886531 (#592) --- tests/integration_tests/bugs/test_lp1886531.py | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/integration_tests/bugs/test_lp1886531.py (limited to 'tests/integration_tests/bugs') diff --git a/tests/integration_tests/bugs/test_lp1886531.py b/tests/integration_tests/bugs/test_lp1886531.py new file mode 100644 index 00000000..b1112185 --- /dev/null +++ b/tests/integration_tests/bugs/test_lp1886531.py @@ -0,0 +1,27 @@ +"""Integration test for LP: #1886531 + +This test replicates the failure condition (absent /etc/fstab) on all releases +by removing it in a bootcmd; this runs well before the part of cloud-init which +causes the failure. + +The only required assertion is that cloud-init does not emit a WARNING to the +log: this indicates that the fstab parsing code has not failed. + +https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1886531 +""" +import pytest + + +USER_DATA = """\ +#cloud-config +bootcmd: +- rm /etc/fstab +""" + + +class TestLp1886531: + + @pytest.mark.user_data(USER_DATA) + def test_lp1886531(self, client): + log_content = client.read_from_file("/var/log/cloud-init.log") + assert "WARNING" not in log_content -- cgit v1.2.3 From 2ea3121fece7dcdb0d5c424cb6fc597699c0e895 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Mon, 2 Nov 2020 13:08:53 -0500 Subject: test_lp1886531: don't assume /etc/fstab exists (#639) As the bug manifested because groovy doesn't ship /etc/fstab, we should not assume that /etc/fstab will be present for us to remove in our bootcmd. Co-authored-by: Rick Harding --- tests/integration_tests/bugs/test_lp1886531.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/integration_tests/bugs') diff --git a/tests/integration_tests/bugs/test_lp1886531.py b/tests/integration_tests/bugs/test_lp1886531.py index b1112185..058ea8bb 100644 --- a/tests/integration_tests/bugs/test_lp1886531.py +++ b/tests/integration_tests/bugs/test_lp1886531.py @@ -15,7 +15,7 @@ import pytest USER_DATA = """\ #cloud-config bootcmd: -- rm /etc/fstab +- rm -f /etc/fstab """ -- cgit v1.2.3 From 5d4a9a4a50a496d27510f63217bcc0c25d9a8939 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 20 Nov 2020 14:12:54 -0500 Subject: add integration test for LP: #1900837 (#679) As the first test of this SRU cycle, this also introduces the sru_2020_11 mark to allow us to easily identify the set of tests generated for this SRU. --- tests/integration_tests/bugs/test_lp1900837.py | 28 ++++++++++++++++++++++++++ tox.ini | 1 + 2 files changed, 29 insertions(+) create mode 100644 tests/integration_tests/bugs/test_lp1900837.py (limited to 'tests/integration_tests/bugs') diff --git a/tests/integration_tests/bugs/test_lp1900837.py b/tests/integration_tests/bugs/test_lp1900837.py new file mode 100644 index 00000000..3fe7d0d0 --- /dev/null +++ b/tests/integration_tests/bugs/test_lp1900837.py @@ -0,0 +1,28 @@ +"""Integration test for LP: #1900836. + +This test mirrors the reproducing steps from the reported bug: it changes the +permissions on cloud-init.log to 600 and confirms that they remain 600 after a +reboot. +""" +import pytest + + +def _get_log_perms(client): + return client.execute("stat -c %a /var/log/cloud-init.log") + + +@pytest.mark.sru_2020_11 +class TestLogPermissionsNotResetOnReboot: + def test_permissions_unchanged(self, client): + # Confirm that the current permissions aren't 600 + assert "644" == _get_log_perms(client) + + # Set permissions to 600 and confirm our assertion passes pre-reboot + client.execute("chmod 600 /var/log/cloud-init.log") + assert "600" == _get_log_perms(client) + + # Reboot + client.instance.restart() + + # Check that permissions are not reset on reboot + assert "600" == _get_log_perms(client) diff --git a/tox.ini b/tox.ini index c86d38e9..066f923a 100644 --- a/tox.ini +++ b/tox.ini @@ -169,3 +169,4 @@ markers = lxd_container: test will only run in LXD container user_data: the user data to be passed to the test instance instance_name: the name to be used for the test instance + sru_2020_11: test is part of the 2020/11 SRU verification -- cgit v1.2.3 From e454dea5855019a5acdd6acafdef2ae07d069235 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Mon, 23 Nov 2020 11:50:57 -0600 Subject: Integration test for fallocate falling back to dd (#681) See #585 --- tests/integration_tests/bugs/test_lp1897099.py | 31 ++++++++++++++++++++++++++ tests/integration_tests/conftest.py | 15 ++++++++++--- tox.ini | 1 + 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/integration_tests/bugs/test_lp1897099.py (limited to 'tests/integration_tests/bugs') diff --git a/tests/integration_tests/bugs/test_lp1897099.py b/tests/integration_tests/bugs/test_lp1897099.py new file mode 100644 index 00000000..27c8927f --- /dev/null +++ b/tests/integration_tests/bugs/test_lp1897099.py @@ -0,0 +1,31 @@ +""" Integration test for LP #187099 + +Ensure that if fallocate fails during mkswap that we fall back to using dd + +https://bugs.launchpad.net/cloud-init/+bug/1897099 +""" + +import pytest + + +USER_DATA = """\ +#cloud-config +bootcmd: + - echo 'whoops' > /usr/bin/fallocate +swap: + filename: /swap.img + size: 10000000 + maxsize: 10000000 +""" + + +@pytest.mark.sru_2020_11 +@pytest.mark.user_data(USER_DATA) +@pytest.mark.no_container('Containers cannot configure swap') +def test_fallocate_fallback(client): + log = client.read_from_file('/var/log/cloud-init.log') + assert '/swap.img' in client.execute('cat /proc/swaps') + assert '/swap.img' in client.execute('cat /etc/fstab') + assert 'fallocate swap creation failed, will attempt with dd' in log + assert "Running command ['dd', 'if=/dev/zero', 'of=/swap.img'" in log + assert 'SUCCESS: config-mounts ran successfully' in log diff --git a/tests/integration_tests/conftest.py b/tests/integration_tests/conftest.py index e31a9192..54867096 100644 --- a/tests/integration_tests/conftest.py +++ b/tests/integration_tests/conftest.py @@ -37,11 +37,20 @@ def pytest_runtest_setup(item): specified, then we assume the test can be run anywhere. """ all_platforms = platforms.keys() - supported_platforms = set(all_platforms).intersection( - mark.name for mark in item.iter_markers()) + test_marks = [mark.name for mark in item.iter_markers()] + supported_platforms = set(all_platforms).intersection(test_marks) current_platform = integration_settings.PLATFORM + unsupported_message = 'Cannot run on platform {}'.format(current_platform) + if 'no_container' in test_marks: + if 'lxd_container' in test_marks: + raise Exception( + 'lxd_container and no_container marks simultaneously set ' + 'on test' + ) + if current_platform == 'lxd_container': + pytest.skip(unsupported_message) if supported_platforms and current_platform not in supported_platforms: - pytest.skip('Cannot run on platform {}'.format(current_platform)) + pytest.skip(unsupported_message) # disable_subp_usage is defined at a higher level, but we don't diff --git a/tox.ini b/tox.ini index 066f923a..f08e0f03 100644 --- a/tox.ini +++ b/tox.ini @@ -167,6 +167,7 @@ markers = azure: test will only run on Azure platform oci: test will only run on OCI platform lxd_container: test will only run in LXD container + no_container: test cannot run in a container user_data: the user data to be passed to the test instance instance_name: the name to be used for the test instance sru_2020_11: test is part of the 2020/11 SRU verification -- cgit v1.2.3