From 6760f57e3c28ba360c65ab8e09ca09626f4c1a34 Mon Sep 17 00:00:00 2001 From: mulhern Date: Wed, 20 Sep 2023 16:16:38 -0400 Subject: [PATCH 1/4] Use Packit/TMT to run Python-based udev tests Run all the tests defined in the udev subdirectory that should be run as continuous integration and not as part of nightly CI. Signed-off-by: mulhern --- .fmf/version | 1 + .github/workflows/python.yml | 155 ----------------------------------- .packit.yaml | 6 +- plans/all.fmf | 18 ++++ test/loop/main.fmf | 12 +++ test/udev/main.fmf | 12 +++ 6 files changed, 48 insertions(+), 156 deletions(-) create mode 100644 .fmf/version delete mode 100644 .github/workflows/python.yml create mode 100644 plans/all.fmf create mode 100644 test/loop/main.fmf create mode 100644 test/udev/main.fmf diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml deleted file mode 100644 index 7cc1a2401f..0000000000 --- a/.github/workflows/python.yml +++ /dev/null @@ -1,155 +0,0 @@ ---- -name: stratisd python-based tests - -# yamllint disable-line rule:truthy -on: - push: - branches: - - master - paths-ignore: - - 'CHANGES.txt' - - '**/README.md' - - 'README_tests.md' - - ".packit.yaml" - pull_request: - branches: - - master - paths-ignore: - - 'CHANGES.txt' - - '**/README.md' - - 'README_tests.md' - - ".packit.yaml" - - workflow_dispatch: - -# cancel the in-progress workflow when PR is refreshed. -# yamllint disable rule:line-length -concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} - cancel-in-progress: true - -jobs: - - python-based-tests: - strategy: - matrix: - include: - # MANDATORY CHECKS USING CURRENT DEVELOPMENT ENVIRONMENT - - toolchain: 1.72.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN - # MANDATORY CHECKS USING LOWEST SUPPORTED ENVIRONMENT PROXY - - toolchain: 1.71.1 # LOWEST SUPPORTED RUST TOOLCHAIN - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - name: Run apt-get update - run: sudo apt-get -q update - - name: Install dependencies for Ubuntu - run: > - DEBIAN_FRONTEND=noninteractive - sudo apt-get install -y - asciidoc - clang - curl - libblkid-dev - libcryptsetup-dev - libdbus-1-dev - libdevmapper-dev - libsystemd-dev - libudev-dev - make - thin-provisioning-tools - udev - xfsprogs - - name: Install Python dependencies - run: > - sudo python -m pip install - dbus-python - dbus-client-gen - dbus-python-client-gen - psutil - pyudev - - uses: dtolnay/rust-toolchain@master - with: - components: cargo - toolchain: ${{ matrix.toolchain }} - - name: Build stratisd - run: PROFILEDIR=debug make -f Makefile build-all - - name: Install stratisd - run: sudo make PROFILEDIR=debug -f Makefile install - - name: Workaround for dbus inotify - run: sudo cp stratisd.conf /usr/share/dbus-1/system.d - - name: Reload udev - run: sudo udevadm control --reload - - name: Tests using Rust ${{ matrix.toolchain }} - run: > - sudo make - RUST_LOG=stratisd=debug - STRATIS_DUMPMETADATA=/usr/bin/stratis-dumpmetadata - STRATISD=/usr/libexec/stratisd - PYTHONPATH=./src - udev-tests dump-metadata-tests startup-tests - working-directory: ./tests/client-dbus - - # PYTHON-BASED TESTS WITH TANG - python-based-checks_with_tang: - runs-on: ubuntu-22.04 - container: - image: fedora:38 # CURRENT DEVELOPMENT ENVIRONMENT - options: --privileged -v /dev:/dev --userns=host --ipc=host -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro -v /usr/share/dbus-1:/usr/share/dbus-1 -v /run/udev:/run/udev -v /usr/lib/udev:/usr/lib/udev - services: - tang: - # yamllint disable rule:line-length - image: ghcr.io/stratis-storage/stratisd/tang:38 # CURRENT DEVELOPMENT ENVIRONMENT - credentials: - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - options: --privileged -p 80:80 - steps: - - uses: actions/checkout@v3 - - name: Install dependencies for Fedora - # cracklib-dicts: https://github.com/stratis-storage/project/issues/581 - run: > - dnf install -y - asciidoc - clang - clevis - clevis-luks - cryptsetup-devel - cracklib-dicts - curl - dbus-devel - dbus-tools - device-mapper-devel - device-mapper-persistent-data - glibc-static - libblkid-devel - make - ncurses - python3-dbus - python3-dbus-client-gen - python3-dbus-python-client-gen - python3-psutil - python3-pyudev - systemd-devel - systemd-udev - xfsprogs - - uses: dtolnay/rust-toolchain@master - with: - components: cargo - toolchain: 1.72.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN - - name: Build stratisd - run: PROFILEDIR=debug make -f Makefile build-all - - name: Install stratisd - run: PROFILEDIR=debug make -f Makefile install - - name: Workaround for dbus inotify - run: cp stratisd.conf /usr/share/dbus-1/system.d - - name: Reload udev - run: udevadm control --reload - - name: Run D-Bus based bind tests - run: > - TANG_URL=tang - RUST_LOG=stratisd=debug - STRATISD=/usr/libexec/stratisd - PYTHONPATH=./src - make -f Makefile tang-tests - working-directory: ./tests/client-dbus diff --git a/.packit.yaml b/.packit.yaml index 243e3d9666..93464b84da 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -29,6 +29,10 @@ srpm_build_deps: jobs: - job: copr_build trigger: pull_request - manual_trigger: true + targets: + - fedora-stable + + - job: tests + trigger: pull_request targets: - fedora-stable diff --git a/plans/all.fmf b/plans/all.fmf new file mode 100644 index 0000000000..679cf40f1e --- /dev/null +++ b/plans/all.fmf @@ -0,0 +1,18 @@ +summary: top level management +prepare: + - name: Install packages + how: install + package: + - tang + - systemd + - name: Start tang server + how: shell + script: systemctl enable tangd.socket --now + - name: Reload udev + how: shell + script: udevadm control --reload +discover: + how: fmf +execute: + how: tmt + exit-first: false diff --git a/test/loop/main.fmf b/test/loop/main.fmf new file mode 100644 index 0000000000..785361b4f6 --- /dev/null +++ b/test/loop/main.fmf @@ -0,0 +1,12 @@ +summary: Run tests that use loopbacked device framework +duration: 20m +require: + - clevis-luks + - make + - python3-dbus + - python3-dbus-client-gen + - python3-dbus-python-client-gen + - python3-psutil + - python3-pyudev +test: TANG_URL=localhost RUST_LOG=stratisd=debug STRATISD=/usr/libexec/stratisd STRATIS_DUMPMETADATA=/usr/bin/stratis-dumpmetadata PYTHONPATH=./src make -f Makefile tang-tests dump-metadata-tests +path: /tests/client-dbus diff --git a/test/udev/main.fmf b/test/udev/main.fmf new file mode 100644 index 0000000000..af74a1e5a0 --- /dev/null +++ b/test/udev/main.fmf @@ -0,0 +1,12 @@ +summary: Run udev tests +duration: 20m +require: + - clevis-luks + - make + - python3-dbus + - python3-dbus-client-gen + - python3-dbus-python-client-gen + - python3-psutil + - python3-pyudev +test: TANG_URL=localhost RUST_LOG=stratisd=debug STRATISD=/usr/libexec/stratisd STRATIS_DUMPMETADATA=/usr/bin/stratis-dumpmetadata PYTHONPATH=./src make -f Makefile udev-tests +path: /tests/client-dbus From 1bcf354c7403fa4afd8eb8813f1c35d2eb4d6773 Mon Sep 17 00:00:00 2001 From: mulhern Date: Thu, 21 Sep 2023 20:23:02 -0400 Subject: [PATCH 2/4] Add tmtlint support Signed-off-by: mulhern --- .github/workflows/support.yml | 4 ++-- .github/workflows/weekly.yml | 4 ++-- Makefile | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/support.yml b/.github/workflows/support.yml index bce8cd6c19..4d49d5aa21 100644 --- a/.github/workflows/support.yml +++ b/.github/workflows/support.yml @@ -45,8 +45,8 @@ jobs: - dependencies: black python3-isort task: make -f Makefile fmt-ci working-directory: ./tests/client-dbus - - dependencies: yamllint - task: make -f Makefile yamllint + - dependencies: yamllint tmt + task: make -f Makefile yamllint tmtlint working-directory: . runs-on: ubuntu-22.04 container: fedora:38 # CURRENT DEVELOPMENT ENVIRONMENT diff --git a/.github/workflows/weekly.yml b/.github/workflows/weekly.yml index 5be9712813..58831a5a19 100644 --- a/.github/workflows/weekly.yml +++ b/.github/workflows/weekly.yml @@ -29,8 +29,8 @@ jobs: - dependencies: black python3-isort task: make -f Makefile fmt-ci working-directory: ./tests/client-dbus - - dependencies: yamllint - task: make -f Makefile yamllint + - dependencies: yamllint tmt + task: make -f Makefile yamllint tmtlint working-directory: . - dependencies: shfmt task: make -f Makefile fmt-shell-ci diff --git a/Makefile b/Makefile index e48b8301fe..99d41d9940 100644 --- a/Makefile +++ b/Makefile @@ -425,6 +425,10 @@ test-stratis-min: yamllint: yamllint --strict .github/workflows/*.yml .packit.yaml +## Run tmt lint +tmtlint: + tmt lint + ## Build docs-rust for CI docs-ci: docs-rust @@ -507,6 +511,7 @@ clippy: clippy-macros clippy-min clippy-udev-utils clippy-no-ipc test-clevis-loop-should-fail-valgrind test-clevis-real test-clevis-real-should-fail + tmtlint yamllint # COLORS From e55dd640d07542c309da1efc198af8b0af145c34 Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 22 Sep 2023 12:06:43 -0400 Subject: [PATCH 3/4] Do not use first created loopbacked device Some vaguery of the test system causes it to be disappeared from the udev database. Signed-off-by: mulhern --- tests/client-dbus/tests/udev/_loopback.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/client-dbus/tests/udev/_loopback.py b/tests/client-dbus/tests/udev/_loopback.py index f7386d176e..b05c61f686 100644 --- a/tests/client-dbus/tests/udev/_loopback.py +++ b/tests/client-dbus/tests/udev/_loopback.py @@ -97,11 +97,21 @@ def create_devices(self, number): Note: The first time a loop back device is known it will generate a udev "add" event, subsequent backing file changes do not, thus we will need to generate it synthetically. + + If this is the absolute first time calling losetup for this sequence, + make an extra loop device and skip the first loop device created. + :param int number: the number of devices to create :return: list of keys for the devices :rtype: list of uuid.UUID """ tokens = [] + + first_creation = self.count == 0 + + if first_creation: + number = number + 1 + for _ in range(number): backing_file = os.path.join(self.dir, f"block_device_{self.count}") self.count += 1 @@ -119,6 +129,9 @@ def create_devices(self, number): self.devices[token] = (device, backing_file) tokens.append(token) + if first_creation: + tokens = tokens[1:] + self._wait_for_udev(tokens) self.generate_synthetic_udev_events(tokens, UDEV_ADD_EVENT) return tokens From a6a335b3b664ff995f26ea3bc2aa4fcefb946d84 Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 22 Sep 2023 12:57:28 -0400 Subject: [PATCH 4/4] Remove startup tests These don't simulate very well stratisd/stratisd-min's current operation, in fact they ignore stratisd-min entirely. Also, the best way to test lock file handling is in the context of systemd's operation, i.e., on start up. These tests have gone back to just being clutter and we should remove them. Signed-off-by: mulhern --- tests/client-dbus/tests/misc/test_startup.py | 90 -------------------- 1 file changed, 90 deletions(-) delete mode 100644 tests/client-dbus/tests/misc/test_startup.py diff --git a/tests/client-dbus/tests/misc/test_startup.py b/tests/client-dbus/tests/misc/test_startup.py deleted file mode 100644 index fbe3690eab..0000000000 --- a/tests/client-dbus/tests/misc/test_startup.py +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright 2019 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -Test unique stratis instance. -""" - - -# isort: STDLIB -import os -import subprocess -import time -import unittest - -# isort: THIRDPARTY -import psutil - -_STRATISD = os.environ["STRATISD"] - - -class TestUniqueInstance(unittest.TestCase): - """ - Test that only one instance of stratisd can be running at any given time. - """ - - # pylint: disable=consider-using-with - def setUp(self): - """ - Start the original stratisd instance. Register a cleanup function to - terminate it once started. - """ - process = subprocess.Popen( - [_STRATISD, "--sim"], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - close_fds=True, - env=os.environ, - ) - - for _ in range(5): - if psutil.pid_exists(process.pid): - break - time.sleep(1) - else: - raise RuntimeError("Initial stratisd process was not started.") - - def cleanup(): - process.terminate() - process.wait() - - self.addCleanup(cleanup) - - def test_unique_instance(self): - """ - Verify that a second stratisd instance can not be started. - """ - - stratisd_lock_file = "/run/stratisd.pid" - - for _ in range(5): - if os.path.exists(stratisd_lock_file): - break - time.sleep(1) - else: - raise RuntimeError( - f"Lock file {stratisd_lock_file} does not seem to exist." - ) - - env = dict(os.environ) - env["RUST_LOG"] = env.get("RUST_LOG", "") + ",nix::fcntl=debug" - with subprocess.Popen( - [_STRATISD, "--sim"], - stderr=subprocess.STDOUT, - text=True, - close_fds=True, - env=env, - ) as process: - (_, _) = process.communicate() - self.assertEqual(process.returncode, 1)