示例#1
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:
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: