Skip to content

Commit b8ce419

Browse files
committed
feat(fistpoint): Add fistpoint interface in lib
And a `exit_on_fistpoint` fixture to enable the behavior of exiting instead of pausing 30 seconds at normal fistpoint Signed-off-by: Damien Thenot <[email protected]>
1 parent d2fdebe commit b8ce419

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,15 @@ def nfs_iso_sr(host, nfs_iso_device_config):
742742
# teardown
743743
sr.forget()
744744

745+
@pytest.fixture(scope='module')
746+
def exit_on_fistpoint(host):
747+
from lib.fistpoint import FistPoint
748+
logging.info(">> Enabling exit on fistpoint")
749+
FistPoint.enable_exit_on_fistpoint(host)
750+
yield
751+
logging.info("<< Disabling exit on fistpoint")
752+
FistPoint.disable_exit_on_fistpoint(host)
753+
745754
@pytest.fixture(scope='module')
746755
def cifs_iso_sr(host, cifs_iso_device_config):
747756
""" A Samba/CIFS SR. """

lib/fistpoint.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import logging
2+
from typing import Final
3+
4+
from lib.host import Host
5+
6+
FISTPOINT_DIR: Final = "/tmp"
7+
LVHDRT_EXIT_FIST: Final = "fist_LVHDRT_exit"
8+
9+
class FistPoint:
10+
fistpointName: str
11+
12+
def __init__(self, host: Host, name: str):
13+
self.fistpointName = self._get_name(name)
14+
self.host = host
15+
16+
@staticmethod
17+
def enable_exit_on_fistpoint(host: Host):
18+
host.create_file(FistPoint._get_path(LVHDRT_EXIT_FIST), "")
19+
20+
@staticmethod
21+
def disable_exit_on_fistpoint(host: Host):
22+
host.ssh(["rm", FistPoint._get_path(LVHDRT_EXIT_FIST)])
23+
24+
@staticmethod
25+
def _get_name(name: str) -> str:
26+
if name.startswith("fist_"):
27+
return name
28+
else:
29+
return f"fist_{name}"
30+
31+
@staticmethod
32+
def _get_path(name) -> str:
33+
return f"{FISTPOINT_DIR}/{name}"
34+
35+
def enable(self):
36+
logging.info(f"Enable fistpoint {self.fistpointName}")
37+
self.host.create_file(self._get_path(self.fistpointName), "")
38+
39+
def disable(self):
40+
logging.info(f"Disabling fistpoint {self.fistpointName}")
41+
self.host.ssh(["rm", self._get_path(self.fistpointName)])
42+
43+
def __enter__(self):
44+
self.enable()
45+
return self
46+
47+
def __exit__(self, *_):
48+
self.disable()

0 commit comments

Comments
 (0)