12 logging.basicConfig(level=logging.INFO)
17 def update_script(path, val):
18 with open(path+"_", "w") as f:
20 os.chmod(path+"_", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
21 os.rename(path+"_", path)
24 def set_squeue(actions, checks, k, g):
25 update_script(os.path.join(fake_slurm, "squeue"), """#!/bin/sh
26 echo '1|100|100|ReqNodeNotAvail|34t0i-dz642-h42bg3hq4bdfpf9'
30 def set_sinfo_alloc(actions, checks, k, g):
31 update_script(os.path.join(fake_slurm, "sinfo"), """#!/bin/sh
35 update_script(os.path.join(fake_slurm, "squeue"), """#!/bin/sh
36 echo '1|100|100|Running|34t0i-dz642-h42bg3hq4bdfpf9'
40 compute_nodes[g.group(1)] = g.group(3)
43 def set_sinfo_idle(actions, checks, k, g):
44 update_script(os.path.join(fake_slurm, "sinfo"), """#!/bin/sh
46 """ % (compute_nodes[g.group(1)]))
49 def noop(actions, checks, k, g):
52 def down_fail(actions, checks, k, g):
56 def run_test(actions, checks, driver_class):
60 fake_slurm = tempfile.mkdtemp()
61 logging.info("fake_slurm is %s", fake_slurm)
66 env = os.environ.copy()
67 env["PATH"] = fake_slurm + ":" + env["PATH"]
69 update_script(os.path.join(fake_slurm, "squeue"), "#!/bin/sh\n")
70 update_script(os.path.join(fake_slurm, "sinfo"), "#!/bin/sh\n")
72 with open("tests/fake.cfg.template") as f:
73 with open(os.path.join(fake_slurm, "id_rsa.pub"), "w") as ssh:
75 with open(os.path.join(fake_slurm, "fake.cfg"), "w") as cfg:
76 cfg.write(f.read().format(host=os.environ["ARVADOS_API_HOST"],
77 token=os.environ["ARVADOS_API_TOKEN"],
78 driver_class=driver_class,
79 ssh_key=os.path.join(fake_slurm, "id_rsa.pub")))
81 timeout = time.time() + 300
83 p = subprocess.Popen(["bin/arvados-node-manager", "--foreground", "--config", os.path.join(fake_slurm, "fake.cfg")],
84 bufsize=1, stderr=subprocess.PIPE, env=env)
86 sys.stdout.write(line)
88 if time.time() > timeout:
89 logging.error("Exceeded timeout")
93 for k,v in actions.items():
96 logging.info("Triggered action %s", k)
98 code = v(actions, checks, k, g)
100 logging.error("Action failed")
103 for k,v in checks.items():
104 g = re.match(k, line)
106 logging.info("Triggered check %s", k)
107 code = v(actions, checks, k, g)
109 logging.error("Check failed")
115 #shutil.rmtree(fake_slurm)
122 r".*Daemon started": set_squeue,
123 r".*Cloud node (\S+) is now paired with Arvados node (\S+) with hostname (\S+)": set_sinfo_alloc,
124 r".*ComputeNodeMonitorActor\..*\.([^[]*).*Not eligible for shut down because node state is \('busy', 'open', .*\)": set_sinfo_idle,
125 r".*ComputeNodeMonitorActor\..*\.([^[]*).*Suggesting shutdown because node state is \('idle', 'open', .*\)": noop,
126 r".*Shutdown success": noop,
128 r".*Suggesting shutdown because node state is \('down', .*\)": down_fail
130 "arvnodeman.test.fake_driver.FakeDriver")