10 ARV_API_SERVER_DIR = '../../services/api'
11 SERVER_PID_PATH = 'tmp/pids/server.pid'
12 WEBSOCKETS_SERVER_PID_PATH = 'tmp/pids/passenger.3001.pid'
14 def find_server_pid(PID_PATH):
15 timeout = time.time() + 10
17 while (not good_pid) and (time.time() < timeout):
20 with open(PID_PATH, 'r') as f:
21 server_pid = int(f.read())
22 good_pid = (os.kill(server_pid, 0) == None)
27 raise Exception("could not find API server Rails pid")
31 def run(websockets=False):
33 os.chdir(ARV_API_SERVER_DIR)
34 os.environ["RAILS_ENV"] = "test"
35 subprocess.call(['bundle', 'exec', 'rake', 'db:test:load'])
36 subprocess.call(['bundle', 'exec', 'rake', 'db:fixtures:load'])
38 os.environ["ARVADOS_WEBSOCKETS"] = "true"
39 subprocess.call(['openssl', 'req', '-new', '-x509', '-nodes',
40 '-out', './self-signed.pem',
41 '-keyout', './self-signed.key',
43 '-subj', '/CN=localhost'])
44 subprocess.call(['passenger', 'start', '-d', '-p3001', '--ssl',
45 '--ssl-certificate', 'self-signed.pem',
46 '--ssl-certificate-key', 'self-signed.key'])
47 find_server_pid(WEBSOCKETS_SERVER_PID_PATH)
49 subprocess.call(['bundle', 'exec', 'rails', 'server', '-d', '-p3001'])
50 find_server_pid(SERVER_PID_PATH)
51 #os.environ["ARVADOS_API_HOST"] = "localhost:3001"
52 os.environ["ARVADOS_API_HOST"] = "127.0.0.1:3001"
53 os.environ["ARVADOS_API_HOST_INSECURE"] = "true"
56 def stop(websockets=False):
58 os.chdir(ARV_API_SERVER_DIR)
60 os.kill(find_server_pid(WEBSOCKETS_SERVER_PID_PATH), signal.SIGTERM)
61 os.unlink('self-signed.pem')
62 os.unlink('self-signed.key')
64 os.kill(find_server_pid(SERVER_PID_PATH), signal.SIGTERM)
68 '''load a fixture yaml file'''
69 with open(os.path.join(ARV_API_SERVER_DIR, "test", "fixtures",
71 return yaml.load(f.read())
73 def authorize_with(token):
74 '''token is the symbolic name of the token from the api_client_authorizations fixture'''
75 arvados.config.settings()["ARVADOS_API_TOKEN"] = fixture("api_client_authorizations")[token]["api_token"]
77 if __name__ == "__main__":
78 parser = argparse.ArgumentParser()
79 parser.add_argument('action', type=str, help='''one of "start" or "stop"''')
80 parser.add_argument('--websockets', action='store_true', default=False)
81 args = parser.parse_args()
83 if args.action == 'start':
85 elif args.action == 'stop':