commit/galaxy-central: inithello: Core twill framework for automatically installing a defined list of tool shed repositories. This is the first component of a suite of scripts to install a repository, then run all functional tests defined in its tools, and record the result.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/b9a5aee402b3/ changeset: b9a5aee402b3 user: inithello date: 2013-02-15 20:13:33 summary: Core twill framework for automatically installing a defined list of tool shed repositories. This is the first component of a suite of scripts to install a repository, then run all functional tests defined in its tools, and record the result. affected #: 7 files diff -r 8e430a612aee6bb14fe373ae9e67d80ba84723d9 -r b9a5aee402b31c2a316de0f68efe66fdb141418e test/install_and_test_tool_shed_repositories/__init__.py --- /dev/null +++ b/test/install_and_test_tool_shed_repositories/__init__.py @@ -0,0 +1,1 @@ +"""Install and test tool shed repositories.""" \ No newline at end of file diff -r 8e430a612aee6bb14fe373ae9e67d80ba84723d9 -r b9a5aee402b31c2a316de0f68efe66fdb141418e test/install_and_test_tool_shed_repositories/base/test_db_util.py --- /dev/null +++ b/test/install_and_test_tool_shed_repositories/base/test_db_util.py @@ -0,0 +1,47 @@ +import logging +import galaxy.model as model +from galaxy.model.orm import and_ +from galaxy.model.mapping import context as sa_session + +log = logging.getLogger(__name__) + +def delete_obj( obj ): + sa_session.delete( obj ) + sa_session.flush() +def delete_user_roles( user ): + for ura in user.roles: + sa_session.delete( ura ) + sa_session.flush() +def flush( obj ): + sa_session.add( obj ) + sa_session.flush() +def get_repository( repository_id ): + return sa_session.query( model.ToolShedRepository ) \ + .filter( model.ToolShedRepository.table.c.id == repository_id ) \ + .first() +def get_installed_repository_by_name_owner_changeset_revision( name, owner, changeset_revision ): + return sa_session.query( model.ToolShedRepository ) \ + .filter( and_( model.ToolShedRepository.table.c.name == name, + model.ToolShedRepository.table.c.owner == owner, + model.ToolShedRepository.table.c.installed_changeset_revision == changeset_revision ) ) \ + .one() +def get_private_role( user ): + for role in user.all_roles(): + if role.name == user.email and role.description == 'Private Role for %s' % user.email: + return role + raise AssertionError( "Private role not found for user '%s'" % user.email ) +def mark_obj_deleted( obj ): + obj.deleted = True + sa_session.add( obj ) + sa_session.flush() +def refresh( obj ): + sa_session.refresh( obj ) +def get_private_role( user ): + for role in user.all_roles(): + if role.name == user.email and role.description == 'Private Role for %s' % user.email: + return role + raise AssertionError( "Private role not found for user '%s'" % user.email ) +def get_user( email ): + return sa_session.query( model.User ) \ + .filter( model.User.table.c.email==email ) \ + .first() diff -r 8e430a612aee6bb14fe373ae9e67d80ba84723d9 -r b9a5aee402b31c2a316de0f68efe66fdb141418e test/install_and_test_tool_shed_repositories/base/twilltestcase.py --- /dev/null +++ b/test/install_and_test_tool_shed_repositories/base/twilltestcase.py @@ -0,0 +1,124 @@ +import galaxy.model as model +import common, string, os, re, test_db_util, simplejson, logging, time, sys +import galaxy.util as util +from base.twilltestcase import tc, from_json_string, TwillTestCase, security, urllib +from galaxy.tool_shed.encoding_util import tool_shed_encode, tool_shed_decode + +log = logging.getLogger( __name__ ) + +class InstallTestRepository( TwillTestCase ): + def setUp( self ): + # Security helper + id_secret = os.environ.get( 'GALAXY_INSTALL_TEST_SECRET', 'changethisinproductiontoo' ) + self.security = security.SecurityHelper( id_secret=id_secret ) + self.history_id = None + self.test_tmp_dir = os.environ.get( 'GALAXY_INSTALL_TEST_TMP_DIR', None) + self.host = os.environ.get( 'GALAXY_INSTALL_TEST_HOST' ) + self.port = os.environ.get( 'GALAXY_INSTALL_TEST_PORT' ) + self.url = "http://%s:%s" % ( self.host, self.port ) + self.shed_tool_data_table_conf = os.environ.get( 'GALAXY_INSTALL_TEST_SHED_TOOL_DATA_TABLE_CONF' ) + self.file_dir = os.environ.get( 'GALAXY_INSTALL_TEST_FILE_DIR', None ) + self.tool_data_path = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_DATA_PATH' ) + self.shed_tool_conf = os.environ.get( 'GALAXY_INSTALL_TEST_SHED_TOOL_CONF' ) + # TODO: Figure out a way to alter these attributes during tests. + self.galaxy_tool_dependency_dir = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR' ) + self.shed_tools_dict = {} + self.home() + def initiate_installation_process( self, + install_tool_dependencies=False, + install_repository_dependencies=True, + no_changes=True, + new_tool_panel_section=None ): + html = self.last_page() + # Since the installation process is by necessity asynchronous, we have to get the parameters to 'manually' initiate the + # installation process. This regex will return the tool shed repository IDs in group(1), the encoded_kwd parameter in + # group(2), and the reinstalling flag in group(3) and pass them to the manage_repositories method in the Galaxy + # admin_toolshed controller. + install_parameters = re.search( 'initiate_repository_installation\( "([^"]+)", "([^"]+)", "([^"]+)" \);', html ) + if install_parameters: + iri_ids = install_parameters.group(1) + # In some cases, the returned iri_ids are of the form: "[u'<encoded id>', u'<encoded id>']" + # This regex ensures that non-hex characters are stripped out of the list, so that util.listify/decode_id + # will handle them correctly. It's safe to pass the cleaned list to manage_repositories, because it can parse + # comma-separated values. + repository_ids = str( iri_ids ) + repository_ids = re.sub( '[^a-fA-F0-9,]+', '', repository_ids ) + encoded_kwd = install_parameters.group(2) + reinstalling = install_parameters.group(3) + url = '/admin_toolshed/manage_repositories?operation=install&tool_shed_repository_ids=%s&encoded_kwd=%s&reinstalling=%s' % \ + ( ','.join( util.listify( repository_ids ) ), encoded_kwd, reinstalling ) + self.visit_url( url ) + return util.listify( repository_ids ) + def install_repository( self, repository_info_dict, install_tool_dependencies=True, install_repository_dependencies=True, + strings_displayed=[], strings_not_displayed=[], preview_strings_displayed=[], + post_submit_strings_displayed=[], new_tool_panel_section=None, **kwd ): + name = repository_info_dict[ 'name' ] + owner = repository_info_dict[ 'owner' ] + changeset_revision = repository_info_dict[ 'changeset_revision' ] + encoded_repository_id = repository_info_dict[ 'encoded_repository_id' ] + tool_shed_url = repository_info_dict[ 'tool_shed_url' ] + preview_params = urllib.urlencode( dict( repository_id=encoded_repository_id, changeset_revision=changeset_revision ) ) + self.visit_url( '%s/repository/preview_tools_in_changeset?%s' % ( tool_shed_url, preview_params ) ) + install_params = urllib.urlencode( dict( repository_ids=encoded_repository_id, + changeset_revisions=changeset_revision, + galaxy_url=self.url ) ) + # If the tool shed does not have the same hostname as the Galaxy server being used for these tests, + # twill will not carry over previously set cookies for the Galaxy server when following the + # install_repositories_by_revision redirect, so we have to include 403 in the allowed HTTP + # status codes and log in again. + url = '%s/repository/install_repositories_by_revision?%s' % ( tool_shed_url, install_params ) + self.visit_url( url, allowed_codes=[ 200, 403 ] ) + self.logout() + self.login( email='test@bx.psu.edu', username='test' ) + install_params = urllib.urlencode( dict( repository_ids=encoded_repository_id, + changeset_revisions=changeset_revision, + tool_shed_url=tool_shed_url ) ) + url = '/admin_toolshed/prepare_for_install?%s' % install_params + self.visit_url( url ) + # This section is tricky, due to the way twill handles form submission. The tool dependency checkbox needs to + # be hacked in through tc.browser, putting the form field in kwd doesn't work. + if 'install_tool_dependencies' in self.last_page(): + form = tc.browser.get_form( 'select_tool_panel_section' ) + checkbox = form.find_control( id="install_tool_dependencies" ) + checkbox.disabled = False + if install_tool_dependencies: + checkbox.selected = True + kwd[ 'install_tool_dependencies' ] = 'True' + else: + checkbox.selected = False + kwd[ 'install_tool_dependencies' ] = 'False' + if 'install_repository_dependencies' in self.last_page(): + kwd[ 'install_repository_dependencies' ] = str( install_repository_dependencies ).lower() + if 'shed_tool_conf' not in kwd: + kwd[ 'shed_tool_conf' ] = self.shed_tool_conf + if new_tool_panel_section: + kwd[ 'new_tool_panel_section' ] = new_tool_panel_section + self.submit_form( 1, 'select_tool_panel_section_button', **kwd ) + self.check_for_strings( post_submit_strings_displayed, strings_not_displayed ) + repository_ids = self.initiate_installation_process( new_tool_panel_section=new_tool_panel_section ) + self.wait_for_repository_installation( repository_ids ) + def visit_url( self, url, allowed_codes=[ 200 ] ): + new_url = tc.go( url ) + return_code = tc.browser.get_code() + assert return_code in allowed_codes, 'Invalid HTTP return code %s, allowed codes: %s' % \ + ( return_code, ', '.join( str( code ) for code in allowed_codes ) ) + return new_url + def wait_for_repository_installation( self, repository_ids ): + final_states = [ model.ToolShedRepository.installation_status.ERROR, + model.ToolShedRepository.installation_status.INSTALLED ] + # Wait until all repositories are in a final state before returning. This ensures that subsequent tests + # are running against an installed repository, and not one that is still in the process of installing. + if repository_ids: + for repository_id in repository_ids: + galaxy_repository = test_db_util.get_repository( self.security.decode_id( repository_id ) ) + timeout_counter = 0 + while galaxy_repository.status not in final_states: + test_db_util.refresh( galaxy_repository ) + timeout_counter = timeout_counter + 1 + # This timeout currently defaults to 180 seconds, or 3 minutes. + if timeout_counter > common.repository_installation_timeout: + raise AssertionError( 'Repository installation timed out, %d seconds elapsed, repository state is %s.' % \ + ( timeout_counter, repository.status ) ) + break + time.sleep( 1 ) + diff -r 8e430a612aee6bb14fe373ae9e67d80ba84723d9 -r b9a5aee402b31c2a316de0f68efe66fdb141418e test/install_and_test_tool_shed_repositories/functional/__init__.py --- /dev/null +++ b/test/install_and_test_tool_shed_repositories/functional/__init__.py @@ -0,0 +1,1 @@ +'''Tests''' \ No newline at end of file diff -r 8e430a612aee6bb14fe373ae9e67d80ba84723d9 -r b9a5aee402b31c2a316de0f68efe66fdb141418e test/install_and_test_tool_shed_repositories/functional/test_install_repositories.py --- /dev/null +++ b/test/install_and_test_tool_shed_repositories/functional/test_install_repositories.py @@ -0,0 +1,39 @@ +import new +import install_and_test_tool_shed_repositories.base.test_db_util as test_db_util +from install_and_test_tool_shed_repositories.base.twilltestcase import InstallTestRepository + +class TestInstallRepositories( InstallTestRepository ): + """Abstract test case that installs a predefined list of repositories.""" + def do_installation( self, repository_info_dict ): + self.logout() + self.login( email='test@bx.psu.edu', username='test' ) + admin_user = test_db_util.get_user( 'test@bx.psu.edu' ) + assert admin_user is not None, 'Problem retrieving user with email %s from the database' % admin_email + admin_user_private_role = test_db_util.get_private_role( admin_user ) + self.install_repository( repository_info_dict ) + +def build_tests( repository_dict=None ): + """Generate abstract test cases for the defined list of repositories.""" + if repository_dict is None: + return + # Push all the toolbox tests to module level + G = globals() + # Eliminate all previous tests from G. + for key, val in G.items(): + if key.startswith( 'TestInstallRepository_' ): + del G[ key ] + # Create a new subclass with a method named install_repository_XXX that installs the repository specified by the provided dict. + name = "TestInstallRepository_" + repository_dict[ 'name' ] + baseclasses = ( TestInstallRepositories, ) + namespace = dict() + def make_install_method( repository_dict ): + def test_install_repository( self ): + self.do_installation( repository_dict ) + return test_install_repository + test_method = make_install_method( repository_dict ) + test_method.__doc__ = "Install the repository %s from %s." % ( repository_dict[ 'name' ], repository_dict[ 'tool_shed_url' ] ) + namespace[ 'install_repository_%s' % repository_dict[ 'name' ] ] = test_method + # The new.classobj function returns a new class object, with name name, derived + # from baseclasses (which should be a tuple of classes) and with namespace dict. + new_class_obj = new.classobj( name, baseclasses, namespace ) + G[ name ] = new_class_obj diff -r 8e430a612aee6bb14fe373ae9e67d80ba84723d9 -r b9a5aee402b31c2a316de0f68efe66fdb141418e test/install_and_test_tool_shed_repositories/functional_tests.py --- /dev/null +++ b/test/install_and_test_tool_shed_repositories/functional_tests.py @@ -0,0 +1,323 @@ +#!/usr/bin/env python + +import os, sys, shutil, tempfile, re, string + +# Assume we are run from the galaxy root directory, add lib to the python path +cwd = os.getcwd() +sys.path.append( cwd ) + +test_home_directory = os.path.join( cwd, 'test', 'install_and_test_tool_shed_repositories' ) +default_test_file_dir = os.path.join( test_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. +galaxy_test_tmp_dir = os.path.join( test_home_directory, 'tmp' ) +default_galaxy_locales = 'en' +default_galaxy_test_file_dir = "test-data" +os.environ[ 'GALAXY_INSTALL_TEST_TMP_DIR' ] = galaxy_test_tmp_dir +new_path = [ os.path.join( cwd, "lib" ), os.path.join( cwd, 'test' ) ] +new_path.extend( sys.path ) +sys.path = new_path + +from galaxy import eggs + +eggs.require( "nose" ) +eggs.require( "NoseHTML" ) +eggs.require( "NoseTestDiff" ) +eggs.require( "twill==0.9" ) +eggs.require( "Paste" ) +eggs.require( "PasteDeploy" ) +eggs.require( "Cheetah" ) +eggs.require( "simplejson" ) + +# This should not be required, but it is under certain conditions, thanks to this bug: http://code.google.com/p/python-nose/issues/detail?id=284 +eggs.require( "pysqlite" ) + +import atexit, logging, os, os.path, sys, tempfile, simplejson +import twill, unittest, time +import sys, threading, random +import httplib, socket +from paste import httpserver + +# This is for the galaxy application. +import galaxy.app +from galaxy.app import UniverseApplication +from galaxy.web import buildapp + +import nose.core +import nose.config +import nose.loader +import nose.plugins.manager + +log = logging.getLogger( 'install_and_test_repositories' ) + +default_galaxy_test_port_min = 10000 +default_galaxy_test_port_max = 10999 +default_galaxy_test_host = '127.0.0.1' + +# Optionally, set the environment variable GALAXY_INSTALL_TEST_TOOL_SHEDS_CONF +# to the location of a tool sheds configuration file that includes the tool shed +# that repositories will be installed from. + +tool_sheds_conf_xml = '''<?xml version="1.0"?> +<tool_sheds> + <tool_shed name="Galaxy main tool shed" url="http://toolshed.g2.bx.psu.edu/"/> + <tool_shed name="Galaxy test tool shed" url="http://testtoolshed.g2.bx.psu.edu/"/> +</tool_sheds> +''' + +shed_tool_conf_xml_template = '''<?xml version="1.0"?> +<toolbox tool_path="${shed_tool_path}"> +</toolbox> +''' + +tool_conf_xml = '''<?xml version="1.0"?> +<toolbox> + <section name="Get Data" id="getext"> + <tool file="data_source/upload.xml"/> + </section> +</toolbox> +''' + +tool_data_table_conf_xml_template = '''<?xml version="1.0"?> +<tables> +</tables> +''' + +galaxy_repository_list = os.environ.get( 'GALAXY_INSTALL_TEST_REPOSITORY_FILE', 'repository_list.json' ) + +if 'GALAXY_INSTALL_TEST_SECRET' not in os.environ: + galaxy_encode_secret = 'changethisinproductiontoo' + os.environ[ 'GALAXY_INSTALL_TEST_SECRET' ] = galaxy_encode_secret +else: + galaxy_encode_secret = os.environ[ 'GALAXY_INSTALL_TEST_SECRET' ] + +def get_repositories_to_install(): + ''' + Get a list of repository info dicts to install. This method expects a json list of dicts with the following structure: + [ + { + "changeset_revision": <revision>, + "encoded_repository_id": <encoded repository id from the tool shed>, + "name": <name>, + "owner": <owner>, + "tool_shed_url": <url> + }, + ... + ] + NOTE: If the tool shed URL specified in any dict is not present in the tool_sheds_conf.xml, the installation will fail. + ''' + return simplejson.loads( file( galaxy_repository_list, 'r' ).read() ) + +def run_tests( test_config ): + loader = nose.loader.TestLoader( config=test_config ) + plug_loader = test_config.plugins.prepareTestLoader( loader ) + if plug_loader is not None: + loader = plug_loader + tests = loader.loadTestsFromNames( test_config.testNames ) + test_runner = nose.core.TextTestRunner( stream=test_config.stream, + verbosity=test_config.verbosity, + config=test_config ) + plug_runner = test_config.plugins.prepareTestRunner( test_runner ) + if plug_runner is not None: + test_runner = plug_runner + return test_runner.run( tests ) + +def main(): + # ---- Configuration ------------------------------------------------------ + galaxy_test_host = os.environ.get( 'GALAXY_INSTALL_TEST_HOST', default_galaxy_test_host ) + galaxy_test_port = os.environ.get( 'GALAXY_INSTALL_TEST_PORT', None ) + + tool_path = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_PATH', 'tools' ) + if 'HTTP_ACCEPT_LANGUAGE' not in os.environ: + os.environ[ 'HTTP_ACCEPT_LANGUAGE' ] = default_galaxy_locales + galaxy_test_file_dir = os.environ.get( 'GALAXY_INSTALL_TEST_FILE_DIR', default_galaxy_test_file_dir ) + if not os.path.isabs( galaxy_test_file_dir ): + galaxy_test_file_dir = os.path.abspath( galaxy_test_file_dir ) + tool_dependency_dir = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR', None ) + use_distributed_object_store = os.environ.get( 'GALAXY_INSTALL_TEST_USE_DISTRIBUTED_OBJECT_STORE', False ) + if not os.path.isdir( galaxy_test_tmp_dir ): + os.mkdir( galaxy_test_tmp_dir ) + galaxy_test_proxy_port = None + shed_tool_data_table_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_SHED_TOOL_DATA_TABLE_CONF', os.path.join( galaxy_test_tmp_dir, 'test_shed_tool_data_table_conf.xml' ) ) + galaxy_tool_data_table_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_DATA_TABLE_CONF', os.path.join( galaxy_test_tmp_dir, 'test_tool_data_table_conf.xml' ) ) + galaxy_tool_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_CONF', os.path.join( galaxy_test_tmp_dir, 'test_tool_conf.xml' ) ) + galaxy_shed_tool_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_SHED_TOOL_CONF', os.path.join( galaxy_test_tmp_dir, 'test_shed_tool_conf.xml' ) ) + galaxy_migrated_tool_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_MIGRATED_TOOL_CONF', os.path.join( galaxy_test_tmp_dir, 'test_migrated_tool_conf.xml' ) ) + galaxy_tool_sheds_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_SHEDS_CONF', os.path.join( galaxy_test_tmp_dir, 'test_tool_sheds_conf.xml' ) ) + shed_tool_dict = os.environ.get( 'GALAXY_INSTALL_TEST_SHED_TOOL_DICT_FILE', os.path.join( galaxy_test_tmp_dir, 'shed_tool_dict' ) ) + if 'GALAXY_INSTALL_TEST_TOOL_DATA_PATH' in os.environ: + tool_data_path = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_DATA_PATH' ) + else: + tool_data_path = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + os.environ[ 'GALAXY_INSTALL_TEST_TOOL_DATA_PATH' ] = tool_data_path + if 'GALAXY_INSTALL_TEST_DBPATH' in os.environ: + galaxy_db_path = os.environ[ 'GALAXY_INSTALL_TEST_DBPATH' ] + else: + tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + galaxy_db_path = os.path.join( tempdir, 'database' ) + galaxy_file_path = os.path.join( galaxy_db_path, 'files' ) + new_repos_path = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + galaxy_tempfiles = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + galaxy_shed_tool_path = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + galaxy_migrated_tool_path = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + galaxy_tool_dependency_dir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir ) + os.environ[ 'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR' ] = galaxy_tool_dependency_dir + if 'GALAXY_INSTALL_TEST_DBURI' in os.environ: + database_connection = os.environ[ 'GALAXY_INSTALL_TEST_DBURI' ] + else: + database_connection = 'sqlite:///' + os.path.join( galaxy_db_path, 'install_and_test_repositories.sqlite' ) + kwargs = {} + for dir in [ galaxy_test_tmp_dir ]: + try: + os.makedirs( dir ) + except OSError: + pass + + print "Database connection: ", 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 ) + os.environ[ 'GALAXY_INSTALL_TEST_TOOL_DATA_TABLE_CONF' ] = galaxy_tool_data_table_conf_file + # 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[ 'GALAXY_INSTALL_TEST_SHED_TOOL_DATA_TABLE_CONF' ] = shed_tool_data_table_conf_file + # ---- Start up a Galaxy instance ------------------------------------------------------ + # Generate the tool_conf.xml file. + file( galaxy_tool_conf_file, 'w' ).write( tool_conf_xml ) + # Generate the tool_sheds_conf.xml file, but only if a the user has not specified an existing one in the environment. + if 'GALAXY_INSTALL_TEST_TOOL_SHEDS_CONF' not in os.environ: + file( galaxy_tool_sheds_conf_file, 'w' ).write( tool_sheds_conf_xml ) + # Generate the shed_tool_conf.xml file. + tool_conf_template_parser = string.Template( shed_tool_conf_xml_template ) + shed_tool_conf_xml = 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 ) + os.environ[ 'GALAXY_INSTALL_TEST_SHED_TOOL_CONF' ] = galaxy_shed_tool_conf_file + # Generate the migrated_tool_conf.xml file. + migrated_tool_conf_xml = 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 ) + + # ---- Build Galaxy Application -------------------------------------------------- + global_conf = { '__file__' : 'universe_wsgi.ini.sample' } + if not database_connection.startswith( 'sqlite://' ): + kwargs[ 'database_engine_option_max_overflow' ] = '20' + app = UniverseApplication( admin_users = 'test@bx.psu.edu', + allow_user_creation = True, + allow_user_deletion = True, + allow_library_path_paste = True, + database_connection = database_connection, + database_engine_option_pool_size = '10', + datatype_converters_config_file = "datatype_converters_conf.xml.sample", + file_path = galaxy_file_path, + global_conf = global_conf, + id_secret = galaxy_encode_secret, + 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_tool_data_table_config = shed_tool_data_table_conf_file, + shed_tool_path = galaxy_shed_tool_path, + template_path = "templates", + tool_config_file = [ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ], + tool_data_path = tool_data_path, + tool_data_table_config_path = galaxy_tool_data_table_conf_file, + tool_dependency_dir = galaxy_tool_dependency_dir, + tool_path = tool_path, + tool_parse_help = False, + tool_sheds_config_file = galaxy_tool_sheds_conf_file, + update_integrated_tool_panel = False, + use_heartbeat = False, + **kwargs ) + + log.info( "Embedded Galaxy application started" ) + + # ---- Run galaxy webserver ------------------------------------------------------ + server = None + webapp = buildapp.app_factory( dict( database_file=database_connection ), + use_translogger=False, + static_enabled=False, + app=app ) + + 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 ) ) + if galaxy_test_proxy_port: + os.environ[ 'GALAXY_INSTALL_TEST_PORT' ] = galaxy_test_proxy_port + else: + os.environ[ 'GALAXY_INSTALL_TEST_PORT' ] = galaxy_test_port + t = threading.Thread( target=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" ) + log.info( "Embedded galaxy web server started" ) + # ---- Load the module to generate installation methods ------------------- + import install_and_test_tool_shed_repositories.functional.test_install_repositories as test_install_repositories + if galaxy_test_proxy_port: + log.info( "Tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_proxy_port ) ) + else: + log.info( "Tests will be run against %s:%s" % ( galaxy_test_host, galaxy_test_port ) ) + success = False + try: + for repository_dict in get_repositories_to_install(): + test_install_repositories.build_tests( repository_dict ) + os.environ[ 'GALAXY_INSTALL_TEST_HOST' ] = galaxy_test_host + test_config = nose.config.Config( env=os.environ, plugins=nose.plugins.manager.DefaultPluginManager() ) + test_config.configure( sys.argv ) + # Run the tests. + result = run_tests( test_config ) + success = result.wasSuccessful() + except: + log.exception( "Failure running tests" ) + + log.info( "Shutting down" ) + # ---- Tear down ----------------------------------------------------------- + if server: + log.info( "Shutting down embedded galaxy web server" ) + server.server_close() + server = None + log.info( "Embedded galaxy server stopped" ) + if app: + log.info( "Shutting down galaxy application" ) + app.shutdown() + app = None + log.info( "Embedded galaxy application stopped" ) + if 'GALAXY_INSTALL_TEST_NO_CLEANUP' not in os.environ: + try: + for dir in [ galaxy_test_tmp_dir ]: + if os.path.exists( dir ): + log.info( "Cleaning up temporary files in %s" % dir ) + shutil.rmtree( dir ) + except: + pass + else: + log.debug( 'GALAXY_INSTALL_TEST_NO_CLEANUP set, not cleaning up.' ) + if success: + return 0 + else: + return 1 + +if __name__ == "__main__": + sys.exit( main() ) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket