summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Falcon <TheRealFalcon@users.noreply.github.com>2020-11-23 11:50:57 -0600
committerGitHub <noreply@github.com>2020-11-23 12:50:57 -0500
commite454dea5855019a5acdd6acafdef2ae07d069235 (patch)
treeb046d998d43666c2dd5e9b95ebbd620bbaa10b56
parent66a851aca7acf3ae39cb5c03fc97c563716b5aa3 (diff)
downloadcloud-init-git-e454dea5855019a5acdd6acafdef2ae07d069235.tar.gz
Integration test for fallocate falling back to dd (#681)
See #585
-rw-r--r--tests/integration_tests/bugs/test_lp1897099.py31
-rw-r--r--tests/integration_tests/conftest.py15
-rw-r--r--tox.ini1
3 files changed, 44 insertions, 3 deletions
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