summaryrefslogtreecommitdiffstats
path: root/test/features/environment.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-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()