Skip to content

Commit 2359991

Browse files
committed
Add a docstring for fistpoint
Signed-off-by: Damien Thenot <[email protected]>
1 parent 38026d3 commit 2359991

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

lib/fistpoint.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
import logging
2-
from typing import Final
32

43
from lib.host import Host
54

5+
from typing import Final
6+
67
FISTPOINT_DIR: Final = "/tmp"
78
LVHDRT_EXIT_FIST: Final = "fist_LVHDRT_exit"
89

10+
911
class FistPoint:
12+
"""
13+
A fistpoint is an action that you can enable in the smapi for tests.
14+
15+
It allows for example, add a sleep at some point or raise an exception.
16+
For example:
17+
```
18+
with FistPoint(vm.host, "blktap_activate_inject_failure"):
19+
with pytest.raises(SSHCommandFailed):
20+
vm.start()
21+
vm.shutdown(force=True)
22+
```
23+
Activating the fistpoint `blktap_activate_inject_failure` mean that the VDI
24+
activation will fail. This fistpoint always raise an exception but most
25+
fistpoint just add a sleep at a point in the code.
26+
Using the fixture `exit_on_fistpoint` make all fistpoints raise an
27+
exception instead by enabling a special fistpoint called `fist_LVHDRT_exit`
28+
"""
29+
1030
fistpointName: str
1131

1232
def __init__(self, host: Host, name: str):

tests/storage/ext/test_ext_sr.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44

5+
from lib.commands import SSHCommandFailed
56
from lib.common import vm_image, wait_for
67
from lib.fistpoint import FistPoint
78
from lib.vdi import VDI
@@ -64,12 +65,9 @@ def test_snapshot(self, vm_on_ext_sr):
6465
def test_blktap_activate_failure(self, vm_on_ext_sr):
6566
from lib.fistpoint import FistPoint
6667
vm = vm_on_ext_sr
67-
with FistPoint(vm.host, "blktap_activate_inject_failure"):
68-
try:
69-
vm.start()
70-
vm.shutdown(force=True)
71-
except Exception as e:
72-
logging.info(f"Expected failure {e}")
68+
with FistPoint(vm.host, "blktap_activate_inject_failure"), pytest.raises(SSHCommandFailed):
69+
vm.start()
70+
vm.shutdown(force=True)
7371

7472
@pytest.mark.small_vm
7573
@pytest.mark.big_vm
@@ -94,7 +92,7 @@ def test_failing_resize(self, host, ext_sr, vm_on_ext_sr, exit_on_fistpoint):
9492
with FistPoint(vm.host, "LVHDRT_inflate_after_setSize"):
9593
try:
9694
vdi.resize(new_size)
97-
except:
95+
except Exception:
9896
logging.info(f"Launching SR scan for {ext_sr} after failure")
9997
host.xe("sr-scan", {"uuid": ext_sr})
10098

tests/storage/lvm/test_lvm_sr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def test_failing_resize_on_inflate_after_setSize(self, host, lvm_sr, vm_on_lvm_s
8686
host.xe("sr-scan", {"uuid": lvm_sr.uuid})
8787
except SSHCommandFailed as e:
8888
assert False, f"Failing to scan following a inflate error {e}"
89-
assert not lvinflate in host.lvs(f"VG_XenStorage-{lvm_sr.uuid}"), "Inflate journal still exist following the scan"
89+
assert lvinflate not in host.lvs(f"VG_XenStorage-{lvm_sr.uuid}"), \
90+
"Inflate journal still exist following the scan"
9091

9192
@pytest.mark.small_vm
9293
@pytest.mark.big_vm
@@ -116,7 +117,8 @@ def test_failing_resize_on_inflate_after_setSizePhys(self, host, lvm_sr, vm_on_l
116117
host.xe("sr-scan", {"uuid": lvm_sr.uuid})
117118
except SSHCommandFailed as e:
118119
assert False, f"Failing to scan following a inflate error {e}"
119-
assert not lvinflate in host.lvs(f"VG_XenStorage-{lvm_sr.uuid}"), "Inflate journal still exist following the scan"
120+
assert lvinflate not in host.lvs(f"VG_XenStorage-{lvm_sr.uuid}"), \
121+
"Inflate journal still exist following the scan"
120122

121123
# *** tests with reboots (longer tests).
122124

0 commit comments

Comments
 (0)