aboutsummaryrefslogtreecommitdiff
path: root/scenarios/fragments/shared.py
diff options
context:
space:
mode:
Diffstat (limited to 'scenarios/fragments/shared.py')
-rw-r--r--scenarios/fragments/shared.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/scenarios/fragments/shared.py b/scenarios/fragments/shared.py
new file mode 100644
index 0000000..e0cd449
--- /dev/null
+++ b/scenarios/fragments/shared.py
@@ -0,0 +1,28 @@
+import os, time
+
+binary_path = "/tmp/mknet-bin"
+storage_path = "/tmp/mknet-store"
+
+def exec(s):
+ if os.system(s) != 0:
+ raise Exception("Command terminated with an error")
+def exec_retry(s, cnt=16):
+ print(s)
+ for i in range(cnt):
+ time.sleep(i) # this is expected to sleep before running the command to reduce the noise
+ if os.system(s) == 0: return
+ raise Exception("Command terminated with an error too many times")
+def fn_retry(f, cnt=5):
+ for i in range(cnt):
+ try:
+ r = f()
+ return r
+ except Exception as e:
+ if i+1 == cnt: raise e
+ log(f"failed call, retry in {i} sec")
+ time.sleep(i)
+
+def id(): return int(os.environ['ID'])
+def count(): return int(os.environ['SERVER_COUNT'])
+def log(*args): print(f"[{id()}/{count()} - {os.environ['HOST']}]", *args)
+