Example #1
0
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' )
    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

    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, '<?xml version="1.0"?>\n' )
        os.write( fd, '<toolbox>\n' )
        os.write( fd, '<tool file="data_source/upload.xml"/>\n' )
        os.write( fd, '</toolbox>\n' )
        os.close( fd )
        tool_config_file = tmp_tool_panel_conf
        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.
        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' )
        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' ) )
        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
        ignore_files = ()

    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

    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'
    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()

    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

    galaxy_test_proxy_port = None
    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' )
        # Configure the paths Galaxy needs to  test tools.
        file_path = os.path.join( galaxy_db_path, 'files' )
        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'] )
                __copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'], db_path)
                database_auto_migrate = True
            database_connection = 'sqlite:///%s' % db_path
        kwargs = {}
        for dir in file_path, new_file_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
    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
    if start_server:
        kwargs = dict( admin_users='*****@*****.**',
                       api_allow_run_as='*****@*****.**',
                       allow_library_path_paste=True,
                       allow_user_creation=True,
                       allow_user_deletion=True,
                       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,
                       library_import_dir=library_import_dir,
                       log_destination="stdout",
                       new_file_path=new_file_path,
                       running_functional_tests=True,
                       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,
                       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,
                       user_library_import_dir=user_library_import_dir,
                       master_api_key=master_api_key,
                       use_tasked_jobs=True,
                       cleanup_job='onsuccess',
                       enable_beta_tool_formats=True,
                       data_manager_config_file=data_manager_config_file )
        if install_database_connection is not None:
            kwargs[ 'install_database_connection' ] = install_database_connection
        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 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.
        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' ] = get_webapp_global_conf()
        kwargs[ 'global_conf' ][ '__file__' ] = galaxy_config_file
        kwargs[ 'config_file' ] = galaxy_config_file
        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" )

    # ---- Run webserver ------------------------------------------------------
    server = None

    if start_server:
        webapp = buildapp.app_factory( kwargs[ 'global_conf' ], app=app,
            use_translogger=False, static_enabled=STATIC_ENABLED )
        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 ) )
