summaryrefslogtreecommitdiff
path: root/tests/integration_tests/bugs/test_lp1897099.py
blob: 1f5030ce5945da8a06dc33e6e45dc1f68b68fb55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
""" 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.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