def test_serve_daemon(self): """Test serving a galaxy tool via a daemon Galaxy process.""" port = network_util.get_free_port() cat_path = os.path.join(TEST_REPOS_DIR, "single_tool", "cat.xml") config = galaxy_serve( self.test_context, [for_path(cat_path)], install_galaxy=True, port=port, daemon=True, no_dependency_resolution=True, ) assert network_util.wait_net_service( "localhost", config.port, timeout=.1, ) config_dict = config.gi.config.get_config() assert "allow_user_dataset_purge" in config_dict config.kill() assert not network_util.wait_net_service( "localhost", config.port, timeout=.1, )
def _launch_thread_and_wait(self, func, port): t = threading.Thread(target=func) t.daemon = True t.start() time.sleep(15) assert network_util.wait_net_service("127.0.0.1", port) time.sleep(.1) assert network_util.wait_net_service("127.0.0.1", port)
def _launch_thread_and_wait(self, func, args=[]): target = functools.partial(func, args) port = self._port t = threading.Thread(target=target) t.daemon = True t.start() time.sleep(10) assert network_util.wait_net_service("127.0.0.1", port) time.sleep(.1) assert network_util.wait_net_service("127.0.0.1", port)
def _launch_thread_and_wait(self, func, args=[]): target = functools.partial(func, args) port = self._port t = threading.Thread(target=target) t.daemon = True t.start() time.sleep(10) assert network_util.wait_net_service("127.0.0.1", port) time.sleep(1) assert network_util.wait_net_service("127.0.0.1", port) time.sleep(1) assert network_util.wait_net_service("127.0.0.1", port)
def test_serve(self): port = network_util.get_free_port() serve = functools.partial(self._run, port) t = threading.Thread(target=serve) t.daemon = True t.start() time.sleep(15) assert network_util.wait_net_service("127.0.0.1", port)
def setup_mock_shed(): port = network_util.get_free_port() directory = mkdtemp() model = mock_model(directory) def run(): app.debug = True app.config["model"] = model run_simple('localhost', port, app, use_reloader=False, use_debugger=True) t = threading.Thread(target=run) t.start() network_util.wait_net_service("localhost", port, DEFAULT_OP_TIMEOUT) return MockShed("http://localhost:%d" % port, directory, t, model)
def launch_and_wait_for_service(port, func, args=[]): """Run func(args) in a thread and wait on port for service. Service should remain up so check network a few times, this prevents the code that finds a free port from causing a false positive when detecting that the port is bound to. """ target = functools.partial(func, *args) t = threading.Thread(target=target) t.daemon = True t.start() time.sleep(5) assert network_util.wait_net_service("127.0.0.1", port, timeout=600) time.sleep(1) assert network_util.wait_net_service("127.0.0.1", port, timeout=600) time.sleep(1) assert network_util.wait_net_service("127.0.0.1", port, timeout=600) return t
def _assert_service_up(config): assert network_util.wait_net_service( "localhost", config.port, timeout=.1, ) galaxy_config_api = config.gi.config config_dict = galaxy_config_api.get_config() assert "allow_user_dataset_purge" in config_dict
def setup_mock_shed(): port = network_util.get_free_port() directory = mkdtemp() model = mock_model(directory) def run(): app.debug = True app.config["model"] = model run_simple( 'localhost', port, app, use_reloader=False, use_debugger=True ) t = threading.Thread(target=run) t.start() network_util.wait_net_service("localhost", port, DEFAULT_OP_TIMEOUT) return MockShed("http://localhost:%d" % port, directory, t, model)
def serve(ctx, paths, **kwds): # TODO: Preceate a user. # TODO: Setup an admin user. # TODO: Pass through more parameters. # TODO: Populate test-data directory as FTP directory. daemon = kwds.get("daemon", False) if daemon: kwds["no_cleanup"] = True with galaxy_config(ctx, paths, **kwds) as config: pid_file = config.pid_file # TODO: Allow running dockerized Galaxy here instead. setup_venv_command = setup_venv(ctx, kwds) run_script = os.path.join(config.galaxy_root, "run.sh") run_script += " $COMMON_STARTUP_ARGS" if daemon: run_script += " --pid-file '%s' --daemon" % pid_file config.env["GALAXY_RUN_ALL"] = "1" else: run_script += " --server-name '%s' --reload" % config.server_name server_ini = os.path.join(config.config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini cd_to_galaxy_command = "cd %s" % config.galaxy_root cmd = io.shell_join( cd_to_galaxy_command, setup_venv_command, run_script, ) action = "Starting galaxy" run_galaxy_command( ctx, cmd, config.env, action, ) host = kwds.get("host", "127.0.0.1") port = kwds.get("port") assert network_util.wait_net_service(host, port) time.sleep(.1) assert network_util.wait_net_service(host, port) return config
def _serve(ctx, runnables, **kwds): engine = kwds.get("engine", "galaxy") if engine == "docker_galaxy": kwds["dockerize"] = True daemon = kwds.get("daemon", False) if daemon: kwds["no_cleanup"] = True with galaxy_config(ctx, runnables, **kwds) as config: cmd = config.startup_command(ctx, **kwds) action = "Starting galaxy" exit_code = run_galaxy_command( ctx, cmd, config.env, action, ) if exit_code: message = "Problem running Galaxy command [%s]." % config.log_contents io.warn(message) raise Exception(message) host = kwds.get("host", "127.0.0.1") port = kwds.get("port", None) if port is None: port = network_util.get_free_port() ctx.vlog("Waiting for service on (%s, %s)" % (host, port)) assert network_util.wait_net_service(host, port) time.sleep(.1) ctx.vlog("Waiting for service on (%s, %s)" % (host, port)) assert network_util.wait_net_service(host, port) time.sleep(5) ctx.vlog("Waiting for service on (%s, %s)" % (host, port)) assert network_util.wait_net_service(host, port) config.install_workflows() return config
def test_serve_daemon(self): port = network_util.get_free_port() cat_path = os.path.join(TEST_REPOS_DIR, "single_tool", "cat.xml") config = galaxy_serve( self.test_context, cat_path, install_galaxy=True, port=port, daemon=True, ) assert network_util.wait_net_service( "localhost", config.port, timeout=.1, ) config_dict = config.gi.config.get_config() assert "allow_user_dataset_purge" in config_dict config.kill() assert not network_util.wait_net_service( "localhost", config.port, timeout=.1, )
def test_serve_profile(self): port = network_util.get_free_port() pid_file = os.path.join(self._home, "test.pid") extra_args = [ "--daemon", "--pid_file", pid_file, "--profile", "moo", ] serve = functools.partial(self._run, port, extra_args) self._launch_thread_and_wait(serve, port) assert network_util.wait_net_service("127.0.0.1", port) admin_gi = api.gi(port) user_api_key = api.user_api_key(admin_gi) user_gi = api.gi(port, user_api_key) assert len(user_gi.histories.get_histories(name=TEST_HISTORY_NAME)) == 0 user_gi.histories.create_history(TEST_HISTORY_NAME) kill_pid_file(pid_file) self._launch_thread_and_wait(serve, port) assert len(user_gi.histories.get_histories(name=TEST_HISTORY_NAME)) == 1
def test_shed_serve_daemon(self): port = network_util.get_free_port() fastqc_path = os.path.join(TEST_REPOS_DIR, "fastqc") ctx = self.test_context install_args_list = shed.install_arg_lists( ctx, [fastqc_path], shed_target="toolshed", ) with shed_serve( ctx, install_args_list, port=port, skip_dependencies=True, install_galaxy=True, ) as config: assert network_util.wait_net_service( "localhost", config.port, timeout=.1, )
def test_serve_profile(self): port = network_util.get_free_port() pid_file = os.path.join(self._home, "test.pid") extra_args = [ "--daemon", "--pid_file", pid_file, "--profile", "moo", ] serve = functools.partial(self._run, port, extra_args) self._launch_thread_and_wait(serve, port) assert network_util.wait_net_service("127.0.0.1", port) admin_gi = api.gi(port) user_api_key = api.user_api_key(admin_gi) user_gi = api.gi(port, user_api_key) assert len( user_gi.histories.get_histories(name=TEST_HISTORY_NAME)) == 0 user_gi.histories.create_history(TEST_HISTORY_NAME) kill_pid_file(pid_file) self._launch_thread_and_wait(serve, port) assert len( user_gi.histories.get_histories(name=TEST_HISTORY_NAME)) == 1
def _assert_service_down(config): assert not network_util.wait_net_service( "localhost", config.port, timeout=.1, )