Example #2
0
def main():
    if install_and_test_base_util.tool_shed_api_key is None:
        # If the tool shed URL specified in any dict is not present in the tool_sheds_conf.xml, the installation will fail.
        log.debug(
            'Cannot proceed without a valid tool shed API key set in the enviroment variable GALAXY_INSTALL_TEST_TOOL_SHED_API_KEY.'
        )
        return 1
    if install_and_test_base_util.galaxy_tool_shed_url is None:
        log.debug(
            'Cannot proceed without a valid Tool Shed base URL set in the environment variable GALAXY_INSTALL_TEST_TOOL_SHED_URL.'
        )
        return 1
    # ---- Configuration ------------------------------------------------------
    galaxy_test_host = os.environ.get(
        'GALAXY_INSTALL_TEST_HOST',
        install_and_test_base_util.default_galaxy_test_host)
    # Set the GALAXY_INSTALL_TEST_HOST variable so that Twill will have the Galaxy url to which to
    # install repositories.
    os.environ['GALAXY_INSTALL_TEST_HOST'] = galaxy_test_host
    # Set the GALAXY_TEST_HOST environment variable so that the toolbox tests will have the Galaxy url
    # on which to to run tool functional tests.
    os.environ['GALAXY_TEST_HOST'] = galaxy_test_host
    galaxy_test_port = os.environ.get(
        'GALAXY_INSTALL_TEST_PORT',
        str(install_and_test_base_util.default_galaxy_test_port_max))
    os.environ['GALAXY_TEST_PORT'] = galaxy_test_port
    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)
    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)
    # Set up the configuration files for the Galaxy instance.
    galaxy_shed_tool_path = os.environ.get(
        'GALAXY_INSTALL_TEST_SHED_TOOL_PATH',
        tempfile.mkdtemp(dir=galaxy_test_tmp_dir, prefix='shed_tools'))
    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',
        install_and_test_base_util.tool_data_table_conf)
    galaxy_tool_conf_file = os.environ.get(
        'GALAXY_INSTALL_TEST_TOOL_CONF',
        os.path.join(galaxy_test_tmp_dir, 'test_tool_conf.xml'))
    galaxy_job_conf_file = os.environ.get(
        'GALAXY_INSTALL_TEST_JOB_CONF',
        os.path.join(galaxy_test_tmp_dir, 'test_job_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'))
    galaxy_shed_tools_dict_file = os.environ.get(
        'GALAXY_INSTALL_TEST_SHED_TOOL_DICT_FILE',
        os.path.join(galaxy_test_tmp_dir, 'shed_tool_dict'))
    install_and_test_base_util.populate_galaxy_shed_tools_dict_file(
        galaxy_shed_tools_dict_file, shed_tools_dict=None)
    # Set the GALAXY_TOOL_SHED_TEST_FILE environment variable to the path of the shed_tools_dict file so that
    # test.base.twilltestcase.setUp will find and parse it properly.
    os.environ['GALAXY_TOOL_SHED_TEST_FILE'] = galaxy_shed_tools_dict_file
    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
    # Configure the database connection and 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')
    # Configure the paths Galaxy needs to install and test tools.
    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_migrated_tool_path = tempfile.mkdtemp(dir=galaxy_test_tmp_dir)
    # Set up the tool dependency path for the Galaxy instance.
    tool_dependency_dir = os.environ.get(
        'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR', None)
    if tool_dependency_dir is None:
        tool_dependency_dir = tempfile.mkdtemp(dir=galaxy_test_tmp_dir)
        os.environ[
            'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR'] = tool_dependency_dir
    os.environ['GALAXY_TOOL_DEPENDENCY_DIR'] = 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')
    if 'GALAXY_INSTALL_TEST_INSTALL_DBURI' in os.environ:
        install_database_connection = os.environ[
            'GALAXY_INSTALL_TEST_INSTALL_DBURI']
    elif asbool(
            os.environ.get('GALAXY_TEST_INSTALL_DB_MERGED',
                           default_install_db_merged)):
        install_database_connection = database_connection
    else:
        install_galaxy_db_path = os.path.join(galaxy_db_path, 'install.sqlite')
        install_database_connection = 'sqlite:///%s' % install_galaxy_db_path
    kwargs = {}
    for dir in [galaxy_test_tmp_dir]:
        try:
            os.makedirs(dir)
        except OSError:
            pass
    print "Database connection: ", database_connection
    print "Install database connection: ", install_database_connection
    # Generate the shed_tool_data_table_conf.xml file.
    file(shed_tool_data_table_conf_file, 'w').write(
        install_and_test_base_util.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(install_and_test_base_util.tool_conf_xml)
    # Generate the job_conf.xml file.
    file(galaxy_job_conf_file,
         'w').write(install_and_test_base_util.job_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(install_and_test_base_util.tool_sheds_conf_xml)
    # Generate the shed_tool_conf.xml file.
    install_and_test_base_util.populate_shed_conf_file(
        galaxy_shed_tool_conf_file, galaxy_shed_tool_path, xml_elems=None)
    os.environ[
        'GALAXY_INSTALL_TEST_SHED_TOOL_CONF'] = galaxy_shed_tool_conf_file
    # Generate the migrated_tool_conf.xml file.
    install_and_test_base_util.populate_shed_conf_file(
        galaxy_migrated_tool_conf_file,
        galaxy_migrated_tool_path,
        xml_elems=None)
    # Write the embedded web application's specific configuration to a temporary file. This is necessary in order for
    # the external metadata script to find the right datasets.
    kwargs = dict(
        admin_users='*****@*****.**',
        master_api_key=install_and_test_base_util.
        default_galaxy_master_api_key,
        allow_user_creation=True,
        allow_user_deletion=True,
        allow_library_path_paste=True,
        database_connection=database_connection,
        datatype_converters_config_file="datatype_converters_conf.xml.sample",
        file_path=galaxy_file_path,
        id_secret=install_and_test_base_util.galaxy_encode_secret,
        install_database_connection=install_database_connection,
        job_config_file=galaxy_job_conf_file,
        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=','.join(
            [galaxy_tool_conf_file, galaxy_shed_tool_conf_file]),
        tool_data_path=tool_data_path,
        tool_dependency_dir=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)
    if os.path.exists(galaxy_tool_data_table_conf_file):
        kwargs[
            'tool_data_table_config_path'] = galaxy_tool_data_table_conf_file
    galaxy_config_file = os.environ.get('GALAXY_INSTALL_TEST_INI_FILE', None)
    # If the user has passed in a path for the .ini file, do not overwrite it.
    if not galaxy_config_file:
        galaxy_config_file = os.path.join(
            galaxy_test_tmp_dir,
            'install_test_tool_shed_repositories_wsgi.ini')
        config_items = []
        for label in kwargs:
            config_tuple = label, kwargs[label]
            config_items.append(config_tuple)
        # Write a temporary file, based on galaxy.ini.sample, using the configuration options defined above.
        generate_config_file('config/galaxy.ini.sample', galaxy_config_file,
                             config_items)
    kwargs['tool_config_file'] = [
        galaxy_tool_conf_file, galaxy_shed_tool_conf_file
    ]
    # Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh.
    kwargs['global_conf'] = install_and_test_base_util.get_webapp_global_conf()
    kwargs['global_conf']['__file__'] = galaxy_config_file
    # ---- Build Galaxy Application --------------------------------------------------
    if not database_connection.startswith('sqlite://'):
        kwargs['database_engine_option_max_overflow'] = '20'
        kwargs['database_engine_option_pool_size'] = '10'
    kwargs['config_file'] = galaxy_config_file
    app = UniverseApplication(**kwargs)
    database_contexts.galaxy_context = app.model.context
    database_contexts.install_context = app.install_model.context

    log.debug("Embedded Galaxy application started...")
    # ---- Run galaxy webserver ------------------------------------------------------
    server = None
    global_conf = install_and_test_base_util.get_webapp_global_conf()
    global_conf['database_file'] = database_connection
    webapp = buildapp.app_factory(
        global_conf,
        use_translogger=False,
        static_enabled=install_and_test_base_util.STATIC_ENABLED,
        app=app)
    # Serve the app on a specified or random port.
    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(
                        install_and_test_base_util.
                        default_galaxy_test_port_min,
                        install_and_test_base_util.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:
Example #3
0
                                            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,
                                            tool_data_table_config_path = galaxy_tool_data_table_conf_file,
                                            update_integrated_tool_panel = False,
                                            use_heartbeat = False,
                                            **kwargs )
     
     log.info( "Embedded Galaxy application started" )
 
     # ---- Run galaxy webserver ------------------------------------------------------
     galaxy_server = None
     galaxywebapp = galaxybuildapp.app_factory( dict( database_file=galaxy_database_connection ),
                                                      use_translogger=False,
                                                      static_enabled=False,
                                                      app=galaxyapp )
 
     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
Example #4
0
        # ---- Build Galaxy Application --------------------------------------------------
        if not galaxy_database_connection.startswith(
                'sqlite://'
        ) and not install_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,
                                                  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))
