summaryrefslogtreecommitdiffstats
path: root/test/features/environment.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:48:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:48:59 +0000
commitd835b2cae8abc71958b69362162e6a70c3d7ef63 (patch)
tree81052e3d2ce3e1bcda085f73d925e9d6257dec15 /test/features/environment.py
parentInitial commit. (diff)
downloadcrmsh-d835b2cae8abc71958b69362162e6a70c3d7ef63.tar.xz
crmsh-d835b2cae8abc71958b69362162e6a70c3d7ef63.zip
Adding upstream version 4.6.0.upstream/4.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/features/environment.py')
-rw-r--r--test/features/environment.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/features/environment.py b/test/features/environment.py
new file mode 100644
index 0000000..61d2ac2
--- /dev/null
+++ b/test/features/environment.py
@@ -0,0 +1,53 @@
+import logging
+import re
+import subprocess
+import time
+
+import crmsh.userdir
+import crmsh.utils
+from crmsh.sh import ShellUtils
+
+
+def get_online_nodes():
+ _, out, _ = ShellUtils().get_stdout_stderr('sudo crm_node -l')
+ if out:
+ return re.findall(r'[0-9]+ (.*) member', out)
+ else:
+ return None
+
+
+def resource_cleanup():
+ subprocess.run(
+ ['sudo', 'crm', 'resource', 'cleanup'],
+ stdin=subprocess.DEVNULL,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
+
+
+def before_step(context, step):
+ context.logger = logging.getLogger("Step:{}".format(step.name))
+
+
+def before_tag(context, tag):
+ # tag @clean means need to stop cluster service
+ if tag == "clean":
+ time.sleep(3)
+ online_nodes = get_online_nodes()
+ if online_nodes:
+ resource_cleanup()
+ while True:
+ time.sleep(1)
+ rc, stdout, _ = ShellUtils().get_stdout_stderr('sudo crmadmin -D -t 1')
+ if rc == 0 and stdout.startswith('Designated'):
+ break
+ subprocess.call(
+ ['sudo', 'crm', 'cluster', 'stop', '--all'],
+ stdin=subprocess.DEVNULL,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
+ if tag == "skip_non_root":
+ sudoer = crmsh.userdir.get_sudoer()
+ if sudoer or crmsh.userdir.getuser() != 'root':
+ context.scenario.skip()