From a8ac6fd7ca149e0f5f3f5621d3cff33f5bfcd7aa Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 31 May 2024 18:59:23 +0200 Subject: [PATCH 1/3] Move tool shed specific driver function to tool_shed.test Should fix https://github.com/galaxyproject/galaxy/issues/18282 --- lib/galaxy_test/driver/driver_util.py | 24 ------------- lib/tool_shed/test/base/driver.py | 49 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/lib/galaxy_test/driver/driver_util.py b/lib/galaxy_test/driver/driver_util.py index 88e956da5cfc..4e9c2b3d8e43 100644 --- a/lib/galaxy_test/driver/driver_util.py +++ b/lib/galaxy_test/driver/driver_util.py @@ -50,8 +50,6 @@ DEFAULT_WEB_HOST, target_url_parts, ) -from tool_shed.webapp.app import UniverseApplication as ToolshedUniverseApplication -from tool_shed.webapp.fast_app import initialize_fast_app as init_tool_shed_fast_app from .test_logging import logging_config_file galaxy_root = galaxy_directory() @@ -583,26 +581,6 @@ def build_galaxy_app(simple_kwargs) -> GalaxyUniverseApplication: return app -def build_shed_app(simple_kwargs): - """Build a Galaxy app object from a simple keyword arguments. - - Construct paste style complex dictionary. Also setup "global" reference - to sqlalchemy database context for tool shed database. - """ - log.info("Tool shed database connection: %s", simple_kwargs["database_connection"]) - # TODO: Simplify global_conf to match Galaxy above... - simple_kwargs["__file__"] = "tool_shed_wsgi.yml.sample" - simple_kwargs["global_conf"] = get_webapp_global_conf() - - app = ToolshedUniverseApplication(**simple_kwargs) - log.info("Embedded Toolshed application started") - - global tool_shed_context - tool_shed_context = app.model.context - - return app - - def explicitly_configured_host_and_port(prefix, config_object): host_env_key = f"{prefix}_TEST_HOST" port_env_key = f"{prefix}_TEST_PORT" @@ -794,8 +772,6 @@ def launch_server(app_factory, webapp_factory, prefix=DEFAULT_CONFIG_PREFIX, gal ) if name == "galaxy": asgi_app = init_galaxy_fast_app(wsgi_webapp, app) - elif name == "tool_shed": - asgi_app = init_tool_shed_fast_app(wsgi_webapp, app) else: raise NotImplementedError(f"Launching {name} not implemented") diff --git a/lib/tool_shed/test/base/driver.py b/lib/tool_shed/test/base/driver.py index b342a749f591..b236d371fca5 100644 --- a/lib/tool_shed/test/base/driver.py +++ b/lib/tool_shed/test/base/driver.py @@ -11,6 +11,8 @@ from galaxy_test.driver import driver_util from tool_shed.test.base.api_util import get_admin_api_key from tool_shed.webapp import buildapp as toolshedbuildapp +from tool_shed.webapp.app import UniverseApplication as ToolshedUniverseApplication +from tool_shed.webapp.fast_app import initialize_fast_app as init_tool_shed_fast_app log = driver_util.build_logger() @@ -38,6 +40,48 @@ """ +def build_shed_app(simple_kwargs): + """Build a Galaxy app object from a simple keyword arguments. + + Construct paste style complex dictionary. Also setup "global" reference + to sqlalchemy database context for tool shed database. + """ + log.info("Tool shed database connection: %s", simple_kwargs["database_connection"]) + # TODO: Simplify global_conf to match Galaxy above... + simple_kwargs["__file__"] = "tool_shed_wsgi.yml.sample" + simple_kwargs["global_conf"] = driver_util.get_webapp_global_conf() + + app = ToolshedUniverseApplication(**simple_kwargs) + log.info("Embedded Toolshed application started") + + global tool_shed_context + tool_shed_context = app.model.context + + return app + + +def launch_shed_server(app_factory, webapp_factory, prefix="TOOL_SHED", galaxy_config=None, config_object=None): + name = prefix.lower() + host, port = driver_util.explicitly_configured_host_and_port(prefix, config_object) + port = driver_util.attempt_ports(port) + + app = app_factory() + url_prefix = getattr(app.config, f"{name}_url_prefix", "/") + wsgi_webapp = webapp_factory( + galaxy_config["global_conf"], + app=app, + use_translogger=False, + static_enabled=True, + register_shutdown_at_exit=False, + ) + asgi_app = init_tool_shed_fast_app(wsgi_webapp, app) + + server, port, thread = driver_util.uvicorn_serve(asgi_app, host=host, port=port) + driver_util.set_and_wait_for_http_target(prefix, host, port, url_prefix=url_prefix) + log.debug(f"Embedded uvicorn web server for {name} started at {host}:{port}{url_prefix}") + return driver_util.EmbeddedServerWrapper(app, server, name, host, port, thread=thread, prefix=url_prefix) + + class ToolShedTestDriver(driver_util.TestDriver): """Instantiate a Galaxy-style TestDriver for testing the tool shed.""" @@ -116,11 +160,10 @@ def _setup_local(self): os.environ["TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF"] = shed_tool_data_table_conf_file # ---- Run tool shed webserver ------------------------------------------------------ # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') - tool_shed_server_wrapper = driver_util.launch_server( - app_factory=lambda: driver_util.build_shed_app(kwargs), + tool_shed_server_wrapper = launch_shed_server( + app_factory=lambda: build_shed_app(kwargs), webapp_factory=toolshedbuildapp.app_factory, galaxy_config=kwargs, - prefix="TOOL_SHED", ) self.server_wrappers.append(tool_shed_server_wrapper) tool_shed_test_host = tool_shed_server_wrapper.host From e2f4043324671fcfc1e70978e69485acc4553724 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 31 May 2024 19:53:11 +0200 Subject: [PATCH 2/3] Pass init_fast_app in launch_server function --- lib/galaxy_test/driver/driver_util.py | 14 +++++++++----- lib/tool_shed/test/base/driver.py | 26 +++----------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/lib/galaxy_test/driver/driver_util.py b/lib/galaxy_test/driver/driver_util.py index 4e9c2b3d8e43..298506b701dc 100644 --- a/lib/galaxy_test/driver/driver_util.py +++ b/lib/galaxy_test/driver/driver_util.py @@ -736,7 +736,14 @@ def launch_gravity(port, gxit_port=None, galaxy_config=None): ) -def launch_server(app_factory, webapp_factory, prefix=DEFAULT_CONFIG_PREFIX, galaxy_config=None, config_object=None): +def launch_server( + app_factory, + webapp_factory, + prefix=DEFAULT_CONFIG_PREFIX, + galaxy_config=None, + config_object=None, + init_fast_app=init_galaxy_fast_app, +): name = prefix.lower() host, port = explicitly_configured_host_and_port(prefix, config_object) port = attempt_ports(port) @@ -770,10 +777,7 @@ def launch_server(app_factory, webapp_factory, prefix=DEFAULT_CONFIG_PREFIX, gal static_enabled=True, register_shutdown_at_exit=False, ) - if name == "galaxy": - asgi_app = init_galaxy_fast_app(wsgi_webapp, app) - else: - raise NotImplementedError(f"Launching {name} not implemented") + asgi_app = init_fast_app(wsgi_webapp, app) server, port, thread = uvicorn_serve(asgi_app, host=host, port=port) set_and_wait_for_http_target(prefix, host, port, url_prefix=url_prefix) diff --git a/lib/tool_shed/test/base/driver.py b/lib/tool_shed/test/base/driver.py index b236d371fca5..1af08f1eb642 100644 --- a/lib/tool_shed/test/base/driver.py +++ b/lib/tool_shed/test/base/driver.py @@ -60,28 +60,6 @@ def build_shed_app(simple_kwargs): return app -def launch_shed_server(app_factory, webapp_factory, prefix="TOOL_SHED", galaxy_config=None, config_object=None): - name = prefix.lower() - host, port = driver_util.explicitly_configured_host_and_port(prefix, config_object) - port = driver_util.attempt_ports(port) - - app = app_factory() - url_prefix = getattr(app.config, f"{name}_url_prefix", "/") - wsgi_webapp = webapp_factory( - galaxy_config["global_conf"], - app=app, - use_translogger=False, - static_enabled=True, - register_shutdown_at_exit=False, - ) - asgi_app = init_tool_shed_fast_app(wsgi_webapp, app) - - server, port, thread = driver_util.uvicorn_serve(asgi_app, host=host, port=port) - driver_util.set_and_wait_for_http_target(prefix, host, port, url_prefix=url_prefix) - log.debug(f"Embedded uvicorn web server for {name} started at {host}:{port}{url_prefix}") - return driver_util.EmbeddedServerWrapper(app, server, name, host, port, thread=thread, prefix=url_prefix) - - class ToolShedTestDriver(driver_util.TestDriver): """Instantiate a Galaxy-style TestDriver for testing the tool shed.""" @@ -160,10 +138,12 @@ def _setup_local(self): os.environ["TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF"] = shed_tool_data_table_conf_file # ---- Run tool shed webserver ------------------------------------------------------ # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') - tool_shed_server_wrapper = launch_shed_server( + tool_shed_server_wrapper = driver_util.launch_server( app_factory=lambda: build_shed_app(kwargs), webapp_factory=toolshedbuildapp.app_factory, galaxy_config=kwargs, + prefix="TOOL_SHED", + init_fast_app=init_tool_shed_fast_app, ) self.server_wrappers.append(tool_shed_server_wrapper) tool_shed_test_host = tool_shed_server_wrapper.host From 0d648375778916b1352f835addb95de6dd8fd700 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 31 May 2024 19:56:54 +0200 Subject: [PATCH 3/3] Fix global variable --- lib/galaxy_test/driver/driver_util.py | 3 +-- lib/tool_shed/test/base/driver.py | 3 +++ lib/tool_shed/test/base/test_db_util.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/galaxy_test/driver/driver_util.py b/lib/galaxy_test/driver/driver_util.py index 298506b701dc..6fbfcee86d70 100644 --- a/lib/galaxy_test/driver/driver_util.py +++ b/lib/galaxy_test/driver/driver_util.py @@ -69,9 +69,8 @@ log = logging.getLogger("test_driver") -# Global variables to pass database contexts around - only needed for older +# Global variable to pass database contexts around - only needed for older # Tool Shed twill tests that didn't utilize the API for such interactions. -tool_shed_context = None install_context = None diff --git a/lib/tool_shed/test/base/driver.py b/lib/tool_shed/test/base/driver.py index 1af08f1eb642..a4fa67efdfb5 100644 --- a/lib/tool_shed/test/base/driver.py +++ b/lib/tool_shed/test/base/driver.py @@ -38,6 +38,9 @@ """ +# Global variable to pass database contexts around - only needed for older +# Tool Shed twill tests that didn't utilize the API for such interactions. +tool_shed_context = None def build_shed_app(simple_kwargs): diff --git a/lib/tool_shed/test/base/test_db_util.py b/lib/tool_shed/test/base/test_db_util.py index 03b1bbcc7550..f957cfe0ea2c 100644 --- a/lib/tool_shed/test/base/test_db_util.py +++ b/lib/tool_shed/test/base/test_db_util.py @@ -18,7 +18,7 @@ def sa_session(): - from galaxy_test.driver.driver_util import tool_shed_context as sa_session + from .driver import tool_shed_context as sa_session return sa_session