|
| 1 | +# Copyright 2024 Red Hat, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +""" |
| 15 | +Use hypothesis stateful testing to test stratisd. |
| 16 | +""" |
| 17 | + |
| 18 | +# isort: STDLIB |
| 19 | +from time import sleep |
| 20 | + |
| 21 | +# isort: THIRDPARTY |
| 22 | +from hypothesis import HealthCheck, settings |
| 23 | +from hypothesis.stateful import RuleBasedStateMachine, precondition, rule |
| 24 | + |
| 25 | +from ._utils import _Service, processes |
| 26 | + |
| 27 | + |
| 28 | +class StratisOrders(RuleBasedStateMachine): |
| 29 | + """ |
| 30 | + Rule based machine for doing testing. |
| 31 | + """ |
| 32 | + |
| 33 | + def __init__(self): # pylint: disable=super-init-not-called |
| 34 | + """ |
| 35 | + Initialize. |
| 36 | + """ |
| 37 | + super().__init__() |
| 38 | + self.service = _Service() |
| 39 | + |
| 40 | + @precondition(lambda self: next(processes("stratisd"), None) is not None) |
| 41 | + @rule() |
| 42 | + def start_stratisd(self): |
| 43 | + """ |
| 44 | + Start stratisd. |
| 45 | + """ |
| 46 | + sleep(5) |
| 47 | + self.service.start_service() |
| 48 | + |
| 49 | + @precondition(lambda self: True) |
| 50 | + @rule() |
| 51 | + def stop_stratisd(self): |
| 52 | + """ |
| 53 | + Stop stratisd. |
| 54 | + """ |
| 55 | + sleep(5) |
| 56 | + self.service.stop_service() |
| 57 | + |
| 58 | + @precondition(lambda self: True) |
| 59 | + @rule() |
| 60 | + def create_pool(self): |
| 61 | + """ |
| 62 | + Create a pool. |
| 63 | + """ |
| 64 | + |
| 65 | + @precondition(lambda self: True) |
| 66 | + @rule() |
| 67 | + def destroy_pool(self): |
| 68 | + """ |
| 69 | + Destroy a pool. |
| 70 | + """ |
| 71 | + |
| 72 | + |
| 73 | +StratisOrders.TestCase.settings = settings(suppress_health_check=[HealthCheck.too_slow]) |
| 74 | +TestStratis = StratisOrders.TestCase |
0 commit comments