From 39c4631f0b09d5f4f1274385238b14212309ef91 Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 13 Sep 2024 16:34:17 -0400 Subject: [PATCH] Initial test that just starts and stops stratisd Signed-off-by: mulhern --- .github/workflows/support.yml | 1 + tests-fmf/python.fmf | 21 +----- tests/client-dbus/Makefile | 4 + .../tests/udev/test_hypothesis_stateful.py | 74 +++++++++++++++++++ 4 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 tests/client-dbus/tests/udev/test_hypothesis_stateful.py diff --git a/.github/workflows/support.yml b/.github/workflows/support.yml index 0f7adcf087..5b92d2df50 100644 --- a/.github/workflows/support.yml +++ b/.github/workflows/support.yml @@ -42,6 +42,7 @@ jobs: pylint python3-dbus-client-gen python3-dbus-python-client-gen + python3-hypothesis python3-justbytes python3-psutil python3-pyudev diff --git a/tests-fmf/python.fmf b/tests-fmf/python.fmf index 52c8237fbd..153f4cb5f4 100644 --- a/tests-fmf/python.fmf +++ b/tests-fmf/python.fmf @@ -8,6 +8,7 @@ require: - python3-dbus - python3-dbus-client-gen - python3-dbus-python-client-gen + - python3-hypothesis - python3-psutil - python3-pyudev - python3-tenacity @@ -19,22 +20,6 @@ environment: STRATIS_DUMPMETADATA: /usr/bin/stratis-dumpmetadata PYTHONPATH: ./src -/legacy: - environment+: - LEGACY_POOL: /usr/local/bin/stratis-legacy-pool - -/legacy/udev: - summary: Run Python udev tests - test: make -f Makefile udev-tests - -/legacy/loop: - summary: Run Python tests that use loopbacked device framework - test: make -f Makefile tang-tests dump-metadata-tests startup-tests - /v2/udev: - summary: Run Python udev tests - test: make -f Makefile udev-tests - -/v2/loop: - summary: Run Python tests that use loopbacked device framework - test: make -f Makefile tang-tests dump-metadata-tests startup-tests + summary: Run Python model tests + test: make -f Makefile model-tests diff --git a/tests/client-dbus/Makefile b/tests/client-dbus/Makefile index db20f1460b..ac4e5dcd86 100644 --- a/tests/client-dbus/Makefile +++ b/tests/client-dbus/Makefile @@ -38,3 +38,7 @@ filesystem-predict-tests: .PHONY: dump-metadata-tests dump-metadata-tests: python3 -m unittest ${UNITTEST_OPTS} tests.udev.test_dump + +.PHONY: model-tests +model-tests: + python3 -m unittest ${UNITTEST_OPTS} tests.udev.test_hypothesis_stateful diff --git a/tests/client-dbus/tests/udev/test_hypothesis_stateful.py b/tests/client-dbus/tests/udev/test_hypothesis_stateful.py new file mode 100644 index 0000000000..be328271b8 --- /dev/null +++ b/tests/client-dbus/tests/udev/test_hypothesis_stateful.py @@ -0,0 +1,74 @@ +# Copyright 2024 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. +""" +Use hypothesis stateful testing to test stratisd. +""" + +# isort: STDLIB +from time import sleep + +# isort: THIRDPARTY +from hypothesis import HealthCheck, settings +from hypothesis.stateful import RuleBasedStateMachine, precondition, rule + +from ._utils import _Service, processes + + +class StratisOrders(RuleBasedStateMachine): + """ + Rule based machine for doing testing. + """ + + def __init__(self): # pylint: disable=super-init-not-called + """ + Initialize. + """ + super().__init__() + self.service = _Service() + + @precondition(lambda self: next(processes("stratisd"), None) is not None) + @rule() + def start_stratisd(self): + """ + Start stratisd. + """ + sleep(5) + self.service.start_service() + + @precondition(lambda self: True) + @rule() + def stop_stratisd(self): + """ + Stop stratisd. + """ + sleep(5) + self.service.stop_service() + + @precondition(lambda self: True) + @rule() + def create_pool(self): + """ + Create a pool. + """ + + @precondition(lambda self: True) + @rule() + def destroy_pool(self): + """ + Destroy a pool. + """ + + +StratisOrders.TestCase.settings = settings(suppress_health_check=[HealthCheck.too_slow]) +TestStratis = StratisOrders.TestCase