diff options
author | Brett Holman <brett.holman@canonical.com> | 2021-11-17 11:35:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-17 12:35:00 -0600 |
commit | 7f03da357e4e72f7fe09e9b35b23ba1d83477f6c (patch) | |
tree | 1fe38ed74d9396cfc96cfb97f28ff4e769c7d59d /tests/integration_tests | |
parent | 8c52bb3fc530742fce50f7f1061a24f3c453ef94 (diff) | |
download | vyos-cloud-init-7f03da357e4e72f7fe09e9b35b23ba1d83477f6c.tar.gz vyos-cloud-init-7f03da357e4e72f7fe09e9b35b23ba1d83477f6c.zip |
testing: add growpart integration test (#1104)
Add growpart integration test and associated unit tests
Additionally, a small runcmd check for a commented line.
Diffstat (limited to 'tests/integration_tests')
-rw-r--r-- | tests/integration_tests/modules/test_combined.py | 2 | ||||
-rw-r--r-- | tests/integration_tests/modules/test_growpart.py | 62 |
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/integration_tests/modules/test_combined.py b/tests/integration_tests/modules/test_combined.py index 2635d41a..bc19c2a2 100644 --- a/tests/integration_tests/modules/test_combined.py +++ b/tests/integration_tests/modules/test_combined.py @@ -53,6 +53,8 @@ rsyslog: me: "127.0.0.1" runcmd: - echo 'hello world' > /var/tmp/runcmd_output + + - # - logger "My test log" snap: squashfuse_in_container: true diff --git a/tests/integration_tests/modules/test_growpart.py b/tests/integration_tests/modules/test_growpart.py new file mode 100644 index 00000000..af1e3a15 --- /dev/null +++ b/tests/integration_tests/modules/test_growpart.py @@ -0,0 +1,62 @@ +import os +import pytest +import pathlib +import json +from uuid import uuid4 +from pycloudlib.lxd.instance import LXDInstance + +from cloudinit.subp import subp +from tests.integration_tests.instances import IntegrationInstance + +DISK_PATH = '/tmp/test_disk_setup_{}'.format(uuid4()) + + +def setup_and_mount_lxd_disk(instance: LXDInstance): + subp('lxc config device add {} test-disk-setup-disk disk source={}'.format( + instance.name, DISK_PATH).split()) + + +@pytest.fixture(scope='class', autouse=True) +def create_disk(): + """Create 16M sparse file""" + pathlib.Path(DISK_PATH).touch() + os.truncate(DISK_PATH, 1 << 24) + yield + os.remove(DISK_PATH) + + +# Create undersized partition in bootcmd +ALIAS_USERDATA = """\ +#cloud-config +bootcmd: + - parted /dev/sdb --script \ + mklabel gpt \ + mkpart primary 0 1MiB + - parted /dev/sdb --script print +growpart: + devices: + - "/" + - "/dev/sdb1" +runcmd: + - parted /dev/sdb --script print +""" + + +@pytest.mark.user_data(ALIAS_USERDATA) +@pytest.mark.lxd_setup.with_args(setup_and_mount_lxd_disk) +@pytest.mark.ubuntu +@pytest.mark.lxd_vm +class TestGrowPart: + """Test growpart""" + + def test_grow_part(self, client: IntegrationInstance): + """Verify """ + log = client.read_from_file('/var/log/cloud-init.log') + assert ("cc_growpart.py[INFO]: '/dev/sdb1' resized:" + " changed (/dev/sdb, 1) from") in log + + lsblk = json.loads(client.execute('lsblk --json')) + sdb = [x for x in lsblk['blockdevices'] if x['name'] == 'sdb'][0] + assert len(sdb['children']) == 1 + assert sdb['children'][0]['name'] == 'sdb1' + assert sdb['size'] == '16M' |