From bd25fe519dc3fd797f4f402bc20e71ac87737399 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Mon, 13 Nov 2023 12:32:04 +0100 Subject: [PATCH 1/6] Add flag to control LVM devices file support We want to be able to control whether the devices are added to the LVM devices file. For example Anaconda doesn't want to create the file when running an image installation. --- blivet/flags.py | 3 +++ blivet/formats/lvmpv.py | 5 +++++ tests/unit_tests/formats_tests/lvmpv_test.py | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/blivet/flags.py b/blivet/flags.py index e1f2279b2..66edf01ca 100644 --- a/blivet/flags.py +++ b/blivet/flags.py @@ -71,6 +71,9 @@ def __init__(self): # backup metadata in /etc/lvm/{archive,backup} self.lvm_metadata_backup = True + # set to False to not write new LVM PVs to /etc/lvm/devices/system.devices + self.lvm_devices_file = True + # whether to include nodev filesystems in the devicetree self.include_nodev = False diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py index b72ea519e..142e37b82 100644 --- a/blivet/formats/lvmpv.py +++ b/blivet/formats/lvmpv.py @@ -37,6 +37,7 @@ from . import DeviceFormat, register_device_format from .. import udev from ..static_data.lvm_info import pvs_info, vgs_info +from ..flags import flags import logging log = logging.getLogger("blivet") @@ -136,6 +137,10 @@ def lvmdevices_add(self, force=True): self.device, lvm.LVM_DEVICES_FILE) return + if not flags.lvm_devices_file: + log.debug("Not adding %s to devices file: 'lvm_devices_file' flag is set to False", self.device) + return + try: blockdev.lvm.devices_add(self.device) except blockdev.LVMError as e: diff --git a/tests/unit_tests/formats_tests/lvmpv_test.py b/tests/unit_tests/formats_tests/lvmpv_test.py index 6490c7d48..2d22d2f1d 100644 --- a/tests/unit_tests/formats_tests/lvmpv_test.py +++ b/tests/unit_tests/formats_tests/lvmpv_test.py @@ -8,6 +8,7 @@ import unittest from blivet.formats.lvmpv import LVMPhysicalVolume +from blivet.flags import flags class LVMPVNodevTestCase(unittest.TestCase): @@ -71,3 +72,18 @@ def test_lvm_devices(self): fmt._create() mock["blockdev"].lvm.devices_add.assert_not_called() + + with self.patches() as mock: + # LVM devices file enabled and devices file exists + # but flag set to false -> devices_add should not be called + mock["lvm"].HAVE_LVMDEVICES = True + mock["os"].path.exists.return_value = True + mock["vgs_info"].cache = {} + flags.lvm_devices_file = False + + fmt._create() + + mock["blockdev"].lvm.devices_add.assert_not_called() + + # reset the flag back + flags.lvm_devices_file = True From 59e132bcd2970a1d1755caccc8689aa6b709d37e Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Mon, 13 Nov 2023 12:33:17 +0100 Subject: [PATCH 2/6] Fix failing tests when running as a non-root user Just one more LVM call we need to mock to be able to run the unit tests as a normal user. --- tests/unit_tests/formats_tests/methods_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/formats_tests/methods_test.py b/tests/unit_tests/formats_tests/methods_test.py index f9e2aebf7..48d0a35c3 100644 --- a/tests/unit_tests/formats_tests/methods_test.py +++ b/tests/unit_tests/formats_tests/methods_test.py @@ -388,6 +388,7 @@ class LVMPhysicalVolumeMethodsTestCase(FormatMethodsTestCase): def set_patches(self): super(LVMPhysicalVolumeMethodsTestCase, self).set_patches() self.patchers["blockdev"] = patch("blivet.formats.lvmpv.blockdev") + self.patchers["vgs_info"] = patch("blivet.formats.lvmpv.vgs_info") def _test_destroy_backend(self): self.format.exists = True From f09da70796ad74dbdd98ffd2fc71d14e09c4f85c Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 14 Nov 2023 08:43:33 +0100 Subject: [PATCH 3/6] ci: Allow installing only build dependencies without test deps --- misc/install-test-dependencies.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/misc/install-test-dependencies.yml b/misc/install-test-dependencies.yml index 19c3b4f72..691a92292 100644 --- a/misc/install-test-dependencies.yml +++ b/misc/install-test-dependencies.yml @@ -7,6 +7,8 @@ --- - hosts: all become: true + vars: + test_dependencies: true # whether to install test dependencies or not tasks: ####### Fedora @@ -53,7 +55,7 @@ - python3-paramiko - targetcli - iscsi-initiator-utils - when: ansible_distribution == 'Fedora' + when: ansible_distribution == 'Fedora' and test_dependencies|bool ####### CentOS 8/9 - name: Install basic build tools (CentOS) @@ -104,15 +106,15 @@ - python3-pip - targetcli - iscsi-initiator-utils - when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '8' + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '8' and test_dependencies|bool - name: Install paramiko using pip (not available in EPEL yet) (CentOS 9) pip: name=paramiko executable=pip3 - when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '9' + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '9' and test_dependencies|bool - name: Install pocketlint using pip (CentOS) pip: name=pocketlint executable=pip3 - when: ansible_distribution == 'CentOS' + when: ansible_distribution == 'CentOS' and test_dependencies|bool ####### Debian/Ubuntu - name: Update apt cache (Debian/Ubuntu) @@ -159,7 +161,7 @@ - python3-pip - targetcli-fb - open-iscsi - when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' and test_dependencies|bool - name: Install libmount (Debian/Ubuntu) block: @@ -175,4 +177,4 @@ - name: Install pocketlint using pip (Debian/Ubuntu) pip: name=pocketlint executable=pip3 - when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' and test_dependencies|bool From 4ea77c3f1f0dd93b35eecb556b6a0dde4360333a Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 14 Nov 2023 08:44:04 +0100 Subject: [PATCH 4/6] ci: Add a Dockerfile for building a CI container --- misc/ci.Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 misc/ci.Dockerfile diff --git a/misc/ci.Dockerfile b/misc/ci.Dockerfile new file mode 100644 index 000000000..eecf79e23 --- /dev/null +++ b/misc/ci.Dockerfile @@ -0,0 +1,10 @@ +# latest fedora image for running some of our tests in GH actions + +FROM registry.fedoraproject.org/fedora:latest + +RUN set -e; \ + dnf install -y ansible python3-pip git which dnf-plugins-core; \ + git clone --depth 1 https://github.com/storaged-project/ci.git; \ + git clone --depth 1 https://github.com/storaged-project/blivet-gui.git; + +WORKDIR / From ef7f24bd0a72c90c15dc2f041b071b16efb1b46c Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 14 Nov 2023 08:44:29 +0100 Subject: [PATCH 5/6] ci: Add a GH action to run blivet-gui test suite on PRs Reverse dependency testing for blivet-gui. --- .github/workflows/blivetgui_tests.yml | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/blivetgui_tests.yml diff --git a/.github/workflows/blivetgui_tests.yml b/.github/workflows/blivetgui_tests.yml new file mode 100644 index 000000000..3a8b3bedb --- /dev/null +++ b/.github/workflows/blivetgui_tests.yml @@ -0,0 +1,53 @@ +name: Blivet-GUI tests + +on: + pull_request: + branches: + - 3.*-devel + +jobs: + build: + name: blivetgui-tests + runs-on: ubuntu-22.04 + env: + CI_CONTAINER: blivet-ci-blivetgui-tests + steps: + - name: Checkout blivet repository + uses: actions/checkout@v4 + + - name: Install podman + run: | + sudo apt -qq update + sudo apt -y -qq install podman + + - name: Build the container + run: | + podman build --no-cache -t ${{ env.CI_CONTAINER }} -f misc/ci.Dockerfile . + + - name: Start the container + run: | + podman run -d -t --name ${{ env.CI_CONTAINER }} --privileged --volume "$(pwd):/app" --workdir "/app" ${{ env.CI_CONTAINER }} + + - name: Install Blivet-GUI test dependencies in the container + run: | + podman exec -it ${{ env.CI_CONTAINER }} bash -c "ansible-playbook -i "localhost," -c local /blivet-gui/misc/install-test-dependencies.yml" + + - name: Remove Blivet from the container (we want to install from source) + run: | + podman exec -it ${{ env.CI_CONTAINER }} bash -c "dnf -y remove python3-blivet --noautoremove" + + - name: Install Blivet build dependencies in the container + run: | + podman exec -it ${{ env.CI_CONTAINER }} bash -c "ansible-playbook -i "localhost," -c local misc/install-test-dependencies.yml" + + - name: Build and install Blivet in the container + run: | + podman exec -it ${{ env.CI_CONTAINER }} bash -c "python3 setup.py install --prefix=/usr" + + - name: Run Blivet-GUI static analysis in the container + run: | + podman exec -it ${{ env.CI_CONTAINER }} bash -c "cd /blivet-gui && make check" + + - name: Run Blivet-GUI unit tests in the container + run: | + podman exec -it ${{ env.CI_CONTAINER }} bash -c "cd /blivet-gui && make gui-test" From 6c282c2781cdeef1eb17052e974051ec2fde262d Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 15 Nov 2023 09:03:12 +0100 Subject: [PATCH 6/6] Fix passing extra mkfs arguments to libblockdev Resolves: https://github.com/rhinstaller/kickstart-tests/issues/1028 --- blivet/tasks/fsmkfs.py | 9 ++++++++- tests/storage_tests/formats_test/fs_test.py | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/blivet/tasks/fsmkfs.py b/blivet/tasks/fsmkfs.py index 062d54777..e9daa9ea3 100644 --- a/blivet/tasks/fsmkfs.py +++ b/blivet/tasks/fsmkfs.py @@ -272,11 +272,18 @@ def do_task(self, options=None, label=False, set_uuid=False, nodiscard=False): " is unacceptable for this filesystem." % (self.fs.label, self.fs.type)) + if self.fs.create_options: + create_options = shlex.split(self.fs.create_options) + else: + create_options = [] + if options: + create_options += options + try: bd_options = BlockDev.FSMkfsOptions(label=self.fs.label if label else None, uuid=self.fs.uuid if set_uuid else None, no_discard=self.fs._mkfs_nodiscard if nodiscard else False) - BlockDev.fs.mkfs(self.fs.device, self.fstype, bd_options, extra=options or []) + BlockDev.fs.mkfs(self.fs.device, self.fstype, bd_options, extra={k: '' for k in create_options}) except BlockDev.FSError as e: raise FSError(str(e)) diff --git a/tests/storage_tests/formats_test/fs_test.py b/tests/storage_tests/formats_test/fs_test.py index 7c9ec58b3..e566670d5 100644 --- a/tests/storage_tests/formats_test/fs_test.py +++ b/tests/storage_tests/formats_test/fs_test.py @@ -10,6 +10,7 @@ from blivet.formats import get_format from blivet.devices import PartitionDevice, DiskDevice from blivet.flags import flags +from blivet.util import capture_output from .loopbackedtestcase import LoopBackedTestCase @@ -67,6 +68,25 @@ def test_online_resize(self): an_fs.unmount() + def test_create_options(self): + label = "root-test-label" + uuid = "c1b9d5a2-f162-11cf-9ece-0020afc76f16" + + an_fs = self._fs_class() + if not an_fs.formattable: + self.skipTest("can not create filesystem %s" % an_fs.name) + an_fs.device = self.loop_devices[0] + + # custom fs create options -- -L