def main():
    if install_and_test_base_util.tool_shed_api_key is None:
        # If the tool shed URL specified in any dict is not present in the tool_sheds_conf.xml, the installation will fail.
        log.debug( 'Cannot proceed without a valid tool shed API key set in the enviroment variable GALAXY_INSTALL_TEST_TOOL_SHED_API_KEY.' )
        return 1
    if install_and_test_base_util.galaxy_tool_shed_url is None:
        log.debug( 'Cannot proceed without a valid Tool Shed base URL set in the environment variable GALAXY_INSTALL_TEST_TOOL_SHED_URL.' )
        return 1
    # ---- Configuration ------------------------------------------------------
    galaxy_test_host = os.environ.get( 'GALAXY_INSTALL_TEST_HOST', install_and_test_base_util.default_galaxy_test_host )
    # Set the GALAXY_INSTALL_TEST_HOST variable so that Twill will have the Galaxy url to which to
    # install repositories.
    os.environ[ 'GALAXY_INSTALL_TEST_HOST' ] = galaxy_test_host
    # Set the GALAXY_TEST_HOST environment variable so that the toolbox tests will have the Galaxy url
    # on which to to run tool functional tests.
    os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host
    galaxy_test_port = os.environ.get( 'GALAXY_INSTALL_TEST_PORT', str( install_and_test_base_util.default_galaxy_test_port_max ) )
    os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_port
    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 )
    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 )
    # Set up the configuration files for the Galaxy instance.
    galaxy_shed_tool_path = os.environ.get( 'GALAXY_INSTALL_TEST_SHED_TOOL_PATH',
                                            tempfile.mkdtemp( dir=galaxy_test_tmp_dir, prefix='shed_tools' ) )
    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',
                                                       install_and_test_base_util.tool_data_table_conf )
    galaxy_tool_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_CONF',
                                            os.path.join( galaxy_test_tmp_dir, 'test_tool_conf.xml' ) )
    galaxy_job_conf_file = os.environ.get( 'GALAXY_INSTALL_TEST_JOB_CONF',
                                           os.path.join( galaxy_test_tmp_dir, 'test_job_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' ) )
    galaxy_shed_tools_dict_file = os.environ.get( 'GALAXY_INSTALL_TEST_SHED_TOOL_DICT_FILE',
                                                       os.path.join( galaxy_test_tmp_dir, 'shed_tool_dict' ) )
    install_and_test_base_util.populate_galaxy_shed_tools_dict_file( galaxy_shed_tools_dict_file,
                                                                     shed_tools_dict=None )
    # Set the GALAXY_TOOL_SHED_TEST_FILE environment variable to the path of the shed_tools_dict file so that
    # test.base.twilltestcase.setUp will find and parse it properly.
    os.environ[ 'GALAXY_TOOL_SHED_TEST_FILE' ] = galaxy_shed_tools_dict_file
    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
    # Configure the database connection and 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' )
    # Configure the paths Galaxy needs to install and test tools.
    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_migrated_tool_path = tempfile.mkdtemp( dir=galaxy_test_tmp_dir )
    # Set up the tool dependency path for the Galaxy instance.
    tool_dependency_dir = os.environ.get( 'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR', None )
    if tool_dependency_dir is None:
        tool_dependency_dir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir )
        os.environ[ 'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR' ] = tool_dependency_dir
    os.environ[ 'GALAXY_TOOL_DEPENDENCY_DIR' ] = 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' )
    if 'GALAXY_INSTALL_TEST_INSTALL_DBURI' in os.environ:
        install_database_connection = os.environ[ 'GALAXY_INSTALL_TEST_INSTALL_DBURI' ]
    elif asbool( os.environ.get( 'GALAXY_TEST_INSTALL_DB_MERGED', default_install_db_merged ) ):
        install_database_connection = database_connection
    else:
        install_galaxy_db_path = os.path.join( galaxy_db_path, 'install.sqlite' )
        install_database_connection = 'sqlite:///%s' % install_galaxy_db_path
    kwargs = {}
    for dir in [ galaxy_test_tmp_dir ]:
        try:
            os.makedirs( dir )
        except OSError:
            pass
    print "Database connection: ", database_connection
    print "Install database connection: ", install_database_connection
    # Generate the shed_tool_data_table_conf.xml file.
    file( shed_tool_data_table_conf_file, 'w' ).write( install_and_test_base_util.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( install_and_test_base_util.tool_conf_xml )
    # Generate the job_conf.xml file.
    file( galaxy_job_conf_file, 'w' ).write( install_and_test_base_util.job_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( install_and_test_base_util.tool_sheds_conf_xml )
    # Generate the shed_tool_conf.xml file.
    install_and_test_base_util.populate_shed_conf_file( galaxy_shed_tool_conf_file, galaxy_shed_tool_path, xml_elems=None )
    os.environ[ 'GALAXY_INSTALL_TEST_SHED_TOOL_CONF' ] = galaxy_shed_tool_conf_file
    # Generate the migrated_tool_conf.xml file.
    install_and_test_base_util.populate_shed_conf_file( galaxy_migrated_tool_conf_file, galaxy_migrated_tool_path, xml_elems=None )
    # Write the embedded web application's specific configuration to a temporary file. This is necessary in order for
    # the external metadata script to find the right datasets.
    kwargs = dict( admin_users = '*****@*****.**',
                   master_api_key = install_and_test_base_util.default_galaxy_master_api_key,
                   allow_user_creation = True,
                   allow_user_deletion = True,
                   allow_library_path_paste = True,
                   database_connection = database_connection,
                   datatype_converters_config_file = "datatype_converters_conf.xml.sample",
                   file_path = galaxy_file_path,
                   id_secret = install_and_test_base_util.galaxy_encode_secret,
                   install_database_connection = install_database_connection,
                   job_config_file = galaxy_job_conf_file,
                   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 = ','.join( [ 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 = 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 )
    galaxy_config_file = os.environ.get( 'GALAXY_INSTALL_TEST_INI_FILE', None )
    # If the user has passed in a path for the .ini file, do not overwrite it.
    if not galaxy_config_file:
        galaxy_config_file = os.path.join( galaxy_test_tmp_dir, 'install_test_tool_shed_repositories_wsgi.ini' )
        config_items = []
        for label in kwargs:
            config_tuple = label, kwargs[ label ]
            config_items.append( config_tuple )
        # Write a temporary file, based on universe_wsgi.ini.sample, using the configuration options defined above.
        generate_config_file( 'universe_wsgi.ini.sample', galaxy_config_file, config_items )
    kwargs[ 'tool_config_file' ] = [ galaxy_tool_conf_file, galaxy_shed_tool_conf_file ]
    # Set the global_conf[ '__file__' ] option to the location of the temporary .ini file, which gets passed to set_metadata.sh.
    kwargs[ 'global_conf' ] = install_and_test_base_util.get_webapp_global_conf()
    kwargs[ 'global_conf' ][ '__file__' ] = galaxy_config_file
    # ---- Build Galaxy Application --------------------------------------------------
    if not database_connection.startswith( 'sqlite://' ):
        kwargs[ 'database_engine_option_max_overflow' ] = '20'
        kwargs[ 'database_engine_option_pool_size' ] = '10'
    kwargs[ 'config_file' ] = galaxy_config_file
    app = UniverseApplication( **kwargs )
    database_contexts.galaxy_context = app.model.context
    database_contexts.install_context = app.install_model.context

    log.debug( "Embedded Galaxy application started..." )
    # ---- Run galaxy webserver ------------------------------------------------------
    server = None
    global_conf = install_and_test_base_util.get_webapp_global_conf()
    global_conf[ 'database_file' ] = database_connection
    webapp = buildapp.app_factory( global_conf,
                                   use_translogger=False,
                                   static_enabled=install_and_test_base_util.STATIC_ENABLED,
                                   app=app )
    # Serve the app on a specified or random port.
    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( install_and_test_base_util.default_galaxy_test_port_min,
                                                        install_and_test_base_util.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:
                       update_integrated_tool_panel = False,
                       use_heartbeat = False )
    
        # ---- Build Galaxy Application -------------------------------------------------- 
        if not galaxy_database_connection.startswith( 'sqlite://' ) and not install_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,
                                                   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:
Example #7
0
                                            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,
                                            tool_data_table_config_path = galaxy_tool_data_table_conf_file,
                                            update_integrated_tool_panel = False,
                                            use_heartbeat = False,
                                            **kwargs )
     
     log.info( "Embedded Galaxy application started" )
 
     # ---- Run galaxy webserver ------------------------------------------------------
     galaxy_server = None
     galaxywebapp = galaxybuildapp.app_factory( dict( database_file=galaxy_database_connection ),
                                                      use_translogger=False,
                                                      static_enabled=False,
                                                      app=galaxyapp )
 
     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
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' )
    if 'HTTP_ACCEPT_LANGUAGE' not in os.environ:
        os.environ[ 'HTTP_ACCEPT_LANGUAGE' ] = default_galaxy_locales
    testing_migrated_tools = '-migrated' in sys.argv
    testing_installed_tools = '-installed' in sys.argv

    if testing_migrated_tools or testing_installed_tools:
        sys.argv.pop()
        # 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, '<?xml version="1.0"?>\n' )
        os.write( fd, '<toolbox>\n' )
        os.write( fd, '<tool file="data_source/upload.xml"/>\n' )
        os.write( fd, '</toolbox>\n' )
        os.close( fd )
        tool_config_file = tmp_tool_panel_conf
        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:
        tool_config_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', 'tool_conf.xml.sample' )
        galaxy_test_file_dir = os.environ.get( 'GALAXY_TEST_FILE_DIR', default_galaxy_test_file_dir )
        if not os.path.isabs( galaxy_test_file_dir ):
            galaxy_test_file_dir = os.path.join( os.getcwd(), galaxy_test_file_dir )
        library_import_dir = galaxy_test_file_dir
        user_library_import_dir = os.path.join( galaxy_test_file_dir, 'users' )
        ignore_files = ()

    start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ
    if os.path.exists( 'tool_data_table_conf.test.xml' ):
        tool_data_table_config_path = 'tool_data_table_conf.test.xml'
    else:    
        tool_data_table_config_path = 'tool_data_table_conf.xml'
    shed_tool_data_table_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 )
    
    if start_server:
        psu_production = False
        galaxy_test_proxy_port = None
        if 'GALAXY_TEST_PSU_PRODUCTION' in os.environ:
            if not galaxy_test_port:
                raise Exception( 'Please set GALAXY_TEST_PORT to the port to which the proxy server will proxy' )
            galaxy_test_proxy_port = os.environ.get( 'GALAXY_TEST_PROXY_PORT', None )
            if not galaxy_test_proxy_port:
                raise Exception( 'Please set GALAXY_TEST_PROXY_PORT to the port on which the proxy server is listening' )
            base_file_path = os.environ.get( 'GALAXY_TEST_BASE_FILE_PATH', None )
            if not base_file_path:
                raise Exception( 'Please set GALAXY_TEST_BASE_FILE_PATH to the directory which will contain the dataset files directory' )
            base_new_file_path = os.environ.get( 'GALAXY_TEST_BASE_NEW_FILE_PATH', None )
            if not base_new_file_path:
                raise Exception( 'Please set GALAXY_TEST_BASE_NEW_FILE_PATH to the directory which will contain the temporary directory' )
            database_connection = os.environ.get( 'GALAXY_TEST_DBURI', None )
            if not database_connection:
                raise Exception( 'Please set GALAXY_TEST_DBURI to the URI of the database to be used for tests' )
            nginx_upload_store = os.environ.get( 'GALAXY_TEST_NGINX_UPLOAD_STORE', None )
            if not nginx_upload_store:
                raise Exception( 'Please set GALAXY_TEST_NGINX_UPLOAD_STORE to the path where the nginx upload module places uploaded files' )
            tool_config_file = 'tool_conf.xml.main'
            default_cluster_job_runner = os.environ.get( 'GALAXY_TEST_DEFAULT_CLUSTER_JOB_RUNNER', 'pbs:///' )
            file_path = tempfile.mkdtemp( dir=base_file_path )
            new_file_path = tempfile.mkdtemp( dir=base_new_file_path )
            cluster_files_directory = os.path.join( new_file_path, 'pbs' )
            job_working_directory = os.path.join( new_file_path, 'job_working_directory' )
            os.mkdir( cluster_files_directory )
            os.mkdir( job_working_directory )
            kwargs = dict( database_engine_option_pool_size = '10',
                           database_engine_option_max_overflow = '20',
                           database_engine_option_strategy = 'threadlocal',
                           nginx_x_accel_redirect_base = '/_x_accel_redirect',
                           nginx_upload_store = nginx_upload_store,
                           nginx_upload_path = '/_upload',
                           allow_library_path_paste = 'True',
                           cluster_files_directory = cluster_files_directory,
                           job_working_directory = job_working_directory,
                           outputs_to_working_directory = 'True',
                           set_metadata_externally = 'True',
                           static_enabled = 'False',
                           debug = 'False',
                           track_jobs_in_database = 'True',
                           job_scheduler_policy = 'FIFO',
                           start_job_runners = 'pbs',
                           default_cluster_job_runner = default_cluster_job_runner )
            psu_production = True
        else:
            if 'GALAXY_TEST_DBPATH' in os.environ:
                db_path = os.environ['GALAXY_TEST_DBPATH']
            else: 
                tempdir = tempfile.mkdtemp()
                db_path = os.path.join( tempdir, 'database' )
            file_path = os.path.join( db_path, 'files' )
            new_file_path = os.path.join( db_path, 'tmp' )
            if 'GALAXY_TEST_DBURI' in os.environ:
                database_connection = os.environ['GALAXY_TEST_DBURI']
            else:
                database_connection = 'sqlite:///' + os.path.join( db_path, 'universe.sqlite' )
            kwargs = {}
        for dir in file_path, new_file_path:
            try:
                os.makedirs( dir )
            except OSError:
                pass
    log.info( "Database connection:", database_connection )

    # ---- Build Application -------------------------------------------------- 
    app = None 
    if start_server:
        global_conf = { '__file__' : 'universe_wsgi.ini.sample' }
        if psu_production:
            global_conf = None
        if not 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
        if use_distributed_object_store:
            kwargs[ 'object_store' ] = 'distributed'
            kwargs[ 'distributed_object_store_config_file' ] = 'distributed_object_store_conf.xml.sample'
        # Build the Universe Application
        app = UniverseApplication( job_queue_workers = 5,
                                   id_secret = 'changethisinproductiontoo',
                                   template_path = "templates",
                                   database_connection = database_connection,
                                   database_engine_option_pool_size = '10',
                                   file_path = file_path,
                                   new_file_path = new_file_path,
                                   tool_path = tool_path,
                                   update_integrated_tool_panel = False,
                                   tool_config_file = tool_config_file,
                                   datatype_converters_config_file = "datatype_converters_conf.xml.sample",
                                   tool_parse_help = False,
                                   test_conf = "test.conf",
                                   tool_data_table_config_path = tool_data_table_config_path,
                                   shed_tool_data_table_config = shed_tool_data_table_config,
                                   log_destination = "stdout",
                                   use_heartbeat = False,
                                   allow_user_creation = True,
                                   allow_user_deletion = True,
                                   admin_users = '*****@*****.**',
                                   allow_library_path_paste = True,
                                   library_import_dir = library_import_dir,
                                   user_library_import_dir = user_library_import_dir,
                                   global_conf = global_conf,
                                   running_functional_tests=True,
                                   **kwargs )
        log.info( "Embedded Universe application started" )
    # ---- Run webserver ------------------------------------------------------
    server = None
    
    if start_server:
        webapp = buildapp.app_factory( get_webapp_global_conf(), app=app,
            use_translogger=False, static_enabled=STATIC_ENABLED )
        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 ) )
