+import getpass
import logging
import os
+import psutil
import subprocess
import sys
import yaml
if archive_dir is None:
archive_dir = teuth_config.archive_base
+ # Refuse to start more than one dispatcher per machine type
+ procs = find_dispatcher_processes(tube)
+ if procs:
+ raise RuntimeError(
+ "There is already a teuthology-dispatcher process running:"
+ f" {procs}"
+ )
+
# setup logging for disoatcher in {log_dir}
loglevel = logging.INFO
if verbose:
return max(returncodes)
+def find_dispatcher_processes(machine_type):
+ user = getpass.getuser()
+ def match(proc):
+ if proc.username() != user:
+ return False
+ cmdline = proc.cmdline()
+ if len(cmdline) < 3:
+ return False
+ if not cmdline[1].endswith("/teuthology-dispatcher"):
+ return False
+ if cmdline[2] == "--supervisor":
+ return False
+ if machine_type not in cmdline:
+ return False
+ if proc.pid == os.getpid():
+ return False
+ return True
+
+ attrs = ["pid", "username", "cmdline"]
+ procs = list(filter(match, psutil.process_iter(attrs=attrs)))
+ return procs
+
+
def lock_machines(job_config):
report.try_push_job_info(job_config, dict(status='running'))
fake_ctx = supervisor.create_fake_context(job_config, block=True)