From 3cb2bb1c359a7dd9f66e07e04490262b753e83e6 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 13:22:09 -0400 Subject: [PATCH 01/69] Start work on synchronizing functional test drivers. - Tweak paths in same way. - Don't write tool shed temp files to GALAXY_ROOT - respect /tmp. - Build identical loggers. --- scripts/functional_tests.py | 8 +++++--- test/base/driver_util.py | 32 ++++++++++++++++++++++++++++++ test/tool_shed/functional_tests.py | 15 +++++--------- 3 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 test/base/driver_util.py diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 192dfc17206..065ab538a28 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python + import httplib -import logging import os import os.path import random @@ -24,6 +24,10 @@ from paste import httpserver galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] +from base import driver_util +driver_util.configure_environment() +log = driver_util.build_logger() + from base.api_util import get_master_api_key, get_user_api_key from base.nose_util import run from base.instrument import StructuredTestDataPlugin @@ -35,8 +39,6 @@ from galaxy.app import UniverseApplication from galaxy.util.properties import load_app_properties from galaxy.web import buildapp -log = logging.getLogger( "functional_tests.py" ) - default_galaxy_test_host = "localhost" default_galaxy_test_port_min = 8000 default_galaxy_test_port_max = 9999 diff --git a/test/base/driver_util.py b/test/base/driver_util.py new file mode 100644 index 00000000000..a0f3a90adfd --- /dev/null +++ b/test/base/driver_util.py @@ -0,0 +1,32 @@ +"""Scripts for drivers of Galaxy functional tests.""" + +import tempfile +import os +import logging + + +def setup_tool_shed_tmp_dir(): + tool_shed_test_tmp_dir = os.environ.get('TOOL_SHED_TEST_TMP_DIR', None) + if tool_shed_test_tmp_dir is None: + tool_shed_test_tmp_dir = tempfile.mkdtemp() + # Here's the directory where everything happens. Temporary directories are created within this directory to contain + # the hgweb.config file, the database, new repositories, etc. Since the tool shed browses repository contents via HTTP, + # the full path to the temporary directroy wher eht repositories are located cannot contain invalid url characters. + os.environ[ 'TOOL_SHED_TEST_TMP_DIR' ] = tool_shed_test_tmp_dir + return tool_shed_test_tmp_dir + + +def configure_environment(): + """Hack up environment for test cases.""" + # no op remove if unused + + +def build_logger(): + """Build a logger for test driver script.""" + return logging.getLogger("test_driver") + + +__all__ = [ + "configure_environment", + "build_logger" +] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 6d3da018b51..c631207a838 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -2,7 +2,6 @@ from __future__ import absolute_import import httplib -import logging import os import random import shutil @@ -15,13 +14,6 @@ import time import urllib galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) -tool_shed_home_directory = os.path.join( galaxy_root, 'test', 'tool_shed' ) -default_tool_shed_test_file_dir = os.path.join( tool_shed_home_directory, 'test_data' ) -# Here's the directory where everything happens. Temporary directories are created within this directory to contain -# the hgweb.config file, the database, new repositories, etc. Since the tool shed browses repository contents via HTTP, -# the full path to the temporary directroy wher eht repositories are located cannot contain invalid url characters. -tool_shed_test_tmp_dir = os.path.join( tool_shed_home_directory, 'tmp' ) -os.environ[ 'TOOL_SHED_TEST_TMP_DIR' ] = tool_shed_test_tmp_dir # Need to remove this directory from sys.path sys.path[0:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] @@ -31,6 +23,11 @@ import nose.core import nose.loader import nose.plugins.manager +from base import driver_util +driver_util.configure_environment() +log = driver_util.build_logger() +tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir() + # This is for the tool shed application. from galaxy.webapps.tool_shed import buildapp as toolshedbuildapp from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication @@ -42,8 +39,6 @@ from galaxy.web import buildapp as galaxybuildapp from base import nose_util from functional import database_contexts -log = logging.getLogger( "tool_shed_functional_tests.py" ) - default_tool_shed_test_host = "localhost" default_tool_shed_test_port_min = 8000 default_tool_shed_test_port_max = 8999 From 9d1a54e88c9ce55e9473cfd823c2d1ebe5cd7b8e Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 13:35:27 -0400 Subject: [PATCH 02/69] Synchronize main() handling between functional test driver scripts. --- test/tool_shed/functional_tests.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index c631207a838..ea5da647f16 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -483,8 +483,4 @@ def __copy_database_template( source, db_path ): if __name__ == "__main__": - try: - sys.exit( main() ) - except Exception, e: - log.exception( str( e ) ) - exit(1) + sys.exit( main() ) From 3369dfafa0ed12886d1adea7ea2155fc3ebe31aa Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 13:51:17 -0400 Subject: [PATCH 03/69] Synchronize a bunch of test launch and nose configure stuff. --- scripts/functional_tests.py | 19 ++----------- test/base/driver_util.py | 44 ++++++++++++++++++++++++++++-- test/tool_shed/functional_tests.py | 16 +---------- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 065ab538a28..588a45ab01e 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -15,10 +15,6 @@ import urllib from ConfigParser import SafeConfigParser from json import dumps -import nose.core -import nose.config -import nose.loader -import nose.plugins.manager from paste import httpserver galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) @@ -29,8 +25,6 @@ driver_util.configure_environment() log = driver_util.build_logger() from base.api_util import get_master_api_key, get_user_api_key -from base.nose_util import run -from base.instrument import StructuredTestDataPlugin from base.test_logging import logging_config_file from base.tool_shed_util import parse_tool_panel_config from functional import database_contexts @@ -140,10 +134,6 @@ def generate_config_file( input_filename, output_filename, config_items ): fh.close() -def run_tests( test_config ): - return run( test_config ) - - def __copy_database_template( source, db_path ): """ Copy a 'clean' sqlite template database (from file or URL) to specified @@ -444,12 +434,9 @@ def main(): master_api_key=master_api_key, user_api_key=get_user_api_key(), ) - test_config = nose.config.Config( env=os.environ, ignoreFiles=ignore_files, plugins=nose.plugins.manager.DefaultPluginManager() ) - test_config.plugins.addPlugin( StructuredTestDataPlugin() ) - test_config.configure( sys.argv ) - result = run_tests( test_config ) - success = result.wasSuccessful() - return success + return driver_util.nose_config_and_run( + ignore_files=ignore_files, + ) if testing_migrated_tools or testing_installed_tools: shed_tools_dict = {} diff --git a/test/base/driver_util.py b/test/base/driver_util.py index a0f3a90adfd..073779538d3 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -1,8 +1,17 @@ """Scripts for drivers of Galaxy functional tests.""" -import tempfile -import os import logging +import os +import sys +import tempfile + +import nose.config +import nose.core +import nose.loader +import nose.plugins.manager + +from .nose_util import run +from .instrument import StructuredTestDataPlugin def setup_tool_shed_tmp_dir(): @@ -26,7 +35,36 @@ def build_logger(): return logging.getLogger("test_driver") +def nose_config_and_run( argv=None, env=None, ignore_files=[], plugins=None ): + """Setup a nose context and run tests. + + Tests are specified by argv (defaulting to sys.argv). + """ + if env is None: + env = os.environ + if plugins is None: + plugins = nose.plugins.manager.DefaultPluginManager() + if argv is None: + argv = sys.argv + + test_config = nose.config.Config( + env=os.environ, + ignoreFiles=ignore_files, + plugins=plugins, + ) + + # Add custom plugin to produce JSON data used by planemo. + test_config.plugins.addPlugin( StructuredTestDataPlugin() ) + test_config.configure( argv ) + + result = run( test_config ) + + success = result.wasSuccessful() + return success + + __all__ = [ "configure_environment", - "build_logger" + "build_logger", + "nose_config_and_run", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index ea5da647f16..d2ca5e9022f 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -18,10 +18,6 @@ galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pa sys.path[0:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] from paste import httpserver -import nose.config -import nose.core -import nose.loader -import nose.plugins.manager from base import driver_util driver_util.configure_environment() @@ -36,7 +32,6 @@ from galaxy.app import UniverseApplication as GalaxyUniverseApplication from galaxy.util import asbool from galaxy.web import buildapp as galaxybuildapp -from base import nose_util from functional import database_contexts default_tool_shed_test_host = "localhost" @@ -119,10 +114,6 @@ shed_data_manager_conf_xml_template = ''' ''' -def run_tests( test_config ): - return nose_util.run( test_config ) - - def main(): # ---- Configuration ------------------------------------------------------ tool_shed_test_host = os.environ.get( 'TOOL_SHED_TEST_HOST', default_tool_shed_test_host ) @@ -135,7 +126,6 @@ def main(): tool_shed_test_file_dir = os.environ.get( 'TOOL_SHED_TEST_FILE_DIR', default_tool_shed_test_file_dir ) if not os.path.isabs( tool_shed_test_file_dir ): tool_shed_test_file_dir = tool_shed_test_file_dir - ignore_files = () tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) use_distributed_object_store = os.environ.get( 'TOOL_SHED_USE_DISTRIBUTED_OBJECT_STORE', False ) if not os.path.isdir( tool_shed_test_tmp_dir ): @@ -422,11 +412,7 @@ def main(): os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host if tool_shed_test_file_dir: os.environ[ 'TOOL_SHED_TEST_FILE_DIR' ] = tool_shed_test_file_dir - test_config = nose.config.Config( env=os.environ, ignoreFiles=ignore_files, plugins=nose.plugins.manager.DefaultPluginManager() ) - test_config.configure( sys.argv ) - # Run the tests. - result = run_tests( test_config ) - success = result.wasSuccessful() + success = driver_util.nose_config_and_run() except: log.exception( "Failure running tests" ) From 55297b75e10a49ffe081087e5a7d5a1140af38ff Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 13:59:25 -0400 Subject: [PATCH 04/69] Sync code for retrieving prepopulated databases. --- scripts/functional_tests.py | 18 +----------------- test/base/driver_util.py | 21 +++++++++++++++++++++ test/tool_shed/functional_tests.py | 18 +----------------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 588a45ab01e..ce84d09ed63 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -11,7 +11,6 @@ import sys import tempfile import threading import time -import urllib from ConfigParser import SafeConfigParser from json import dumps @@ -134,21 +133,6 @@ def generate_config_file( input_filename, output_filename, config_items ): fh.close() -def __copy_database_template( source, db_path ): - """ - Copy a 'clean' sqlite template database (from file or URL) to specified - database path. - """ - os.makedirs( os.path.dirname( db_path ) ) - if os.path.exists( source ): - shutil.copy( source, db_path ) - assert os.path.exists( db_path ) - elif source.lower().startswith( ( "http://", "https://", "ftp://" ) ): - urllib.urlretrieve( source, db_path ) - else: - raise Exception( "Failed to copy database template from source %s" % source ) - - def main(): # ---- Configuration ------------------------------------------------------ galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) @@ -260,7 +244,7 @@ def main(): # time, the latter results in test failures in certain # cases (namely tool shed tests expecting clean database). log.debug( "Copying database template from %s.", os.environ['GALAXY_TEST_DB_TEMPLATE'] ) - __copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) + driver_util.copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) database_auto_migrate = True database_connection = 'sqlite:///%s' % db_path kwargs = {} diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 073779538d3..bbc0ef09aab 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -2,9 +2,12 @@ import logging import os +import shutil import sys import tempfile +from six.moves.urllib.request import urlretrieve + import nose.config import nose.core import nose.loader @@ -63,8 +66,26 @@ def nose_config_and_run( argv=None, env=None, ignore_files=[], plugins=None ): return success +def copy_database_template( source, db_path ): + """Copy a 'clean' sqlite template database. + + From file or URL to specified path for sqlite database. + """ + db_path_dir = os.path.dirname(db_path) + if not os.path.exists(db_path_dir): + os.makedirs(db_path_dir) + if os.path.exists(source): + shutil.copy(source, db_path) + assert os.path.exists(db_path) + elif source.lower().startswith(("http://", "https://", "ftp://")): + urlretrieve(source, db_path) + else: + raise Exception( "Failed to copy database template from source %s" % source ) + + __all__ = [ "configure_environment", + "copy_database_template", "build_logger", "nose_config_and_run", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index d2ca5e9022f..60ba547ca28 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -11,7 +11,6 @@ import sys import tempfile import threading import time -import urllib galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) # Need to remove this directory from sys.path @@ -181,7 +180,7 @@ def main(): # GALAXY_TEST_DBURI. The former requires a lot of setup # time, the latter results in test failures in certain # cases (namely tool shed tests expecting clean database). - __copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) + driver_util.copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) galaxy_database_auto_migrate = True if not os.path.exists(galaxy_db_path): os.makedirs(galaxy_db_path) @@ -453,20 +452,5 @@ def main(): return 1 -def __copy_database_template( source, db_path ): - """ - Copy a 'clean' sqlite template database (from file or URL) to specified - database path. - """ - os.makedirs( os.path.dirname( db_path ) ) - if os.path.exists( source ): - shutil.copy( source, db_path ) - assert os.path.exists( db_path ) - elif source.startswith("http"): - urllib.urlretrieve( source, db_path ) - else: - raise Exception( "Failed to copy database template from source %s" % source ) - - if __name__ == "__main__": sys.exit( main() ) From 173d98484bc50cec7f755d85c46ae941b1e5bc50 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 14:18:38 -0400 Subject: [PATCH 05/69] Eliminate always True variable to simplify test driver logic. For now, always serve static content with these tests. --- scripts/functional_tests.py | 9 ++------- test/tool_shed/functional_tests.py | 7 +------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index ce84d09ed63..2fe5427731d 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -43,9 +43,6 @@ installed_tool_panel_configs = [ ] -# should this serve static resources (scripts, images, styles, etc.) -STATIC_ENABLED = True - # Set up a job_conf.xml that explicitly limits jobs to 10 minutes. job_conf_xml = ''' @@ -77,7 +74,6 @@ def get_static_settings(): static_dir = os.path.join( cwd, 'static' ) # TODO: these should be copied from config/galaxy.ini return dict( - # TODO: static_enabled needed here? static_enabled=True, static_cache_time=360, static_dir=static_dir, @@ -94,8 +90,7 @@ def get_webapp_global_conf(): """ # (was originally sent 'dict()') - nothing here for now except static settings global_conf = dict() - if STATIC_ENABLED: - global_conf.update( get_static_settings() ) + global_conf.update( get_static_settings() ) return global_conf @@ -338,7 +333,7 @@ def main(): if start_server: webapp = buildapp.app_factory( kwargs[ 'global_conf' ], app=app, - use_translogger=False, static_enabled=STATIC_ENABLED ) + use_translogger=False, static_enabled=True ) if galaxy_test_port is not None: server = httpserver.serve( webapp, host=galaxy_test_host, port=galaxy_test_port, start_loop=False ) else: diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 60ba547ca28..f6b4f44148a 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -46,9 +46,6 @@ default_galaxy_test_host = 'localhost' # behavior. default_install_db_merged = False -# should this serve static resources (scripts, images, styles, etc.) -STATIC_ENABLED = True - def get_static_settings(): """Returns dictionary of the settings necessary for a galaxy App @@ -60,7 +57,6 @@ def get_static_settings(): static_dir = os.path.join( galaxy_root, 'static' ) # TODO: these should be copied from galaxy.ini return dict( - # TODO: static_enabled needed here? static_enabled=True, static_cache_time=360, static_dir=static_dir, @@ -77,8 +73,7 @@ def get_webapp_global_conf(): """ # (was originally sent 'dict()') - nothing here for now except static settings global_conf = dict() - if STATIC_ENABLED: - global_conf.update( get_static_settings() ) + global_conf.update( get_static_settings() ) return global_conf tool_sheds_conf_xml_template = ''' From d60fe9f5aa3bb264d2a1873aaa383ee9657487ad Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 14:29:25 -0400 Subject: [PATCH 06/69] Synchronize static configuration stuff. --- scripts/functional_tests.py | 33 +--------------------------- test/base/driver_util.py | 35 ++++++++++++++++++++++++++++++ test/tool_shed/functional_tests.py | 33 ++-------------------------- 3 files changed, 38 insertions(+), 63 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 2fe5427731d..8a8faec10c8 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -63,37 +63,6 @@ job_conf_xml = ''' ''' -def get_static_settings(): - """Returns dictionary of the settings necessary for a galaxy App - to be wrapped in the static middleware. - - This mainly consists of the filesystem locations of url-mapped - static resources. - """ - cwd = os.getcwd() - static_dir = os.path.join( cwd, 'static' ) - # TODO: these should be copied from config/galaxy.ini - return dict( - static_enabled=True, - static_cache_time=360, - static_dir=static_dir, - static_images_dir=os.path.join( static_dir, 'images', '' ), - static_favicon_dir=os.path.join( static_dir, 'favicon.ico' ), - static_scripts_dir=os.path.join( static_dir, 'scripts', '' ), - static_style_dir=os.path.join( static_dir, 'june_2007_style', 'blue' ), - static_robots_txt=os.path.join( static_dir, 'robots.txt' ), - ) - - -def get_webapp_global_conf(): - """Get the global_conf dictionary sent as the first argument to app_factory. - """ - # (was originally sent 'dict()') - nothing here for now except static settings - global_conf = dict() - global_conf.update( get_static_settings() ) - return global_conf - - def generate_config_file( input_filename, output_filename, config_items ): ''' Generate a config file with the configuration that has been defined for the embedded web application. @@ -317,7 +286,7 @@ def main(): # Write a temporary file, based on config/galaxy.ini.sample, using the configuration options defined above. generate_config_file( 'config/galaxy.ini.sample', galaxy_config_file, config_items ) # Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh. - kwargs[ 'global_conf' ] = get_webapp_global_conf() + kwargs[ 'global_conf' ] = driver_util.get_webapp_global_conf() kwargs[ 'global_conf' ][ '__file__' ] = galaxy_config_file kwargs[ 'config_file' ] = galaxy_config_file kwargs = load_app_properties( diff --git a/test/base/driver_util.py b/test/base/driver_util.py index bbc0ef09aab..aeda67acb96 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -16,6 +16,8 @@ import nose.plugins.manager from .nose_util import run from .instrument import StructuredTestDataPlugin +galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) + def setup_tool_shed_tmp_dir(): tool_shed_test_tmp_dir = os.environ.get('TOOL_SHED_TEST_TMP_DIR', None) @@ -83,9 +85,42 @@ def copy_database_template( source, db_path ): raise Exception( "Failed to copy database template from source %s" % source ) +def _get_static_settings(): + """Configuration required for Galaxy static middleware. + + Returns dictionary of the settings necessary for a galaxy App + to be wrapped in the static middleware. + + This mainly consists of the filesystem locations of url-mapped + static resources. + """ + static_dir = os.path.join(galaxy_root, "static") + + # TODO: these should be copied from config/galaxy.ini + return dict( + static_enabled=True, + static_cache_time=360, + static_dir=static_dir, + static_images_dir=os.path.join(static_dir, 'images', ''), + static_favicon_dir=os.path.join(static_dir, 'favicon.ico'), + static_scripts_dir=os.path.join(static_dir, 'scripts', ''), + static_style_dir=os.path.join(static_dir, 'june_2007_style', 'blue'), + static_robots_txt=os.path.join(static_dir, 'robots.txt'), + ) + + +def get_webapp_global_conf(): + """Get the global_conf dictionary sent to ``app_factory``.""" + # (was originally sent 'dict()') - nothing here for now except static settings + global_conf = dict() + global_conf.update( _get_static_settings() ) + return global_conf + + __all__ = [ "configure_environment", "copy_database_template", "build_logger", + "get_webapp_global_conf", "nose_config_and_run", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index f6b4f44148a..01b7a9caa18 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -47,35 +47,6 @@ default_galaxy_test_host = 'localhost' default_install_db_merged = False -def get_static_settings(): - """Returns dictionary of the settings necessary for a galaxy App - to be wrapped in the static middleware. - - This mainly consists of the filesystem locations of url-mapped - static resources. - """ - static_dir = os.path.join( galaxy_root, 'static' ) - # TODO: these should be copied from galaxy.ini - return dict( - static_enabled=True, - static_cache_time=360, - static_dir=static_dir, - static_images_dir=os.path.join( static_dir, 'images', '' ), - static_favicon_dir=os.path.join( static_dir, 'favicon.ico' ), - static_scripts_dir=os.path.join( static_dir, 'scripts', '' ), - static_style_dir=os.path.join( static_dir, 'june_2007_style', 'blue' ), - static_robots_txt=os.path.join( static_dir, 'robots.txt' ), - ) - - -def get_webapp_global_conf(): - """Get the global_conf dictionary sent as the first argument to app_factory. - """ - # (was originally sent 'dict()') - nothing here for now except static settings - global_conf = dict() - global_conf.update( get_static_settings() ) - return global_conf - tool_sheds_conf_xml_template = ''' @@ -187,7 +158,7 @@ def main(): else: install_galaxy_db_path = os.path.join( galaxy_db_path, 'install.sqlite' ) install_galaxy_database_connection = 'sqlite:///%s' % install_galaxy_db_path - tool_shed_global_conf = get_webapp_global_conf() + tool_shed_global_conf = driver_util.get_webapp_global_conf() tool_shed_global_conf[ '__file__' ] = 'tool_shed_wsgi.ini.sample' kwargs = dict( admin_users='test@bx.psu.edu', allow_user_creation=True, @@ -303,7 +274,7 @@ def main(): # Generate shed_data_manager_conf.xml if not os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF' ): open( galaxy_shed_data_manager_conf_file, 'wb' ).write( shed_data_manager_conf_xml_template ) - galaxy_global_conf = get_webapp_global_conf() + galaxy_global_conf = driver_util.get_webapp_global_conf() galaxy_global_conf[ '__file__' ] = 'config/galaxy.ini.sample' kwargs = dict( allow_user_creation=True, From b7c75f20a5bfb625d01c85d1821d11ff50fb5949 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 14:59:02 -0400 Subject: [PATCH 07/69] Eliminate duplication in waiting for HTTP servers in test drivers. --- scripts/functional_tests.py | 12 +----------- test/base/driver_util.py | 19 +++++++++++++++++++ test/tool_shed/functional_tests.py | 24 ++---------------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 8a8faec10c8..8fc09bfd88d 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import httplib import os import os.path import random @@ -10,7 +9,6 @@ import socket import sys import tempfile import threading -import time from ConfigParser import SafeConfigParser from json import dumps @@ -326,15 +324,7 @@ def main(): t = threading.Thread( target=server.serve_forever ) t.start() - # Test if the server is up - for i in range( 10 ): - conn = httplib.HTTPConnection( galaxy_test_host, galaxy_test_port ) # directly test the app, not the proxy - conn.request( "GET", "/" ) - if conn.getresponse().status == 200: - break - time.sleep( 0.1 ) - else: - raise Exception( "Test HTTP server did not return '200 OK' after 10 tries" ) + driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded web server started" ) # ---- Find tests --------------------------------------------------------- diff --git a/test/base/driver_util.py b/test/base/driver_util.py index aeda67acb96..d8c36be55fe 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -1,10 +1,12 @@ """Scripts for drivers of Galaxy functional tests.""" +import httplib import logging import os import shutil import sys import tempfile +import time from six.moves.urllib.request import urlretrieve @@ -117,10 +119,27 @@ def get_webapp_global_conf(): return global_conf +def wait_for_http_server(host, port): + """Wait for an HTTP server to boot up.""" + # Test if the server is up + for i in range( 10 ): + # directly test the app, not the proxy + conn = httplib.HTTPConnection(host, port) + conn.request( "GET", "/" ) + if conn.getresponse().status == 200: + break + time.sleep( 0.1 ) + else: + template = "Test HTTP server on host %s and port %s did not return '200 OK' after 10 tries" + message = template % (host, port) + raise Exception(message) + + __all__ = [ "configure_environment", "copy_database_template", "build_logger", "get_webapp_global_conf", "nose_config_and_run", + "wait_for_http_server", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 01b7a9caa18..b1d24fbb26c 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -1,7 +1,6 @@ #!/usr/bin/env python from __future__ import absolute_import -import httplib import os import random import shutil @@ -10,7 +9,6 @@ import string import sys import tempfile import threading -import time galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) # Need to remove this directory from sys.path @@ -243,16 +241,7 @@ def main(): os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_port t = threading.Thread( target=tool_shed_server.serve_forever ) t.start() - # Test if the server is up - for i in range( 10 ): - # Directly test the app, not the proxy. - conn = httplib.HTTPConnection( tool_shed_test_host, tool_shed_test_port ) - conn.request( "GET", "/" ) - if conn.getresponse().status == 200: - break - time.sleep( 0.1 ) - else: - raise Exception( "Test HTTP server did not return '200 OK' after 10 tries" ) + driver_util.wait_for_http_server(tool_shed_test_host, tool_shed_test_port) log.info( "Embedded web server started" ) # ---- Optionally start up a Galaxy instance ------------------------------------------------------ @@ -350,16 +339,7 @@ def main(): os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_port t = threading.Thread( target=galaxy_server.serve_forever ) t.start() - # Test if the server is up - for i in range( 10 ): - # Directly test the app, not the proxy. - conn = httplib.HTTPConnection( galaxy_test_host, galaxy_test_port ) - conn.request( "GET", "/" ) - if conn.getresponse().status == 200: - break - time.sleep( 0.1 ) - else: - raise Exception( "Test HTTP server did not return '200 OK' after 10 tries" ) + driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded galaxy web server started" ) # ---- Find tests --------------------------------------------------------- if tool_shed_test_proxy_port: From 103098c7e421043b79b3629c8c6f61b1ee792fb1 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 15:22:12 -0400 Subject: [PATCH 08/69] De-duplicate and simplify launching a webapp for functional tests. --- scripts/functional_tests.py | 27 +-------------- test/base/driver_util.py | 32 ++++++++++++++++++ test/tool_shed/functional_tests.py | 54 ++++-------------------------- 3 files changed, 40 insertions(+), 73 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 8fc09bfd88d..df504c523f7 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -2,18 +2,13 @@ import os import os.path -import random import re import shutil -import socket import sys import tempfile -import threading from ConfigParser import SafeConfigParser from json import dumps -from paste import httpserver - galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] @@ -31,8 +26,6 @@ from galaxy.util.properties import load_app_properties from galaxy.web import buildapp default_galaxy_test_host = "localhost" -default_galaxy_test_port_min = 8000 -default_galaxy_test_port_max = 9999 default_galaxy_locales = 'en' default_galaxy_test_file_dir = "test-data,https://github.com/galaxyproject/galaxy-test-data.git" migrated_tool_panel_config = 'config/migrated_tools_conf.xml' @@ -301,29 +294,11 @@ def main(): if start_server: webapp = buildapp.app_factory( kwargs[ 'global_conf' ], app=app, use_translogger=False, static_enabled=True ) - if galaxy_test_port is not None: - server = httpserver.serve( webapp, host=galaxy_test_host, port=galaxy_test_port, start_loop=False ) - else: - random.seed() - for i in range( 0, 9 ): - try: - galaxy_test_port = str( random.randint( default_galaxy_test_port_min, default_galaxy_test_port_max ) ) - log.debug( "Attempting to serve app on randomly chosen port: %s" % galaxy_test_port ) - server = httpserver.serve( webapp, host=galaxy_test_host, port=galaxy_test_port, start_loop=False ) - break - except socket.error, e: - if e[0] == 98: - continue - raise - else: - raise Exception( "Unable to open a port between %s and %s to start Galaxy server" % ( default_galaxy_test_port_min, default_galaxy_test_port_max ) ) + server, galaxy_test_port = driver_util.serve_webapp( webapp, host=galaxy_test_host, port=galaxy_test_port ) if galaxy_test_proxy_port: os.environ['GALAXY_TEST_PORT'] = galaxy_test_proxy_port else: os.environ['GALAXY_TEST_PORT'] = galaxy_test_port - - t = threading.Thread( target=server.serve_forever ) - t.start() driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded web server started" ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index d8c36be55fe..51e2e3c41c9 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -3,9 +3,12 @@ import httplib import logging import os +import random import shutil +import socket import sys import tempfile +import threading import time from six.moves.urllib.request import urlretrieve @@ -15,6 +18,8 @@ import nose.core import nose.loader import nose.plugins.manager +from paste import httpserver + from .nose_util import run from .instrument import StructuredTestDataPlugin @@ -135,6 +140,33 @@ def wait_for_http_server(host, port): raise Exception(message) +def serve_webapp(webapp, port=None, host=None): + """Serve the webapp on a recommend port or a free one. + + Return the port the webapp is running one. + """ + server = None + if port is not None: + server = httpserver.serve( webapp, host=host, port=port, start_loop=False ) + else: + random.seed() + for i in range( 0, 9 ): + try: + port = str( random.randint( 8000, 10000 ) ) + server = httpserver.serve( webapp, host=host, port=port, start_loop=False ) + break + except socket.error, e: + if e[0] == 98: + continue + raise + else: + raise Exception( "Unable to open a port between %s and %s to start Galaxy server" % ( 8000, 1000 ) ) + + t = threading.Thread( target=server.serve_forever ) + t.start() + + return server, port + __all__ = [ "configure_environment", "copy_database_template", diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index b1d24fbb26c..31d4ae68fbb 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -2,20 +2,15 @@ from __future__ import absolute_import import os -import random import shutil -import socket import string import sys import tempfile -import threading galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) # Need to remove this directory from sys.path sys.path[0:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] -from paste import httpserver - from base import driver_util driver_util.configure_environment() log = driver_util.build_logger() @@ -32,11 +27,7 @@ from galaxy.web import buildapp as galaxybuildapp from functional import database_contexts default_tool_shed_test_host = "localhost" -default_tool_shed_test_port_min = 8000 -default_tool_shed_test_port_max = 8999 default_tool_shed_locales = 'en' -default_galaxy_test_port_min = 9000 -default_galaxy_test_port_max = 9999 default_galaxy_test_host = 'localhost' # Use separate databases for Galaxy and tool shed install info by default, @@ -213,34 +204,19 @@ def main(): log.info( "Embedded Toolshed application started" ) # ---- Run tool shed webserver ------------------------------------------------------ - tool_shed_server = None tool_shed_global_conf[ 'database_connection' ] = toolshed_database_connection toolshedwebapp = toolshedbuildapp.app_factory( tool_shed_global_conf, use_translogger=False, static_enabled=True, app=toolshedapp ) - if tool_shed_test_port is not None: - tool_shed_server = httpserver.serve( toolshedwebapp, host=tool_shed_test_host, port=tool_shed_test_port, start_loop=False ) - else: - random.seed() - for i in range( 0, 9 ): - try: - tool_shed_test_port = str( random.randint( default_tool_shed_test_port_min, default_tool_shed_test_port_max ) ) - log.debug( "Attempting to serve app on randomly chosen port: %s" % tool_shed_test_port ) - tool_shed_server = httpserver.serve( toolshedwebapp, host=tool_shed_test_host, port=tool_shed_test_port, start_loop=False ) - break - except socket.error, e: - if e[0] == 98: - continue - raise - else: - raise Exception( "Unable to open a port between %s and %s to start Galaxy server" % ( default_tool_shed_test_port_min, default_tool_shed_test_port_max ) ) + + tool_shed_server, tool_shed_test_port = driver_util.serve_webapp( + toolshedwebapp, host=tool_shed_test_host, port=tool_shed_test_port + ) if tool_shed_test_proxy_port: os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_proxy_port else: os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_port - t = threading.Thread( target=tool_shed_server.serve_forever ) - t.start() driver_util.wait_for_http_server(tool_shed_test_host, tool_shed_test_port) log.info( "Embedded web server started" ) @@ -316,29 +292,13 @@ def main(): app=galaxyapp ) database_contexts.galaxy_context = galaxyapp.model.context database_contexts.install_context = galaxyapp.install_model.context - if galaxy_test_port is not None: - galaxy_server = httpserver.serve( galaxywebapp, host=galaxy_test_host, port=galaxy_test_port, start_loop=False ) - else: - random.seed() - for i in range( 0, 9 ): - try: - galaxy_test_port = str( random.randint( default_galaxy_test_port_min, default_galaxy_test_port_max ) ) - log.debug( "Attempting to serve app on randomly chosen port: %s" % galaxy_test_port ) - galaxy_server = httpserver.serve( galaxywebapp, host=galaxy_test_host, port=galaxy_test_port, start_loop=False ) - break - except socket.error, e: - if e[0] == 98: - continue - raise - else: - raise Exception( "Unable to open a port between %s and %s to start Galaxy server" % - ( default_galaxy_test_port_min, default_galaxy_test_port_max ) ) + galaxy_server, galaxy_test_port = driver_util.serve_webapp( + galaxywebapp, host=galaxy_test_host, port=galaxy_test_port + ) if galaxy_test_proxy_port: os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_proxy_port else: os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_port - t = threading.Thread( target=galaxy_server.serve_forever ) - t.start() driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded galaxy web server started" ) # ---- Find tests --------------------------------------------------------- From d0ee53f8017ef4fde97efb05ee82b4f95d037b62 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 19:20:38 -0400 Subject: [PATCH 09/69] Simplify ignore_files logic in scripts/functional_tests.py. These details are taken care of by run_tests.sh. --- scripts/functional_tests.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index df504c523f7..6ace4052293 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -2,7 +2,6 @@ import os import os.path -import re import shutil import sys import tempfile @@ -114,8 +113,6 @@ def main(): galaxy_test_file_dir = None library_import_dir = None user_library_import_dir = None - # Exclude all files except test_toolbox.py. - ignore_files = ( re.compile( r'^test_[adghlmsu]*' ), re.compile( r'^test_ta*' ) ) else: framework_tool_dir = os.path.join('test', 'functional', 'tools') framework_test = __check_arg( '-framework' ) # Run through suite of tests testing framework. @@ -139,7 +136,6 @@ def main(): user_library_import_dir = import_dir else: user_library_import_dir = None - ignore_files = () start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ tool_data_table_config_path = None @@ -347,9 +343,7 @@ def main(): master_api_key=master_api_key, user_api_key=get_user_api_key(), ) - return driver_util.nose_config_and_run( - ignore_files=ignore_files, - ) + return driver_util.nose_config_and_run() if testing_migrated_tools or testing_installed_tools: shed_tools_dict = {} From 34f154d92e162bcb56e4ffa9524bdaae4cb4f140 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 19:25:41 -0400 Subject: [PATCH 10/69] Rework upload tool. --- scripts/functional_tests.py | 15 +++------------ test/functional/tools/upload_tool_conf.xml | 6 ++++++ 2 files changed, 9 insertions(+), 12 deletions(-) create mode 100644 test/functional/tools/upload_tool_conf.xml diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 6ace4052293..70058585daa 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -99,22 +99,17 @@ def main(): testing_installed_tools = __check_arg( '-installed' ) datatypes_conf_override = None + framework_tool_dir = os.path.join('test', 'functional', 'tools') + if testing_migrated_tools or testing_installed_tools: # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. galaxy_tool_shed_test_file = 'shed_tools_dict' # We need the upload tool for functional tests, so we'll create a temporary tool panel config that defines it. - fd, tmp_tool_panel_conf = tempfile.mkstemp() - os.write( fd, '\n' ) - os.write( fd, '\n' ) - os.write( fd, '\n' ) - os.write( fd, '\n' ) - os.close( fd ) - tool_config_file = tmp_tool_panel_conf + tool_config_file = os.path.join( framework_tool_dir, 'upload_tool_conf.xml' ) galaxy_test_file_dir = None library_import_dir = None user_library_import_dir = None else: - framework_tool_dir = os.path.join('test', 'functional', 'tools') framework_test = __check_arg( '-framework' ) # Run through suite of tests testing framework. if framework_test: tool_conf = os.path.join( framework_tool_dir, 'samples_tool_conf.xml' ) @@ -369,10 +364,6 @@ def main(): tool_configs.append( installed_tool_panel_config ) app.toolbox = tools.ToolBox( tool_configs, app.config.tool_path, app ) success = _run_functional_test( testing_shed_tools=True ) - try: - os.unlink( tmp_tool_panel_conf ) - except: - log.info( "Unable to remove temporary file: %s" % tmp_tool_panel_conf ) try: os.unlink( galaxy_tool_shed_test_file ) except: diff --git a/test/functional/tools/upload_tool_conf.xml b/test/functional/tools/upload_tool_conf.xml new file mode 100644 index 00000000000..0865acc83cd --- /dev/null +++ b/test/functional/tools/upload_tool_conf.xml @@ -0,0 +1,6 @@ + + +
+ +
+
From 8c857694f3792520950cbdf6a2dcd5df4e7f332c Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 19:44:51 -0400 Subject: [PATCH 11/69] Synchronize locale handling for test drivers. --- scripts/functional_tests.py | 4 ---- test/base/driver_util.py | 4 ++++ test/tool_shed/functional_tests.py | 3 --- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 70058585daa..9a50511f709 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -25,7 +25,6 @@ from galaxy.util.properties import load_app_properties from galaxy.web import buildapp default_galaxy_test_host = "localhost" -default_galaxy_locales = 'en' default_galaxy_test_file_dir = "test-data,https://github.com/galaxyproject/galaxy-test-data.git" migrated_tool_panel_config = 'config/migrated_tools_conf.xml' installed_tool_panel_configs = [ @@ -93,14 +92,11 @@ def main(): galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) galaxy_test_save = os.environ.get( 'GALAXY_TEST_SAVE', None) tool_path = os.environ.get( 'GALAXY_TEST_TOOL_PATH', 'tools' ) - if 'HTTP_ACCEPT_LANGUAGE' not in os.environ: - os.environ[ 'HTTP_ACCEPT_LANGUAGE' ] = default_galaxy_locales testing_migrated_tools = __check_arg( '-migrated' ) testing_installed_tools = __check_arg( '-installed' ) datatypes_conf_override = None framework_tool_dir = os.path.join('test', 'functional', 'tools') - if testing_migrated_tools or testing_installed_tools: # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. galaxy_tool_shed_test_file = 'shed_tools_dict' diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 51e2e3c41c9..dc126717060 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -25,6 +25,8 @@ from .instrument import StructuredTestDataPlugin galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) +DEFAULT_LOCALES = "en" + def setup_tool_shed_tmp_dir(): tool_shed_test_tmp_dir = os.environ.get('TOOL_SHED_TEST_TMP_DIR', None) @@ -40,6 +42,8 @@ def setup_tool_shed_tmp_dir(): def configure_environment(): """Hack up environment for test cases.""" # no op remove if unused + if 'HTTP_ACCEPT_LANGUAGE' not in os.environ: + os.environ[ 'HTTP_ACCEPT_LANGUAGE' ] = DEFAULT_LOCALES def build_logger(): diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 31d4ae68fbb..32d4165c8b1 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -27,7 +27,6 @@ from galaxy.web import buildapp as galaxybuildapp from functional import database_contexts default_tool_shed_test_host = "localhost" -default_tool_shed_locales = 'en' default_galaxy_test_host = 'localhost' # Use separate databases for Galaxy and tool shed install info by default, @@ -75,8 +74,6 @@ def main(): galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) tool_path = os.environ.get( 'TOOL_SHED_TEST_TOOL_PATH', 'tools' ) - if 'HTTP_ACCEPT_LANGUAGE' not in os.environ: - os.environ[ 'HTTP_ACCEPT_LANGUAGE' ] = default_tool_shed_locales tool_shed_test_file_dir = os.environ.get( 'TOOL_SHED_TEST_FILE_DIR', default_tool_shed_test_file_dir ) if not os.path.isabs( tool_shed_test_file_dir ): tool_shed_test_file_dir = tool_shed_test_file_dir From e0a9d6b67fd9a7063b292a7f2ede04ae70c470fc Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 19:58:00 -0400 Subject: [PATCH 12/69] De-duplicate code for setting up Galaxy database. --- scripts/functional_tests.py | 15 +-------------- test/base/driver_util.py | 20 ++++++++++++++++++++ test/tool_shed/functional_tests.py | 17 +---------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 9a50511f709..5866e117fa4 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -175,20 +175,7 @@ def main(): new_file_path = tempfile.mkdtemp( prefix='new_files_path_', dir=tempdir ) job_working_directory = tempfile.mkdtemp( prefix='job_working_directory_', dir=tempdir ) install_database_connection = os.environ.get( 'GALAXY_TEST_INSTALL_DBURI', None ) - if 'GALAXY_TEST_DBURI' in os.environ: - database_connection = os.environ['GALAXY_TEST_DBURI'] - else: - db_path = os.path.join( galaxy_db_path, 'universe.sqlite' ) - if 'GALAXY_TEST_DB_TEMPLATE' in os.environ: - # Middle ground between recreating a completely new - # database and pointing at existing database with - # GALAXY_TEST_DBURI. The former requires a lot of setup - # time, the latter results in test failures in certain - # cases (namely tool shed tests expecting clean database). - log.debug( "Copying database template from %s.", os.environ['GALAXY_TEST_DB_TEMPLATE'] ) - driver_util.copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) - database_auto_migrate = True - database_connection = 'sqlite:///%s' % db_path + database_connection, database_auto_migrate = driver_util.galaxy_database_conf(galaxy_db_path) kwargs = {} for dir in file_path, new_file_path, template_cache_path: try: diff --git a/test/base/driver_util.py b/test/base/driver_util.py index dc126717060..57d07a32c7d 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -96,6 +96,25 @@ def copy_database_template( source, db_path ): raise Exception( "Failed to copy database template from source %s" % source ) +def galaxy_database_conf(db_path): + """Find (and populate if needed) Galaxy database connection.""" + database_auto_migrate = False + if 'GALAXY_TEST_DBURI' in os.environ: + database_connection = os.environ['GALAXY_TEST_DBURI'] + else: + db_path = os.path.join(db_path, 'universe.sqlite') + if 'GALAXY_TEST_DB_TEMPLATE' in os.environ: + # Middle ground between recreating a completely new + # database and pointing at existing database with + # GALAXY_TEST_DBURI. The former requires a lot of setup + # time, the latter results in test failures in certain + # cases (namely tool shed tests expecting clean database). + copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) + database_auto_migrate = True + database_connection = 'sqlite:///%s' % db_path + return database_connection, database_auto_migrate + + def _get_static_settings(): """Configuration required for Galaxy static middleware. @@ -175,6 +194,7 @@ __all__ = [ "configure_environment", "copy_database_template", "build_logger", + "galaxy_database_conf", "get_webapp_global_conf", "nose_config_and_run", "wait_for_http_server", diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 32d4165c8b1..e7166b528a5 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -121,22 +121,7 @@ def main(): toolshed_database_connection = os.environ[ 'TOOL_SHED_TEST_DBURI' ] else: toolshed_database_connection = 'sqlite:///' + os.path.join( shed_db_path, 'community_test.sqlite' ) - galaxy_database_auto_migrate = False - if 'GALAXY_TEST_DBURI' in os.environ: - galaxy_database_connection = os.environ[ 'GALAXY_TEST_DBURI' ] - else: - db_path = os.path.join( galaxy_db_path, 'universe.sqlite' ) - if 'GALAXY_TEST_DB_TEMPLATE' in os.environ: - # Middle ground between recreating a completely new - # database and pointing at existing database with - # GALAXY_TEST_DBURI. The former requires a lot of setup - # time, the latter results in test failures in certain - # cases (namely tool shed tests expecting clean database). - driver_util.copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) - galaxy_database_auto_migrate = True - if not os.path.exists(galaxy_db_path): - os.makedirs(galaxy_db_path) - galaxy_database_connection = 'sqlite:///%s' % db_path + galaxy_database_connection, galaxy_database_auto_migrate = driver_util.galaxy_database_conf(galaxy_db_path) if 'GALAXY_TEST_INSTALL_DBURI' in os.environ: install_galaxy_database_connection = os.environ[ 'GALAXY_TEST_INSTALL_DBURI' ] elif asbool( os.environ.get( 'GALAXY_TEST_INSTALL_DB_MERGED', default_install_db_merged ) ): From 887edb647b5175c9e24a3e432a0ef38fe84ed02c Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 20:07:32 -0400 Subject: [PATCH 13/69] Remove no longer valid sample references in scripts/functional_tests.py. --- scripts/functional_tests.py | 4 ---- test/tool_shed/functional_tests.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 5866e117fa4..c434f6c9d37 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -149,7 +149,6 @@ def main(): data_manager_config_file = "%s,test/functional/tools/sample_data_manager_conf.xml" % default_data_manager_config shed_tool_data_table_config = 'config/shed_tool_data_table_conf.xml' tool_dependency_dir = os.environ.get( 'GALAXY_TOOL_DEPENDENCY_DIR', None ) - use_distributed_object_store = os.environ.get( 'GALAXY_USE_DISTRIBUTED_OBJECT_STORE', False ) galaxy_test_tmp_dir = os.environ.get( 'GALAXY_TEST_TMP_DIR', None ) if galaxy_test_tmp_dir is None: galaxy_test_tmp_dir = tempfile.mkdtemp() @@ -235,9 +234,6 @@ def main(): kwargs[ 'database_engine_option_pool_size' ] = '10' if tool_dependency_dir is not None: kwargs[ 'tool_dependency_dir' ] = tool_dependency_dir - if use_distributed_object_store: - kwargs[ 'object_store' ] = 'distributed' - kwargs[ 'distributed_object_store_config_file' ] = 'distributed_object_store_conf.xml.sample' if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override # If the user has passed in a path for the .ini file, do not overwrite it. diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index e7166b528a5..c7b69737e49 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -78,7 +78,6 @@ def main(): if not os.path.isabs( tool_shed_test_file_dir ): tool_shed_test_file_dir = tool_shed_test_file_dir tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) - use_distributed_object_store = os.environ.get( 'TOOL_SHED_USE_DISTRIBUTED_OBJECT_STORE', False ) if not os.path.isdir( tool_shed_test_tmp_dir ): os.mkdir( tool_shed_test_tmp_dir ) tool_shed_test_proxy_port = None @@ -172,9 +171,6 @@ def main(): # kwargs[ 'database_engine_option_max_overflow' ] = '20' if tool_dependency_dir is not None: kwargs[ 'tool_dependency_dir' ] = tool_dependency_dir - if use_distributed_object_store: - kwargs[ 'object_store' ] = 'distributed' - kwargs[ 'distributed_object_store_config_file' ] = 'distributed_object_store_conf.xml.sample' kwargs[ 'global_conf' ] = tool_shed_global_conf From fe39f5bf553dd3b2a41b5bfaf960b9a175e8d904 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 20:17:11 -0400 Subject: [PATCH 14/69] Revise test driver logging so log is available in driver_util. --- test/base/driver_util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 57d07a32c7d..efab121331b 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -27,6 +27,8 @@ galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pa DEFAULT_LOCALES = "en" +log = logging.getLogger("test_driver") + def setup_tool_shed_tmp_dir(): tool_shed_test_tmp_dir = os.environ.get('TOOL_SHED_TEST_TMP_DIR', None) @@ -48,7 +50,7 @@ def configure_environment(): def build_logger(): """Build a logger for test driver script.""" - return logging.getLogger("test_driver") + return log def nose_config_and_run( argv=None, env=None, ignore_files=[], plugins=None ): From db37011d700d3ba174033dc68808a9882525268d Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 20:21:25 -0400 Subject: [PATCH 15/69] De-duplicate code for cleaning up test directories. --- scripts/functional_tests.py | 10 +--------- test/base/driver_util.py | 18 ++++++++++++++++++ test/tool_shed/functional_tests.py | 10 +--------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index c434f6c9d37..90110fede75 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -2,7 +2,6 @@ import os import os.path -import shutil import sys import tempfile from ConfigParser import SafeConfigParser @@ -366,14 +365,7 @@ def main(): app.shutdown() app = None log.info( "Embedded Universe application stopped" ) - try: - if os.path.exists( tempdir ) and 'GALAXY_TEST_NO_CLEANUP' not in os.environ: - log.info( "Cleaning up temporary files in %s" % tempdir ) - shutil.rmtree( tempdir ) - else: - log.info( "GALAXY_TEST_NO_CLEANUP is on. Temporary files in %s" % tempdir ) - except: - pass + driver_util.cleanup_directory(tempdir) if success: return 0 else: diff --git a/test/base/driver_util.py b/test/base/driver_util.py index efab121331b..48f455555ee 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -192,7 +192,25 @@ def serve_webapp(webapp, port=None, host=None): return server, port + +def cleanup_directory(tempdir): + """Clean up temporary files used by test unless GALAXY_TEST_NO_CLEANUP is set. + + Also respect TOOL_SHED_TEST_NO_CLEANUP for legacy reasons. + """ + skip_cleanup = "GALAXY_TEST_NO_CLEANUP" in os.environ or "TOOL_SHED_TEST_NO_CLEANUP" in os.environ + if skip_cleanup: + log.info( "GALAXY_TEST_NO_CLEANUP is on. Temporary files in %s" % tempdir ) + return + try: + if os.path.exists(tempdir) and skip_cleanup: + shutil.rmtree(tempdir) + except Exception: + pass + + __all__ = [ + "cleanup_directory", "configure_environment", "copy_database_template", "build_logger", diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index c7b69737e49..688649c3700 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -2,7 +2,6 @@ from __future__ import absolute_import import os -import shutil import string import sys import tempfile @@ -322,14 +321,7 @@ def main(): galaxyapp.shutdown() galaxyapp = None log.info( "Embedded galaxy application stopped" ) - if 'TOOL_SHED_TEST_NO_CLEANUP' not in os.environ: - try: - for dir in [ tool_shed_test_tmp_dir ]: - if os.path.exists( dir ): - log.info( "Cleaning up temporary files in %s" % dir ) - shutil.rmtree( dir ) - except: - pass + driver_util.cleanup_directory(tool_shed_test_tmp_dir) if success: return 0 else: From 91a71068979ca19763ca18cde73d350a37546ec4 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 20:23:52 -0400 Subject: [PATCH 16/69] Remove unused proxy port stuff in test drivers. --- scripts/functional_tests.py | 11 ++--------- test/tool_shed/functional_tests.py | 22 ++++------------------ 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 90110fede75..161bbc21746 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -159,7 +159,6 @@ def main(): database_auto_migrate = False - galaxy_test_proxy_port = None if start_server: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) # Configure the database path. @@ -264,18 +263,12 @@ def main(): webapp = buildapp.app_factory( kwargs[ 'global_conf' ], app=app, use_translogger=False, static_enabled=True ) server, galaxy_test_port = driver_util.serve_webapp( webapp, host=galaxy_test_host, port=galaxy_test_port ) - if galaxy_test_proxy_port: - os.environ['GALAXY_TEST_PORT'] = galaxy_test_proxy_port - else: - os.environ['GALAXY_TEST_PORT'] = galaxy_test_port + os.environ['GALAXY_TEST_PORT'] = galaxy_test_port driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded web server started" ) # ---- Find tests --------------------------------------------------------- - if galaxy_test_proxy_port: - log.info( "Functional tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_proxy_port ) ) - else: - log.info( "Functional tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) + log.info( "Functional tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) success = False try: tool_configs = app.config.tool_configs diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 688649c3700..74461866708 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -79,8 +79,6 @@ def main(): tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) if not os.path.isdir( tool_shed_test_tmp_dir ): os.mkdir( tool_shed_test_tmp_dir ) - tool_shed_test_proxy_port = None - galaxy_test_proxy_port = None if 'TOOL_SHED_TEST_DBPATH' in os.environ: shed_db_path = os.environ[ 'TOOL_SHED_TEST_DBPATH' ] else: @@ -190,10 +188,7 @@ def main(): tool_shed_server, tool_shed_test_port = driver_util.serve_webapp( toolshedwebapp, host=tool_shed_test_host, port=tool_shed_test_port ) - if tool_shed_test_proxy_port: - os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_proxy_port - else: - os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_port + os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_port driver_util.wait_for_http_server(tool_shed_test_host, tool_shed_test_port) log.info( "Embedded web server started" ) @@ -272,21 +267,12 @@ def main(): galaxy_server, galaxy_test_port = driver_util.serve_webapp( galaxywebapp, host=galaxy_test_host, port=galaxy_test_port ) - if galaxy_test_proxy_port: - os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_proxy_port - else: - os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_port + os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_port driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded galaxy web server started" ) # ---- Find tests --------------------------------------------------------- - if tool_shed_test_proxy_port: - log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_proxy_port ) ) - else: - log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_port ) ) - if galaxy_test_proxy_port: - log.info( "Galaxy tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_proxy_port ) ) - else: - log.info( "Galaxy tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) + log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_port ) ) + log.info( "Galaxy tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) success = False try: # Pass in through script set env, will leave a copy of ALL test validate files. From ce9a55207fe5f467a71e03fb3f364fc08ed4f943 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 25 Mar 2016 20:33:11 -0400 Subject: [PATCH 17/69] Remove unused or un-useful code from tool shed test driver. --- test/tool_shed/functional_tests.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 74461866708..984c65cd970 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -73,9 +73,6 @@ def main(): galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) tool_path = os.environ.get( 'TOOL_SHED_TEST_TOOL_PATH', 'tools' ) - tool_shed_test_file_dir = os.environ.get( 'TOOL_SHED_TEST_FILE_DIR', default_tool_shed_test_file_dir ) - if not os.path.isabs( tool_shed_test_file_dir ): - tool_shed_test_file_dir = tool_shed_test_file_dir tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) if not os.path.isdir( tool_shed_test_tmp_dir ): os.mkdir( tool_shed_test_tmp_dir ) From 97070b4b532b2fd8f11276d8056dc036a4155d50 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 26 Mar 2016 07:53:35 -0400 Subject: [PATCH 18/69] Move tool shed test data handling into driver_util. --- test/base/driver_util.py | 5 +++++ test/tool_shed/functional_tests.py | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 48f455555ee..a6fcb73e5f0 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -24,6 +24,7 @@ from .nose_util import run from .instrument import StructuredTestDataPlugin galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) +TOOL_SHED_TEST_DATA = os.path.join(galaxy_root, "test", "tool_shed", "test_data") DEFAULT_LOCALES = "en" @@ -47,6 +48,10 @@ def configure_environment(): if 'HTTP_ACCEPT_LANGUAGE' not in os.environ: os.environ[ 'HTTP_ACCEPT_LANGUAGE' ] = DEFAULT_LOCALES + # Used by get_filename in tool shed's twilltestcase. + if "TOOL_SHED_TEST_FILE_DIR" not in os.environ: + os.environ["TOOL_SHED_TEST_FILE_DIR"] = TOOL_SHED_TEST_DATA + def build_logger(): """Build a logger for test driver script.""" diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 984c65cd970..1f4d6cd44d3 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -275,8 +275,6 @@ def main(): # Pass in through script set env, will leave a copy of ALL test validate files. os.environ[ 'TOOL_SHED_TEST_HOST' ] = tool_shed_test_host os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host - if tool_shed_test_file_dir: - os.environ[ 'TOOL_SHED_TEST_FILE_DIR' ] = tool_shed_test_file_dir success = driver_util.nose_config_and_run() except: log.exception( "Failure running tests" ) From fd46a1f987fe6c9fa95b62e9b21bc00273c36fe9 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 26 Mar 2016 08:05:52 -0400 Subject: [PATCH 19/69] Move tool_conf logic for drivers into driver_util. - Don't generate a tool_conf for upload in tool shed tests - just use the fixed one setup for framework tools. - Move every mention of that directory and files into constants in driver_util. --- scripts/functional_tests.py | 9 ++++----- test/base/driver_util.py | 10 +++++++++- test/tool_shed/functional_tests.py | 12 +----------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 161bbc21746..d172c0c883e 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -95,25 +95,24 @@ def main(): testing_installed_tools = __check_arg( '-installed' ) datatypes_conf_override = None - framework_tool_dir = os.path.join('test', 'functional', 'tools') if testing_migrated_tools or testing_installed_tools: # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. galaxy_tool_shed_test_file = 'shed_tools_dict' # We need the upload tool for functional tests, so we'll create a temporary tool panel config that defines it. - tool_config_file = os.path.join( framework_tool_dir, 'upload_tool_conf.xml' ) + tool_config_file = driver_util.FRAMEWORK_UPLOAD_TOOL_CONF galaxy_test_file_dir = None library_import_dir = None user_library_import_dir = None else: framework_test = __check_arg( '-framework' ) # Run through suite of tests testing framework. if framework_test: - tool_conf = os.path.join( framework_tool_dir, 'samples_tool_conf.xml' ) - datatypes_conf_override = os.path.join( framework_tool_dir, 'sample_datatypes_conf.xml' ) + tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF + datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF else: # Use tool_conf.xml toolbox. tool_conf = None if __check_arg( '-with_framework_test_tools' ): - tool_conf = "%s,%s" % ( 'config/tool_conf.xml.sample', os.path.join( framework_tool_dir, 'samples_tool_conf.xml' ) ) + tool_conf = "%s,%s" % ( 'config/tool_conf.xml.sample', driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF ) test_dir = default_galaxy_test_file_dir tool_config_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', tool_conf ) galaxy_test_file_dir = os.environ.get( 'GALAXY_TEST_FILE_DIR', test_dir ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index a6fcb73e5f0..b26f96cab42 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -24,7 +24,12 @@ from .nose_util import run from .instrument import StructuredTestDataPlugin galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) -TOOL_SHED_TEST_DATA = os.path.join(galaxy_root, "test", "tool_shed", "test_data") +GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test") +TOOL_SHED_TEST_DATA = os.path.join(GALAXY_TEST_DIRECTORY, "tool_shed", "test_data") +FRAMEWORK_TOOLS_DIR = os.path.join(GALAXY_TEST_DIRECTORY, "functional", "tools") +FRAMEWORK_UPLOAD_TOOL_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "upload_tool_conf.xml") +FRAMEWORK_SAMPLE_TOOLS_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "samples_tool_conf.xml") +FRAMEWORK_DATATYPES_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "sample_datatypes_conf.xml") DEFAULT_LOCALES = "en" @@ -219,6 +224,9 @@ __all__ = [ "configure_environment", "copy_database_template", "build_logger", + "FRAMEWORK_UPLOAD_TOOL_CONF", + "FRAMEWORK_SAMPLE_TOOLS_CONF", + "FRAMEWORK_DATATYPES_CONF", "galaxy_database_conf", "get_webapp_global_conf", "nose_config_and_run", diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 1f4d6cd44d3..7eb95d487f9 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -47,14 +47,6 @@ shed_tool_conf_xml_template = ''' ''' -tool_conf_xml = ''' - -
- -
-
-''' - tool_data_table_conf_xml_template = ''' @@ -84,7 +76,7 @@ def main(): shed_tool_data_table_conf_file = os.environ.get( 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml' ) ) galaxy_shed_data_manager_conf_file = os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_data_manager_conf.xml' ) ) galaxy_tool_data_table_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'tool_data_table_conf.xml' ) ) - galaxy_tool_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_tool_conf.xml' ) ) + galaxy_tool_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', driver_util.FRAMEWORK_UPLOAD_TOOL_CONF ) galaxy_shed_tool_conf_file = os.environ.get( 'GALAXY_TEST_SHED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml' ) ) galaxy_migrated_tool_conf_file = os.environ.get( 'GALAXY_TEST_MIGRATED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_migrated_tool_conf.xml' ) ) galaxy_tool_sheds_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_SHEDS_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_sheds_conf.xml' ) ) @@ -191,8 +183,6 @@ def main(): # ---- Optionally start up a Galaxy instance ------------------------------------------------------ if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ: - # Generate the tool_conf.xml file. - file( galaxy_tool_conf_file, 'w' ).write( tool_conf_xml ) # Generate the shed_tool_conf.xml file. tool_sheds_conf_template_parser = string.Template( tool_sheds_conf_xml_template ) tool_sheds_conf_xml = tool_sheds_conf_template_parser.safe_substitute( shed_url=tool_shed_test_host, shed_port=tool_shed_test_port ) From 9804eb56bf6d4ba4df0ec787501366d1dab8102e Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 26 Mar 2016 08:20:49 -0400 Subject: [PATCH 20/69] De-duplicate test driver logic for install database connection. --- scripts/functional_tests.py | 5 ++--- test/base/driver_util.py | 16 ++++++++++++++++ test/tool_shed/functional_tests.py | 13 +++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index d172c0c883e..2bb934fc2a8 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -170,8 +170,8 @@ def main(): template_cache_path = os.path.join( galaxy_db_path, 'compiled_templates' ) new_file_path = tempfile.mkdtemp( prefix='new_files_path_', dir=tempdir ) job_working_directory = tempfile.mkdtemp( prefix='job_working_directory_', dir=tempdir ) - install_database_connection = os.environ.get( 'GALAXY_TEST_INSTALL_DBURI', None ) database_connection, database_auto_migrate = driver_util.galaxy_database_conf(galaxy_db_path) + install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=True) kwargs = {} for dir in file_path, new_file_path, template_cache_path: try: @@ -224,8 +224,7 @@ def main(): enable_beta_tool_formats=True, auto_configure_logging=logging_config_file is None, data_manager_config_file=data_manager_config_file ) - if install_database_connection is not None: - kwargs[ 'install_database_connection' ] = install_database_connection + kwargs.update(install_database_conf) if not database_connection.startswith( 'sqlite://' ): kwargs[ 'database_engine_option_max_overflow' ] = '20' kwargs[ 'database_engine_option_pool_size' ] = '10' diff --git a/test/base/driver_util.py b/test/base/driver_util.py index b26f96cab42..7861305250a 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -23,6 +23,8 @@ from paste import httpserver from .nose_util import run from .instrument import StructuredTestDataPlugin +from galaxy.util import asbool + galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test") TOOL_SHED_TEST_DATA = os.path.join(GALAXY_TEST_DIRECTORY, "tool_shed", "test_data") @@ -127,6 +129,20 @@ def galaxy_database_conf(db_path): return database_connection, database_auto_migrate +def install_database_conf(db_path, default_merged=False): + if 'GALAXY_TEST_INSTALL_DBURI' in os.environ: + install_galaxy_database_connection = os.environ['GALAXY_TEST_INSTALL_DBURI'] + elif asbool(os.environ.get('GALAXY_TEST_INSTALL_DB_MERGED', default_merged)): + install_galaxy_database_connection = None + else: + install_galaxy_db_path = os.path.join(db_path, 'install.sqlite') + install_galaxy_database_connection = 'sqlite:///%s' % install_galaxy_db_path + conf = {} + if install_galaxy_database_connection is not None: + conf["install_database_connection"] = install_galaxy_database_connection + return conf + + def _get_static_settings(): """Configuration required for Galaxy static middleware. diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 7eb95d487f9..0f9708a931a 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -20,7 +20,6 @@ from galaxy.webapps.tool_shed import buildapp as toolshedbuildapp from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication # This is for the galaxy application. from galaxy.app import UniverseApplication as GalaxyUniverseApplication -from galaxy.util import asbool from galaxy.web import buildapp as galaxybuildapp from functional import database_contexts @@ -107,13 +106,7 @@ def main(): else: toolshed_database_connection = 'sqlite:///' + os.path.join( shed_db_path, 'community_test.sqlite' ) galaxy_database_connection, galaxy_database_auto_migrate = driver_util.galaxy_database_conf(galaxy_db_path) - if 'GALAXY_TEST_INSTALL_DBURI' in os.environ: - install_galaxy_database_connection = os.environ[ 'GALAXY_TEST_INSTALL_DBURI' ] - elif asbool( os.environ.get( 'GALAXY_TEST_INSTALL_DB_MERGED', default_install_db_merged ) ): - install_galaxy_database_connection = galaxy_database_connection - else: - install_galaxy_db_path = os.path.join( galaxy_db_path, 'install.sqlite' ) - install_galaxy_database_connection = 'sqlite:///%s' % install_galaxy_db_path + install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=False) tool_shed_global_conf = driver_util.get_webapp_global_conf() tool_shed_global_conf[ '__file__' ] = 'tool_shed_wsgi.ini.sample' kwargs = dict( admin_users='test@bx.psu.edu', @@ -205,7 +198,6 @@ def main(): allow_user_deletion=True, admin_users='test@bx.psu.edu', allow_library_path_paste=True, - install_database_connection=install_galaxy_database_connection, database_connection=galaxy_database_connection, database_auto_migrate=galaxy_database_auto_migrate, datatype_converters_config_file="datatype_converters_conf.xml.sample", @@ -234,8 +226,9 @@ def main(): update_integrated_tool_panel=False, use_heartbeat=False ) + kwargs.update(install_database_conf) # ---- Build Galaxy Application -------------------------------------------------- - if not galaxy_database_connection.startswith( 'sqlite://' ) and not install_galaxy_database_connection.startswith( 'sqlite://' ): + if not galaxy_database_connection.startswith( 'sqlite://' ): kwargs[ 'database_engine_option_pool_size' ] = '10' kwargs[ 'database_engine_option_max_overflow' ] = '20' galaxyapp = GalaxyUniverseApplication( **kwargs ) From 72716750d1f6ba1b91781144d12c6fd90ce51bca Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 26 Mar 2016 09:07:03 -0400 Subject: [PATCH 21/69] Simplify GALAXY_TEST_SAVE logic... ... script/functional_tests.py was just pulling it out of the environ and sticking it back in - made no sense. --- scripts/functional_tests.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 2bb934fc2a8..b3728873925 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -89,7 +89,6 @@ def main(): # ---- Configuration ------------------------------------------------------ galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) - galaxy_test_save = os.environ.get( 'GALAXY_TEST_SAVE', None) tool_path = os.environ.get( 'GALAXY_TEST_TOOL_PATH', 'tools' ) testing_migrated_tools = __check_arg( '-migrated' ) testing_installed_tools = __check_arg( '-installed' ) @@ -271,8 +270,6 @@ def main(): try: tool_configs = app.config.tool_configs # What requires these? Handy for (eg) functional tests to save outputs? - if galaxy_test_save: - os.environ[ 'GALAXY_TEST_SAVE' ] = galaxy_test_save # Pass in through script setenv, will leave a copy of ALL test validate files os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host From 75f0cb470c69d05ad69ff4e4d96d83ff036940cd Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 26 Mar 2016 09:19:44 -0400 Subject: [PATCH 22/69] Eliminate ability to set Galaxy tool path for tool shed tests... Makes sense in Galaxy tests but not for tool shed tests, I see no reason for this extension point. If it is needed GALAXY_CONFIG_TOOL_PATH will work instead of TOOL_SHED_TEST_TOOL_PATH. --- test/tool_shed/functional_tests.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 0f9708a931a..534b718ce54 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -63,7 +63,6 @@ def main(): tool_shed_test_port = os.environ.get( 'TOOL_SHED_TEST_PORT', None ) galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) - tool_path = os.environ.get( 'TOOL_SHED_TEST_TOOL_PATH', 'tools' ) tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) if not os.path.isdir( tool_shed_test_tmp_dir ): os.mkdir( tool_shed_test_tmp_dir ) @@ -126,7 +125,6 @@ def main(): smtp_server='smtp.dummy.string.tld', email_from='functional@localhost', template_path='templates', - tool_path=tool_path, tool_parse_help=False, tool_data_table_config_path=galaxy_tool_data_table_conf_file, use_heartbeat=False ) @@ -218,7 +216,6 @@ def main(): template_path="templates", tool_data_path=tool_data_path, tool_dependency_dir=galaxy_tool_dependency_dir, - tool_path=tool_path, tool_config_file=[ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], tool_sheds_config_file=galaxy_tool_sheds_conf_file, tool_parse_help=False, From 16c0ae216aa5414b4a9d19c53b47a9d94fc6e3af Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 26 Mar 2016 11:38:33 -0400 Subject: [PATCH 23/69] De-duplicate XXX_TEST_DBPATH logic. --- scripts/functional_tests.py | 6 ++---- test/base/driver_util.py | 15 +++++++++++++++ test/tool_shed/functional_tests.py | 12 ++---------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index b3728873925..499863801bb 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -160,10 +160,8 @@ def main(): if start_server: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) # Configure the database path. - if 'GALAXY_TEST_DBPATH' in os.environ: - galaxy_db_path = os.environ[ 'GALAXY_TEST_DBPATH' ] - else: - galaxy_db_path = os.path.join( tempdir, 'database' ) + galaxy_db_path = driver_util.database_files_path(tempdir) + # Configure the paths Galaxy needs to test tools. file_path = os.path.join( galaxy_db_path, 'files' ) template_cache_path = os.path.join( galaxy_db_path, 'compiled_templates' ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 7861305250a..f724b8d38e5 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -143,6 +143,21 @@ def install_database_conf(db_path, default_merged=False): return conf +def database_files_path(test_tmpdir, prefix="GALAXY"): + """Create a mock database/ directory like in GALAXY_ROOT. + + Use prefix to default this if TOOL_SHED_TEST_DBPATH or + GALAXY_TEST_DBPATH is set in the environment. + """ + environ_var = "%s_TEST_DBPATH" % prefix + if environ_var in os.environ: + db_path = os.environ[environ_var] + else: + tempdir = tempfile.mkdtemp(dir=test_tmpdir) + db_path = os.path.join(tempdir, 'database') + return db_path + + def _get_static_settings(): """Configuration required for Galaxy static middleware. diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 534b718ce54..9c517055e1c 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -66,11 +66,7 @@ def main(): tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) if not os.path.isdir( tool_shed_test_tmp_dir ): os.mkdir( tool_shed_test_tmp_dir ) - if 'TOOL_SHED_TEST_DBPATH' in os.environ: - shed_db_path = os.environ[ 'TOOL_SHED_TEST_DBPATH' ] - else: - tempdir = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - shed_db_path = os.path.join( tempdir, 'database' ) + shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir, prefix="TOOL_SHED") shed_tool_data_table_conf_file = os.environ.get( 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml' ) ) galaxy_shed_data_manager_conf_file = os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_data_manager_conf.xml' ) ) galaxy_tool_data_table_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'tool_data_table_conf.xml' ) ) @@ -83,11 +79,7 @@ def main(): else: tool_data_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) os.environ[ 'GALAXY_TEST_TOOL_DATA_PATH' ] = tool_data_path - if 'GALAXY_TEST_DBPATH' in os.environ: - galaxy_db_path = os.environ[ 'GALAXY_TEST_DBPATH' ] - else: - tempdir = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - galaxy_db_path = os.path.join( tempdir, 'database' ) + galaxy_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir) shed_file_path = os.path.join( shed_db_path, 'files' ) galaxy_file_path = os.path.join( galaxy_db_path, 'files' ) hgweb_config_file_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) From c2b260539b58291c6a207f1d779ac8465302c831 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 10:07:23 -0400 Subject: [PATCH 24/69] Start list of environment variables used for testing. --- run_tests.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/run_tests.sh b/run_tests.sh index c4cf50e493a..7c5173ed98b 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -45,6 +45,43 @@ Extra options: --dockerize Run tests in a pre-configured Docker container (must be first argument if present). --db For use with --dockerize, run tests using partially migrated 'postgres', 'mysql', or 'sqlite' databases. + +Environment Variables: + +In addition to the above command-line options, many environment Variables +can be used to control the Galaxy functional testing processing. + +Functional Test Environment Variables + +GALAXY_TEST_DBURI Database connection string used for functional test + database for Galaxy. +GALAXY_TEST_INSTALL_DBURI Database connection string used for functional test + database for Galaxy's install framework. +GALAXY_TEST_INSTALL_DB_MERGED Set to use same database for Galaxy and install framework, + this defaults to True for Galaxy tests an False for shed tests. +GALAXY_TEST_DB_TEMPLATE If GALAXY_TEST_DBURI is unset, this URL can be retrieved + and should be an sqlite database that will be upgraded + and tested against. +HTTP_ACCEPT_LANGUAGE Defaults to 'en' +GALAXY_TEST_NO_CLEANUP Do not cleanup main test directory after tests, + the deprecated option TOOL_SHED_TEST_NO_CLEANUP does the + same thing. +GALAXY_TEST_HOST Host to use for Galaxy server setup for testing. +GALAXY_TEST_PORT Port to use for Galaxy server setup for testing. +GALAXY_TEST_TOOL_PATH Defaults to 'tools' + +TOOL_SHED_TEST_HOST Host to use for shed server setup for testing. +TOOL_SHED_TEST_PORT Port to use for shed server setup for testing. +TOOL_SHED_TEST_FILE_DIR Defaults to test/tool_shed/test_data. +TOOL_SHED_TEST_TMP_DIR Defaults to random /tmp directory - place for tool shed + test server files to be placed. +TOOL_SHED_TEST_OMIT_GALAXY Do not launch a Galaxy server for tool shed testing. + +Unit Test Environment Variables + +GALAXY_TEST_INCLUDE_SLOW - Used in unit tests to trigger slower tests that + aren't included by default with --unit/-u. + EOF } From e86fa83e863b7da20ba1cc1b2ce96bec6dd76896 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 10:26:57 -0400 Subject: [PATCH 25/69] Begin work on test driver function for setting up Galaxy config. --- scripts/functional_tests.py | 26 +++++--------------------- test/base/driver_util.py | 25 +++++++++++++++++++++++++ test/tool_shed/functional_tests.py | 2 +- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 499863801bb..7b37d7fecd4 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -24,7 +24,6 @@ from galaxy.util.properties import load_app_properties from galaxy.web import buildapp default_galaxy_test_host = "localhost" -default_galaxy_test_file_dir = "test-data,https://github.com/galaxyproject/galaxy-test-data.git" migrated_tool_panel_config = 'config/migrated_tools_conf.xml' installed_tool_panel_configs = [ os.environ.get('GALAXY_TEST_SHED_TOOL_CONF', 'config/shed_tool_conf.xml') @@ -94,14 +93,13 @@ def main(): testing_installed_tools = __check_arg( '-installed' ) datatypes_conf_override = None - if testing_migrated_tools or testing_installed_tools: + use_test_file_dir = not (testing_migrated_tools or testing_installed_tools) + galaxy_config = driver_util.setup_galaxy_config(use_test_file_dir=use_test_file_dir) + if not use_test_file_dir: # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. galaxy_tool_shed_test_file = 'shed_tools_dict' # We need the upload tool for functional tests, so we'll create a temporary tool panel config that defines it. tool_config_file = driver_util.FRAMEWORK_UPLOAD_TOOL_CONF - galaxy_test_file_dir = None - library_import_dir = None - user_library_import_dir = None else: framework_test = __check_arg( '-framework' ) # Run through suite of tests testing framework. if framework_test: @@ -112,18 +110,7 @@ def main(): tool_conf = None if __check_arg( '-with_framework_test_tools' ): tool_conf = "%s,%s" % ( 'config/tool_conf.xml.sample', driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF ) - test_dir = default_galaxy_test_file_dir tool_config_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', tool_conf ) - galaxy_test_file_dir = os.environ.get( 'GALAXY_TEST_FILE_DIR', test_dir ) - first_test_file_dir = galaxy_test_file_dir.split(",")[0] - if not os.path.isabs( first_test_file_dir ): - first_test_file_dir = os.path.join( os.getcwd(), first_test_file_dir ) - library_import_dir = first_test_file_dir - import_dir = os.path.join( first_test_file_dir, 'users' ) - if os.path.exists(import_dir): - user_library_import_dir = import_dir - else: - user_library_import_dir = None start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ tool_data_table_config_path = None @@ -198,7 +185,6 @@ def main(): id_secret='changethisinproductiontoo', job_queue_workers=5, job_working_directory=job_working_directory, - library_import_dir=library_import_dir, log_destination="stdout", new_file_path=new_file_path, template_cache_path=template_cache_path, @@ -213,7 +199,6 @@ def main(): tool_parse_help=False, update_integrated_tool_panel=False, use_heartbeat=False, - user_library_import_dir=user_library_import_dir, master_api_key=master_api_key, use_tasked_jobs=True, check_migrate_tools=False, @@ -221,6 +206,7 @@ def main(): enable_beta_tool_formats=True, auto_configure_logging=logging_config_file is None, data_manager_config_file=data_manager_config_file ) + kwargs.update(galaxy_config) kwargs.update(install_database_conf) if not database_connection.startswith( 'sqlite://' ): kwargs[ 'database_engine_option_max_overflow' ] = '20' @@ -304,7 +290,7 @@ def main(): ) return driver_util.nose_config_and_run() - if testing_migrated_tools or testing_installed_tools: + if not use_test_file_dir: shed_tools_dict = {} if testing_migrated_tools: has_test_data, shed_tools_dict = parse_tool_panel_config( migrated_tool_panel_config, shed_tools_dict ) @@ -333,8 +319,6 @@ def main(): except: log.info( "Unable to remove file: %s" % galaxy_tool_shed_test_file ) else: - if galaxy_test_file_dir: - os.environ[ 'GALAXY_TEST_FILE_DIR' ] = galaxy_test_file_dir success = _run_functional_test( ) except: log.exception( "Failure running tests" ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index f724b8d38e5..276058c7899 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -27,6 +27,7 @@ from galaxy.util import asbool galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test") +GALAXY_TEST_FILE_DIR = "test-data,https://github.com/galaxyproject/galaxy-test-data.git" TOOL_SHED_TEST_DATA = os.path.join(GALAXY_TEST_DIRECTORY, "tool_shed", "test_data") FRAMEWORK_TOOLS_DIR = os.path.join(GALAXY_TEST_DIRECTORY, "functional", "tools") FRAMEWORK_UPLOAD_TOOL_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "upload_tool_conf.xml") @@ -65,6 +66,29 @@ def build_logger(): return log +def setup_galaxy_config(use_test_file_dir=False): + """Setup environment and build config for test Galaxy instance.""" + if use_test_file_dir: + galaxy_test_file_dir = os.environ.get('GALAXY_TEST_FILE_DIR', GALAXY_TEST_FILE_DIR) + os.environ['GALAXY_TEST_FILE_DIR'] = galaxy_test_file_dir + first_test_file_dir = galaxy_test_file_dir.split(",")[0] + if not os.path.isabs(first_test_file_dir): + first_test_file_dir = os.path.join(galaxy_root, first_test_file_dir) + library_import_dir = first_test_file_dir + import_dir = os.path.join(first_test_file_dir, 'users') + if os.path.exists(import_dir): + user_library_import_dir = import_dir + else: + user_library_import_dir = None + else: + user_library_import_dir = None + library_import_dir = None + return dict( + library_import_dir=library_import_dir, + user_library_import_dir=user_library_import_dir, + ) + + def nose_config_and_run( argv=None, env=None, ignore_files=[], plugins=None ): """Setup a nose context and run tests. @@ -261,5 +285,6 @@ __all__ = [ "galaxy_database_conf", "get_webapp_global_conf", "nose_config_and_run", + "setup_galaxy_config", "wait_for_http_server", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 9c517055e1c..808172d4b0f 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -214,7 +214,7 @@ def main(): tool_data_table_config_path=galaxy_tool_data_table_conf_file, update_integrated_tool_panel=False, use_heartbeat=False ) - + kwargs.setup_galaxy_config(use_test_file_dir=False) kwargs.update(install_database_conf) # ---- Build Galaxy Application -------------------------------------------------- if not galaxy_database_connection.startswith( 'sqlite://' ): From a18cbd5930cc21a3997cdc0d69fcf4f0ba53ea55 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 10:36:43 -0400 Subject: [PATCH 26/69] De-duplicate test driver - move more Galaxy config into common method. --- scripts/functional_tests.py | 13 +------------ test/base/driver_util.py | 15 +++++++++++++++ test/tool_shed/functional_tests.py | 17 ++--------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 7b37d7fecd4..81a34059af8 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -173,22 +173,15 @@ def main(): master_api_key = get_master_api_key() app = None if start_server: - kwargs = dict( admin_users='test@bx.psu.edu', - api_allow_run_as='test@bx.psu.edu', - allow_library_path_paste=True, - allow_user_creation=True, - allow_user_deletion=True, - database_connection=database_connection, + kwargs = dict( database_connection=database_connection, database_auto_migrate=database_auto_migrate, datatype_converters_config_file="datatype_converters_conf.xml.sample", file_path=file_path, - id_secret='changethisinproductiontoo', job_queue_workers=5, job_working_directory=job_working_directory, log_destination="stdout", new_file_path=new_file_path, template_cache_path=template_cache_path, - running_functional_tests=True, shed_tool_data_table_config=shed_tool_data_table_config, template_path="templates", test_conf="test.conf", @@ -196,12 +189,8 @@ def main(): tool_data_table_config_path=tool_data_table_config_path, tool_path=tool_path, galaxy_data_manager_data_path=galaxy_data_manager_data_path, - tool_parse_help=False, update_integrated_tool_panel=False, - use_heartbeat=False, master_api_key=master_api_key, - use_tasked_jobs=True, - check_migrate_tools=False, cleanup_job='onsuccess', enable_beta_tool_formats=True, auto_configure_logging=logging_config_file is None, diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 276058c7899..fe3ccc3defd 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -84,7 +84,22 @@ def setup_galaxy_config(use_test_file_dir=False): user_library_import_dir = None library_import_dir = None return dict( + admin_users='test@bx.psu.edu', + allow_library_path_paste=True, + allow_user_creation=True, + allow_user_deletion=True, + api_allow_run_as='test@bx.psu.edu', + check_migrate_tools=False, + id_secret='changethisinproductiontoo', + job_queue_workers=5, library_import_dir=library_import_dir, + log_destination="stdout", + running_functional_tests=True, + template_path='templates', + tool_parse_help=False, + update_integrated_tool_panel=False, + use_tasked_jobs=True, + use_heartbeat=False, user_library_import_dir=user_library_import_dir, ) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 808172d4b0f..8ee95202108 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -184,36 +184,23 @@ def main(): galaxy_global_conf = driver_util.get_webapp_global_conf() galaxy_global_conf[ '__file__' ] = 'config/galaxy.ini.sample' - kwargs = dict( allow_user_creation=True, - allow_user_deletion=True, - admin_users='test@bx.psu.edu', - allow_library_path_paste=True, - database_connection=galaxy_database_connection, + kwargs = dict( database_connection=galaxy_database_connection, database_auto_migrate=galaxy_database_auto_migrate, datatype_converters_config_file="datatype_converters_conf.xml.sample", - check_migrate_tools=False, enable_tool_shed_check=True, file_path=galaxy_file_path, global_conf=galaxy_global_conf, hours_between_check=0.001, - id_secret='changethisinproductiontoo', - job_queue_workers=5, - log_destination="stdout", migrated_tools_config=galaxy_migrated_tool_conf_file, new_file_path=galaxy_tempfiles, - running_functional_tests=True, shed_data_manager_config_file=galaxy_shed_data_manager_conf_file, shed_tool_data_table_config=shed_tool_data_table_conf_file, shed_tool_path=galaxy_shed_tool_path, - template_path="templates", tool_data_path=tool_data_path, tool_dependency_dir=galaxy_tool_dependency_dir, tool_config_file=[ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], tool_sheds_config_file=galaxy_tool_sheds_conf_file, - tool_parse_help=False, - tool_data_table_config_path=galaxy_tool_data_table_conf_file, - update_integrated_tool_panel=False, - use_heartbeat=False ) + tool_data_table_config_path=galaxy_tool_data_table_conf_file ) kwargs.setup_galaxy_config(use_test_file_dir=False) kwargs.update(install_database_conf) # ---- Build Galaxy Application -------------------------------------------------- From ec3f0506c9ee791b8c2e3ba22eb158e14375a267 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 10:37:39 -0400 Subject: [PATCH 27/69] Remove unused config variable from test drivers. --- scripts/functional_tests.py | 1 - test/tool_shed/functional_tests.py | 1 - 2 files changed, 2 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 81a34059af8..ad6f8441881 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -175,7 +175,6 @@ def main(): if start_server: kwargs = dict( database_connection=database_connection, database_auto_migrate=database_auto_migrate, - datatype_converters_config_file="datatype_converters_conf.xml.sample", file_path=file_path, job_queue_workers=5, job_working_directory=job_working_directory, diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 8ee95202108..60008df8f45 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -186,7 +186,6 @@ def main(): kwargs = dict( database_connection=galaxy_database_connection, database_auto_migrate=galaxy_database_auto_migrate, - datatype_converters_config_file="datatype_converters_conf.xml.sample", enable_tool_shed_check=True, file_path=galaxy_file_path, global_conf=galaxy_global_conf, From e309c7f6ebaf7b29a00902af9fb71fd69fac4070 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 11:06:13 -0400 Subject: [PATCH 28/69] Make XXX_TEST_DBPATH and XXX_TEST_DB_TEMPLATE generic and shared with shed. Now the variable TOOL_SHED_TEST_DB_TEMPLATE works as one might expect like GALAXY_TEST_DB_TEMPLATE. --- scripts/functional_tests.py | 2 +- test/base/driver_util.py | 17 ++++++++++------- test/tool_shed/functional_tests.py | 8 +++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index ad6f8441881..7ec71a99d5e 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -154,7 +154,7 @@ def main(): template_cache_path = os.path.join( galaxy_db_path, 'compiled_templates' ) new_file_path = tempfile.mkdtemp( prefix='new_files_path_', dir=tempdir ) job_working_directory = tempfile.mkdtemp( prefix='job_working_directory_', dir=tempdir ) - database_connection, database_auto_migrate = driver_util.galaxy_database_conf(galaxy_db_path) + database_connection, database_auto_migrate = driver_util.database_conf(galaxy_db_path) install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=True) kwargs = {} for dir in file_path, new_file_path, template_cache_path: diff --git a/test/base/driver_util.py b/test/base/driver_util.py index fe3ccc3defd..1b61b21be66 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -149,20 +149,23 @@ def copy_database_template( source, db_path ): raise Exception( "Failed to copy database template from source %s" % source ) -def galaxy_database_conf(db_path): +def database_conf(db_path, prefix="GALAXY"): """Find (and populate if needed) Galaxy database connection.""" database_auto_migrate = False - if 'GALAXY_TEST_DBURI' in os.environ: - database_connection = os.environ['GALAXY_TEST_DBURI'] + dburi_var = "%s_TEST_DBURI" % prefix + if dburi_var in os.environ: + database_connection = os.environ[dburi_var] else: - db_path = os.path.join(db_path, 'universe.sqlite') - if 'GALAXY_TEST_DB_TEMPLATE' in os.environ: + default_db_filename = "%s.sqlite" % prefix.lower() + template_var = "%s_TEST_DB_TEMPLATE" % prefix + db_path = os.path.join(db_path, default_db_filename) + if template_var in os.environ: # Middle ground between recreating a completely new # database and pointing at existing database with # GALAXY_TEST_DBURI. The former requires a lot of setup # time, the latter results in test failures in certain # cases (namely tool shed tests expecting clean database). - copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path) + copy_database_template(os.environ[template_var], db_path) database_auto_migrate = True database_connection = 'sqlite:///%s' % db_path return database_connection, database_auto_migrate @@ -297,7 +300,7 @@ __all__ = [ "FRAMEWORK_UPLOAD_TOOL_CONF", "FRAMEWORK_SAMPLE_TOOLS_CONF", "FRAMEWORK_DATATYPES_CONF", - "galaxy_database_conf", + "database_conf", "get_webapp_global_conf", "nose_config_and_run", "setup_galaxy_config", diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 60008df8f45..b0b8c34d896 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -92,11 +92,8 @@ def main(): hgweb_config_dir = hgweb_config_file_path os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir print "Directory location for hgweb.config:", hgweb_config_dir - if 'TOOL_SHED_TEST_DBURI' in os.environ: - toolshed_database_connection = os.environ[ 'TOOL_SHED_TEST_DBURI' ] - else: - toolshed_database_connection = 'sqlite:///' + os.path.join( shed_db_path, 'community_test.sqlite' ) - galaxy_database_connection, galaxy_database_auto_migrate = driver_util.galaxy_database_conf(galaxy_db_path) + toolshed_database_connection, toolshed_database_auto_migrate = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED") + galaxy_database_connection, galaxy_database_auto_migrate = driver_util.database_conf(galaxy_db_path) install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=False) tool_shed_global_conf = driver_util.get_webapp_global_conf() tool_shed_global_conf[ '__file__' ] = 'tool_shed_wsgi.ini.sample' @@ -104,6 +101,7 @@ def main(): allow_user_creation=True, allow_user_deletion=True, database_connection=toolshed_database_connection, + database_auto_migrate=toolshed_database_auto_migrate, datatype_converters_config_file='datatype_converters_conf.xml.sample', file_path=shed_file_path, global_conf=tool_shed_global_conf, From 7eab64eed0e06872d3eb209f68f1f32667dda65e Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 11:18:43 -0400 Subject: [PATCH 29/69] Remove unused shed tool dependency logic in tool shed tests. --- test/tool_shed/functional_tests.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index b0b8c34d896..7e004888513 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -63,7 +63,6 @@ def main(): tool_shed_test_port = os.environ.get( 'TOOL_SHED_TEST_PORT', None ) galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) - tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) if not os.path.isdir( tool_shed_test_tmp_dir ): os.mkdir( tool_shed_test_tmp_dir ) shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir, prefix="TOOL_SHED") @@ -134,11 +133,6 @@ def main(): os.environ[ 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF' ] = shed_tool_data_table_conf_file # ---- Build Tool Shed Application -------------------------------------------------- toolshedapp = None -# if not toolshed_database_connection.startswith( 'sqlite://' ): -# kwargs[ 'database_engine_option_max_overflow' ] = '20' - if tool_dependency_dir is not None: - kwargs[ 'tool_dependency_dir' ] = tool_dependency_dir - kwargs[ 'global_conf' ] = tool_shed_global_conf if not toolshed_database_connection.startswith( 'sqlite://' ): From dcbdcbe081bdeebdc8e2539007d210db267dcb37 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 11:34:13 -0400 Subject: [PATCH 30/69] Unify tool dependency dir handling between test driver scripts. --- scripts/functional_tests.py | 5 +---- test/base/driver_util.py | 13 +++++++++++-- test/tool_shed/functional_tests.py | 5 +---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 7ec71a99d5e..dd5b7bad2fa 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -94,7 +94,6 @@ def main(): datatypes_conf_override = None use_test_file_dir = not (testing_migrated_tools or testing_installed_tools) - galaxy_config = driver_util.setup_galaxy_config(use_test_file_dir=use_test_file_dir) if not use_test_file_dir: # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. galaxy_tool_shed_test_file = 'shed_tools_dict' @@ -132,7 +131,6 @@ def main(): default_data_manager_config = data_manager_config data_manager_config_file = "%s,test/functional/tools/sample_data_manager_conf.xml" % default_data_manager_config shed_tool_data_table_config = 'config/shed_tool_data_table_conf.xml' - tool_dependency_dir = os.environ.get( 'GALAXY_TOOL_DEPENDENCY_DIR', None ) galaxy_test_tmp_dir = os.environ.get( 'GALAXY_TEST_TMP_DIR', None ) if galaxy_test_tmp_dir is None: galaxy_test_tmp_dir = tempfile.mkdtemp() @@ -146,6 +144,7 @@ def main(): if start_server: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + galaxy_config = driver_util.setup_galaxy_config(tempdir, use_test_file_dir=use_test_file_dir) # Configure the database path. galaxy_db_path = driver_util.database_files_path(tempdir) @@ -199,8 +198,6 @@ def main(): if not database_connection.startswith( 'sqlite://' ): kwargs[ 'database_engine_option_max_overflow' ] = '20' kwargs[ 'database_engine_option_pool_size' ] = '10' - if tool_dependency_dir is not None: - kwargs[ 'tool_dependency_dir' ] = tool_dependency_dir if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override # If the user has passed in a path for the .ini file, do not overwrite it. diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 1b61b21be66..c2bdc316d15 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -66,7 +66,7 @@ def build_logger(): return log -def setup_galaxy_config(use_test_file_dir=False): +def setup_galaxy_config(tmpdir, use_test_file_dir=False): """Setup environment and build config for test Galaxy instance.""" if use_test_file_dir: galaxy_test_file_dir = os.environ.get('GALAXY_TEST_FILE_DIR', GALAXY_TEST_FILE_DIR) @@ -83,7 +83,10 @@ def setup_galaxy_config(use_test_file_dir=False): else: user_library_import_dir = None library_import_dir = None - return dict( + tool_dependency_dir = os.environ.get('GALAXY_TOOL_DEPENDENCY_DIR', None) + if tool_dependency_dir is None: + tool_dependency_dir = tempfile.mkdtemp(dir=tmpdir, prefix="tool_dependencies") + config = dict( admin_users='test@bx.psu.edu', allow_library_path_paste=True, allow_user_creation=True, @@ -102,6 +105,12 @@ def setup_galaxy_config(use_test_file_dir=False): use_heartbeat=False, user_library_import_dir=user_library_import_dir, ) + if tool_dependency_dir: + config["tool_dependency_dir"] = tool_dependency_dir + # Used by shed's twill dependency stuff - todo read from + # Galaxy's config API. + os.environ["GALAXY_TEST_TOOL_DEPENDENCY_DIR"] = tool_dependency_dir + return config def nose_config_and_run( argv=None, env=None, ignore_files=[], plugins=None ): diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 7e004888513..9864fd55ab6 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -86,8 +86,6 @@ def main(): galaxy_tempfiles = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) galaxy_shed_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) galaxy_migrated_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - galaxy_tool_dependency_dir = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - os.environ[ 'GALAXY_TEST_TOOL_DEPENDENCY_DIR' ] = galaxy_tool_dependency_dir hgweb_config_dir = hgweb_config_file_path os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir print "Directory location for hgweb.config:", hgweb_config_dir @@ -188,11 +186,10 @@ def main(): shed_tool_data_table_config=shed_tool_data_table_conf_file, shed_tool_path=galaxy_shed_tool_path, tool_data_path=tool_data_path, - tool_dependency_dir=galaxy_tool_dependency_dir, tool_config_file=[ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], tool_sheds_config_file=galaxy_tool_sheds_conf_file, tool_data_table_config_path=galaxy_tool_data_table_conf_file ) - kwargs.setup_galaxy_config(use_test_file_dir=False) + kwargs.update(driver_util.setup_galaxy_config(tool_shed_test_tmp_dir, use_test_file_dir=False)) kwargs.update(install_database_conf) # ---- Build Galaxy Application -------------------------------------------------- if not galaxy_database_connection.startswith( 'sqlite://' ): From 5af770972d47fcabf7d2c062fa9b4f1739ec146a Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 11:45:36 -0400 Subject: [PATCH 31/69] Fix naming and comment best practices for test driver scripts. --- scripts/functional_tests.py | 26 ++++++++++++++++---------- test/tool_shed/functional_tests.py | 5 +++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index dd5b7bad2fa..44e61d430fc 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -1,4 +1,9 @@ #!/usr/bin/env python +"""Test driver for many Galaxy Python functional tests. + +Launch this script by running ``run_tests.sh`` from GALAXY_ROOT, see +that script for a list of options. +""" import os import os.path @@ -51,11 +56,11 @@ job_conf_xml = ''' def generate_config_file( input_filename, output_filename, config_items ): - ''' - Generate a config file with the configuration that has been defined for the embedded web application. + """Generate a config file with the configuration that has been defined for the embedded web application. + This is mostly relevant when setting metadata externally, since the script for doing that does not have access to app.config. - ''' + """ cp = SafeConfigParser() cp.read( input_filename ) config_items_by_section = [] @@ -85,12 +90,13 @@ def generate_config_file( input_filename, output_filename, config_items ): def main(): + """Entry point for test driver script.""" # ---- Configuration ------------------------------------------------------ galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) tool_path = os.environ.get( 'GALAXY_TEST_TOOL_PATH', 'tools' ) - testing_migrated_tools = __check_arg( '-migrated' ) - testing_installed_tools = __check_arg( '-installed' ) + testing_migrated_tools = _check_arg( '-migrated' ) + testing_installed_tools = _check_arg( '-installed' ) datatypes_conf_override = None use_test_file_dir = not (testing_migrated_tools or testing_installed_tools) @@ -100,14 +106,14 @@ def main(): # We need the upload tool for functional tests, so we'll create a temporary tool panel config that defines it. tool_config_file = driver_util.FRAMEWORK_UPLOAD_TOOL_CONF else: - framework_test = __check_arg( '-framework' ) # Run through suite of tests testing framework. + framework_test = _check_arg( '-framework' ) # Run through suite of tests testing framework. if framework_test: tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF else: # Use tool_conf.xml toolbox. tool_conf = None - if __check_arg( '-with_framework_test_tools' ): + if _check_arg( '-with_framework_test_tools' ): tool_conf = "%s,%s" % ( 'config/tool_conf.xml.sample', driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF ) tool_config_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', tool_conf ) @@ -243,13 +249,13 @@ def main(): os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host def _run_functional_test( testing_shed_tools=None ): - workflow_test = __check_arg( '-workflow', param=True ) + workflow_test = _check_arg( '-workflow', param=True ) if workflow_test: import functional.workflow functional.workflow.WorkflowTestCase.workflow_test_file = workflow_test functional.workflow.WorkflowTestCase.master_api_key = master_api_key functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key() - data_manager_test = __check_arg( '-data_managers', param=False ) + data_manager_test = _check_arg( '-data_managers', param=False ) if data_manager_test: import functional.test_data_managers functional.test_data_managers.data_managers = app.data_managers # seems like a hack... @@ -327,7 +333,7 @@ def main(): return 1 -def __check_arg( name, param=False ): +def _check_arg( name, param=False ): try: index = sys.argv.index( name ) del sys.argv[ index ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 9864fd55ab6..050e11bd8fd 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +"""Test driver for tool shed functional tests. + +Launch this script by running ``run_tests.sh -t`` from GALAXY_ROOT. +""" from __future__ import absolute_import import os @@ -58,6 +62,7 @@ shed_data_manager_conf_xml_template = ''' def main(): + """Entry point for test driver script.""" # ---- Configuration ------------------------------------------------------ tool_shed_test_host = os.environ.get( 'TOOL_SHED_TEST_HOST', default_tool_shed_test_host ) tool_shed_test_port = os.environ.get( 'TOOL_SHED_TEST_PORT', None ) From 6b278478d30f03298ac9cc8a5ebeaf6c2f1bd04f Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 12:05:01 -0400 Subject: [PATCH 32/69] Move tool_path logic into setup_galaxy_config. --- scripts/functional_tests.py | 2 -- test/base/driver_util.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 44e61d430fc..6825882aaaa 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -94,7 +94,6 @@ def main(): # ---- Configuration ------------------------------------------------------ galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) - tool_path = os.environ.get( 'GALAXY_TEST_TOOL_PATH', 'tools' ) testing_migrated_tools = _check_arg( '-migrated' ) testing_installed_tools = _check_arg( '-installed' ) datatypes_conf_override = None @@ -191,7 +190,6 @@ def main(): test_conf="test.conf", tool_config_file=tool_config_file, tool_data_table_config_path=tool_data_table_config_path, - tool_path=tool_path, galaxy_data_manager_data_path=galaxy_data_manager_data_path, update_integrated_tool_panel=False, master_api_key=master_api_key, diff --git a/test/base/driver_util.py b/test/base/driver_util.py index c2bdc316d15..55910163a92 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -83,6 +83,7 @@ def setup_galaxy_config(tmpdir, use_test_file_dir=False): else: user_library_import_dir = None library_import_dir = None + tool_path = os.environ.get('GALAXY_TEST_TOOL_PATH', 'tools') tool_dependency_dir = os.environ.get('GALAXY_TOOL_DEPENDENCY_DIR', None) if tool_dependency_dir is None: tool_dependency_dir = tempfile.mkdtemp(dir=tmpdir, prefix="tool_dependencies") @@ -100,6 +101,7 @@ def setup_galaxy_config(tmpdir, use_test_file_dir=False): running_functional_tests=True, template_path='templates', tool_parse_help=False, + tool_path=tool_path, update_integrated_tool_panel=False, use_tasked_jobs=True, use_heartbeat=False, From 18c366c6d064147a118ab8397a1c2cbc3b0ec4d0 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 12:10:33 -0400 Subject: [PATCH 33/69] Remove now unused variable and documentation. --- test/tool_shed/functional_tests.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 050e11bd8fd..115ea6c5222 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -31,11 +31,6 @@ from functional import database_contexts default_tool_shed_test_host = "localhost" default_galaxy_test_host = 'localhost' -# Use separate databases for Galaxy and tool shed install info by default, -# set GALAXY_TEST_INSTALL_DB_MERGED to True to revert to merged databases -# behavior. -default_install_db_merged = False - tool_sheds_conf_xml_template = ''' From 88ce7a2fa4ac7a5c44e08ca4dcea9fcfe257f406 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 12:11:32 -0400 Subject: [PATCH 34/69] Remove unused branch for tool shed test driver code. --- test/tool_shed/functional_tests.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 115ea6c5222..9c20730d763 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -115,11 +115,6 @@ def main(): tool_parse_help=False, tool_data_table_config_path=galaxy_tool_data_table_conf_file, use_heartbeat=False ) - for dir in [ tool_shed_test_tmp_dir ]: - try: - os.makedirs( dir ) - except OSError: - pass print "Tool shed database connection:", toolshed_database_connection print "Galaxy database connection:", galaxy_database_connection From d03651f4ef7c5e5540d3a23c84b38e840900b500 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 12:20:00 -0400 Subject: [PATCH 35/69] Move more shared galaxy configuration into driver_util. --- scripts/functional_tests.py | 24 ++++-------------------- test/base/driver_util.py | 11 +++++++++++ test/tool_shed/functional_tests.py | 6 +----- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 6825882aaaa..858d3fb1594 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -149,24 +149,15 @@ def main(): if start_server: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) - galaxy_config = driver_util.setup_galaxy_config(tempdir, use_test_file_dir=use_test_file_dir) # Configure the database path. galaxy_db_path = driver_util.database_files_path(tempdir) + galaxy_config = driver_util.setup_galaxy_config( + galaxy_db_path, + use_test_file_dir=use_test_file_dir + ) - # Configure the paths Galaxy needs to test tools. - file_path = os.path.join( galaxy_db_path, 'files' ) - template_cache_path = os.path.join( galaxy_db_path, 'compiled_templates' ) - new_file_path = tempfile.mkdtemp( prefix='new_files_path_', dir=tempdir ) - job_working_directory = tempfile.mkdtemp( prefix='job_working_directory_', dir=tempdir ) database_connection, database_auto_migrate = driver_util.database_conf(galaxy_db_path) install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=True) - kwargs = {} - for dir in file_path, new_file_path, template_cache_path: - try: - if not os.path.exists( dir ): - os.makedirs( dir ) - except OSError: - pass # Data Manager testing temp path # For storing Data Manager outputs and .loc files so that real ones don't get clobbered @@ -179,14 +170,7 @@ def main(): if start_server: kwargs = dict( database_connection=database_connection, database_auto_migrate=database_auto_migrate, - file_path=file_path, - job_queue_workers=5, - job_working_directory=job_working_directory, - log_destination="stdout", - new_file_path=new_file_path, - template_cache_path=template_cache_path, shed_tool_data_table_config=shed_tool_data_table_config, - template_path="templates", test_conf="test.conf", tool_config_file=tool_config_file, tool_data_table_config_path=tool_data_table_config_path, diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 55910163a92..49537b7fbac 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -68,6 +68,13 @@ def build_logger(): def setup_galaxy_config(tmpdir, use_test_file_dir=False): """Setup environment and build config for test Galaxy instance.""" + if not os.path.exists(tmpdir): + os.makedirs(tmpdir) + file_path = os.path.join(tmpdir, 'files') + template_cache_path = tempfile.mkdtemp(prefix='compiled_templates_', dir=tmpdir) + new_file_path = tempfile.mkdtemp(prefix='new_files_path_', dir=tmpdir ) + job_working_directory = tempfile.mkdtemp(prefix='job_working_directory_', dir=tmpdir) + if use_test_file_dir: galaxy_test_file_dir = os.environ.get('GALAXY_TEST_FILE_DIR', GALAXY_TEST_FILE_DIR) os.environ['GALAXY_TEST_FILE_DIR'] = galaxy_test_file_dir @@ -94,11 +101,15 @@ def setup_galaxy_config(tmpdir, use_test_file_dir=False): allow_user_deletion=True, api_allow_run_as='test@bx.psu.edu', check_migrate_tools=False, + file_path=file_path, id_secret='changethisinproductiontoo', + job_working_directory=job_working_directory, job_queue_workers=5, library_import_dir=library_import_dir, log_destination="stdout", + new_file_path=new_file_path, running_functional_tests=True, + template_cache_path=template_cache_path, template_path='templates', tool_parse_help=False, tool_path=tool_path, diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 9c20730d763..f735c294846 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -80,10 +80,8 @@ def main(): os.environ[ 'GALAXY_TEST_TOOL_DATA_PATH' ] = tool_data_path galaxy_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir) shed_file_path = os.path.join( shed_db_path, 'files' ) - galaxy_file_path = os.path.join( galaxy_db_path, 'files' ) hgweb_config_file_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) new_repos_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - galaxy_tempfiles = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) galaxy_shed_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) galaxy_migrated_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) hgweb_config_dir = hgweb_config_file_path @@ -172,11 +170,9 @@ def main(): kwargs = dict( database_connection=galaxy_database_connection, database_auto_migrate=galaxy_database_auto_migrate, enable_tool_shed_check=True, - file_path=galaxy_file_path, global_conf=galaxy_global_conf, hours_between_check=0.001, migrated_tools_config=galaxy_migrated_tool_conf_file, - new_file_path=galaxy_tempfiles, shed_data_manager_config_file=galaxy_shed_data_manager_conf_file, shed_tool_data_table_config=shed_tool_data_table_conf_file, shed_tool_path=galaxy_shed_tool_path, @@ -184,7 +180,7 @@ def main(): tool_config_file=[ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], tool_sheds_config_file=galaxy_tool_sheds_conf_file, tool_data_table_config_path=galaxy_tool_data_table_conf_file ) - kwargs.update(driver_util.setup_galaxy_config(tool_shed_test_tmp_dir, use_test_file_dir=False)) + kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False)) kwargs.update(install_database_conf) # ---- Build Galaxy Application -------------------------------------------------- if not galaxy_database_connection.startswith( 'sqlite://' ): From e7b5293534d6cf9a704b9d295271abffda0f3c5d Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 12:46:43 -0400 Subject: [PATCH 36/69] Refactor toolbox hacks used by installed and migration tool tests out... into driver_util. This greatly simplifies the code structure of scripts/functional_tests.py's main method. Add description of GALAXY_TEST_SHED_TOOL_CONF and some documentation to all of this. --- run_tests.sh | 3 ++- scripts/functional_tests.py | 50 ++++++++++--------------------------- test/base/driver_util.py | 38 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 7c5173ed98b..2b8b7d8ee8b 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -69,7 +69,8 @@ GALAXY_TEST_NO_CLEANUP Do not cleanup main test directory after tests, GALAXY_TEST_HOST Host to use for Galaxy server setup for testing. GALAXY_TEST_PORT Port to use for Galaxy server setup for testing. GALAXY_TEST_TOOL_PATH Defaults to 'tools' - +GALAXY_TEST_SHED_TOOL_CONF Shed toolbox conf (defaults to config/shed_tool_conf.xml) + used when testing installed to tools with -installed. TOOL_SHED_TEST_HOST Host to use for shed server setup for testing. TOOL_SHED_TEST_PORT Port to use for shed server setup for testing. TOOL_SHED_TEST_FILE_DIR Defaults to test/tool_shed/test_data. diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 858d3fb1594..674785863b3 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -10,7 +10,6 @@ import os.path import sys import tempfile from ConfigParser import SafeConfigParser -from json import dumps galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] @@ -21,18 +20,12 @@ log = driver_util.build_logger() from base.api_util import get_master_api_key, get_user_api_key from base.test_logging import logging_config_file -from base.tool_shed_util import parse_tool_panel_config from functional import database_contexts -from galaxy import tools from galaxy.app import UniverseApplication from galaxy.util.properties import load_app_properties from galaxy.web import buildapp default_galaxy_test_host = "localhost" -migrated_tool_panel_config = 'config/migrated_tools_conf.xml' -installed_tool_panel_configs = [ - os.environ.get('GALAXY_TEST_SHED_TOOL_CONF', 'config/shed_tool_conf.xml') -] # Set up a job_conf.xml that explicitly limits jobs to 10 minutes. @@ -98,13 +91,14 @@ def main(): testing_installed_tools = _check_arg( '-installed' ) datatypes_conf_override = None - use_test_file_dir = not (testing_migrated_tools or testing_installed_tools) - if not use_test_file_dir: + testing_shed_tools = testing_migrated_tools or testing_installed_tools + if testing_shed_tools: # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. galaxy_tool_shed_test_file = 'shed_tools_dict' # We need the upload tool for functional tests, so we'll create a temporary tool panel config that defines it. tool_config_file = driver_util.FRAMEWORK_UPLOAD_TOOL_CONF else: + galaxy_tool_shed_test_file = None framework_test = _check_arg( '-framework' ) # Run through suite of tests testing framework. if framework_test: tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF @@ -153,7 +147,7 @@ def main(): galaxy_db_path = driver_util.database_files_path(tempdir) galaxy_config = driver_util.setup_galaxy_config( galaxy_db_path, - use_test_file_dir=use_test_file_dir + use_test_file_dir=not testing_shed_tools, ) database_connection, database_auto_migrate = driver_util.database_conf(galaxy_db_path) @@ -225,7 +219,6 @@ def main(): log.info( "Functional tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) success = False try: - tool_configs = app.config.tool_configs # What requires these? Handy for (eg) functional tests to save outputs? # Pass in through script setenv, will leave a copy of ALL test validate files os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host @@ -263,36 +256,19 @@ def main(): ) return driver_util.nose_config_and_run() - if not use_test_file_dir: - shed_tools_dict = {} - if testing_migrated_tools: - has_test_data, shed_tools_dict = parse_tool_panel_config( migrated_tool_panel_config, shed_tools_dict ) - elif testing_installed_tools: - for shed_tool_config in installed_tool_panel_configs: - has_test_data, shed_tools_dict = parse_tool_panel_config( shed_tool_config, shed_tools_dict ) - # Persist the shed_tools_dict to the galaxy_tool_shed_test_file. - shed_tools_file = open( galaxy_tool_shed_test_file, 'w' ) - shed_tools_file.write( dumps( shed_tools_dict ) ) - shed_tools_file.close() - if not os.path.isabs( galaxy_tool_shed_test_file ): - galaxy_tool_shed_test_file = os.path.join( os.getcwd(), galaxy_tool_shed_test_file ) - os.environ[ 'GALAXY_TOOL_SHED_TEST_FILE' ] = galaxy_tool_shed_test_file - if testing_installed_tools: - # Eliminate the migrated_tool_panel_config from the app's tool_configs, append the list of installed_tool_panel_configs, - # and reload the app's toolbox. - relative_migrated_tool_panel_config = os.path.join( app.config.root, migrated_tool_panel_config ) - if relative_migrated_tool_panel_config in tool_configs: - tool_configs.remove( relative_migrated_tool_panel_config ) - for installed_tool_panel_config in installed_tool_panel_configs: - tool_configs.append( installed_tool_panel_config ) - app.toolbox = tools.ToolBox( tool_configs, app.config.tool_path, app ) - success = _run_functional_test( testing_shed_tools=True ) + if testing_shed_tools: + driver_util.setup_shed_tools_for_test( + app, + galaxy_tool_shed_test_file, + testing_migrated_tools, + testing_installed_tools, + ) + success = _run_functional_test( testing_shed_tools=True ) + if galaxy_tool_shed_test_file is not None: try: os.unlink( galaxy_tool_shed_test_file ) except: log.info( "Unable to remove file: %s" % galaxy_tool_shed_test_file ) - else: - success = _run_functional_test( ) except: log.exception( "Failure running tests" ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 49537b7fbac..8f215554ee2 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -1,6 +1,7 @@ """Scripts for drivers of Galaxy functional tests.""" import httplib +import json import logging import os import random @@ -20,6 +21,7 @@ import nose.plugins.manager from paste import httpserver +from .tool_shed_util import parse_tool_panel_config from .nose_util import run from .instrument import StructuredTestDataPlugin @@ -33,6 +35,10 @@ FRAMEWORK_TOOLS_DIR = os.path.join(GALAXY_TEST_DIRECTORY, "functional", "tools") FRAMEWORK_UPLOAD_TOOL_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "upload_tool_conf.xml") FRAMEWORK_SAMPLE_TOOLS_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "samples_tool_conf.xml") FRAMEWORK_DATATYPES_CONF = os.path.join(FRAMEWORK_TOOLS_DIR, "sample_datatypes_conf.xml") +MIGRATED_TOOL_PANEL_CONFIG = 'config/migrated_tools_conf.xml' +INSTALLED_TOOL_PANEL_CONFIGS = [ + os.environ.get('GALAXY_TEST_SHED_TOOL_CONF', 'config/shed_tool_conf.xml') +] DEFAULT_LOCALES = "en" @@ -314,6 +320,37 @@ def cleanup_directory(tempdir): pass +def setup_shed_tools_for_test(app, galaxy_tool_shed_test_file, testing_migrated_tools, testing_installed_tools): + """Modify Galaxy app's toolbox for migrated or installed tool tests.""" + shed_tools_dict = {} + if testing_migrated_tools: + has_test_data, shed_tools_dict = parse_tool_panel_config(MIGRATED_TOOL_PANEL_CONFIG, shed_tools_dict) + elif testing_installed_tools: + for shed_tool_config in INSTALLED_TOOL_PANEL_CONFIGS: + has_test_data, shed_tools_dict = parse_tool_panel_config(shed_tool_config, shed_tools_dict) + # Persist the shed_tools_dict to the galaxy_tool_shed_test_file. + with open(galaxy_tool_shed_test_file, 'w') as shed_tools_file: + shed_tools_file.write(json.dumps(shed_tools_dict)) + if not os.path.isabs(galaxy_tool_shed_test_file): + galaxy_tool_shed_test_file = os.path.join(galaxy_root, galaxy_tool_shed_test_file) + os.environ['GALAXY_TOOL_SHED_TEST_FILE'] = galaxy_tool_shed_test_file + if testing_installed_tools: + # TODO: Do this without modifying app - that is a pretty violation + # of Galaxy's abstraction - we shouldn't require app at all let alone + # be modifying it. + + tool_configs = app.config.tool_configs + # Eliminate the migrated_tool_panel_config from the app's tool_configs, append the list of installed_tool_panel_configs, + # and reload the app's toolbox. + relative_migrated_tool_panel_config = os.path.join(app.config.root, MIGRATED_TOOL_PANEL_CONFIG) + if relative_migrated_tool_panel_config in tool_configs: + tool_configs.remove(relative_migrated_tool_panel_config) + for installed_tool_panel_config in INSTALLED_TOOL_PANEL_CONFIGS: + tool_configs.append(installed_tool_panel_config) + from galaxy import tools # noqa, delay import because this brings in so many modules for small tests + app.toolbox = tools.ToolBox(tool_configs, app.config.tool_path, app) + + __all__ = [ "cleanup_directory", "configure_environment", @@ -326,5 +363,6 @@ __all__ = [ "get_webapp_global_conf", "nose_config_and_run", "setup_galaxy_config", + "setup_shed_tools_for_test", "wait_for_http_server", ] From 651b91248b350de951c95e5c2bd8edd6e517b9d2 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 12:57:11 -0400 Subject: [PATCH 37/69] Restructure scripts/functional_test.py's main() to reflect recent simplifications. --- scripts/functional_tests.py | 68 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 674785863b3..a4bb7688dfb 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -223,39 +223,6 @@ def main(): # Pass in through script setenv, will leave a copy of ALL test validate files os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host - def _run_functional_test( testing_shed_tools=None ): - workflow_test = _check_arg( '-workflow', param=True ) - if workflow_test: - import functional.workflow - functional.workflow.WorkflowTestCase.workflow_test_file = workflow_test - functional.workflow.WorkflowTestCase.master_api_key = master_api_key - functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key() - data_manager_test = _check_arg( '-data_managers', param=False ) - if data_manager_test: - import functional.test_data_managers - functional.test_data_managers.data_managers = app.data_managers # seems like a hack... - functional.test_data_managers.build_tests( - tmp_dir=data_manager_test_tmp_path, - testing_shed_tools=testing_shed_tools, - master_api_key=master_api_key, - user_api_key=get_user_api_key(), - ) - else: - # We must make sure that functional.test_toolbox is always imported after - # database_contexts.galaxy_content is set (which occurs in this method above). - # If functional.test_toolbox is imported before database_contexts.galaxy_content - # is set, sa_session will be None in all methods that use it. - import functional.test_toolbox - functional.test_toolbox.toolbox = app.toolbox - # When testing data managers, do not test toolbox. - functional.test_toolbox.build_tests( - app=app, - testing_shed_tools=testing_shed_tools, - master_api_key=master_api_key, - user_api_key=get_user_api_key(), - ) - return driver_util.nose_config_and_run() - if testing_shed_tools: driver_util.setup_shed_tools_for_test( app, @@ -263,7 +230,40 @@ def main(): testing_migrated_tools, testing_installed_tools, ) - success = _run_functional_test( testing_shed_tools=True ) + workflow_test = _check_arg( '-workflow', param=True ) + if workflow_test: + import functional.workflow + functional.workflow.WorkflowTestCase.workflow_test_file = workflow_test + functional.workflow.WorkflowTestCase.master_api_key = master_api_key + functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key() + data_manager_test = _check_arg( '-data_managers', param=False ) + if data_manager_test: + import functional.test_data_managers + functional.test_data_managers.data_managers = app.data_managers # seems like a hack... + functional.test_data_managers.build_tests( + tmp_dir=data_manager_test_tmp_path, + testing_shed_tools=testing_shed_tools, + master_api_key=master_api_key, + user_api_key=get_user_api_key(), + ) + + # We must make sure that functional.test_toolbox is always imported after + # database_contexts.galaxy_content is set (which occurs in this method above). + # If functional.test_toolbox is imported before database_contexts.galaxy_content + # is set, sa_session will be None in all methods that use it. + import functional.test_toolbox + functional.test_toolbox.toolbox = app.toolbox + # When testing data managers, do not test toolbox. + functional.test_toolbox.build_tests( + app=app, + testing_shed_tools=testing_shed_tools, + master_api_key=master_api_key, + user_api_key=get_user_api_key(), + ) + + success = driver_util.nose_config_and_run() + + # TODO: just put this in tempdir being managed for this test. if galaxy_tool_shed_test_file is not None: try: os.unlink( galaxy_tool_shed_test_file ) From be0107b6204b5b47b9c6e8ea3196a893d4409c05 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 13:06:55 -0400 Subject: [PATCH 38/69] Simplify test tool_data_table_config logic. Added with https://github.com/galaxyproject/galaxy/commit/246ea04cc7ee1d0d470a514302bf2623f845ed8f. --- scripts/functional_tests.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index a4bb7688dfb..93d73d2b815 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -112,17 +112,13 @@ def main(): start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ tool_data_table_config_path = None - if os.path.exists( 'tool_data_table_conf.test.xml' ): - # If explicitly defined tables for test, use those. - tool_data_table_config_path = 'tool_data_table_conf.test.xml' - else: - # ... otherise find whatever Galaxy would use as the default and - # the sample data for fucntional tests to that. - default_tool_data_config = 'config/tool_data_table_conf.xml.sample' - for tool_data_config in ['config/tool_data_table_conf.xml', 'tool_data_table_conf.xml' ]: - if os.path.exists( tool_data_config ): - default_tool_data_config = tool_data_config - tool_data_table_config_path = '%s,test/functional/tool-data/sample_tool_data_tables.xml' % default_tool_data_config + # ... otherise find whatever Galaxy would use as the default and + # the sample data for fucntional tests to that. + default_tool_data_config = 'config/tool_data_table_conf.xml.sample' + for tool_data_config in ['config/tool_data_table_conf.xml', 'tool_data_table_conf.xml' ]: + if os.path.exists( tool_data_config ): + default_tool_data_config = tool_data_config + tool_data_table_config_path = '%s,test/functional/tool-data/sample_tool_data_tables.xml' % default_tool_data_config default_data_manager_config = 'config/data_manager_conf.xml.sample' for data_manager_config in ['config/data_manager_conf.xml', 'data_manager_conf.xml' ]: From 528b74ca1e470499d53719ccbeb8acd78002ee33 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 13:13:19 -0400 Subject: [PATCH 39/69] Remove unused test job conf stuff. Not that this wouldn't be useful - it would be but it wasn't wired up to do anything currently. --- scripts/functional_tests.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 93d73d2b815..659a882eb54 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -28,26 +28,6 @@ from galaxy.web import buildapp default_galaxy_test_host = "localhost" -# Set up a job_conf.xml that explicitly limits jobs to 10 minutes. -job_conf_xml = ''' - - - - - - - - - - - - - 00:10:00 - - -''' - - def generate_config_file( input_filename, output_filename, config_items ): """Generate a config file with the configuration that has been defined for the embedded web application. @@ -130,11 +110,6 @@ def main(): if galaxy_test_tmp_dir is None: galaxy_test_tmp_dir = tempfile.mkdtemp() - galaxy_job_conf_file = os.environ.get( 'GALAXY_TEST_JOB_CONF', - os.path.join( galaxy_test_tmp_dir, 'test_job_conf.xml' ) ) - # Generate the job_conf.xml file. - file( galaxy_job_conf_file, 'w' ).write( job_conf_xml ) - database_auto_migrate = False if start_server: From fe460008faf33a673185672ee2f34b26b8878ea5 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 13:28:44 -0400 Subject: [PATCH 40/69] More work on syncrhonized test database configuration... for test drivers. --- scripts/functional_tests.py | 12 +++--------- test/base/driver_util.py | 9 ++++++++- test/tool_shed/functional_tests.py | 27 +++++++++------------------ 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 659a882eb54..6950f1b661e 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -110,8 +110,6 @@ def main(): if galaxy_test_tmp_dir is None: galaxy_test_tmp_dir = tempfile.mkdtemp() - database_auto_migrate = False - if start_server: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) # Configure the database path. @@ -121,7 +119,7 @@ def main(): use_test_file_dir=not testing_shed_tools, ) - database_connection, database_auto_migrate = driver_util.database_conf(galaxy_db_path) + database_conf = driver_util.database_conf(galaxy_db_path) install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=True) # Data Manager testing temp path @@ -133,9 +131,7 @@ def main(): master_api_key = get_master_api_key() app = None if start_server: - kwargs = dict( database_connection=database_connection, - database_auto_migrate=database_auto_migrate, - shed_tool_data_table_config=shed_tool_data_table_config, + kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, test_conf="test.conf", tool_config_file=tool_config_file, tool_data_table_config_path=tool_data_table_config_path, @@ -147,10 +143,8 @@ def main(): auto_configure_logging=logging_config_file is None, data_manager_config_file=data_manager_config_file ) kwargs.update(galaxy_config) + kwargs.update(database_conf) kwargs.update(install_database_conf) - if not database_connection.startswith( 'sqlite://' ): - kwargs[ 'database_engine_option_max_overflow' ] = '20' - kwargs[ 'database_engine_option_pool_size' ] = '10' if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override # If the user has passed in a path for the .ini file, do not overwrite it. diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 8f215554ee2..ddcec16fa31 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -196,7 +196,14 @@ def database_conf(db_path, prefix="GALAXY"): copy_database_template(os.environ[template_var], db_path) database_auto_migrate = True database_connection = 'sqlite:///%s' % db_path - return database_connection, database_auto_migrate + config = { + "database_connection": database_connection, + "database_auto_migrate": database_auto_migrate + } + if not database_connection.startswith("sqlite://"): + config["database_engine_option_max_overflow"] = "20" + config["database_engine_option_pool_size"] = "10" + return config def install_database_conf(db_path, default_merged=False): diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index f735c294846..881fdb58658 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -87,16 +87,14 @@ def main(): hgweb_config_dir = hgweb_config_file_path os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir print "Directory location for hgweb.config:", hgweb_config_dir - toolshed_database_connection, toolshed_database_auto_migrate = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED") - galaxy_database_connection, galaxy_database_auto_migrate = driver_util.database_conf(galaxy_db_path) + toolshed_database_conf = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED") + galaxy_database_conf = driver_util.database_conf(galaxy_db_path) install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=False) tool_shed_global_conf = driver_util.get_webapp_global_conf() tool_shed_global_conf[ '__file__' ] = 'tool_shed_wsgi.ini.sample' kwargs = dict( admin_users='test@bx.psu.edu', allow_user_creation=True, allow_user_deletion=True, - database_connection=toolshed_database_connection, - database_auto_migrate=toolshed_database_auto_migrate, datatype_converters_config_file='datatype_converters_conf.xml.sample', file_path=shed_file_path, global_conf=tool_shed_global_conf, @@ -113,9 +111,9 @@ def main(): tool_parse_help=False, tool_data_table_config_path=galaxy_tool_data_table_conf_file, use_heartbeat=False ) - - print "Tool shed database connection:", toolshed_database_connection - print "Galaxy database connection:", galaxy_database_connection + kwargs.update(toolshed_database_conf) + print "Tool shed database connection:", toolshed_database_conf["database_connection"] + print "Galaxy database connection:", galaxy_database_conf["database_connection"] # Generate the tool_data_table_conf.xml file. file( galaxy_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) @@ -126,15 +124,13 @@ def main(): toolshedapp = None kwargs[ 'global_conf' ] = tool_shed_global_conf - if not toolshed_database_connection.startswith( 'sqlite://' ): - kwargs[ 'database_engine_option_pool_size' ] = '10' - toolshedapp = ToolshedUniverseApplication( **kwargs ) database_contexts.tool_shed_context = toolshedapp.model.context log.info( "Embedded Toolshed application started" ) # ---- Run tool shed webserver ------------------------------------------------------ - tool_shed_global_conf[ 'database_connection' ] = toolshed_database_connection + # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') + tool_shed_global_conf[ 'database_connection' ] = kwargs["database_connection"] toolshedwebapp = toolshedbuildapp.app_factory( tool_shed_global_conf, use_translogger=False, static_enabled=True, @@ -167,9 +163,7 @@ def main(): galaxy_global_conf = driver_util.get_webapp_global_conf() galaxy_global_conf[ '__file__' ] = 'config/galaxy.ini.sample' - kwargs = dict( database_connection=galaxy_database_connection, - database_auto_migrate=galaxy_database_auto_migrate, - enable_tool_shed_check=True, + kwargs = dict( enable_tool_shed_check=True, global_conf=galaxy_global_conf, hours_between_check=0.001, migrated_tools_config=galaxy_migrated_tool_conf_file, @@ -181,18 +175,15 @@ def main(): tool_sheds_config_file=galaxy_tool_sheds_conf_file, tool_data_table_config_path=galaxy_tool_data_table_conf_file ) kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False)) + kwargs.update(galaxy_database_conf) kwargs.update(install_database_conf) # ---- Build Galaxy Application -------------------------------------------------- - if not galaxy_database_connection.startswith( 'sqlite://' ): - kwargs[ 'database_engine_option_pool_size' ] = '10' - kwargs[ 'database_engine_option_max_overflow' ] = '20' galaxyapp = GalaxyUniverseApplication( **kwargs ) log.info( "Embedded Galaxy application started" ) # ---- Run galaxy webserver ------------------------------------------------------ galaxy_server = None - galaxy_global_conf[ 'database_file' ] = galaxy_database_connection galaxywebapp = galaxybuildapp.app_factory( galaxy_global_conf, use_translogger=False, static_enabled=True, From 2729699bf69c7b4ca6750fbc628f4eb147c12717 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 13:39:17 -0400 Subject: [PATCH 41/69] Further unification of how to setup Galaxy databases for testing. Reuse setup_galaxy_config for this task. --- scripts/functional_tests.py | 6 +----- test/base/driver_util.py | 5 ++++- test/tool_shed/functional_tests.py | 8 ++------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 6950f1b661e..c04fc9d4201 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -117,11 +117,9 @@ def main(): galaxy_config = driver_util.setup_galaxy_config( galaxy_db_path, use_test_file_dir=not testing_shed_tools, + default_install_db_merged=True, ) - database_conf = driver_util.database_conf(galaxy_db_path) - install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=True) - # Data Manager testing temp path # For storing Data Manager outputs and .loc files so that real ones don't get clobbered data_manager_test_tmp_path = tempfile.mkdtemp( prefix='data_manager_test_tmp', dir=galaxy_test_tmp_dir ) @@ -143,8 +141,6 @@ def main(): auto_configure_logging=logging_config_file is None, data_manager_config_file=data_manager_config_file ) kwargs.update(galaxy_config) - kwargs.update(database_conf) - kwargs.update(install_database_conf) if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override # If the user has passed in a path for the .ini file, do not overwrite it. diff --git a/test/base/driver_util.py b/test/base/driver_util.py index ddcec16fa31..142a91a5689 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -72,7 +72,7 @@ def build_logger(): return log -def setup_galaxy_config(tmpdir, use_test_file_dir=False): +def setup_galaxy_config(tmpdir, use_test_file_dir=False, default_install_db_merged=True): """Setup environment and build config for test Galaxy instance.""" if not os.path.exists(tmpdir): os.makedirs(tmpdir) @@ -124,6 +124,9 @@ def setup_galaxy_config(tmpdir, use_test_file_dir=False): use_heartbeat=False, user_library_import_dir=user_library_import_dir, ) + config.update(database_conf(tmpdir)) + config.update(install_database_conf(tmpdir, default_merged=default_install_db_merged)) + if tool_dependency_dir: config["tool_dependency_dir"] = tool_dependency_dir # Used by shed's twill dependency stuff - todo read from diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 881fdb58658..d57d13a513d 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -88,8 +88,6 @@ def main(): os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir print "Directory location for hgweb.config:", hgweb_config_dir toolshed_database_conf = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED") - galaxy_database_conf = driver_util.database_conf(galaxy_db_path) - install_database_conf = driver_util.install_database_conf(galaxy_db_path, default_merged=False) tool_shed_global_conf = driver_util.get_webapp_global_conf() tool_shed_global_conf[ '__file__' ] = 'tool_shed_wsgi.ini.sample' kwargs = dict( admin_users='test@bx.psu.edu', @@ -113,7 +111,6 @@ def main(): use_heartbeat=False ) kwargs.update(toolshed_database_conf) print "Tool shed database connection:", toolshed_database_conf["database_connection"] - print "Galaxy database connection:", galaxy_database_conf["database_connection"] # Generate the tool_data_table_conf.xml file. file( galaxy_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) @@ -174,9 +171,8 @@ def main(): tool_config_file=[ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], tool_sheds_config_file=galaxy_tool_sheds_conf_file, tool_data_table_config_path=galaxy_tool_data_table_conf_file ) - kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False)) - kwargs.update(galaxy_database_conf) - kwargs.update(install_database_conf) + kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False, default_install_db_merged=False)) + print "Galaxy database connection:", kwargs["database_connection"] # ---- Build Galaxy Application -------------------------------------------------- galaxyapp = GalaxyUniverseApplication( **kwargs ) From ec0a12384994774522380165302934531ca12901 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 13:54:08 -0400 Subject: [PATCH 42/69] Unify and simplify how Galaxy is launched across test drivers. --- scripts/functional_tests.py | 49 ++---------------------------- test/tool_shed/functional_tests.py | 15 +++++---- 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index c04fc9d4201..25808a65901 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -9,7 +9,6 @@ import os import os.path import sys import tempfile -from ConfigParser import SafeConfigParser galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] @@ -28,40 +27,6 @@ from galaxy.web import buildapp default_galaxy_test_host = "localhost" -def generate_config_file( input_filename, output_filename, config_items ): - """Generate a config file with the configuration that has been defined for the embedded web application. - - This is mostly relevant when setting metadata externally, since the script for doing that does not - have access to app.config. - """ - cp = SafeConfigParser() - cp.read( input_filename ) - config_items_by_section = [] - for label, value in config_items: - found = False - # Attempt to determine the correct section for this configuration option. - for section in cp.sections(): - if cp.has_option( section, label ): - config_tuple = section, label, value - config_items_by_section.append( config_tuple ) - found = True - continue - # Default to app:main if no section was found. - if not found: - config_tuple = 'app:main', label, value - config_items_by_section.append( config_tuple ) - print( config_items_by_section ) - - # Replace the default values with the provided configuration. - for section, label, value in config_items_by_section: - if cp.has_option( section, label ): - cp.remove_option( section, label ) - cp.set( section, label, str( value ) ) - fh = open( output_filename, 'w' ) - cp.write( fh ) - fh.close() - - def main(): """Entry point for test driver script.""" # ---- Configuration ------------------------------------------------------ @@ -143,20 +108,10 @@ def main(): kwargs.update(galaxy_config) if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override - # If the user has passed in a path for the .ini file, do not overwrite it. - galaxy_config_file = os.environ.get( 'GALAXY_TEST_INI_FILE', None ) - if not galaxy_config_file: - galaxy_config_file = os.path.join( galaxy_test_tmp_dir, 'functional_tests_wsgi.ini' ) - config_items = [] - for label in kwargs: - config_tuple = label, kwargs[ label ] - config_items.append( config_tuple ) - # Write a temporary file, based on config/galaxy.ini.sample, using the configuration options defined above. - generate_config_file( 'config/galaxy.ini.sample', galaxy_config_file, config_items ) + # Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh. kwargs[ 'global_conf' ] = driver_util.get_webapp_global_conf() - kwargs[ 'global_conf' ][ '__file__' ] = galaxy_config_file - kwargs[ 'config_file' ] = galaxy_config_file + kwargs[ 'global_conf' ][ '__file__' ] = "config/galaxy.ini.sample" kwargs = load_app_properties( kwds=kwargs ) diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index d57d13a513d..db25e0b8379 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -25,6 +25,7 @@ from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverse # This is for the galaxy application. from galaxy.app import UniverseApplication as GalaxyUniverseApplication from galaxy.web import buildapp as galaxybuildapp +from galaxy.util.properties import load_app_properties from functional import database_contexts @@ -157,11 +158,7 @@ def main(): # Generate shed_data_manager_conf.xml if not os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF' ): open( galaxy_shed_data_manager_conf_file, 'wb' ).write( shed_data_manager_conf_xml_template ) - galaxy_global_conf = driver_util.get_webapp_global_conf() - galaxy_global_conf[ '__file__' ] = 'config/galaxy.ini.sample' - kwargs = dict( enable_tool_shed_check=True, - global_conf=galaxy_global_conf, hours_between_check=0.001, migrated_tools_config=galaxy_migrated_tool_conf_file, shed_data_manager_config_file=galaxy_shed_data_manager_conf_file, @@ -173,14 +170,20 @@ def main(): tool_data_table_config_path=galaxy_tool_data_table_conf_file ) kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False, default_install_db_merged=False)) print "Galaxy database connection:", kwargs["database_connection"] - # ---- Build Galaxy Application -------------------------------------------------- + # Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh. + kwargs[ 'global_conf' ] = driver_util.get_webapp_global_conf() + kwargs[ 'global_conf' ][ '__file__' ] = "config/galaxy.ini.sample" + kwargs = load_app_properties( + kwds=kwargs + ) + # Build the Universe Application galaxyapp = GalaxyUniverseApplication( **kwargs ) log.info( "Embedded Galaxy application started" ) # ---- Run galaxy webserver ------------------------------------------------------ galaxy_server = None - galaxywebapp = galaxybuildapp.app_factory( galaxy_global_conf, + galaxywebapp = galaxybuildapp.app_factory( kwargs['global_conf'], use_translogger=False, static_enabled=True, app=galaxyapp ) From ecbb7326658ee4f400be865cfc7d3a4baf199b39 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 13:50:48 -0400 Subject: [PATCH 43/69] Move construction of test driver app objects into driver_util. This de-duplicates some of the Galaxy stuff and makes the tool shed stuff look very uniform. --- scripts/functional_tests.py | 14 +--------- test/base/driver_util.py | 42 ++++++++++++++++++++++++++++++ test/tool_shed/functional_tests.py | 36 ++++--------------------- 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 25808a65901..71248009b92 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -19,9 +19,6 @@ log = driver_util.build_logger() from base.api_util import get_master_api_key, get_user_api_key from base.test_logging import logging_config_file -from functional import database_contexts -from galaxy.app import UniverseApplication -from galaxy.util.properties import load_app_properties from galaxy.web import buildapp default_galaxy_test_host = "localhost" @@ -109,16 +106,7 @@ def main(): if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override - # Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh. - kwargs[ 'global_conf' ] = driver_util.get_webapp_global_conf() - kwargs[ 'global_conf' ][ '__file__' ] = "config/galaxy.ini.sample" - kwargs = load_app_properties( - kwds=kwargs - ) - # Build the Universe Application - app = UniverseApplication( **kwargs ) - database_contexts.galaxy_context = app.model.context - log.info( "Embedded Universe application started" ) + app = driver_util.build_galaxy_app(kwargs) # ---- Run webserver ------------------------------------------------------ server = None diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 142a91a5689..78e1853d8bb 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -25,7 +25,12 @@ from .tool_shed_util import parse_tool_panel_config from .nose_util import run from .instrument import StructuredTestDataPlugin +from functional import database_contexts + +from galaxy.app import UniverseApplication as GalaxyUniverseApplication +from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication from galaxy.util import asbool +from galaxy.util.properties import load_app_properties galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test") @@ -361,6 +366,43 @@ def setup_shed_tools_for_test(app, galaxy_tool_shed_test_file, testing_migrated_ app.toolbox = tools.ToolBox(tool_configs, app.config.tool_path, app) +def build_galaxy_app(simple_kwargs): + """Build a Galaxy app object from a simple keyword arguments. + + Construct paste style complex dictionary and use load_app_properties so + Galaxy override variables are respected. Also setup "global" references + to sqlalchemy database context for Galaxy and install databases. + """ + log.info("Galaxy database connection:", simple_kwargs["database_connection"]) + simple_kwargs['global_conf'] = get_webapp_global_conf() + simple_kwargs['global_conf']['__file__'] = "config/galaxy.ini.sample" + simple_kwargs = load_app_properties( + kwds=simple_kwargs + ) + # Build the Universe Application + app = GalaxyUniverseApplication( **simple_kwargs ) + log.info( "Embedded Galaxy application started" ) + database_contexts.galaxy_context = app.model.context + database_contexts.install_context = app.install_model.context + 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:", simple_kwargs["database_connection"]) + # TODO: Simplify global_conf to match Galaxy above... + simple_kwargs['__file__'] = 'tool_shed_wsgi.ini.sample' + simple_kwargs['global_conf'] = get_webapp_global_conf() + + app = ToolshedUniverseApplication( **simple_kwargs ) + database_contexts.tool_shed_context = app.model.context + log.info( "Embedded Toolshed application started" ) + return app + __all__ = [ "cleanup_directory", "configure_environment", diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index db25e0b8379..7a230a141de 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -21,13 +21,7 @@ tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir() # This is for the tool shed application. from galaxy.webapps.tool_shed import buildapp as toolshedbuildapp -from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication -# This is for the galaxy application. -from galaxy.app import UniverseApplication as GalaxyUniverseApplication from galaxy.web import buildapp as galaxybuildapp -from galaxy.util.properties import load_app_properties - -from functional import database_contexts default_tool_shed_test_host = "localhost" default_galaxy_test_host = 'localhost' @@ -89,14 +83,11 @@ def main(): os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir print "Directory location for hgweb.config:", hgweb_config_dir toolshed_database_conf = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED") - tool_shed_global_conf = driver_util.get_webapp_global_conf() - tool_shed_global_conf[ '__file__' ] = 'tool_shed_wsgi.ini.sample' kwargs = dict( admin_users='test@bx.psu.edu', allow_user_creation=True, allow_user_deletion=True, datatype_converters_config_file='datatype_converters_conf.xml.sample', file_path=shed_file_path, - global_conf=tool_shed_global_conf, hgweb_config_dir=hgweb_config_dir, job_queue_workers=5, id_secret='changethisinproductiontoo', @@ -111,25 +102,19 @@ def main(): tool_data_table_config_path=galaxy_tool_data_table_conf_file, use_heartbeat=False ) kwargs.update(toolshed_database_conf) - print "Tool shed database connection:", toolshed_database_conf["database_connection"] - # Generate the tool_data_table_conf.xml file. file( galaxy_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) # Generate the shed_tool_data_table_conf.xml file. file( shed_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) os.environ[ 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF' ] = shed_tool_data_table_conf_file # ---- Build Tool Shed Application -------------------------------------------------- - toolshedapp = None - kwargs[ 'global_conf' ] = tool_shed_global_conf - - toolshedapp = ToolshedUniverseApplication( **kwargs ) - database_contexts.tool_shed_context = toolshedapp.model.context - log.info( "Embedded Toolshed application started" ) + toolshedapp = driver_util.build_shed_app(kwargs) # ---- Run tool shed webserver ------------------------------------------------------ # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') - tool_shed_global_conf[ 'database_connection' ] = kwargs["database_connection"] - toolshedwebapp = toolshedbuildapp.app_factory( tool_shed_global_conf, + kwargs['global_conf']['database_connection'] = kwargs["database_connection"] + + toolshedwebapp = toolshedbuildapp.app_factory( kwargs['global_conf'], use_translogger=False, static_enabled=True, app=toolshedapp ) @@ -170,25 +155,14 @@ def main(): tool_data_table_config_path=galaxy_tool_data_table_conf_file ) kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False, default_install_db_merged=False)) print "Galaxy database connection:", kwargs["database_connection"] - # Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh. - kwargs[ 'global_conf' ] = driver_util.get_webapp_global_conf() - kwargs[ 'global_conf' ][ '__file__' ] = "config/galaxy.ini.sample" - kwargs = load_app_properties( - kwds=kwargs - ) - # Build the Universe Application - galaxyapp = GalaxyUniverseApplication( **kwargs ) - - log.info( "Embedded Galaxy application started" ) # ---- Run galaxy webserver ------------------------------------------------------ galaxy_server = None + galaxyapp = driver_util.build_galaxy_app(kwargs) galaxywebapp = galaxybuildapp.app_factory( kwargs['global_conf'], use_translogger=False, static_enabled=True, app=galaxyapp ) - database_contexts.galaxy_context = galaxyapp.model.context - database_contexts.install_context = galaxyapp.install_model.context galaxy_server, galaxy_test_port = driver_util.serve_webapp( galaxywebapp, host=galaxy_test_host, port=galaxy_test_port ) From ee537a119b381b78ce1d58769970c0302fe5b684 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 13:56:38 -0400 Subject: [PATCH 44/69] Restructure to simplify the main() in scripts/functional_tests.py. Previously this was entering a conditional on the same condition twice. This simplifies this to just do that once and makes the galaxy and tool shed driver code look more similar with respect to launching a Galaxy webapp. --- scripts/functional_tests.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 71248009b92..b17324913e8 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -86,11 +86,13 @@ def main(): # For storing Data Manager outputs and .loc files so that real ones don't get clobbered data_manager_test_tmp_path = tempfile.mkdtemp( prefix='data_manager_test_tmp', dir=galaxy_test_tmp_dir ) galaxy_data_manager_data_path = tempfile.mkdtemp( prefix='data_manager_tool-data', dir=data_manager_test_tmp_path ) - - # ---- Build Application -------------------------------------------------- master_api_key = get_master_api_key() + app = None + server = None + if start_server: + # ---- Build Application -------------------------------------------------- kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, test_conf="test.conf", tool_config_file=tool_config_file, @@ -107,11 +109,6 @@ def main(): kwargs[ 'datatypes_config_file' ] = datatypes_conf_override app = driver_util.build_galaxy_app(kwargs) - - # ---- Run webserver ------------------------------------------------------ - server = None - - if start_server: webapp = buildapp.app_factory( kwargs[ 'global_conf' ], app=app, use_translogger=False, static_enabled=True ) server, galaxy_test_port = driver_util.serve_webapp( webapp, host=galaxy_test_host, port=galaxy_test_port ) From 0f362294000b005073c8167ac553c88403316951 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 14:16:40 -0400 Subject: [PATCH 45/69] Unify and simplify configuration and launch of test web servers. - Sync up the logic for reading and setting GALAXY_TEST_HOST, GALAXY_TEST_PORT, TOOL_SHED_TEST_HOST, and TOOL_SHED_TEST_PORT. - Setup one high level method for taking a Galaxy-style "app" and creating a webapp from a factory method and then launching a paste server for that entity respecting the above variables. --- scripts/functional_tests.py | 19 ++++---------- test/base/driver_util.py | 31 ++++++++++++++++++++++ test/tool_shed/functional_tests.py | 41 ++++++++---------------------- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index b17324913e8..e34a2ba5866 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -21,14 +21,10 @@ from base.api_util import get_master_api_key, get_user_api_key from base.test_logging import logging_config_file from galaxy.web import buildapp -default_galaxy_test_host = "localhost" - def main(): """Entry point for test driver script.""" # ---- Configuration ------------------------------------------------------ - galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) - galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) testing_migrated_tools = _check_arg( '-migrated' ) testing_installed_tools = _check_arg( '-installed' ) datatypes_conf_override = None @@ -109,21 +105,16 @@ def main(): kwargs[ 'datatypes_config_file' ] = datatypes_conf_override app = driver_util.build_galaxy_app(kwargs) - webapp = buildapp.app_factory( kwargs[ 'global_conf' ], app=app, - use_translogger=False, static_enabled=True ) - server, galaxy_test_port = driver_util.serve_webapp( webapp, host=galaxy_test_host, port=galaxy_test_port ) - os.environ['GALAXY_TEST_PORT'] = galaxy_test_port - driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) - log.info( "Embedded web server started" ) + server, galaxy_test_host, galaxy_test_port = driver_util.launch_server( + app, + buildapp.app_factory, + kwargs, + ) # ---- Find tests --------------------------------------------------------- log.info( "Functional tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) success = False try: - # What requires these? Handy for (eg) functional tests to save outputs? - # Pass in through script setenv, will leave a copy of ALL test validate files - os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host - if testing_shed_tools: driver_util.setup_shed_tools_for_test( app, diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 78e1853d8bb..97aebd59863 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -33,6 +33,7 @@ from galaxy.util import asbool from galaxy.util.properties import load_app_properties galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) +DEFAULT_WEB_HOST = "localhost" GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test") GALAXY_TEST_FILE_DIR = "test-data,https://github.com/galaxyproject/galaxy-test-data.git" TOOL_SHED_TEST_DATA = os.path.join(GALAXY_TEST_DIRECTORY, "tool_shed", "test_data") @@ -403,6 +404,36 @@ def build_shed_app(simple_kwargs): log.info( "Embedded Toolshed application started" ) return app + +def launch_server(app, webapp_factory, kwargs, prefix="GALAXY"): + """Launch a web server for a given app using supplied factory. + + Consistently read either GALAXY_TEST_HOST and GALAXY_TEST_PORT or + TOOL_SHED_TEST_HOST and TOOL_SHED_TEST_PORT and ensure these are + all set after this method has been called. + """ + host_env_key = "%s_TEST_HOST" % prefix + port_env_key = "%s_TEST_PORT" % prefix + host = os.environ.get(host_env_key, DEFAULT_WEB_HOST) + port = os.environ.get(port_env_key, None) + + webapp = webapp_factory( + kwargs[ 'global_conf' ], + app=app, + use_translogger=False, + static_enabled=True + ) + server, port = serve_webapp( + webapp, + host=host, port=port + ) + os.environ[host_env_key] = host + os.environ[port_env_key] = port + wait_for_http_server(host, port) + log.info("Embedded web server for %s started" % prefix.lower()) + return server, host, port + + __all__ = [ "cleanup_directory", "configure_environment", diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 7a230a141de..b667b8fc3e6 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -23,9 +23,6 @@ tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir() from galaxy.webapps.tool_shed import buildapp as toolshedbuildapp from galaxy.web import buildapp as galaxybuildapp -default_tool_shed_test_host = "localhost" -default_galaxy_test_host = 'localhost' - tool_sheds_conf_xml_template = ''' @@ -54,10 +51,6 @@ shed_data_manager_conf_xml_template = ''' def main(): """Entry point for test driver script.""" # ---- Configuration ------------------------------------------------------ - tool_shed_test_host = os.environ.get( 'TOOL_SHED_TEST_HOST', default_tool_shed_test_host ) - tool_shed_test_port = os.environ.get( 'TOOL_SHED_TEST_PORT', None ) - galaxy_test_host = os.environ.get( 'GALAXY_TEST_HOST', default_galaxy_test_host ) - galaxy_test_port = os.environ.get( 'GALAXY_TEST_PORT', None ) if not os.path.isdir( tool_shed_test_tmp_dir ): os.mkdir( tool_shed_test_tmp_dir ) shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir, prefix="TOOL_SHED") @@ -113,18 +106,12 @@ def main(): # ---- Run tool shed webserver ------------------------------------------------------ # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') kwargs['global_conf']['database_connection'] = kwargs["database_connection"] - - toolshedwebapp = toolshedbuildapp.app_factory( kwargs['global_conf'], - use_translogger=False, - static_enabled=True, - app=toolshedapp ) - - tool_shed_server, tool_shed_test_port = driver_util.serve_webapp( - toolshedwebapp, host=tool_shed_test_host, port=tool_shed_test_port + tool_shed_server, tool_shed_test_host, tool_shed_test_port = driver_util.launch_server( + toolshedapp, + toolshedbuildapp.app_factory, + kwargs, + prefix="TOOL_SHED", ) - os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_port - driver_util.wait_for_http_server(tool_shed_test_host, tool_shed_test_port) - log.info( "Embedded web server started" ) # ---- Optionally start up a Galaxy instance ------------------------------------------------------ if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ: @@ -157,26 +144,18 @@ def main(): print "Galaxy database connection:", kwargs["database_connection"] # ---- Run galaxy webserver ------------------------------------------------------ - galaxy_server = None galaxyapp = driver_util.build_galaxy_app(kwargs) - galaxywebapp = galaxybuildapp.app_factory( kwargs['global_conf'], - use_translogger=False, - static_enabled=True, - app=galaxyapp ) - galaxy_server, galaxy_test_port = driver_util.serve_webapp( - galaxywebapp, host=galaxy_test_host, port=galaxy_test_port + galaxy_server, galaxy_test_host, galaxy_test_port = driver_util.launch_server( + galaxyapp, + galaxybuildapp.app_factory, + kwargs, ) - os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_port - driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) - log.info( "Embedded galaxy web server started" ) + # ---- Find tests --------------------------------------------------------- log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_port ) ) log.info( "Galaxy tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) success = False try: - # Pass in through script set env, will leave a copy of ALL test validate files. - os.environ[ 'TOOL_SHED_TEST_HOST' ] = tool_shed_test_host - os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host success = driver_util.nose_config_and_run() except: log.exception( "Failure running tests" ) From 671b6933dd602e47ba8d99ba8e39e0419dde51f3 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 14:35:30 -0400 Subject: [PATCH 46/69] De-duplicate test driver logic for closing apps and stopping severs... --- scripts/functional_tests.py | 19 +++++----------- test/base/driver_util.py | 25 +++++++++++++++++++-- test/tool_shed/functional_tests.py | 36 +++++++++--------------------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index e34a2ba5866..6bb803afbfd 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -85,7 +85,7 @@ def main(): master_api_key = get_master_api_key() app = None - server = None + server_wrapper = None if start_server: # ---- Build Application -------------------------------------------------- @@ -105,14 +105,14 @@ def main(): kwargs[ 'datatypes_config_file' ] = datatypes_conf_override app = driver_util.build_galaxy_app(kwargs) - server, galaxy_test_host, galaxy_test_port = driver_util.launch_server( + server_wrapper = driver_util.launch_server( app, buildapp.app_factory, kwargs, ) + log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port)) # ---- Find tests --------------------------------------------------------- - log.info( "Functional tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) success = False try: if testing_shed_tools: @@ -166,16 +166,9 @@ def main(): log.info( "Shutting down" ) # ---- Tear down ----------------------------------------------------------- - if server: - log.info( "Shutting down embedded web server" ) - server.server_close() - server = None - log.info( "Embedded web server stopped" ) - if app: - log.info( "Shutting down app" ) - app.shutdown() - app = None - log.info( "Embedded Universe application stopped" ) + if server_wrapper is not None: + server_wrapper.stop() + server_wrapper = None driver_util.cleanup_directory(tempdir) if success: return 0 diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 97aebd59863..0b6d51a00d1 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -1,5 +1,6 @@ """Scripts for drivers of Galaxy functional tests.""" +import collections import httplib import json import logging @@ -404,6 +405,22 @@ def build_shed_app(simple_kwargs): log.info( "Embedded Toolshed application started" ) return app +ServerWrapper = collections.namedtuple('ServerWrapper', ['app', 'server', 'name', 'host', 'port']) + + +def _stop(self): + if self.server is not None: + log.info("Shutting down embedded %s web server" % self.name) + self.server.server_close() + log.info("Embedded web server %s stopped" % self.name) + + if self.app is not None: + log.info("Stopping application %s" % self.name) + self.app.shutdown() + log.info("Application %s stopped." % self.name) + +ServerWrapper.stop = _stop + def launch_server(app, webapp_factory, kwargs, prefix="GALAXY"): """Launch a web server for a given app using supplied factory. @@ -412,6 +429,8 @@ def launch_server(app, webapp_factory, kwargs, prefix="GALAXY"): TOOL_SHED_TEST_HOST and TOOL_SHED_TEST_PORT and ensure these are all set after this method has been called. """ + name = prefix.lower() + host_env_key = "%s_TEST_HOST" % prefix port_env_key = "%s_TEST_PORT" % prefix host = os.environ.get(host_env_key, DEFAULT_WEB_HOST) @@ -430,8 +449,10 @@ def launch_server(app, webapp_factory, kwargs, prefix="GALAXY"): os.environ[host_env_key] = host os.environ[port_env_key] = port wait_for_http_server(host, port) - log.info("Embedded web server for %s started" % prefix.lower()) - return server, host, port + log.info("Embedded web server for %s started" % name) + return ServerWrapper( + app, server, name, host, port + ) __all__ = [ diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index b667b8fc3e6..579cb36b3ae 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -106,12 +106,15 @@ def main(): # ---- Run tool shed webserver ------------------------------------------------------ # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') kwargs['global_conf']['database_connection'] = kwargs["database_connection"] - tool_shed_server, tool_shed_test_host, tool_shed_test_port = driver_util.launch_server( + tool_shed_server_wrapper = driver_util.launch_server( toolshedapp, toolshedbuildapp.app_factory, kwargs, prefix="TOOL_SHED", ) + tool_shed_test_host = tool_shed_server_wrapper.host + tool_shed_test_port = tool_shed_server_wrapper.port + log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_port ) ) # ---- Optionally start up a Galaxy instance ------------------------------------------------------ if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ: @@ -145,15 +148,14 @@ def main(): # ---- Run galaxy webserver ------------------------------------------------------ galaxyapp = driver_util.build_galaxy_app(kwargs) - galaxy_server, galaxy_test_host, galaxy_test_port = driver_util.launch_server( + galaxy_server_wrapper = driver_util.launch_server( galaxyapp, galaxybuildapp.app_factory, kwargs, ) + log.info("Galaxy tests will be run against %s:%s" % (galaxy_server_wrapper.host, galaxy_server_wrapper.port)) # ---- Find tests --------------------------------------------------------- - log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_port ) ) - log.info( "Galaxy tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) success = False try: success = driver_util.nose_config_and_run() @@ -162,27 +164,11 @@ def main(): log.info( "Shutting down" ) # ---- Tear down ----------------------------------------------------------- - if tool_shed_server: - log.info( "Shutting down embedded web server" ) - tool_shed_server.server_close() - tool_shed_server = None - log.info( "Embedded web server stopped" ) - if toolshedapp: - log.info( "Shutting down tool shed app" ) - toolshedapp.shutdown() - toolshedapp = None - log.info( "Embedded tool shed application stopped" ) - if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ: - if galaxy_server: - log.info( "Shutting down galaxy web server" ) - galaxy_server.server_close() - galaxy_server = None - log.info( "Embedded galaxy server stopped" ) - if galaxyapp: - log.info( "Shutting down galaxy app" ) - galaxyapp.shutdown() - galaxyapp = None - log.info( "Embedded galaxy application stopped" ) + tool_shed_server_wrapper.stop() + tool_shed_server_wrapper = None + if galaxy_server_wrapper is not None: + galaxy_server_wrapper.stop() + galaxy_server_wrapper = None driver_util.cleanup_directory(tool_shed_test_tmp_dir) if success: return 0 From 33d312b906ac4c50554fb1bff1e0dc39bdaea077 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 15:13:24 -0400 Subject: [PATCH 47/69] [16.01] Fix for running jobs when metadata tool is not in toolbox. Happens when -installed or -migrated are passed into run_tests.sh because of the way the tool shed hacks up Galaxy's tool config. --- lib/galaxy/jobs/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 5fd087be476..25d46b57481 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -1662,10 +1662,12 @@ class JobWrapper( object ): **kwds ) if resolve_metadata_dependencies: metadata_tool = self.app.toolbox.get_tool("__SET_METADATA__") - dependency_shell_commands = metadata_tool.build_dependency_shell_commands(job_directory=self.working_directory) - if dependency_shell_commands: - dependency_shell_commands = "; ".join(dependency_shell_commands) - command = "%s; %s" % (dependency_shell_commands, command) + if metadata_tool is not None: + # Due to tool shed hacks for migrate and installed tool tests... + dependency_shell_commands = metadata_tool.build_dependency_shell_commands(job_directory=self.working_directory) + if dependency_shell_commands: + dependency_shell_commands = "; ".join(dependency_shell_commands) + command = "%s; %s" % (dependency_shell_commands, command) return command @property From 3c47105732febe5ca69a6ba20df875177fb7a31a Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 15:20:56 -0400 Subject: [PATCH 48/69] Fix shed tool test file shed_tools_dict handling. Instead of writing it below GALAXY_ROOT (which it shouldn't do at all) - add to the temp directory managed for the test so that special clean up logic isn't required for it. The global switch GALAXY_TEST_NO_CLEANUP can be used to recover the state of this file if needed now also. --- scripts/functional_tests.py | 12 +----------- test/base/driver_util.py | 4 +++- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 6bb803afbfd..4cd121c7391 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -31,12 +31,9 @@ def main(): testing_shed_tools = testing_migrated_tools or testing_installed_tools if testing_shed_tools: - # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. - galaxy_tool_shed_test_file = 'shed_tools_dict' # We need the upload tool for functional tests, so we'll create a temporary tool panel config that defines it. tool_config_file = driver_util.FRAMEWORK_UPLOAD_TOOL_CONF else: - galaxy_tool_shed_test_file = None framework_test = _check_arg( '-framework' ) # Run through suite of tests testing framework. if framework_test: tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF @@ -118,7 +115,7 @@ def main(): if testing_shed_tools: driver_util.setup_shed_tools_for_test( app, - galaxy_tool_shed_test_file, + galaxy_test_tmp_dir, testing_migrated_tools, testing_installed_tools, ) @@ -154,13 +151,6 @@ def main(): ) success = driver_util.nose_config_and_run() - - # TODO: just put this in tempdir being managed for this test. - if galaxy_tool_shed_test_file is not None: - try: - os.unlink( galaxy_tool_shed_test_file ) - except: - log.info( "Unable to remove file: %s" % galaxy_tool_shed_test_file ) except: log.exception( "Failure running tests" ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 0b6d51a00d1..60c27aa3652 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -337,8 +337,10 @@ def cleanup_directory(tempdir): pass -def setup_shed_tools_for_test(app, galaxy_tool_shed_test_file, testing_migrated_tools, testing_installed_tools): +def setup_shed_tools_for_test(app, tmpdir, testing_migrated_tools, testing_installed_tools): """Modify Galaxy app's toolbox for migrated or installed tool tests.""" + # Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs. + galaxy_tool_shed_test_file = os.path.join(tmpdir, 'shed_tools_dict') shed_tools_dict = {} if testing_migrated_tools: has_test_data, shed_tools_dict = parse_tool_panel_config(MIGRATED_TOOL_PANEL_CONFIG, shed_tools_dict) From d657855b7f075bbcc1b2c7aa7f2e7b679ff1a6dd Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 15:35:46 -0400 Subject: [PATCH 49/69] Remove unused test_conf variable. --- lib/galaxy/config.py | 1 - lib/galaxy/webapps/tool_shed/config.py | 1 - scripts/functional_tests.py | 1 - 3 files changed, 3 deletions(-) diff --git a/lib/galaxy/config.py b/lib/galaxy/config.py index 9f9fe9a5dc2..14d584d632c 100644 --- a/lib/galaxy/config.py +++ b/lib/galaxy/config.py @@ -91,7 +91,6 @@ class Configuration( object ): self.tool_data_path = resolve_path( kwargs.get( "tool_data_path", "tool-data" ), os.getcwd() ) self.builds_file_path = resolve_path( kwargs.get( "builds_file_path", os.path.join( self.tool_data_path, 'shared', 'ucsc', 'builds.txt') ), self.root ) self.len_file_path = resolve_path( kwargs.get( "len_file_path", os.path.join( self.tool_data_path, 'shared', 'ucsc', 'chrom') ), self.root ) - self.test_conf = resolve_path( kwargs.get( "test_conf", "" ), self.root ) # The value of migrated_tools_config is the file reserved for containing only those tools that have been eliminated from the distribution # and moved to the tool shed. self.integrated_tool_panel_config = resolve_path( kwargs.get( 'integrated_tool_panel_config', 'integrated_tool_panel.xml' ), self.root ) diff --git a/lib/galaxy/webapps/tool_shed/config.py b/lib/galaxy/webapps/tool_shed/config.py index d9f69cf8e37..43ae3d4a928 100644 --- a/lib/galaxy/webapps/tool_shed/config.py +++ b/lib/galaxy/webapps/tool_shed/config.py @@ -66,7 +66,6 @@ class Configuration( object ): self.new_file_path = resolve_path( kwargs.get( "new_file_path", "database/tmp" ), self.root ) self.cookie_path = kwargs.get( "cookie_path", "/" ) self.enable_quotas = string_as_bool( kwargs.get( 'enable_quotas', False ) ) - self.test_conf = resolve_path( kwargs.get( "test_conf", "" ), self.root ) self.id_secret = kwargs.get( "id_secret", "USING THE DEFAULT IS NOT SECURE!" ) # Tool stuff self.tool_path = resolve_path( kwargs.get( "tool_path", "tools" ), self.root ) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 4cd121c7391..674277a6011 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -87,7 +87,6 @@ def main(): if start_server: # ---- Build Application -------------------------------------------------- kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, - test_conf="test.conf", tool_config_file=tool_config_file, tool_data_table_config_path=tool_data_table_config_path, galaxy_data_manager_data_path=galaxy_data_manager_data_path, From 65806641c1aa0260923f0733bff7b1f81304d3a3 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 15:49:38 -0400 Subject: [PATCH 50/69] Simplify(?) tool data table config logic at lest in scripts/functional_tests.py. --- scripts/functional_tests.py | 10 ---------- test/base/driver_util.py | 22 +++++++++++++++++++++- test/tool_shed/functional_tests.py | 17 +++++++++++------ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 674277a6011..4594828e7b3 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -46,14 +46,6 @@ def main(): tool_config_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', tool_conf ) start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ - tool_data_table_config_path = None - # ... otherise find whatever Galaxy would use as the default and - # the sample data for fucntional tests to that. - default_tool_data_config = 'config/tool_data_table_conf.xml.sample' - for tool_data_config in ['config/tool_data_table_conf.xml', 'tool_data_table_conf.xml' ]: - if os.path.exists( tool_data_config ): - default_tool_data_config = tool_data_config - tool_data_table_config_path = '%s,test/functional/tool-data/sample_tool_data_tables.xml' % default_tool_data_config default_data_manager_config = 'config/data_manager_conf.xml.sample' for data_manager_config in ['config/data_manager_conf.xml', 'data_manager_conf.xml' ]: @@ -88,7 +80,6 @@ def main(): # ---- Build Application -------------------------------------------------- kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, tool_config_file=tool_config_file, - tool_data_table_config_path=tool_data_table_config_path, galaxy_data_manager_data_path=galaxy_data_manager_data_path, update_integrated_tool_panel=False, master_api_key=master_api_key, @@ -148,7 +139,6 @@ def main(): master_api_key=master_api_key, user_api_key=get_user_api_key(), ) - success = driver_util.nose_config_and_run() except: log.exception( "Failure running tests" ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 60c27aa3652..f11183ba201 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -79,7 +79,12 @@ def build_logger(): return log -def setup_galaxy_config(tmpdir, use_test_file_dir=False, default_install_db_merged=True): +def setup_galaxy_config( + tmpdir, + use_test_file_dir=False, + default_install_db_merged=True, + default_tool_data_table_config_path=None, +): """Setup environment and build config for test Galaxy instance.""" if not os.path.exists(tmpdir): os.makedirs(tmpdir) @@ -107,6 +112,7 @@ def setup_galaxy_config(tmpdir, use_test_file_dir=False, default_install_db_merg tool_dependency_dir = os.environ.get('GALAXY_TOOL_DEPENDENCY_DIR', None) if tool_dependency_dir is None: tool_dependency_dir = tempfile.mkdtemp(dir=tmpdir, prefix="tool_dependencies") + tool_data_table_config_path = _tool_data_table_config_path(default_tool_data_table_config_path) config = dict( admin_users='test@bx.psu.edu', allow_library_path_paste=True, @@ -124,6 +130,7 @@ def setup_galaxy_config(tmpdir, use_test_file_dir=False, default_install_db_merg running_functional_tests=True, template_cache_path=template_cache_path, template_path='templates', + tool_data_table_config_path=tool_data_table_config_path, tool_parse_help=False, tool_path=tool_path, update_integrated_tool_panel=False, @@ -142,6 +149,19 @@ def setup_galaxy_config(tmpdir, use_test_file_dir=False, default_install_db_merg return config +def _tool_data_table_config_path(default_tool_data_table_config_path=None): + tool_data_table_config_path = os.environ.get('GALAXY_TEST_TOOL_DATA_TABLE_CONF', default_tool_data_table_config_path) + if tool_data_table_config_path is None: + # ... otherise find whatever Galaxy would use as the default and + # the sample data for fucntional tests to that. + default_tool_data_config = 'config/tool_data_table_conf.xml.sample' + for tool_data_config in ['config/tool_data_table_conf.xml', 'tool_data_table_conf.xml' ]: + if os.path.exists( tool_data_config ): + default_tool_data_config = tool_data_config + tool_data_table_config_path = '%s,test/functional/tool-data/sample_tool_data_tables.xml' % default_tool_data_config + return tool_data_table_config_path + + def nose_config_and_run( argv=None, env=None, ignore_files=[], plugins=None ): """Setup a nose context and run tests. diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 579cb36b3ae..c2cf566fdcb 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -56,7 +56,7 @@ def main(): shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir, prefix="TOOL_SHED") shed_tool_data_table_conf_file = os.environ.get( 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml' ) ) galaxy_shed_data_manager_conf_file = os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_data_manager_conf.xml' ) ) - galaxy_tool_data_table_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'tool_data_table_conf.xml' ) ) + default_tool_data_table_config_path = os.path.join( tool_shed_test_tmp_dir, 'tool_data_table_conf.xml' ) galaxy_tool_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', driver_util.FRAMEWORK_UPLOAD_TOOL_CONF ) galaxy_shed_tool_conf_file = os.environ.get( 'GALAXY_TEST_SHED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml' ) ) galaxy_migrated_tool_conf_file = os.environ.get( 'GALAXY_TEST_MIGRATED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_migrated_tool_conf.xml' ) ) @@ -92,11 +92,10 @@ def main(): email_from='functional@localhost', template_path='templates', tool_parse_help=False, - tool_data_table_config_path=galaxy_tool_data_table_conf_file, use_heartbeat=False ) kwargs.update(toolshed_database_conf) # Generate the tool_data_table_conf.xml file. - file( galaxy_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) + file( default_tool_data_table_config_path, 'w' ).write( tool_data_table_conf_xml_template ) # Generate the shed_tool_data_table_conf.xml file. file( shed_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) os.environ[ 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF' ] = shed_tool_data_table_conf_file @@ -141,9 +140,15 @@ def main(): shed_tool_path=galaxy_shed_tool_path, tool_data_path=tool_data_path, tool_config_file=[ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], - tool_sheds_config_file=galaxy_tool_sheds_conf_file, - tool_data_table_config_path=galaxy_tool_data_table_conf_file ) - kwargs.update(driver_util.setup_galaxy_config(galaxy_db_path, use_test_file_dir=False, default_install_db_merged=False)) + tool_sheds_config_file=galaxy_tool_sheds_conf_file ) + kwargs.update( + driver_util.setup_galaxy_config( + galaxy_db_path, + use_test_file_dir=False, + default_install_db_merged=False, + default_tool_data_table_config_path=default_tool_data_table_config_path + ) + ) print "Galaxy database connection:", kwargs["database_connection"] # ---- Run galaxy webserver ------------------------------------------------------ From 5b826a0839f6545ee94b3c3cd3ff710e5b8747f3 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:08:46 -0400 Subject: [PATCH 51/69] Move more galaxy config logic into driver_util. This time for galaxy master API key. --- scripts/functional_tests.py | 9 +++------ test/base/driver_util.py | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 4594828e7b3..dce11d70160 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -71,8 +71,6 @@ def main(): # For storing Data Manager outputs and .loc files so that real ones don't get clobbered data_manager_test_tmp_path = tempfile.mkdtemp( prefix='data_manager_test_tmp', dir=galaxy_test_tmp_dir ) galaxy_data_manager_data_path = tempfile.mkdtemp( prefix='data_manager_tool-data', dir=data_manager_test_tmp_path ) - master_api_key = get_master_api_key() - app = None server_wrapper = None @@ -82,7 +80,6 @@ def main(): tool_config_file=tool_config_file, galaxy_data_manager_data_path=galaxy_data_manager_data_path, update_integrated_tool_panel=False, - master_api_key=master_api_key, cleanup_job='onsuccess', enable_beta_tool_formats=True, auto_configure_logging=logging_config_file is None, @@ -113,7 +110,7 @@ def main(): if workflow_test: import functional.workflow functional.workflow.WorkflowTestCase.workflow_test_file = workflow_test - functional.workflow.WorkflowTestCase.master_api_key = master_api_key + functional.workflow.WorkflowTestCase.master_api_key = get_master_api_key() functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key() data_manager_test = _check_arg( '-data_managers', param=False ) if data_manager_test: @@ -122,7 +119,7 @@ def main(): functional.test_data_managers.build_tests( tmp_dir=data_manager_test_tmp_path, testing_shed_tools=testing_shed_tools, - master_api_key=master_api_key, + master_api_key=get_master_api_key(), user_api_key=get_user_api_key(), ) @@ -136,7 +133,7 @@ def main(): functional.test_toolbox.build_tests( app=app, testing_shed_tools=testing_shed_tools, - master_api_key=master_api_key, + master_api_key=get_master_api_key(), user_api_key=get_user_api_key(), ) success = driver_util.nose_config_and_run() diff --git a/test/base/driver_util.py b/test/base/driver_util.py index f11183ba201..7d80a8a7806 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -22,6 +22,7 @@ import nose.plugins.manager from paste import httpserver +from .api_util import get_master_api_key from .tool_shed_util import parse_tool_panel_config from .nose_util import run from .instrument import StructuredTestDataPlugin @@ -113,6 +114,7 @@ def setup_galaxy_config( if tool_dependency_dir is None: tool_dependency_dir = tempfile.mkdtemp(dir=tmpdir, prefix="tool_dependencies") tool_data_table_config_path = _tool_data_table_config_path(default_tool_data_table_config_path) + master_api_key = get_master_api_key() config = dict( admin_users='test@bx.psu.edu', allow_library_path_paste=True, @@ -127,6 +129,7 @@ def setup_galaxy_config( library_import_dir=library_import_dir, log_destination="stdout", new_file_path=new_file_path, + master_api_key=master_api_key, running_functional_tests=True, template_cache_path=template_cache_path, template_path='templates', From e356c80c02e23ff42d0c3ba0b94575865793168c Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:11:34 -0400 Subject: [PATCH 52/69] Move enable_tool_shed_check test driver logic into driver_util. --- test/base/driver_util.py | 5 ++++- test/tool_shed/functional_tests.py | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 7d80a8a7806..953a829208f 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -85,6 +85,7 @@ def setup_galaxy_config( use_test_file_dir=False, default_install_db_merged=True, default_tool_data_table_config_path=None, + enable_tool_shed_check=False, ): """Setup environment and build config for test Galaxy instance.""" if not os.path.exists(tmpdir): @@ -143,7 +144,9 @@ def setup_galaxy_config( ) config.update(database_conf(tmpdir)) config.update(install_database_conf(tmpdir, default_merged=default_install_db_merged)) - + if enable_tool_shed_check: + config["enable_tool_shed_check"] = enable_tool_shed_check + config["hours_between_check"] = 0.001 if tool_dependency_dir: config["tool_dependency_dir"] = tool_dependency_dir # Used by shed's twill dependency stuff - todo read from diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index c2cf566fdcb..ce04f3ea45a 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -132,9 +132,7 @@ def main(): # Generate shed_data_manager_conf.xml if not os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF' ): open( galaxy_shed_data_manager_conf_file, 'wb' ).write( shed_data_manager_conf_xml_template ) - kwargs = dict( enable_tool_shed_check=True, - hours_between_check=0.001, - migrated_tools_config=galaxy_migrated_tool_conf_file, + kwargs = dict( migrated_tools_config=galaxy_migrated_tool_conf_file, shed_data_manager_config_file=galaxy_shed_data_manager_conf_file, shed_tool_data_table_config=shed_tool_data_table_conf_file, shed_tool_path=galaxy_shed_tool_path, @@ -146,7 +144,8 @@ def main(): galaxy_db_path, use_test_file_dir=False, default_install_db_merged=False, - default_tool_data_table_config_path=default_tool_data_table_config_path + default_tool_data_table_config_path=default_tool_data_table_config_path, + enable_tool_shed_check=True, ) ) print "Galaxy database connection:", kwargs["database_connection"] From 1b80e6e8d1e4e2ecddaac4b37337e7cfd7016d57 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:16:47 -0400 Subject: [PATCH 53/69] Move another galaxy config (clean up job) into driver_util. --- scripts/functional_tests.py | 1 - test/base/driver_util.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index dce11d70160..988c552a383 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -80,7 +80,6 @@ def main(): tool_config_file=tool_config_file, galaxy_data_manager_data_path=galaxy_data_manager_data_path, update_integrated_tool_panel=False, - cleanup_job='onsuccess', enable_beta_tool_formats=True, auto_configure_logging=logging_config_file is None, data_manager_config_file=data_manager_config_file ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 953a829208f..a1286349095 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -123,6 +123,7 @@ def setup_galaxy_config( allow_user_deletion=True, api_allow_run_as='test@bx.psu.edu', check_migrate_tools=False, + cleanup_job='onsuccess', file_path=file_path, id_secret='changethisinproductiontoo', job_working_directory=job_working_directory, From 3c72c2129bd5a92e4fe0722e50e5f6d31c5d3737 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:21:02 -0400 Subject: [PATCH 54/69] Move data_manager_config_file setup into driver_util. Seems it doesn't hurt tool shed tests to configure this. --- scripts/functional_tests.py | 8 +------- test/base/driver_util.py | 6 ++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 988c552a383..c2d0c4bd89f 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -47,11 +47,6 @@ def main(): start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ - default_data_manager_config = 'config/data_manager_conf.xml.sample' - for data_manager_config in ['config/data_manager_conf.xml', 'data_manager_conf.xml' ]: - if os.path.exists( data_manager_config ): - default_data_manager_config = data_manager_config - data_manager_config_file = "%s,test/functional/tools/sample_data_manager_conf.xml" % default_data_manager_config shed_tool_data_table_config = 'config/shed_tool_data_table_conf.xml' galaxy_test_tmp_dir = os.environ.get( 'GALAXY_TEST_TMP_DIR', None ) if galaxy_test_tmp_dir is None: @@ -81,8 +76,7 @@ def main(): galaxy_data_manager_data_path=galaxy_data_manager_data_path, update_integrated_tool_panel=False, enable_beta_tool_formats=True, - auto_configure_logging=logging_config_file is None, - data_manager_config_file=data_manager_config_file ) + auto_configure_logging=logging_config_file is None ) kwargs.update(galaxy_config) if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override diff --git a/test/base/driver_util.py b/test/base/driver_util.py index a1286349095..fc172947f5d 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -115,6 +115,11 @@ def setup_galaxy_config( if tool_dependency_dir is None: tool_dependency_dir = tempfile.mkdtemp(dir=tmpdir, prefix="tool_dependencies") tool_data_table_config_path = _tool_data_table_config_path(default_tool_data_table_config_path) + default_data_manager_config = 'config/data_manager_conf.xml.sample' + for data_manager_config in ['config/data_manager_conf.xml', 'data_manager_conf.xml' ]: + if os.path.exists( data_manager_config ): + default_data_manager_config = data_manager_config + data_manager_config_file = "%s,test/functional/tools/sample_data_manager_conf.xml" % default_data_manager_config master_api_key = get_master_api_key() config = dict( admin_users='test@bx.psu.edu', @@ -124,6 +129,7 @@ def setup_galaxy_config( api_allow_run_as='test@bx.psu.edu', check_migrate_tools=False, cleanup_job='onsuccess', + data_manager_config_file=data_manager_config_file, file_path=file_path, id_secret='changethisinproductiontoo', job_working_directory=job_working_directory, From 362194b2c023dc54cd220038a529ae411e6a2ea3 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:24:31 -0400 Subject: [PATCH 55/69] Cleanup logic for GALAXY_TEST_TMP_DIR add docs. --- run_tests.sh | 2 ++ scripts/functional_tests.py | 4 +--- test/base/driver_util.py | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 2b8b7d8ee8b..c610a16f8dc 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -62,6 +62,8 @@ GALAXY_TEST_INSTALL_DB_MERGED Set to use same database for Galaxy and install fr GALAXY_TEST_DB_TEMPLATE If GALAXY_TEST_DBURI is unset, this URL can be retrieved and should be an sqlite database that will be upgraded and tested against. +GALAXY_TEST_TMP_DIR Temp directory used for files required by Galaxy server setup + for Galaxy functional tests. HTTP_ACCEPT_LANGUAGE Defaults to 'en' GALAXY_TEST_NO_CLEANUP Do not cleanup main test directory after tests, the deprecated option TOOL_SHED_TEST_NO_CLEANUP does the diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index c2d0c4bd89f..87da5f6a6f9 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -48,9 +48,7 @@ def main(): start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ shed_tool_data_table_config = 'config/shed_tool_data_table_conf.xml' - galaxy_test_tmp_dir = os.environ.get( 'GALAXY_TEST_TMP_DIR', None ) - if galaxy_test_tmp_dir is None: - galaxy_test_tmp_dir = tempfile.mkdtemp() + galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir() if start_server: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index fc172947f5d..178de4e76a8 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -64,6 +64,14 @@ def setup_tool_shed_tmp_dir(): return tool_shed_test_tmp_dir +def get_galaxy_test_tmp_dir(): + """Create test directory for use by Galaxy server being setup for testing.""" + galaxy_test_tmp_dir = os.environ.get('GALAXY_TEST_TMP_DIR', None) + if galaxy_test_tmp_dir is None: + galaxy_test_tmp_dir = tempfile.mkdtemp() + return galaxy_test_tmp_dir + + def configure_environment(): """Hack up environment for test cases.""" # no op remove if unused From 3546bdf22b0defd8236e184331a041bb3f4f8840 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:29:29 -0400 Subject: [PATCH 56/69] Cleanup Galaxy tempdir handling in driver util. --- scripts/functional_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 87da5f6a6f9..6450951c2c8 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -108,7 +108,7 @@ def main(): import functional.test_data_managers functional.test_data_managers.data_managers = app.data_managers # seems like a hack... functional.test_data_managers.build_tests( - tmp_dir=data_manager_test_tmp_path, + tmp_dir=galaxy_test_tmp_dir, testing_shed_tools=testing_shed_tools, master_api_key=get_master_api_key(), user_api_key=get_user_api_key(), @@ -136,7 +136,7 @@ def main(): if server_wrapper is not None: server_wrapper.stop() server_wrapper = None - driver_util.cleanup_directory(tempdir) + driver_util.cleanup_directory(galaxy_test_tmp_dir) if success: return 0 else: From a8033a543baa7f919e0d7c061baa62263c7f633e Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:32:01 -0400 Subject: [PATCH 57/69] Move galaxy test data manager setup logic into driver_util. --- scripts/functional_tests.py | 5 ----- test/base/driver_util.py | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 6450951c2c8..8e6c9cfa9b6 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -60,10 +60,6 @@ def main(): default_install_db_merged=True, ) - # Data Manager testing temp path - # For storing Data Manager outputs and .loc files so that real ones don't get clobbered - data_manager_test_tmp_path = tempfile.mkdtemp( prefix='data_manager_test_tmp', dir=galaxy_test_tmp_dir ) - galaxy_data_manager_data_path = tempfile.mkdtemp( prefix='data_manager_tool-data', dir=data_manager_test_tmp_path ) app = None server_wrapper = None @@ -71,7 +67,6 @@ def main(): # ---- Build Application -------------------------------------------------- kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, tool_config_file=tool_config_file, - galaxy_data_manager_data_path=galaxy_data_manager_data_path, update_integrated_tool_panel=False, enable_beta_tool_formats=True, auto_configure_logging=logging_config_file is None ) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 178de4e76a8..4462d1f51ac 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -129,6 +129,11 @@ def setup_galaxy_config( default_data_manager_config = data_manager_config data_manager_config_file = "%s,test/functional/tools/sample_data_manager_conf.xml" % default_data_manager_config master_api_key = get_master_api_key() + + # Data Manager testing temp path + # For storing Data Manager outputs and .loc files so that real ones don't get clobbered + galaxy_data_manager_data_path = tempfile.mkdtemp(prefix='data_manager_tool-data', dir=tmpdir) + config = dict( admin_users='test@bx.psu.edu', allow_library_path_paste=True, @@ -139,6 +144,7 @@ def setup_galaxy_config( cleanup_job='onsuccess', data_manager_config_file=data_manager_config_file, file_path=file_path, + galaxy_data_manager_data_path=galaxy_data_manager_data_path, id_secret='changethisinproductiontoo', job_working_directory=job_working_directory, job_queue_workers=5, From f3c757ff1c5349ef683a092cc8b758b93cf84614 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:40:27 -0400 Subject: [PATCH 58/69] Move more galaxy config into driver_util... Handle logging and enabling of beta formats consistently across driver scripts. --- scripts/functional_tests.py | 5 +---- test/base/driver_util.py | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 8e6c9cfa9b6..1cdeb014bac 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -18,7 +18,6 @@ driver_util.configure_environment() log = driver_util.build_logger() from base.api_util import get_master_api_key, get_user_api_key -from base.test_logging import logging_config_file from galaxy.web import buildapp @@ -67,9 +66,7 @@ def main(): # ---- Build Application -------------------------------------------------- kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, tool_config_file=tool_config_file, - update_integrated_tool_panel=False, - enable_beta_tool_formats=True, - auto_configure_logging=logging_config_file is None ) + update_integrated_tool_panel=False, ) kwargs.update(galaxy_config) if datatypes_conf_override: kwargs[ 'datatypes_config_file' ] = datatypes_conf_override diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 4462d1f51ac..7453633056b 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -34,6 +34,8 @@ from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverse from galaxy.util import asbool from galaxy.util.properties import load_app_properties +from base.test_logging import logging_config_file + galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) DEFAULT_WEB_HOST = "localhost" GALAXY_TEST_DIRECTORY = os.path.join(galaxy_root, "test") @@ -140,9 +142,11 @@ def setup_galaxy_config( allow_user_creation=True, allow_user_deletion=True, api_allow_run_as='test@bx.psu.edu', + auto_configure_logging=logging_config_file is None , check_migrate_tools=False, cleanup_job='onsuccess', data_manager_config_file=data_manager_config_file, + enable_beta_tool_formats=True, file_path=file_path, galaxy_data_manager_data_path=galaxy_data_manager_data_path, id_secret='changethisinproductiontoo', From e1aa0b3acc83ef219752cad75b262b71cd232199 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:51:03 -0400 Subject: [PATCH 59/69] Simplify/unify tool conf handling logic across two driver util... --- scripts/functional_tests.py | 14 +++++--------- test/base/driver_util.py | 11 +++++++++++ test/tool_shed/functional_tests.py | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 1cdeb014bac..67fb063293e 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -28,21 +28,17 @@ def main(): testing_installed_tools = _check_arg( '-installed' ) datatypes_conf_override = None + default_tool_conf = None testing_shed_tools = testing_migrated_tools or testing_installed_tools - if testing_shed_tools: - # We need the upload tool for functional tests, so we'll create a temporary tool panel config that defines it. - tool_config_file = driver_util.FRAMEWORK_UPLOAD_TOOL_CONF - else: + if not testing_shed_tools: framework_test = _check_arg( '-framework' ) # Run through suite of tests testing framework. if framework_test: - tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF + default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF else: # Use tool_conf.xml toolbox. - tool_conf = None if _check_arg( '-with_framework_test_tools' ): - tool_conf = "%s,%s" % ( 'config/tool_conf.xml.sample', driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF ) - tool_config_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', tool_conf ) + default_tool_conf = "%s,%s" % ( 'config/tool_conf.xml.sample', driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF ) start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ @@ -57,6 +53,7 @@ def main(): galaxy_db_path, use_test_file_dir=not testing_shed_tools, default_install_db_merged=True, + default_tool_conf=default_tool_conf, ) app = None @@ -65,7 +62,6 @@ def main(): if start_server: # ---- Build Application -------------------------------------------------- kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, - tool_config_file=tool_config_file, update_integrated_tool_panel=False, ) kwargs.update(galaxy_config) if datatypes_conf_override: diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 7453633056b..f48b5344b6d 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -96,6 +96,8 @@ def setup_galaxy_config( default_install_db_merged=True, default_tool_data_table_config_path=None, enable_tool_shed_check=False, + default_tool_conf=None, + shed_tool_conf=None, ): """Setup environment and build config for test Galaxy instance.""" if not os.path.exists(tmpdir): @@ -136,6 +138,14 @@ def setup_galaxy_config( # For storing Data Manager outputs and .loc files so that real ones don't get clobbered galaxy_data_manager_data_path = tempfile.mkdtemp(prefix='data_manager_tool-data', dir=tmpdir) + tool_conf = os.environ.get('GALAXY_TEST_TOOL_CONF', default_tool_conf) + if tool_conf is None: + # As a fallback always at least allow upload. + tool_conf = FRAMEWORK_UPLOAD_TOOL_CONF + + if shed_tool_conf is not None: + tool_conf = "%s,%s" % (tool_conf, shed_tool_conf) + config = dict( admin_users='test@bx.psu.edu', allow_library_path_paste=True, @@ -159,6 +169,7 @@ def setup_galaxy_config( running_functional_tests=True, template_cache_path=template_cache_path, template_path='templates', + tool_config_file=tool_conf, tool_data_table_config_path=tool_data_table_config_path, tool_parse_help=False, tool_path=tool_path, diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index ce04f3ea45a..97f591c9263 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -57,7 +57,6 @@ def main(): shed_tool_data_table_conf_file = os.environ.get( 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml' ) ) galaxy_shed_data_manager_conf_file = os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_data_manager_conf.xml' ) ) default_tool_data_table_config_path = os.path.join( tool_shed_test_tmp_dir, 'tool_data_table_conf.xml' ) - galaxy_tool_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', driver_util.FRAMEWORK_UPLOAD_TOOL_CONF ) galaxy_shed_tool_conf_file = os.environ.get( 'GALAXY_TEST_SHED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml' ) ) galaxy_migrated_tool_conf_file = os.environ.get( 'GALAXY_TEST_MIGRATED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_migrated_tool_conf.xml' ) ) galaxy_tool_sheds_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_SHEDS_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_sheds_conf.xml' ) ) @@ -137,7 +136,7 @@ def main(): shed_tool_data_table_config=shed_tool_data_table_conf_file, shed_tool_path=galaxy_shed_tool_path, tool_data_path=tool_data_path, - tool_config_file=[ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], + tool_sheds_config_file=galaxy_tool_sheds_conf_file ) kwargs.update( driver_util.setup_galaxy_config( @@ -146,6 +145,7 @@ def main(): default_install_db_merged=False, default_tool_data_table_config_path=default_tool_data_table_config_path, enable_tool_shed_check=True, + shed_tool_conf=galaxy_shed_tool_conf_file, ) ) print "Galaxy database connection:", kwargs["database_connection"] From 586fa6801b9d7cec1db1ceaf5488f66dadfbc183 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 17:59:15 -0400 Subject: [PATCH 60/69] Move yet more logic into driver_util to reduce driver method for scripts/functional_tests.py. --- scripts/functional_tests.py | 7 ++----- test/base/driver_util.py | 6 +++++- test/tool_shed/functional_tests.py | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 67fb063293e..84e58f7e1a5 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -54,6 +54,7 @@ def main(): use_test_file_dir=not testing_shed_tools, default_install_db_merged=True, default_tool_conf=default_tool_conf, + datatypes_conf=datatypes_conf_override, ) app = None @@ -61,12 +62,8 @@ def main(): if start_server: # ---- Build Application -------------------------------------------------- - kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config, - update_integrated_tool_panel=False, ) + kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config ) kwargs.update(galaxy_config) - if datatypes_conf_override: - kwargs[ 'datatypes_config_file' ] = datatypes_conf_override - app = driver_util.build_galaxy_app(kwargs) server_wrapper = driver_util.launch_server( app, diff --git a/test/base/driver_util.py b/test/base/driver_util.py index f48b5344b6d..8f26d3cb24d 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -98,6 +98,8 @@ def setup_galaxy_config( enable_tool_shed_check=False, default_tool_conf=None, shed_tool_conf=None, + datatypes_conf=None, + update_integrated_tool_panel=False, ): """Setup environment and build config for test Galaxy instance.""" if not os.path.exists(tmpdir): @@ -173,13 +175,15 @@ def setup_galaxy_config( tool_data_table_config_path=tool_data_table_config_path, tool_parse_help=False, tool_path=tool_path, - update_integrated_tool_panel=False, + update_integrated_tool_panel=update_integrated_tool_panel, use_tasked_jobs=True, use_heartbeat=False, user_library_import_dir=user_library_import_dir, ) config.update(database_conf(tmpdir)) config.update(install_database_conf(tmpdir, default_merged=default_install_db_merged)) + if datatypes_conf is not None: + config['datatypes_config_file'] = datatypes_conf if enable_tool_shed_check: config["enable_tool_shed_check"] = enable_tool_shed_check config["hours_between_check"] = 0.001 diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 97f591c9263..d55ec50176c 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -146,6 +146,7 @@ def main(): default_tool_data_table_config_path=default_tool_data_table_config_path, enable_tool_shed_check=True, shed_tool_conf=galaxy_shed_tool_conf_file, + update_integrated_tool_panel=True, ) ) print "Galaxy database connection:", kwargs["database_connection"] From 93cfdff9103dc4216893ed494e22bdc2d870ff22 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 18:22:19 -0400 Subject: [PATCH 61/69] Eliminate last custom config value setup in scripts/functional_tests.py... ... outside of driver_util. So now we can just use the driver_util config object. --- scripts/functional_tests.py | 7 ++----- test/base/driver_util.py | 6 ++++++ test/tool_shed/functional_tests.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 84e58f7e1a5..fac4e0167dd 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -42,7 +42,6 @@ def main(): start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ - shed_tool_data_table_config = 'config/shed_tool_data_table_conf.xml' galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir() if start_server: @@ -62,13 +61,11 @@ def main(): if start_server: # ---- Build Application -------------------------------------------------- - kwargs = dict( shed_tool_data_table_config=shed_tool_data_table_config ) - kwargs.update(galaxy_config) - app = driver_util.build_galaxy_app(kwargs) + app = driver_util.build_galaxy_app(galaxy_config) server_wrapper = driver_util.launch_server( app, buildapp.app_factory, - kwargs, + galaxy_config, ) log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port)) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 8f26d3cb24d..5411a11f23d 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -95,6 +95,7 @@ def setup_galaxy_config( use_test_file_dir=False, default_install_db_merged=True, default_tool_data_table_config_path=None, + default_shed_tool_data_table_config=None, enable_tool_shed_check=False, default_tool_conf=None, shed_tool_conf=None, @@ -148,6 +149,10 @@ def setup_galaxy_config( if shed_tool_conf is not None: tool_conf = "%s,%s" % (tool_conf, shed_tool_conf) + shed_tool_data_table_config = default_shed_tool_data_table_config + if shed_tool_data_table_config is None: + shed_tool_data_table_config = 'config/shed_tool_data_table_conf.xml' + config = dict( admin_users='test@bx.psu.edu', allow_library_path_paste=True, @@ -169,6 +174,7 @@ def setup_galaxy_config( new_file_path=new_file_path, master_api_key=master_api_key, running_functional_tests=True, + shed_tool_data_table_config=shed_tool_data_table_config, template_cache_path=template_cache_path, template_path='templates', tool_config_file=tool_conf, diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index d55ec50176c..f4860ef1eed 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -133,7 +133,6 @@ def main(): open( galaxy_shed_data_manager_conf_file, 'wb' ).write( shed_data_manager_conf_xml_template ) kwargs = dict( migrated_tools_config=galaxy_migrated_tool_conf_file, shed_data_manager_config_file=galaxy_shed_data_manager_conf_file, - shed_tool_data_table_config=shed_tool_data_table_conf_file, shed_tool_path=galaxy_shed_tool_path, tool_data_path=tool_data_path, @@ -144,6 +143,7 @@ def main(): use_test_file_dir=False, default_install_db_merged=False, default_tool_data_table_config_path=default_tool_data_table_config_path, + default_shed_tool_data_table_config=shed_tool_data_table_conf_file, enable_tool_shed_check=True, shed_tool_conf=galaxy_shed_tool_conf_file, update_integrated_tool_panel=True, From 8fdecbb3bf5c6ba02393531117c3e2160e5ea22b Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 18:33:45 -0400 Subject: [PATCH 62/69] Another simplifcation to method structure in scripts/functional_tests.py. --- scripts/functional_tests.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index fac4e0167dd..7405fd88749 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -44,6 +44,9 @@ def main(): galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir() + app = None + server_wrapper = None + if start_server: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) # Configure the database path. @@ -56,10 +59,6 @@ def main(): datatypes_conf=datatypes_conf_override, ) - app = None - server_wrapper = None - - if start_server: # ---- Build Application -------------------------------------------------- app = driver_util.build_galaxy_app(galaxy_config) server_wrapper = driver_util.launch_server( From fc1861c4d9ab8b7ecae5b959c3e59f33146e6802 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 18:51:10 -0400 Subject: [PATCH 63/69] Move "with framework test tools" logic out of nose driver and into run_tests. --- run_tests.sh | 6 +++++- scripts/functional_tests.py | 4 ---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index c610a16f8dc..e40cef5560a 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -427,7 +427,11 @@ if [ "$driver" = "python" ]; then else structured_data_args="" fi - python $test_script $coverage_arg -v --with-nosehtml --html-report-file $report_file $xunit_args $structured_data_args $with_framework_test_tools_arg $extra_args + if [ -n "$with_framework_test_tools_arg" ]; then + GALAXY_TEST_TOOL_CONF="config/tool_conf.xml.sample,test/functional/tools/samples_tool_conf.xml" + export GALAXY_TEST_TOOL_CONF + fi + python $test_script $coverage_arg -v --with-nosehtml --html-report-file $report_file $xunit_args $structured_data_args $extra_args else ensure_grunt if [ -n "$watch" ]; then diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 7405fd88749..e7de85bfc26 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -35,10 +35,6 @@ def main(): if framework_test: default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF - else: - # Use tool_conf.xml toolbox. - if _check_arg( '-with_framework_test_tools' ): - default_tool_conf = "%s,%s" % ( 'config/tool_conf.xml.sample', driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF ) start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ From 915b7edcb7b0120d4690c3fa59b97e7dbdcb4a2a Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 19:00:50 -0400 Subject: [PATCH 64/69] Unify and simplify script driver argument processing. --- run_tests.sh | 3 ++- scripts/functional_tests.py | 37 ++++++++++++++++--------------------- test/functional/workflow.py | 2 +- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index e40cef5560a..76be1823e68 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -389,7 +389,8 @@ elif [ -n "$data_managers_test" ] ; then [ -n "$test_id" ] && class=":TestForDataManagerTool_$test_id" || class="" extra_args="functional.test_data_managers$class -data_managers" elif [ -n "$workflow_test" ]; then - extra_args="functional.workflow:WorkflowTestCase $workflow_file" + GALAXY_TEST_WORKFLOW_FILE="$workflow_file" + extra_args="functional.workflow:WorkflowTestCase" elif [ -n "$toolshed_script" ]; then extra_args="$toolshed_script" elif [ -n "$api_script" ]; then diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index e7de85bfc26..668f3669ae4 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -24,17 +24,19 @@ from galaxy.web import buildapp def main(): """Entry point for test driver script.""" # ---- Configuration ------------------------------------------------------ - testing_migrated_tools = _check_arg( '-migrated' ) - testing_installed_tools = _check_arg( '-installed' ) - datatypes_conf_override = None - - default_tool_conf = None + testing_migrated_tools = _check_arg('-migrated') + testing_installed_tools = _check_arg('-installed') + testing_framework_tools = _check_arg('-framework') + testing_data_manager = _check_arg('-data_managers') + testing_workflow = _check_arg('-workflow') testing_shed_tools = testing_migrated_tools or testing_installed_tools - if not testing_shed_tools: - framework_test = _check_arg( '-framework' ) # Run through suite of tests testing framework. - if framework_test: - default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF - datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF + + datatypes_conf_override = None + default_tool_conf = None + + if testing_framework_tools: + default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF + datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ @@ -74,14 +76,11 @@ def main(): testing_migrated_tools, testing_installed_tools, ) - workflow_test = _check_arg( '-workflow', param=True ) - if workflow_test: + if testing_workflow: import functional.workflow - functional.workflow.WorkflowTestCase.workflow_test_file = workflow_test functional.workflow.WorkflowTestCase.master_api_key = get_master_api_key() functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key() - data_manager_test = _check_arg( '-data_managers', param=False ) - if data_manager_test: + if testing_data_manager: import functional.test_data_managers functional.test_data_managers.data_managers = app.data_managers # seems like a hack... functional.test_data_managers.build_tests( @@ -120,15 +119,11 @@ def main(): return 1 -def _check_arg( name, param=False ): +def _check_arg( name ): try: index = sys.argv.index( name ) del sys.argv[ index ] - if param: - ret_val = sys.argv[ index ] - del sys.argv[ index ] - else: - ret_val = True + ret_val = True except ValueError: ret_val = False return ret_val diff --git a/test/functional/workflow.py b/test/functional/workflow.py index c75d8940265..9dbba1fbe7e 100644 --- a/test/functional/workflow.py +++ b/test/functional/workflow.py @@ -17,7 +17,7 @@ class WorkflowTestCase( TwillTestCase ): Kind of a shell of a test case for running workflow tests. Probably needs to look more like test_toolbox. """ - workflow_test_file = None + workflow_test_file = os.environ.get("GALAXY_TEST_WORKFLOW_FILE", None) user_api_key = None master_api_key = None From eac6c10ec93a6f5a610a9d07d1e7601049f4f7cf Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 19:55:53 -0400 Subject: [PATCH 65/69] Allow running Galaxy tests on an existing external instance. --- run_tests.sh | 24 ++++++++++++++++++++++++ scripts/functional_tests.py | 33 ++++++++++++++++++--------------- test/base/twilltestcase.py | 3 ++- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 76be1823e68..80fadd5cb68 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -35,6 +35,14 @@ Run a specific API test: ./run_tests.sh -api test/api/test_tools.py:ToolsTestCase.test_map_over_with_output_format_actions +External Tests: + +A small subset of tests can be run against an existing Galxy +instance. The external Galaxy instance URL can be configured with +--external_url. If this is set eithre --external_master_key or +--external_user_key must be set as well - more tests can be executed +with --external_master_key than with a user key. + Extra options: --verbose_errors Force some tests produce more verbose error reporting. --no_cleanup Do not delete temp files for Python functional tests (-toolshed, -framework, etc...) @@ -45,6 +53,10 @@ Extra options: --dockerize Run tests in a pre-configured Docker container (must be first argument if present). --db For use with --dockerize, run tests using partially migrated 'postgres', 'mysql', or 'sqlite' databases. + --external_url External URL to use for Galaxy testing (only certain tests). + --external_master_key Master API key used to configure external tests. + --external_user_key User API used for external tests - not required if + external_master_key is specified. Environment Variables: @@ -200,6 +212,18 @@ do with_framework_test_tools_arg="-with_framework_test_tools" shift ;; + --external_url) + GALAXY_TEST_EXTERNAL=$2 + shift 2 + ;; + --external_master_key) + GALAXY_CONFIG_MASTER_KEY=$2 + shift 2 + ;; + --external_user_key) + GALAXY_TEST_USER_API_KEY=$2 + shift 2 + ;; -w|-workflow|--workflow) if [ $# -gt 1 ]; then workflow_file=$2 diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 668f3669ae4..db49adfcda8 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -38,14 +38,14 @@ def main(): default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF - start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ + external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None) galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir() app = None server_wrapper = None - if start_server: + if external_galaxy is None: tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) # Configure the database path. galaxy_db_path = driver_util.database_files_path(tempdir) @@ -65,6 +65,8 @@ def main(): galaxy_config, ) log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port)) + else: + log.info("Functional tests will be run against %s" % external_galaxy) # ---- Find tests --------------------------------------------------------- success = False @@ -90,19 +92,20 @@ def main(): user_api_key=get_user_api_key(), ) - # We must make sure that functional.test_toolbox is always imported after - # database_contexts.galaxy_content is set (which occurs in this method above). - # If functional.test_toolbox is imported before database_contexts.galaxy_content - # is set, sa_session will be None in all methods that use it. - import functional.test_toolbox - functional.test_toolbox.toolbox = app.toolbox - # When testing data managers, do not test toolbox. - functional.test_toolbox.build_tests( - app=app, - testing_shed_tools=testing_shed_tools, - master_api_key=get_master_api_key(), - user_api_key=get_user_api_key(), - ) + if app is not None: + # We must make sure that functional.test_toolbox is always imported after + # database_contexts.galaxy_content is set (which occurs in this method above). + # If functional.test_toolbox is imported before database_contexts.galaxy_content + # is set, sa_session will be None in all methods that use it. + import functional.test_toolbox + functional.test_toolbox.toolbox = app.toolbox + # When testing data managers, do not test toolbox. + functional.test_toolbox.build_tests( + app=app, + testing_shed_tools=testing_shed_tools, + master_api_key=get_master_api_key(), + user_api_key=get_user_api_key(), + ) success = driver_util.nose_config_and_run() except: log.exception( "Failure running tests" ) diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py index 0a9af77d3c6..3fe965d1835 100644 --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -48,7 +48,8 @@ class TwillTestCase( unittest.TestCase ): self.history_id = os.environ.get( 'GALAXY_TEST_HISTORY_ID', None ) self.host = os.environ.get( 'GALAXY_TEST_HOST' ) self.port = os.environ.get( 'GALAXY_TEST_PORT' ) - self.url = "http://%s:%s" % ( self.host, self.port ) + default_url = "http://%s:%s" % (self.host, self.port) + self.url = os.environ.get('GALAXY_TEST_EXTERNAL', default_url) self.test_data_resolver = TestDataResolver( ) self.tool_shed_test_file = os.environ.get( 'GALAXY_TOOL_SHED_TEST_FILE', None ) if self.tool_shed_test_file: From 8538c0ed774c89416c80e8688723238386a90736 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 20:29:35 -0400 Subject: [PATCH 66/69] Add comment describing metadata_tool hack. --- lib/galaxy/jobs/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 25d46b57481..91e4dfce46a 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -1664,6 +1664,7 @@ class JobWrapper( object ): metadata_tool = self.app.toolbox.get_tool("__SET_METADATA__") if metadata_tool is not None: # Due to tool shed hacks for migrate and installed tool tests... + # see (``setup_shed_tools_for_test`` in test/base/driver_util.py). dependency_shell_commands = metadata_tool.build_dependency_shell_commands(job_directory=self.working_directory) if dependency_shell_commands: dependency_shell_commands = "; ".join(dependency_shell_commands) From 6faef4df2ec5a1b189594bf528debd521e869d96 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 21:28:28 -0400 Subject: [PATCH 67/69] Introduce a TestDriver class to reduce duplication between test drivers. Classes allow de-duplicating logic and state organization in a different way than methods. Use a common setup, run, tear down paradigm for these tests. --- scripts/functional_tests.py | 100 +++++------- test/base/driver_util.py | 55 ++++++- test/tool_shed/functional_tests.py | 240 ++++++++++++++--------------- 3 files changed, 207 insertions(+), 188 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index db49adfcda8..004a1f06c1f 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -14,63 +14,61 @@ galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pa sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] from base import driver_util -driver_util.configure_environment() log = driver_util.build_logger() from base.api_util import get_master_api_key, get_user_api_key from galaxy.web import buildapp -def main(): - """Entry point for test driver script.""" - # ---- Configuration ------------------------------------------------------ - testing_migrated_tools = _check_arg('-migrated') - testing_installed_tools = _check_arg('-installed') - testing_framework_tools = _check_arg('-framework') - testing_data_manager = _check_arg('-data_managers') - testing_workflow = _check_arg('-workflow') - testing_shed_tools = testing_migrated_tools or testing_installed_tools +class GalaxyTestDriver(driver_util.TestDriver): + """Instantial a Galaxy-style nose TestDriver for testing Galaxy.""" - datatypes_conf_override = None - default_tool_conf = None + def setup(self): + """Setup a Galaxy server for functional test (if needed).""" + # ---- Configuration ------------------------------------------------------ + testing_migrated_tools = _check_arg('-migrated') + testing_installed_tools = _check_arg('-installed') + testing_framework_tools = _check_arg('-framework') + testing_data_manager = _check_arg('-data_managers') + testing_workflow = _check_arg('-workflow') + testing_shed_tools = testing_migrated_tools or testing_installed_tools - if testing_framework_tools: - default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF - datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF + datatypes_conf_override = None + default_tool_conf = None - external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None) + if testing_framework_tools: + default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF + datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF - galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir() + external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None) - app = None - server_wrapper = None + galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir() + self.temp_directories.append(galaxy_test_tmp_dir) - if external_galaxy is None: - tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) - # Configure the database path. - galaxy_db_path = driver_util.database_files_path(tempdir) - galaxy_config = driver_util.setup_galaxy_config( - galaxy_db_path, - use_test_file_dir=not testing_shed_tools, - default_install_db_merged=True, - default_tool_conf=default_tool_conf, - datatypes_conf=datatypes_conf_override, - ) + if external_galaxy is None: + tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + # Configure the database path. + galaxy_db_path = driver_util.database_files_path(tempdir) + galaxy_config = driver_util.setup_galaxy_config( + galaxy_db_path, + use_test_file_dir=not testing_shed_tools, + default_install_db_merged=True, + default_tool_conf=default_tool_conf, + datatypes_conf=datatypes_conf_override, + ) - # ---- Build Application -------------------------------------------------- - app = driver_util.build_galaxy_app(galaxy_config) - server_wrapper = driver_util.launch_server( - app, - buildapp.app_factory, - galaxy_config, - ) - log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port)) - else: - log.info("Functional tests will be run against %s" % external_galaxy) + # ---- Build Application -------------------------------------------------- + app = driver_util.build_galaxy_app(galaxy_config) + server_wrapper = driver_util.launch_server( + app, + buildapp.app_factory, + galaxy_config, + ) + self.server_wrappers.append(server_wrapper) + log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port)) + else: + log.info("Functional tests will be run against %s" % external_galaxy) - # ---- Find tests --------------------------------------------------------- - success = False - try: if testing_shed_tools: driver_util.setup_shed_tools_for_test( app, @@ -106,20 +104,6 @@ def main(): master_api_key=get_master_api_key(), user_api_key=get_user_api_key(), ) - success = driver_util.nose_config_and_run() - except: - log.exception( "Failure running tests" ) - - log.info( "Shutting down" ) - # ---- Tear down ----------------------------------------------------------- - if server_wrapper is not None: - server_wrapper.stop() - server_wrapper = None - driver_util.cleanup_directory(galaxy_test_tmp_dir) - if success: - return 0 - else: - return 1 def _check_arg( name ): @@ -132,4 +116,4 @@ def _check_arg( name ): return ret_val if __name__ == "__main__": - sys.exit( main() ) + driver_util.drive_test(GalaxyTestDriver) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index 5411a11f23d..d19fa83c4ff 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -529,11 +529,61 @@ def launch_server(app, webapp_factory, kwargs, prefix="GALAXY"): ) +class TestDriver(object): + """Responsible for the life-cycle of a Galaxy-style functional test. + + Sets up servers, configures tests, runs nose, and tears things + down. This is somewhat like a Python TestCase - but different + because it is meant to provide a main() endpoint. + """ + + def __init__(self): + """Setup tracked resources.""" + self.server_wrappers = [] + self.temp_directories = [] + + def setup(self): + """Called before tests are built.""" + + def build_tests(self): + """After environment is setup, setup nose tests.""" + + def tear_down(self): + """Cleanup resources tracked by this object.""" + for server_wrapper in self.server_wrappers: + server_wrapper.stop() + for temp_directory in self.temp_directories: + cleanup_directory(temp_directory) + + def run(self): + """Driver whole test. + + Setup environment, build tests (if needed), run test, + and finally cleanup resources. + """ + configure_environment() + self.setup() + self.build_tests() + try: + success = nose_config_and_run() + return 0 if success else 1 + except Exception as e: + log.info("Failure running tests") + raise e + finally: + log.info( "Shutting down") + self.tear_down() + + +def drive_test(test_driver_class): + """Instantiate driver class, run, and exit appropriately.""" + sys.exit(test_driver_class().run()) + + __all__ = [ - "cleanup_directory", - "configure_environment", "copy_database_template", "build_logger", + "drive_test", "FRAMEWORK_UPLOAD_TOOL_CONF", "FRAMEWORK_SAMPLE_TOOLS_CONF", "FRAMEWORK_DATATYPES_CONF", @@ -542,5 +592,6 @@ __all__ = [ "nose_config_and_run", "setup_galaxy_config", "setup_shed_tools_for_test", + "TestDriver", "wait_for_http_server", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index f4860ef1eed..dca6e24db31 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -15,9 +15,7 @@ galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pa sys.path[0:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] from base import driver_util -driver_util.configure_environment() log = driver_util.build_logger() -tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir() # This is for the tool shed application. from galaxy.webapps.tool_shed import buildapp as toolshedbuildapp @@ -48,138 +46,124 @@ shed_data_manager_conf_xml_template = ''' ''' -def main(): - """Entry point for test driver script.""" - # ---- Configuration ------------------------------------------------------ - if not os.path.isdir( tool_shed_test_tmp_dir ): - os.mkdir( tool_shed_test_tmp_dir ) - shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir, prefix="TOOL_SHED") - shed_tool_data_table_conf_file = os.environ.get( 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml' ) ) - galaxy_shed_data_manager_conf_file = os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_data_manager_conf.xml' ) ) - default_tool_data_table_config_path = os.path.join( tool_shed_test_tmp_dir, 'tool_data_table_conf.xml' ) - galaxy_shed_tool_conf_file = os.environ.get( 'GALAXY_TEST_SHED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml' ) ) - galaxy_migrated_tool_conf_file = os.environ.get( 'GALAXY_TEST_MIGRATED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_migrated_tool_conf.xml' ) ) - galaxy_tool_sheds_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_SHEDS_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_sheds_conf.xml' ) ) - if 'GALAXY_TEST_TOOL_DATA_PATH' in os.environ: - tool_data_path = os.environ.get( 'GALAXY_TEST_TOOL_DATA_PATH' ) - else: - tool_data_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - os.environ[ 'GALAXY_TEST_TOOL_DATA_PATH' ] = tool_data_path - galaxy_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir) - shed_file_path = os.path.join( shed_db_path, 'files' ) - hgweb_config_file_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - new_repos_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - galaxy_shed_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - galaxy_migrated_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) - hgweb_config_dir = hgweb_config_file_path - os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir - print "Directory location for hgweb.config:", hgweb_config_dir - toolshed_database_conf = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED") - kwargs = dict( admin_users='test@bx.psu.edu', - allow_user_creation=True, - allow_user_deletion=True, - datatype_converters_config_file='datatype_converters_conf.xml.sample', - file_path=shed_file_path, - hgweb_config_dir=hgweb_config_dir, - job_queue_workers=5, - id_secret='changethisinproductiontoo', - log_destination="stdout", - new_file_path=new_repos_path, - running_functional_tests=True, - shed_tool_data_table_config=shed_tool_data_table_conf_file, - smtp_server='smtp.dummy.string.tld', - email_from='functional@localhost', - template_path='templates', - tool_parse_help=False, - use_heartbeat=False ) - kwargs.update(toolshed_database_conf) - # Generate the tool_data_table_conf.xml file. - file( default_tool_data_table_config_path, 'w' ).write( tool_data_table_conf_xml_template ) - # Generate the shed_tool_data_table_conf.xml file. - file( shed_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) - os.environ[ 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF' ] = shed_tool_data_table_conf_file - # ---- Build Tool Shed Application -------------------------------------------------- - toolshedapp = driver_util.build_shed_app(kwargs) +class ToolShedTestDriver(driver_util.TestDriver): + """Instantial a Galaxy-style nose TestDriver for testing the tool shed.""" - # ---- Run tool shed webserver ------------------------------------------------------ - # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') - kwargs['global_conf']['database_connection'] = kwargs["database_connection"] - tool_shed_server_wrapper = driver_util.launch_server( - toolshedapp, - toolshedbuildapp.app_factory, - kwargs, - prefix="TOOL_SHED", - ) - tool_shed_test_host = tool_shed_server_wrapper.host - tool_shed_test_port = tool_shed_server_wrapper.port - log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_port ) ) + def setup(self): + """Entry point for test driver script.""" + # ---- Configuration ------------------------------------------------------ + tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir() + if not os.path.isdir( tool_shed_test_tmp_dir ): + os.mkdir( tool_shed_test_tmp_dir ) + self.temp_directories.append(tool_shed_test_tmp_dir) + shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir, prefix="TOOL_SHED") + shed_tool_data_table_conf_file = os.environ.get( 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF', os.path.join( tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml' ) ) + galaxy_shed_data_manager_conf_file = os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_data_manager_conf.xml' ) ) + default_tool_data_table_config_path = os.path.join( tool_shed_test_tmp_dir, 'tool_data_table_conf.xml' ) + galaxy_shed_tool_conf_file = os.environ.get( 'GALAXY_TEST_SHED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml' ) ) + galaxy_migrated_tool_conf_file = os.environ.get( 'GALAXY_TEST_MIGRATED_TOOL_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_migrated_tool_conf.xml' ) ) + galaxy_tool_sheds_conf_file = os.environ.get( 'GALAXY_TEST_TOOL_SHEDS_CONF', os.path.join( tool_shed_test_tmp_dir, 'test_sheds_conf.xml' ) ) + if 'GALAXY_TEST_TOOL_DATA_PATH' in os.environ: + tool_data_path = os.environ.get( 'GALAXY_TEST_TOOL_DATA_PATH' ) + else: + tool_data_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) + os.environ[ 'GALAXY_TEST_TOOL_DATA_PATH' ] = tool_data_path + galaxy_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir) + shed_file_path = os.path.join( shed_db_path, 'files' ) + hgweb_config_file_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) + new_repos_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) + galaxy_shed_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) + galaxy_migrated_tool_path = tempfile.mkdtemp( dir=tool_shed_test_tmp_dir ) + hgweb_config_dir = hgweb_config_file_path + os.environ[ 'TEST_HG_WEB_CONFIG_DIR' ] = hgweb_config_dir + print "Directory location for hgweb.config:", hgweb_config_dir + toolshed_database_conf = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED") + kwargs = dict( admin_users='test@bx.psu.edu', + allow_user_creation=True, + allow_user_deletion=True, + datatype_converters_config_file='datatype_converters_conf.xml.sample', + file_path=shed_file_path, + hgweb_config_dir=hgweb_config_dir, + job_queue_workers=5, + id_secret='changethisinproductiontoo', + log_destination="stdout", + new_file_path=new_repos_path, + running_functional_tests=True, + shed_tool_data_table_config=shed_tool_data_table_conf_file, + smtp_server='smtp.dummy.string.tld', + email_from='functional@localhost', + template_path='templates', + tool_parse_help=False, + use_heartbeat=False ) + kwargs.update(toolshed_database_conf) + # Generate the tool_data_table_conf.xml file. + file( default_tool_data_table_config_path, 'w' ).write( tool_data_table_conf_xml_template ) + # Generate the shed_tool_data_table_conf.xml file. + file( shed_tool_data_table_conf_file, 'w' ).write( tool_data_table_conf_xml_template ) + os.environ[ 'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF' ] = shed_tool_data_table_conf_file + # ---- Build Tool Shed Application -------------------------------------------------- + toolshedapp = driver_util.build_shed_app(kwargs) - # ---- Optionally start up a Galaxy instance ------------------------------------------------------ - if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ: - # Generate the shed_tool_conf.xml file. - tool_sheds_conf_template_parser = string.Template( tool_sheds_conf_xml_template ) - tool_sheds_conf_xml = tool_sheds_conf_template_parser.safe_substitute( shed_url=tool_shed_test_host, shed_port=tool_shed_test_port ) - file( galaxy_tool_sheds_conf_file, 'w' ).write( tool_sheds_conf_xml ) - # Generate the tool_sheds_conf.xml file. - shed_tool_conf_template_parser = string.Template( shed_tool_conf_xml_template ) - shed_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute( shed_tool_path=galaxy_shed_tool_path ) - file( galaxy_shed_tool_conf_file, 'w' ).write( shed_tool_conf_xml ) - # Generate the migrated_tool_conf.xml file. - migrated_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute( shed_tool_path=galaxy_migrated_tool_path ) - file( galaxy_migrated_tool_conf_file, 'w' ).write( migrated_tool_conf_xml ) - os.environ[ 'GALAXY_TEST_SHED_TOOL_CONF' ] = galaxy_shed_tool_conf_file - # Generate shed_data_manager_conf.xml - if not os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF' ): - open( galaxy_shed_data_manager_conf_file, 'wb' ).write( shed_data_manager_conf_xml_template ) - kwargs = dict( migrated_tools_config=galaxy_migrated_tool_conf_file, - shed_data_manager_config_file=galaxy_shed_data_manager_conf_file, - shed_tool_path=galaxy_shed_tool_path, - tool_data_path=tool_data_path, - - tool_sheds_config_file=galaxy_tool_sheds_conf_file ) - kwargs.update( - driver_util.setup_galaxy_config( - galaxy_db_path, - use_test_file_dir=False, - default_install_db_merged=False, - default_tool_data_table_config_path=default_tool_data_table_config_path, - default_shed_tool_data_table_config=shed_tool_data_table_conf_file, - enable_tool_shed_check=True, - shed_tool_conf=galaxy_shed_tool_conf_file, - update_integrated_tool_panel=True, - ) - ) - print "Galaxy database connection:", kwargs["database_connection"] - - # ---- Run galaxy webserver ------------------------------------------------------ - galaxyapp = driver_util.build_galaxy_app(kwargs) - galaxy_server_wrapper = driver_util.launch_server( - galaxyapp, - galaxybuildapp.app_factory, + # ---- Run tool shed webserver ------------------------------------------------------ + # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py') + kwargs['global_conf']['database_connection'] = kwargs["database_connection"] + tool_shed_server_wrapper = driver_util.launch_server( + toolshedapp, + toolshedbuildapp.app_factory, kwargs, + prefix="TOOL_SHED", ) - log.info("Galaxy tests will be run against %s:%s" % (galaxy_server_wrapper.host, galaxy_server_wrapper.port)) + self.server_wrappers.append(tool_shed_server_wrapper) + tool_shed_test_host = tool_shed_server_wrapper.host + tool_shed_test_port = tool_shed_server_wrapper.port + log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_port ) ) - # ---- Find tests --------------------------------------------------------- - success = False - try: - success = driver_util.nose_config_and_run() - except: - log.exception( "Failure running tests" ) + # ---- Optionally start up a Galaxy instance ------------------------------------------------------ + if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ: + # Generate the shed_tool_conf.xml file. + tool_sheds_conf_template_parser = string.Template( tool_sheds_conf_xml_template ) + tool_sheds_conf_xml = tool_sheds_conf_template_parser.safe_substitute( shed_url=tool_shed_test_host, shed_port=tool_shed_test_port ) + file( galaxy_tool_sheds_conf_file, 'w' ).write( tool_sheds_conf_xml ) + # Generate the tool_sheds_conf.xml file. + shed_tool_conf_template_parser = string.Template( shed_tool_conf_xml_template ) + shed_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute( shed_tool_path=galaxy_shed_tool_path ) + file( galaxy_shed_tool_conf_file, 'w' ).write( shed_tool_conf_xml ) + # Generate the migrated_tool_conf.xml file. + migrated_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute( shed_tool_path=galaxy_migrated_tool_path ) + file( galaxy_migrated_tool_conf_file, 'w' ).write( migrated_tool_conf_xml ) + os.environ[ 'GALAXY_TEST_SHED_TOOL_CONF' ] = galaxy_shed_tool_conf_file + # Generate shed_data_manager_conf.xml + if not os.environ.get( 'GALAXY_SHED_DATA_MANAGER_CONF' ): + open( galaxy_shed_data_manager_conf_file, 'wb' ).write( shed_data_manager_conf_xml_template ) + kwargs = dict( migrated_tools_config=galaxy_migrated_tool_conf_file, + shed_data_manager_config_file=galaxy_shed_data_manager_conf_file, + shed_tool_path=galaxy_shed_tool_path, + tool_data_path=tool_data_path, + tool_sheds_config_file=galaxy_tool_sheds_conf_file ) + kwargs.update( + driver_util.setup_galaxy_config( + galaxy_db_path, + use_test_file_dir=False, + default_install_db_merged=False, + default_tool_data_table_config_path=default_tool_data_table_config_path, + default_shed_tool_data_table_config=shed_tool_data_table_conf_file, + enable_tool_shed_check=True, + shed_tool_conf=galaxy_shed_tool_conf_file, + update_integrated_tool_panel=True, + ) + ) + print "Galaxy database connection:", kwargs["database_connection"] - log.info( "Shutting down" ) - # ---- Tear down ----------------------------------------------------------- - tool_shed_server_wrapper.stop() - tool_shed_server_wrapper = None - if galaxy_server_wrapper is not None: - galaxy_server_wrapper.stop() - galaxy_server_wrapper = None - driver_util.cleanup_directory(tool_shed_test_tmp_dir) - if success: - return 0 - else: - return 1 + # ---- Run galaxy webserver ------------------------------------------------------ + galaxyapp = driver_util.build_galaxy_app(kwargs) + galaxy_server_wrapper = driver_util.launch_server( + galaxyapp, + galaxybuildapp.app_factory, + kwargs, + ) + log.info("Galaxy tests will be run against %s:%s" % (galaxy_server_wrapper.host, galaxy_server_wrapper.port)) + self.server_wrappers.append(galaxy_server_wrapper) if __name__ == "__main__": - sys.exit( main() ) + driver_util.drive_test(ToolShedTestDriver) From 05a2f441261c176dfe2cc802d4743aad6652a9ea Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 28 Mar 2016 22:05:20 -0400 Subject: [PATCH 68/69] Separate different style Galaxy testing behaviors into classes. --- scripts/functional_tests.py | 158 ++++++++++++++++++------------------ test/base/driver_util.py | 70 +++++++++++++++- 2 files changed, 148 insertions(+), 80 deletions(-) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 004a1f06c1f..b1817912fa1 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -8,7 +8,6 @@ that script for a list of options. import os import os.path import sys -import tempfile galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] @@ -17,93 +16,96 @@ from base import driver_util log = driver_util.build_logger() from base.api_util import get_master_api_key, get_user_api_key -from galaxy.web import buildapp -class GalaxyTestDriver(driver_util.TestDriver): - """Instantial a Galaxy-style nose TestDriver for testing Galaxy.""" +class MigratedToolsGalaxyTestDriver(driver_util.GalaxyTestDriver): + """Instantiate a Galaxy-style nose TestDriver for testing migrated Galaxy tools.""" - def setup(self): - """Setup a Galaxy server for functional test (if needed).""" - # ---- Configuration ------------------------------------------------------ - testing_migrated_tools = _check_arg('-migrated') - testing_installed_tools = _check_arg('-installed') - testing_framework_tools = _check_arg('-framework') - testing_data_manager = _check_arg('-data_managers') - testing_workflow = _check_arg('-workflow') - testing_shed_tools = testing_migrated_tools or testing_installed_tools + testing_shed_tools = True - datatypes_conf_override = None - default_tool_conf = None + def build_tests(self): + """Build migrated tool test methods.""" + self.setup_shed_tools( + testing_migrated_tools=True, + ) + self.build_tool_tests() - if testing_framework_tools: - default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF - datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF - external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None) +class InstalledToolsGalaxyTestDriver(driver_util.GalaxyTestDriver): + """Galaxy-style nose TestDriver for testing installed Galaxy tools.""" - galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir() - self.temp_directories.append(galaxy_test_tmp_dir) + testing_shed_tools = True - if external_galaxy is None: - tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) - # Configure the database path. - galaxy_db_path = driver_util.database_files_path(tempdir) - galaxy_config = driver_util.setup_galaxy_config( - galaxy_db_path, - use_test_file_dir=not testing_shed_tools, - default_install_db_merged=True, - default_tool_conf=default_tool_conf, - datatypes_conf=datatypes_conf_override, - ) + def build_tests(self): + """Build installed tool test methods.""" + self.setup_shed_tools( + testing_installed_tools=True, + ) + self.build_tool_tests() - # ---- Build Application -------------------------------------------------- - app = driver_util.build_galaxy_app(galaxy_config) - server_wrapper = driver_util.launch_server( - app, - buildapp.app_factory, - galaxy_config, - ) - self.server_wrappers.append(server_wrapper) - log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port)) - else: - log.info("Functional tests will be run against %s" % external_galaxy) - if testing_shed_tools: - driver_util.setup_shed_tools_for_test( - app, - galaxy_test_tmp_dir, - testing_migrated_tools, - testing_installed_tools, - ) - if testing_workflow: - import functional.workflow - functional.workflow.WorkflowTestCase.master_api_key = get_master_api_key() - functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key() - if testing_data_manager: - import functional.test_data_managers - functional.test_data_managers.data_managers = app.data_managers # seems like a hack... - functional.test_data_managers.build_tests( - tmp_dir=galaxy_test_tmp_dir, - testing_shed_tools=testing_shed_tools, - master_api_key=get_master_api_key(), - user_api_key=get_user_api_key(), - ) +class DefaultGalaxyTestDriver(driver_util.GalaxyTestDriver): + """Default Galaxy-style nose test driver. - if app is not None: - # We must make sure that functional.test_toolbox is always imported after - # database_contexts.galaxy_content is set (which occurs in this method above). - # If functional.test_toolbox is imported before database_contexts.galaxy_content - # is set, sa_session will be None in all methods that use it. - import functional.test_toolbox - functional.test_toolbox.toolbox = app.toolbox - # When testing data managers, do not test toolbox. - functional.test_toolbox.build_tests( - app=app, - testing_shed_tools=testing_shed_tools, - master_api_key=get_master_api_key(), - user_api_key=get_user_api_key(), - ) + Just populate non-shed tool tests and run tests. Works + for tool tests, regular twill tests, and API testing. + """ + + def build_tests(self): + """Build framework tool test methods.""" + self.build_tool_tests() + + +class FrameworkToolsGalaxyTestDriver(DefaultGalaxyTestDriver): + """Galaxy-style nose TestDriver for testing framework Galaxy tools.""" + + default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF + datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF + + +class DataManagersGalaxyTestDriver(driver_util.GalaxyTestDriver): + """Galaxy-style nose TestDriver for testing framework Galaxy tools.""" + + def build_tests(self): + """Build data manager test methods.""" + import functional.test_data_managers + functional.test_data_managers.data_managers = self.app.data_managers + functional.test_data_managers.build_tests( + tmp_dir=self.galaxy_test_tmp_dir, + testing_shed_tools=self.testing_shed_tools, + master_api_key=get_master_api_key(), + user_api_key=get_user_api_key(), + ) + + +class WorkflowGalaxyTestDriver(driver_util.GalaxyTestDriver): + """Galaxy-style nose TestDriver for testing a Galaxy workflow.""" + + def build_tests(self): + """Setup WorkflowTestCase for test execution.""" + import functional.workflow + functional.workflow.WorkflowTestCase.master_api_key = get_master_api_key() + functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key() + + +TEST_DRIVERS = { + '-migrated': MigratedToolsGalaxyTestDriver, + '-installed': InstalledToolsGalaxyTestDriver, + '-framework': FrameworkToolsGalaxyTestDriver, + '-data_managers': DataManagersGalaxyTestDriver, + '-workflow': WorkflowGalaxyTestDriver, +} + + +def find_test_driver(): + """Look at command-line args and find the correct Galaxy test driver.""" + test_driver = DefaultGalaxyTestDriver + + for key in TEST_DRIVERS.keys(): + if _check_arg(key): + test_driver = TEST_DRIVERS[key] + + return test_driver def _check_arg( name ): @@ -116,4 +118,4 @@ def _check_arg( name ): return ret_val if __name__ == "__main__": - driver_util.drive_test(GalaxyTestDriver) + driver_util.drive_test(find_test_driver()) diff --git a/test/base/driver_util.py b/test/base/driver_util.py index d19fa83c4ff..2cbb026f6cb 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -22,7 +22,7 @@ import nose.plugins.manager from paste import httpserver -from .api_util import get_master_api_key +from .api_util import get_master_api_key, get_user_api_key from .tool_shed_util import parse_tool_panel_config from .nose_util import run from .instrument import StructuredTestDataPlugin @@ -30,6 +30,7 @@ from .instrument import StructuredTestDataPlugin from functional import database_contexts from galaxy.app import UniverseApplication as GalaxyUniverseApplication +from galaxy.web import buildapp from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication from galaxy.util import asbool from galaxy.util.properties import load_app_properties @@ -575,6 +576,72 @@ class TestDriver(object): self.tear_down() +class GalaxyTestDriver(TestDriver): + """Instantial a Galaxy-style nose TestDriver for testing Galaxy.""" + + testing_shed_tools = False + + def setup(self): + """Setup a Galaxy server for functional test (if needed).""" + self.external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None) + self.galaxy_test_tmp_dir = get_galaxy_test_tmp_dir() + self.temp_directories.append(self.galaxy_test_tmp_dir) + + testing_shed_tools = getattr(self, "testing_shed_tools", False) + default_tool_conf = getattr(self, "default_tool_conf", None) + datatypes_conf_override = getattr(self, "datatypes_conf_override", None) + + if self.external_galaxy is None: + tempdir = tempfile.mkdtemp(dir=self.galaxy_test_tmp_dir) + # Configure the database path. + galaxy_db_path = database_files_path(tempdir) + galaxy_config = setup_galaxy_config( + galaxy_db_path, + use_test_file_dir=not testing_shed_tools, + default_install_db_merged=True, + default_tool_conf=default_tool_conf, + datatypes_conf=datatypes_conf_override, + ) + + # ---- Build Application -------------------------------------------------- + self.app = build_galaxy_app(galaxy_config) + server_wrapper = launch_server( + self.app, + buildapp.app_factory, + galaxy_config, + ) + self.server_wrappers.append(server_wrapper) + log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port)) + else: + log.info("Functional tests will be run against %s" % self.external_galaxy) + + def setup_shed_tools(self, testing_migrated_tools=False, testing_installed_tools=True): + setup_shed_tools_for_test( + self.app, + self.galaxy_test_tmp_dir, + testing_migrated_tools, + testing_installed_tools + ) + + def build_tool_tests(self): + if self.app is None: + return + + # We must make sure that functional.test_toolbox is always imported after + # database_contexts.galaxy_content is set (which occurs in this method above). + # If functional.test_toolbox is imported before database_contexts.galaxy_content + # is set, sa_session will be None in all methods that use it. + import functional.test_toolbox + functional.test_toolbox.toolbox = self.app.toolbox + # When testing data managers, do not test toolbox. + functional.test_toolbox.build_tests( + app=self.app, + testing_shed_tools=self.testing_shed_tools, + master_api_key=get_master_api_key(), + user_api_key=get_user_api_key(), + ) + + def drive_test(test_driver_class): """Instantiate driver class, run, and exit appropriately.""" sys.exit(test_driver_class().run()) @@ -591,7 +658,6 @@ __all__ = [ "get_webapp_global_conf", "nose_config_and_run", "setup_galaxy_config", - "setup_shed_tools_for_test", "TestDriver", "wait_for_http_server", ] From b8ecf36f2ae52af1cda3eac64f53400e56e895db Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 29 Mar 2016 08:26:21 -0400 Subject: [PATCH 69/69] Improve testing environment variable and CLI documentation. Document many more variables and improve documentation of what is there. Include fixes recommended by @nsoranzo. --- run_tests.sh | 129 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 89 insertions(+), 40 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 80fadd5cb68..e5c13aa9e20 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -39,58 +39,107 @@ External Tests: A small subset of tests can be run against an existing Galxy instance. The external Galaxy instance URL can be configured with ---external_url. If this is set eithre --external_master_key or +--external_url. If this is set, either --external_master_key or --external_user_key must be set as well - more tests can be executed with --external_master_key than with a user key. Extra options: + --verbose_errors Force some tests produce more verbose error reporting. - --no_cleanup Do not delete temp files for Python functional tests (-toolshed, -framework, etc...) - --debug On python test error or failure invoke a pdb shell for interactive debugging of the test - --report_file Path of HTML report to produce (for Python Galaxy functional tests). - --xunit_report_file Path of XUnit report to produce (for Python Galaxy functional tests). - --skip-venv Do not create .venv (passes this flag to common_startup.sh) - --dockerize Run tests in a pre-configured Docker container (must be first argument if present). - --db For use with --dockerize, run tests using partially migrated 'postgres', 'mysql', - or 'sqlite' databases. - --external_url External URL to use for Galaxy testing (only certain tests). - --external_master_key Master API key used to configure external tests. - --external_user_key User API used for external tests - not required if + --no_cleanup Do not delete temp files for Python functional tests + (-toolshed, -framework, etc...) + --debug On python test error or failure invoke a pdb shell for + interactive debugging of the test + --report_file Path of HTML report to produce (for Python Galaxy + functional tests). + --xunit_report_file Path of XUnit report to produce (for Python Galaxy + functional tests). + --skip-venv Do not create .venv (passes this flag to + common_startup.sh) + --dockerize Run tests in a pre-configured Docker container (must be + first argument if present). + --db For use with --dockerize, run tests using partially + migrated 'postgres', 'mysql', or 'sqlite' databases. + --external_url External URL to use for Galaxy testing (only certain + tests). + --external_master_key Master API key used to configure external tests. + --external_user_key User API used for external tests - not required if external_master_key is specified. Environment Variables: -In addition to the above command-line options, many environment Variables -can be used to control the Galaxy functional testing processing. +In addition to the above command-line options, many environment variables +can be used to control the Galaxy functional testing processing. Command-line +options above like (--external_url) will set environment variables - in such +cases the command line argument takes precedent over environment variables set +at the time of running this script. Functional Test Environment Variables -GALAXY_TEST_DBURI Database connection string used for functional test - database for Galaxy. -GALAXY_TEST_INSTALL_DBURI Database connection string used for functional test - database for Galaxy's install framework. -GALAXY_TEST_INSTALL_DB_MERGED Set to use same database for Galaxy and install framework, - this defaults to True for Galaxy tests an False for shed tests. -GALAXY_TEST_DB_TEMPLATE If GALAXY_TEST_DBURI is unset, this URL can be retrieved - and should be an sqlite database that will be upgraded - and tested against. -GALAXY_TEST_TMP_DIR Temp directory used for files required by Galaxy server setup - for Galaxy functional tests. -HTTP_ACCEPT_LANGUAGE Defaults to 'en' -GALAXY_TEST_NO_CLEANUP Do not cleanup main test directory after tests, - the deprecated option TOOL_SHED_TEST_NO_CLEANUP does the - same thing. -GALAXY_TEST_HOST Host to use for Galaxy server setup for testing. -GALAXY_TEST_PORT Port to use for Galaxy server setup for testing. -GALAXY_TEST_TOOL_PATH Defaults to 'tools' -GALAXY_TEST_SHED_TOOL_CONF Shed toolbox conf (defaults to config/shed_tool_conf.xml) - used when testing installed to tools with -installed. -TOOL_SHED_TEST_HOST Host to use for shed server setup for testing. -TOOL_SHED_TEST_PORT Port to use for shed server setup for testing. -TOOL_SHED_TEST_FILE_DIR Defaults to test/tool_shed/test_data. -TOOL_SHED_TEST_TMP_DIR Defaults to random /tmp directory - place for tool shed - test server files to be placed. -TOOL_SHED_TEST_OMIT_GALAXY Do not launch a Galaxy server for tool shed testing. +GALAXY_TEST_DBURI Database connection string used for functional + test database for Galaxy. +GALAXY_TEST_INSTALL_DBURI Database connection string used for functional + test database for Galaxy's install framework. +GALAXY_TEST_INSTALL_DB_MERGED Set to use same database for Galaxy and install + framework, this defaults to True for Galaxy + tests an False for shed tests. +GALAXY_TEST_DB_TEMPLATE If GALAXY_TEST_DBURI is unset, this URL can be + retrieved and should be an sqlite database that + will be upgraded and tested against. +GALAXY_TEST_TMP_DIR Temp directory used for files required by + Galaxy server setup for Galaxy functional tests. +GALAXY_TEST_SAVE Location to save certain test files (such as + tool outputs). +GALAXY_TEST_EXTERNAL Target an external Galaxy as part of testing. +GALAXY_CONFIG_MASTER_KEY Master or admin API key to use as part of + testing with GALAXY_TEST_EXTERNAL. +GALAXY_TEST_USER_API_KEY User API key to use as part of testing with + GALAXY_TEST_EXTERNAL. +GALAXY_TEST_HISTORY_ID Point casperjs tests at specific external + history for testing. +GALAXY_TEST_WORKFLOW_FILE Point casperjs tests at specific workflow + file for testing. +GALAXY_TEST_VERBOSE_ERRORS Enable more verbose errors during API tests. +GALAXY_TEST_UPLOAD_ASYNC Upload tool test inputs asynchronously (may + overwhelm sqlite database). +GALAXY_TEST_RAW_DIFF Don't slice up tool test diffs to keep output + managable - print all output. (default off) +GALAXY_TEST_DEFAULT_WAIT Max time allowed for a tool test before Galaxy + gives up (default 86400) - tools may define a + maxseconds attribute to extend this. +GALAXY_TEST_TOOL_DEPENDENCY_DIR tool dependency dir to use for Galaxy during + functional tests. +GALAXY_TEST_FILE_DIR Test data sources (default to + test-data,https://github.com/galaxyproject/galaxy-test-data.git) +GALAXY_TEST_DIRECTORY $GALAXY_ROOT/test +GALAXY_TEST_TOOL_DATA_PATH Set to override tool data path during tool + shed tests. +GALAXY_TEST_FETCH_DATA Fetch remote test data to + GALAXY_TEST_DATA_REPO_CACHE as part of tool + tests if it is not available locally (default + to True). Requires git to be available on the + command-line. +GALAXY_TEST_DATA_REPO_CACHE Where to cache remote test data to (default to + test-data-cache). +HTTP_ACCEPT_LANGUAGE Defaults to 'en' +GALAXY_TEST_NO_CLEANUP Do not cleanup main test directory after tests, + the deprecated option TOOL_SHED_TEST_NO_CLEANUP + does the same thing. +GALAXY_TEST_HOST Host to use for Galaxy server setup for + testing. +GALAXY_TEST_PORT Port to use for Galaxy server setup for + testing. +GALAXY_TEST_TOOL_PATH Path defaulting to 'tools'. +GALAXY_TEST_SHED_TOOL_CONF Shed toolbox conf (defaults to + config/shed_tool_conf.xml) used when testing + installed to tools with -installed. +TOOL_SHED_TEST_HOST Host to use for shed server setup for testing. +TOOL_SHED_TEST_PORT Port to use for shed server setup for testing. +TOOL_SHED_TEST_FILE_DIR Defaults to test/tool_shed/test_data. +TOOL_SHED_TEST_TMP_DIR Defaults to random /tmp directory - place for + tool shed test server files to be placed. +TOOL_SHED_TEST_OMIT_GALAXY Do not launch a Galaxy server for tool shed + testing. Unit Test Environment Variables