Example #9
0
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 )
    if 'HTTP_ACCEPT_LANGUAGE' not in os.environ:
        os.environ['HTTP_ACCEPT_LANGUAGE'] = default_galaxy_locales
    galaxy_test_file_dir = os.environ.get( 'GALAXY_TEST_FILE_DIR', default_galaxy_test_file_dir )
    if not os.path.isabs( galaxy_test_file_dir ):
        galaxy_test_file_dir = os.path.join( os.getcwd(), galaxy_test_file_dir )
    start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ   
    if start_server:
        if 'GALAXY_TEST_DBPATH' in os.environ:
            db_path = os.environ['GALAXY_TEST_DBPATH']
        else: 
            tempdir = tempfile.mkdtemp()
            db_path = os.path.join( tempdir, 'database' )
        file_path = os.path.join( db_path, 'files' )
        try:
            os.makedirs( file_path )
        except OSError:
            pass
        if 'GALAXY_TEST_DBURI' in os.environ:
            database_connection = os.environ['GALAXY_TEST_DBURI']
        else:
            database_connection = 'sqlite:///' + os.path.join( db_path, 'universe.sqlite' )
        if 'GALAXY_TEST_RUNNERS' in os.environ:
            start_job_runners = os.environ['GALAXY_TEST_RUNNERS']
        else:
            start_job_runners = None
        if 'GALAXY_TEST_DEF_RUNNER' in os.environ:
            default_cluster_job_runner = os.environ['GALAXY_TEST_DEF_RUNNER']
        else:
            default_cluster_job_runner = 'local:///'
        set_metadata_externally = False
        if 'GALAXY_SET_METADATA_EXTERNALLY' in os.environ:
            set_metadata_externally = True
            
    print "Database connection:", database_connection
    
    # What requires these?        
    os.environ['GALAXY_TEST_HOST'] = galaxy_test_host
    os.environ['GALAXY_TEST_FILE_DIR'] = galaxy_test_file_dir
            
    # ---- Build Application --------------------------------------------------
       
    app = None
            
    if start_server:
        
        # Build the Universe Application
        app = UniverseApplication( job_queue_workers = 5,
                                   start_job_runners = start_job_runners,
                                   default_cluster_job_runner = default_cluster_job_runner,
                                   id_secret = 'changethisinproductiontoo',
                                   template_path = "templates",
                                   database_connection = database_connection,
                                   file_path = file_path,
                                   tool_config_file = "tool_conf.xml.sample",
                                   datatype_converters_config_file = "datatype_converters_conf.xml.sample",
                                   tool_path = "tools",
                                   tool_parse_help = False,
                                   test_conf = "test.conf",
                                   log_destination = "stdout",
                                   use_heartbeat = False,
                                   allow_user_creation = True,
                                   allow_user_deletion = True,
                                   admin_users = '*****@*****.**',
                                   library_import_dir = galaxy_test_file_dir,
                                   user_library_import_dir = os.path.join( galaxy_test_file_dir, 'users' ),
                                   set_metadata_externally = set_metadata_externally,
                                   global_conf = { "__file__": "universe_wsgi.ini.sample" } )
        
        log.info( "Embedded Universe application started" );
        
    # ---- Run webserver ------------------------------------------------------
    
    server = None
    
    if start_server:
        
        webapp = buildapp.app_factory( dict(), 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 ) )
