import argparse
import atexit
import errno
+import glob
import httplib2
import os
import pipes
import shutil
import signal
import socket
-import subprocess
import string
+import subprocess
import sys
import tempfile
import time
# Pidfile exists, but we can't parse it. Perhaps the
# server has created the file but hasn't written its PID
# yet?
- print("Parse error reading pidfile {}: {}".format(pidfile, error))
+ print("Parse error reading pidfile {}: {}".format(pidfile, error),
+ file=sys.stderr)
time.sleep(0.1)
now = time.time()
try:
if now >= startTERM:
os.kill(server_pid, signal.SIGTERM)
- print("Sent SIGTERM to {} ({})".format(server_pid, pidfile))
+ print("Sent SIGTERM to {} ({})".format(server_pid, pidfile),
+ file=sys.stderr)
except OSError as error:
if error.errno == errno.ESRCH:
# Thrown by os.getpgid() or os.kill() if the process
now = time.time()
print("Server PID {} ({}) did not exit, giving up after {}s".
- format(server_pid, pidfile, wait))
+ format(server_pid, pidfile, wait),
+ file=sys.stderr)
def find_available_port():
"""Return an IPv4 port number that is not in use right now.
subprocess.check_output(['which', 'lsof'])
except subprocess.CalledProcessError:
print("WARNING: No `lsof` -- cannot wait for port to listen. "+
- "Sleeping 0.5 and hoping for the best.")
+ "Sleeping 0.5 and hoping for the best.",
+ file=sys.stderr)
time.sleep(0.5)
return
deadline = time.time() + timeout
raise
os.mkfifo(fifo, 0700)
subprocess.Popen(
- ['sed', '-e', 's/^/['+label+'] /', fifo],
+ ['stdbuf', '-i0', '-oL', '-eL', 'sed', '-e', 's/^/['+label+'] /', fifo],
stdout=sys.stderr)
return fifo
"""
global my_api_host
- # Delete cached discovery document.
- shutil.rmtree(arvados.http_cache('discovery'))
+ # Delete cached discovery documents.
+ #
+ # This will clear cached docs that belong to other processes (like
+ # concurrent test suites) even if they're still running. They should
+ # be able to tolerate that.
+ for fn in glob.glob(os.path.join(arvados.http_cache('discovery'),
+ '*,arvados,v1,rest,*')):
+ os.unlink(fn)
pid_file = _pidfile('api')
pid_file_ok = find_server_pid(pid_file, 0)
# keepstore services.
proxypidfile = _pidfile('keepproxy')
if os.path.exists(proxypidfile):
- os.kill(int(open(proxypidfile).read()), signal.SIGHUP)
+ try:
+ os.kill(int(open(proxypidfile).read()), signal.SIGHUP)
+ except OSError:
+ os.remove(proxypidfile)
def _stop_keep(n):
kill_server_pid(_pidfile('keep{}'.format(n)))
'service_type': 'proxy',
'service_ssl_flag': False,
}}).execute()
- os.environ["ARVADOS_KEEP_PROXY"] = "http://localhost:{}".format(port)
+ os.environ["ARVADOS_KEEP_SERVICES"] = "http://localhost:{}".format(port)
_setport('keepproxy', port)
_wait_until_port_listens(port)
cls._orig_environ = os.environ.copy()
cls._orig_config = arvados.config.settings().copy()
cls._cleanup_funcs = []
- os.environ.pop('ARVADOS_KEEP_PROXY', None)
+ os.environ.pop('ARVADOS_KEEP_SERVICES', None)
os.environ.pop('ARVADOS_EXTERNAL_CLIENT', None)
for server_kwargs, start_func, stop_func in (
(cls.MAIN_SERVER, run, reset),
args = parser.parse_args()
if args.action not in actions:
- print("Unrecognized action '{}'. Actions are: {}.".format(args.action, actions), file=sys.stderr)
+ print("Unrecognized action '{}'. Actions are: {}.".
+ format(args.action, actions),
+ file=sys.stderr)
sys.exit(1)
if args.action == 'start':
stop(force=('ARVADOS_TEST_API_HOST' not in os.environ))