def setup(self):
        """Entry point for test driver script."""
        # ---- Configuration ------------------------------------------------------
        tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir()
        if not os.path.isdir(tool_shed_test_tmp_dir):
            os.mkdir(tool_shed_test_tmp_dir)
        self.temp_directories.append(tool_shed_test_tmp_dir)
        shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir,
                                                       prefix="TOOL_SHED")
        shed_tool_data_table_conf_file = os.environ.get(
            'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF',
            os.path.join(tool_shed_test_tmp_dir,
                         'shed_tool_data_table_conf.xml'))
        galaxy_shed_data_manager_conf_file = os.environ.get(
            'GALAXY_SHED_DATA_MANAGER_CONF',
            os.path.join(tool_shed_test_tmp_dir,
                         'test_shed_data_manager_conf.xml'))
        default_tool_data_table_config_path = os.path.join(
            tool_shed_test_tmp_dir, 'tool_data_table_conf.xml')
        galaxy_shed_tool_conf_file = os.environ.get(
            'GALAXY_TEST_SHED_TOOL_CONF',
            os.path.join(tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml'))
        galaxy_migrated_tool_conf_file = os.environ.get(
            'GALAXY_TEST_MIGRATED_TOOL_CONF',
            os.path.join(tool_shed_test_tmp_dir,
                         'test_migrated_tool_conf.xml'))
        galaxy_tool_sheds_conf_file = os.environ.get(
            'GALAXY_TEST_TOOL_SHEDS_CONF',
            os.path.join(tool_shed_test_tmp_dir, 'test_sheds_conf.xml'))
        if 'GALAXY_TEST_TOOL_DATA_PATH' in os.environ:
            tool_data_path = os.environ.get('GALAXY_TEST_TOOL_DATA_PATH')
        else:
            tool_data_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
            os.environ['GALAXY_TEST_TOOL_DATA_PATH'] = tool_data_path
        galaxy_db_path = driver_util.database_files_path(
            tool_shed_test_tmp_dir)
        shed_file_path = os.path.join(shed_db_path, 'files')
        hgweb_config_file_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        new_repos_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        galaxy_shed_tool_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        galaxy_migrated_tool_path = tempfile.mkdtemp(
            dir=tool_shed_test_tmp_dir)
        hgweb_config_dir = hgweb_config_file_path
        os.environ['TEST_HG_WEB_CONFIG_DIR'] = hgweb_config_dir
        print("Directory location for hgweb.config:", hgweb_config_dir)
        toolshed_database_conf = driver_util.database_conf(shed_db_path,
                                                           prefix="TOOL_SHED")
        kwargs = dict(
            admin_users='*****@*****.**',
            allow_user_creation=True,
            allow_user_deletion=True,
            datatype_converters_config_file=
            'datatype_converters_conf.xml.sample',
            file_path=shed_file_path,
            hgweb_config_dir=hgweb_config_dir,
            job_queue_workers=5,
            id_secret='changethisinproductiontoo',
            log_destination="stdout",
            new_file_path=new_repos_path,
            running_functional_tests=True,
            shed_tool_data_table_config=shed_tool_data_table_conf_file,
            smtp_server='smtp.dummy.string.tld',
            email_from='functional@localhost',
            template_path='templates',
            tool_parse_help=False,
            use_heartbeat=False)
        kwargs.update(toolshed_database_conf)
        # Generate the tool_data_table_conf.xml file.
        open(default_tool_data_table_config_path,
             'w').write(tool_data_table_conf_xml_template)
        # Generate the shed_tool_data_table_conf.xml file.
        open(shed_tool_data_table_conf_file,
             'w').write(tool_data_table_conf_xml_template)
        os.environ[
            'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF'] = shed_tool_data_table_conf_file
        # ---- Build Tool Shed Application --------------------------------------------------
        toolshedapp = driver_util.build_shed_app(kwargs)

        # ---- Run tool shed webserver ------------------------------------------------------
        # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py')
        kwargs['global_conf']['database_connection'] = kwargs[
            "database_connection"]
        tool_shed_server_wrapper = driver_util.launch_server(
            toolshedapp,
            toolshedbuildapp.app_factory,
            kwargs,
            prefix="TOOL_SHED",
        )
        self.server_wrappers.append(tool_shed_server_wrapper)
        tool_shed_test_host = tool_shed_server_wrapper.host
        tool_shed_test_port = tool_shed_server_wrapper.port
        log.info("Functional tests will be run against %s:%s" %
                 (tool_shed_test_host, tool_shed_test_port))

        # ---- Optionally start up a Galaxy instance ------------------------------------------------------
        if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ:
            # Generate the shed_tool_conf.xml file.
            tool_sheds_conf_template_parser = string.Template(
                tool_sheds_conf_xml_template)
            tool_sheds_conf_xml = tool_sheds_conf_template_parser.safe_substitute(
                shed_url=tool_shed_test_host, shed_port=tool_shed_test_port)
            open(galaxy_tool_sheds_conf_file, 'w').write(tool_sheds_conf_xml)
            # Generate the tool_sheds_conf.xml file.
            shed_tool_conf_template_parser = string.Template(
                shed_tool_conf_xml_template)
            shed_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute(
                shed_tool_path=galaxy_shed_tool_path)
            open(galaxy_shed_tool_conf_file, 'w').write(shed_tool_conf_xml)
            # Generate the migrated_tool_conf.xml file.
            migrated_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute(
                shed_tool_path=galaxy_migrated_tool_path)
            open(galaxy_migrated_tool_conf_file,
                 'w').write(migrated_tool_conf_xml)
            os.environ[
                'GALAXY_TEST_SHED_TOOL_CONF'] = galaxy_shed_tool_conf_file
            # Generate shed_data_manager_conf.xml
            if not os.environ.get('GALAXY_SHED_DATA_MANAGER_CONF'):
                open(galaxy_shed_data_manager_conf_file,
                     'wb').write(shed_data_manager_conf_xml_template)
            kwargs = dict(migrated_tools_config=galaxy_migrated_tool_conf_file,
                          shed_data_manager_config_file=
                          galaxy_shed_data_manager_conf_file,
                          shed_tool_path=galaxy_shed_tool_path,
                          tool_data_path=tool_data_path,
                          tool_sheds_config_file=galaxy_tool_sheds_conf_file)
            kwargs.update(
                driver_util.setup_galaxy_config(
                    galaxy_db_path,
                    use_test_file_dir=False,
                    default_install_db_merged=False,
                    default_tool_data_table_config_path=
                    default_tool_data_table_config_path,
                    default_shed_tool_data_table_config=
                    shed_tool_data_table_conf_file,
                    enable_tool_shed_check=True,
                    shed_tool_conf=galaxy_shed_tool_conf_file,
                    update_integrated_tool_panel=True,
                ))
            print("Galaxy database connection:", kwargs["database_connection"])

            # ---- Run galaxy webserver ------------------------------------------------------
            galaxyapp = driver_util.build_galaxy_app(kwargs)
            galaxy_server_wrapper = driver_util.launch_server(
                galaxyapp,
                galaxybuildapp.app_factory,
                kwargs,
            )
            log.info("Galaxy tests will be run against %s:%s" %
                     (galaxy_server_wrapper.host, galaxy_server_wrapper.port))
            self.server_wrappers.append(galaxy_server_wrapper)
Esempio n. 2
0
    def setup(self):
        """Entry point for test driver script."""
        # ---- Configuration ------------------------------------------------------
        tool_shed_test_tmp_dir = driver_util.setup_tool_shed_tmp_dir()
        if not os.path.isdir(tool_shed_test_tmp_dir):
            os.mkdir(tool_shed_test_tmp_dir)
        self.temp_directories.append(tool_shed_test_tmp_dir)
        shed_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir, prefix="TOOL_SHED")
        shed_tool_data_table_conf_file = os.environ.get('TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF', os.path.join(tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml'))
        galaxy_shed_data_manager_conf_file = os.environ.get('GALAXY_SHED_DATA_MANAGER_CONF', os.path.join(tool_shed_test_tmp_dir, 'test_shed_data_manager_conf.xml'))
        default_tool_data_table_config_path = os.path.join(tool_shed_test_tmp_dir, 'tool_data_table_conf.xml')
        galaxy_shed_tool_conf_file = os.environ.get('GALAXY_TEST_SHED_TOOL_CONF', os.path.join(tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml'))
        galaxy_migrated_tool_conf_file = os.environ.get('GALAXY_TEST_MIGRATED_TOOL_CONF', os.path.join(tool_shed_test_tmp_dir, 'test_migrated_tool_conf.xml'))
        galaxy_tool_sheds_conf_file = os.environ.get('GALAXY_TEST_TOOL_SHEDS_CONF', os.path.join(tool_shed_test_tmp_dir, 'test_sheds_conf.xml'))
        if 'GALAXY_TEST_TOOL_DATA_PATH' in os.environ:
            tool_data_path = os.environ.get('GALAXY_TEST_TOOL_DATA_PATH')
        else:
            tool_data_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
            os.environ['GALAXY_TEST_TOOL_DATA_PATH'] = tool_data_path
        galaxy_db_path = driver_util.database_files_path(tool_shed_test_tmp_dir)
        shed_file_path = os.path.join(shed_db_path, 'files')
        hgweb_config_file_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        new_repos_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        galaxy_shed_tool_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        galaxy_migrated_tool_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        hgweb_config_dir = hgweb_config_file_path
        os.environ['TEST_HG_WEB_CONFIG_DIR'] = hgweb_config_dir
        print("Directory location for hgweb.config:", hgweb_config_dir)
        toolshed_database_conf = driver_util.database_conf(shed_db_path, prefix="TOOL_SHED")
        kwargs = dict(admin_users='*****@*****.**',
                      allow_user_creation=True,
                      allow_user_deletion=True,
                      datatype_converters_config_file='datatype_converters_conf.xml.sample',
                      file_path=shed_file_path,
                      hgweb_config_dir=hgweb_config_dir,
                      job_queue_workers=5,
                      id_secret='changethisinproductiontoo',
                      log_destination="stdout",
                      new_file_path=new_repos_path,
                      running_functional_tests=True,
                      shed_tool_data_table_config=shed_tool_data_table_conf_file,
                      smtp_server='smtp.dummy.string.tld',
                      email_from='functional@localhost',
                      template_path='templates',
                      tool_parse_help=False,
                      use_heartbeat=False)
        kwargs.update(toolshed_database_conf)
        # Generate the tool_data_table_conf.xml file.
        open(default_tool_data_table_config_path, 'w').write(tool_data_table_conf_xml_template)
        # Generate the shed_tool_data_table_conf.xml file.
        open(shed_tool_data_table_conf_file, 'w').write(tool_data_table_conf_xml_template)
        os.environ['TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF'] = shed_tool_data_table_conf_file
        # ---- Build Tool Shed Application --------------------------------------------------
        toolshedapp = driver_util.build_shed_app(kwargs)

        # ---- Run tool shed webserver ------------------------------------------------------
        # TODO: Needed for hg middleware ('lib/galaxy/webapps/tool_shed/framework/middleware/hg.py')
        kwargs['global_conf']['database_connection'] = kwargs["database_connection"]
        tool_shed_server_wrapper = driver_util.launch_server(
            toolshedapp,
            toolshedbuildapp.app_factory,
            kwargs,
            prefix="TOOL_SHED",
        )
        self.server_wrappers.append(tool_shed_server_wrapper)
        tool_shed_test_host = tool_shed_server_wrapper.host
        tool_shed_test_port = tool_shed_server_wrapper.port
        log.info("Functional tests will be run against %s:%s" % (tool_shed_test_host, tool_shed_test_port))

        # ---- Optionally start up a Galaxy instance ------------------------------------------------------
        if 'TOOL_SHED_TEST_OMIT_GALAXY' not in os.environ:
            # Generate the shed_tool_conf.xml file.
            tool_sheds_conf_template_parser = string.Template(tool_sheds_conf_xml_template)
            tool_sheds_conf_xml = tool_sheds_conf_template_parser.safe_substitute(shed_url=tool_shed_test_host, shed_port=tool_shed_test_port)
            open(galaxy_tool_sheds_conf_file, 'w').write(tool_sheds_conf_xml)
            # Generate the tool_sheds_conf.xml file.
            shed_tool_conf_template_parser = string.Template(shed_tool_conf_xml_template)
            shed_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute(shed_tool_path=galaxy_shed_tool_path)
            open(galaxy_shed_tool_conf_file, 'w').write(shed_tool_conf_xml)
            # Generate the migrated_tool_conf.xml file.
            migrated_tool_conf_xml = shed_tool_conf_template_parser.safe_substitute(shed_tool_path=galaxy_migrated_tool_path)
            open(galaxy_migrated_tool_conf_file, 'w').write(migrated_tool_conf_xml)
            os.environ['GALAXY_TEST_SHED_TOOL_CONF'] = galaxy_shed_tool_conf_file
            # Generate shed_data_manager_conf.xml
            if not os.environ.get('GALAXY_SHED_DATA_MANAGER_CONF'):
                open(galaxy_shed_data_manager_conf_file, 'wb').write(shed_data_manager_conf_xml_template)
            kwargs = dict(migrated_tools_config=galaxy_migrated_tool_conf_file,
                          shed_data_manager_config_file=galaxy_shed_data_manager_conf_file,
                          shed_tool_path=galaxy_shed_tool_path,
                          tool_data_path=tool_data_path,
                          tool_sheds_config_file=galaxy_tool_sheds_conf_file)
            kwargs.update(
                driver_util.setup_galaxy_config(
                    galaxy_db_path,
                    use_test_file_dir=False,
                    default_install_db_merged=False,
                    default_tool_data_table_config_path=default_tool_data_table_config_path,
                    default_shed_tool_data_table_config=shed_tool_data_table_conf_file,
                    enable_tool_shed_check=True,
                    shed_tool_conf=galaxy_shed_tool_conf_file,
                    update_integrated_tool_panel=True,
                )
            )
            print("Galaxy database connection:", kwargs["database_connection"])

            # ---- Run galaxy webserver ------------------------------------------------------
            galaxyapp = driver_util.build_galaxy_app(kwargs)
            galaxy_server_wrapper = driver_util.launch_server(
                galaxyapp,
                galaxybuildapp.app_factory,
                kwargs,
            )
            log.info("Galaxy tests will be run against %s:%s" % (galaxy_server_wrapper.host, galaxy_server_wrapper.port))
            self.server_wrappers.append(galaxy_server_wrapper)