Example #10
0
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)
    if 'HTTP_ACCEPT_LANGUAGE' not in os.environ:
        os.environ['HTTP_ACCEPT_LANGUAGE'] = default_galaxy_locales
    galaxy_test_file_dir = os.environ.get('GALAXY_TEST_FILE_DIR',
                                          default_galaxy_test_file_dir)
    if not os.path.isabs(galaxy_test_file_dir):
        galaxy_test_file_dir = os.path.join(os.getcwd(), galaxy_test_file_dir)
    start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ
    if start_server:
        if 'GALAXY_TEST_DBPATH' in os.environ:
            db_path = os.environ['GALAXY_TEST_DBPATH']
        else:
            tempdir = tempfile.mkdtemp()
            db_path = os.path.join(tempdir, 'database')
        file_path = os.path.join(db_path, 'files')
        try:
            os.makedirs(file_path)
        except OSError:
            pass
        if 'GALAXY_TEST_DBURI' in os.environ:
            database_connection = os.environ['GALAXY_TEST_DBURI']
        else:
            database_connection = 'sqlite:///' + os.path.join(
                db_path, 'universe.sqlite')
        if 'GALAXY_TEST_RUNNERS' in os.environ:
            start_job_runners = os.environ['GALAXY_TEST_RUNNERS']
        else:
            start_job_runners = None
        if 'GALAXY_TEST_DEF_RUNNER' in os.environ:
            default_cluster_job_runner = os.environ['GALAXY_TEST_DEF_RUNNER']
        else:
            default_cluster_job_runner = 'local:///'
        set_metadata_externally = False
        if 'GALAXY_SET_METADATA_EXTERNALLY' in os.environ:
            set_metadata_externally = True

    print "Database connection:", database_connection

    # What requires these?
    os.environ['GALAXY_TEST_HOST'] = galaxy_test_host
    os.environ['GALAXY_TEST_FILE_DIR'] = galaxy_test_file_dir

    # ---- Build Application --------------------------------------------------

    app = None

    if start_server:

        # Build the Universe Application
        app = UniverseApplication(
            job_queue_workers=5,
            start_job_runners=start_job_runners,
            default_cluster_job_runner=default_cluster_job_runner,
            id_secret='changethisinproductiontoo',
            template_path="templates",
            database_connection=database_connection,
            file_path=file_path,
            tool_config_file="tool_conf.xml.sample",
            datatype_converters_config_file=
            "datatype_converters_conf.xml.sample",
            tool_path="tools",
            tool_parse_help=False,
            test_conf="test.conf",
            log_destination="stdout",
            use_heartbeat=False,
            allow_user_creation=True,
            allow_user_deletion=True,
            admin_users='*****@*****.**',
            library_import_dir=galaxy_test_file_dir,
            user_library_import_dir=os.path.join(galaxy_test_file_dir,
                                                 'users'),
            set_metadata_externally=set_metadata_externally,
            global_conf={"__file__": "universe_wsgi.ini.sample"})

        log.info("Embedded Universe application started")

    # ---- Run webserver ------------------------------------------------------

    server = None

    if start_server:

        webapp = buildapp.app_factory(dict(),
                                      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))
Example #11
0
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')
    if 'HTTP_ACCEPT_LANGUAGE' not in os.environ:
        os.environ['HTTP_ACCEPT_LANGUAGE'] = default_galaxy_locales
    testing_migrated_tools = '-migrated' in sys.argv
    testing_installed_tools = '-installed' in sys.argv

    if testing_migrated_tools or testing_installed_tools:
        sys.argv.pop()
        # 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, '<?xml version="1.0"?>\n')
        os.write(fd, '<toolbox>\n')
        os.write(fd, '<tool file="data_source/upload.xml"/>\n')
        os.write(fd, '</toolbox>\n')
        os.close(fd)
        tool_config_file = tmp_tool_panel_conf
        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:
        tool_config_file = os.environ.get('GALAXY_TEST_TOOL_CONF',
                                          'tool_conf.xml.sample')
        galaxy_test_file_dir = os.environ.get('GALAXY_TEST_FILE_DIR',
                                              default_galaxy_test_file_dir)
        if not os.path.isabs(galaxy_test_file_dir):
            galaxy_test_file_dir = os.path.join(os.getcwd(),
                                                galaxy_test_file_dir)
        library_import_dir = galaxy_test_file_dir
        user_library_import_dir = os.path.join(galaxy_test_file_dir, 'users')
        ignore_files = ()

    start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ
    if os.path.exists('tool_data_table_conf.test.xml'):
        tool_data_table_config_path = 'tool_data_table_conf.test.xml'
    else:
        tool_data_table_config_path = '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)

    if start_server:
        psu_production = False
        galaxy_test_proxy_port = None
        if 'GALAXY_TEST_PSU_PRODUCTION' in os.environ:
            if not galaxy_test_port:
                raise Exception(
                    'Please set GALAXY_TEST_PORT to the port to which the proxy server will proxy'
                )
            galaxy_test_proxy_port = os.environ.get('GALAXY_TEST_PROXY_PORT',
                                                    None)
            if not galaxy_test_proxy_port:
                raise Exception(
                    'Please set GALAXY_TEST_PROXY_PORT to the port on which the proxy server is listening'
                )
            base_file_path = os.environ.get('GALAXY_TEST_BASE_FILE_PATH', None)
            if not base_file_path:
                raise Exception(
                    'Please set GALAXY_TEST_BASE_FILE_PATH to the directory which will contain the dataset files directory'
                )
            base_new_file_path = os.environ.get(
                'GALAXY_TEST_BASE_NEW_FILE_PATH', None)
            if not base_new_file_path:
                raise Exception(
                    'Please set GALAXY_TEST_BASE_NEW_FILE_PATH to the directory which will contain the temporary directory'
                )
            database_connection = os.environ.get('GALAXY_TEST_DBURI', None)
            if not database_connection:
                raise Exception(
                    'Please set GALAXY_TEST_DBURI to the URI of the database to be used for tests'
                )
            nginx_upload_store = os.environ.get(
                'GALAXY_TEST_NGINX_UPLOAD_STORE', None)
            if not nginx_upload_store:
                raise Exception(
                    'Please set GALAXY_TEST_NGINX_UPLOAD_STORE to the path where the nginx upload module places uploaded files'
                )
            tool_config_file = 'tool_conf.xml.main'
            default_cluster_job_runner = os.environ.get(
                'GALAXY_TEST_DEFAULT_CLUSTER_JOB_RUNNER', 'pbs:///')
            file_path = tempfile.mkdtemp(dir=base_file_path)
            new_file_path = tempfile.mkdtemp(dir=base_new_file_path)
            cluster_files_directory = os.path.join(new_file_path, 'pbs')
            job_working_directory = os.path.join(new_file_path,
                                                 'job_working_directory')
            os.mkdir(cluster_files_directory)
            os.mkdir(job_working_directory)
            kwargs = dict(
                database_engine_option_pool_size='10',
                database_engine_option_max_overflow='20',
                database_engine_option_strategy='threadlocal',
                nginx_x_accel_redirect_base='/_x_accel_redirect',
                nginx_upload_store=nginx_upload_store,
                nginx_upload_path='/_upload',
                allow_library_path_paste='True',
                cluster_files_directory=cluster_files_directory,
                job_working_directory=job_working_directory,
                outputs_to_working_directory='True',
                set_metadata_externally='True',
                static_enabled='False',
                debug='False',
                track_jobs_in_database='True',
                job_scheduler_policy='FIFO',
                start_job_runners='pbs',
                default_cluster_job_runner=default_cluster_job_runner)
            psu_production = True
        else:
            if 'GALAXY_TEST_DBPATH' in os.environ:
                db_path = os.environ['GALAXY_TEST_DBPATH']
            else:
                tempdir = tempfile.mkdtemp()
                db_path = os.path.join(tempdir, 'database')
            file_path = os.path.join(db_path, 'files')
            new_file_path = os.path.join(db_path, 'tmp')
            if 'GALAXY_TEST_DBURI' in os.environ:
                database_connection = os.environ['GALAXY_TEST_DBURI']
            else:
                database_connection = 'sqlite:///' + os.path.join(
                    db_path, 'universe.sqlite')
            kwargs = {}
        for dir in file_path, new_file_path:
            try:
                os.makedirs(dir)
            except OSError:
                pass
    print "Database connection:", database_connection
    # ---- Build Application --------------------------------------------------
    app = None
    if start_server:
        global_conf = {'__file__': 'universe_wsgi.ini.sample'}
        if psu_production:
            global_conf = None
        if not 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
        if use_distributed_object_store:
            kwargs['object_store'] = 'distributed'
            kwargs[
                'distributed_object_store_config_file'] = 'distributed_object_store_conf.xml.sample'
        # Build the Universe Application
        app = UniverseApplication(
            job_queue_workers=5,
            id_secret='changethisinproductiontoo',
            template_path="templates",
            database_connection=database_connection,
            database_engine_option_pool_size='10',
            file_path=file_path,
            new_file_path=new_file_path,
            tool_path=tool_path,
            update_integrated_tool_panel=False,
            tool_config_file=tool_config_file,
            datatype_converters_config_file=
            "datatype_converters_conf.xml.sample",
            tool_parse_help=False,
            test_conf="test.conf",
            tool_data_table_config_path=tool_data_table_config_path,
            log_destination="stdout",
            use_heartbeat=False,
            allow_user_creation=True,
            allow_user_deletion=True,
            admin_users='*****@*****.**',
            allow_library_path_paste=True,
            library_import_dir=library_import_dir,
            user_library_import_dir=user_library_import_dir,
            global_conf=global_conf,
            running_functional_tests=True,
            **kwargs)
        log.info("Embedded Universe application started")
    # ---- Run webserver ------------------------------------------------------
    server = None

    if start_server:
        webapp = buildapp.app_factory(dict(),
                                      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))
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)

    if 'HTTP_ACCEPT_LANGUAGE' not in os.environ:
        os.environ['HTTP_ACCEPT_LANGUAGE'] = default_galaxy_locales
    galaxy_test_file_dir = os.environ.get( 'GALAXY_TEST_FILE_DIR', default_galaxy_test_file_dir )
    if not os.path.isabs( galaxy_test_file_dir ):
        galaxy_test_file_dir = os.path.join( os.getcwd(), galaxy_test_file_dir )
    start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ   
    tool_path = os.environ.get( 'GALAXY_TEST_TOOL_PATH', 'tools' )
    tool_config_file = os.environ.get( 'GALAXY_TEST_TOOL_CONF', 'tool_conf.xml.sample' )
    tool_data_table_config_path = '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 )
    if os.path.exists( 'tool_data_table_conf.test.xml' ):
        tool_data_table_config_path = 'tool_data_table_conf.test.xml'
    if start_server:
        psu_production = False
        galaxy_test_proxy_port = None
        if 'GALAXY_TEST_PSU_PRODUCTION' in os.environ:
            if not galaxy_test_port:
                raise Exception( 'Please set GALAXY_TEST_PORT to the port to which the proxy server will proxy' )
            galaxy_test_proxy_port = os.environ.get( 'GALAXY_TEST_PROXY_PORT', None )
            if not galaxy_test_proxy_port:
                raise Exception( 'Please set GALAXY_TEST_PROXY_PORT to the port on which the proxy server is listening' )
            base_file_path = os.environ.get( 'GALAXY_TEST_BASE_FILE_PATH', None )
            if not base_file_path:
                raise Exception( 'Please set GALAXY_TEST_BASE_FILE_PATH to the directory which will contain the dataset files directory' )
            base_new_file_path = os.environ.get( 'GALAXY_TEST_BASE_NEW_FILE_PATH', None )
            if not base_new_file_path:
                raise Exception( 'Please set GALAXY_TEST_BASE_NEW_FILE_PATH to the directory which will contain the temporary directory' )
            database_connection = os.environ.get( 'GALAXY_TEST_DBURI', None )
            if not database_connection:
                raise Exception( 'Please set GALAXY_TEST_DBURI to the URI of the database to be used for tests' )
            nginx_upload_store = os.environ.get( 'GALAXY_TEST_NGINX_UPLOAD_STORE', None )
            if not nginx_upload_store:
                raise Exception( 'Please set GALAXY_TEST_NGINX_UPLOAD_STORE to the path where the nginx upload module places uploaded files' )
            tool_config_file = 'tool_conf.xml.main'
            default_cluster_job_runner = os.environ.get( 'GALAXY_TEST_DEFAULT_CLUSTER_JOB_RUNNER', 'pbs:///' )
            file_path = tempfile.mkdtemp( dir=base_file_path )
            new_file_path = tempfile.mkdtemp( dir=base_new_file_path )
            cluster_files_directory = os.path.join( new_file_path, 'pbs' )
            job_working_directory = os.path.join( new_file_path, 'job_working_directory' )
            os.mkdir( cluster_files_directory )
            os.mkdir( job_working_directory )
            kwargs = dict( database_engine_option_pool_size = '10',
                           database_engine_option_max_overflow = '20',
                           database_engine_option_strategy = 'threadlocal',
                           nginx_x_accel_redirect_base = '/_x_accel_redirect',
                           nginx_upload_store = nginx_upload_store,
                           nginx_upload_path = '/_upload',
                           allow_library_path_paste = 'True',
                           cluster_files_directory = cluster_files_directory,
                           job_working_directory = job_working_directory,
                           outputs_to_working_directory = 'True',
                           set_metadata_externally = 'True',
                           static_enabled = 'False',
                           debug = 'False',
                           track_jobs_in_database = 'True',
                           job_scheduler_policy = 'FIFO',
                           start_job_runners = 'pbs',
                           default_cluster_job_runner = default_cluster_job_runner )
            psu_production = True
        else:
            if 'GALAXY_TEST_DBPATH' in os.environ:
                db_path = os.environ['GALAXY_TEST_DBPATH']
            else: 
                tempdir = tempfile.mkdtemp()
                db_path = os.path.join( tempdir, 'database' )
            file_path = os.path.join( db_path, 'files' )
            new_file_path = os.path.join( db_path, 'tmp' )
            if 'GALAXY_TEST_DBURI' in os.environ:
                database_connection = os.environ['GALAXY_TEST_DBURI']
            else:
                database_connection = 'sqlite:///' + os.path.join( db_path, 'universe.sqlite' )
            kwargs = {}
        for dir in file_path, new_file_path:
            try:
                os.makedirs( dir )
            except OSError:
                pass
            
    print "Database connection:", database_connection
    
    # 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
    os.environ['GALAXY_TEST_FILE_DIR'] = galaxy_test_file_dir
    # ---- Build Application --------------------------------------------------
       
    app = None
            
    if start_server:
        
        global_conf = { '__file__' : 'universe_wsgi.ini.sample' }
        if psu_production:
            global_conf = None

        if not 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

        if use_distributed_object_store:
            kwargs['object_store'] = 'distributed'
            kwargs['distributed_object_store_config_file'] = 'distributed_object_store_conf.xml.sample'

        # Build the Universe Application
        app = UniverseApplication( job_queue_workers = 5,
                                   id_secret = 'changethisinproductiontoo',
                                   template_path = "templates",
                                   database_connection = database_connection,
                                   database_engine_option_pool_size = '10',
                                   file_path = file_path,
                                   new_file_path = new_file_path,
                                   tool_path = tool_path,
                                   tool_config_file = tool_config_file,
                                   datatype_converters_config_file = "datatype_converters_conf.xml.sample",
                                   tool_parse_help = False,
                                   test_conf = "test.conf",
                                   tool_data_table_config_path = tool_data_table_config_path,
                                   log_destination = "stdout",
                                   use_heartbeat = False,
                                   allow_user_creation = True,
                                   allow_user_deletion = True,
                                   admin_users = '*****@*****.**',
                                   allow_library_path_paste = True,
                                   library_import_dir = galaxy_test_file_dir,
                                   user_library_import_dir = os.path.join( galaxy_test_file_dir, 'users' ),
                                   global_conf = global_conf,
                                   **kwargs )
        
        log.info( "Embedded Universe application started" );
        
    # ---- Run webserver ------------------------------------------------------
    
    server = None
    
    if start_server:
        
        webapp = buildapp.app_factory( dict(), 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 ) )