Esempio n. 1
0
    def tear_down(self):
        """
        Tear down the test environment.
        """
        if self._state == TestWithBaton._SetupState.RUNNING:
            self._state = TestWithBaton._SetupState.STOPPED
            atexit.unregister(self.tear_down)

            if self._irods_version_to_start is not None:
                logging.debug("Stopping iRODS server")
                get_static_irods_server_controller(self._irods_version_to_start).stop_server(self.irods_server)
                self.irods_server = None
            else:
                logging.debug("External iRODS test server used - not tearing down")

            logging.debug("Tearing down binary proxies")
            self._tear_down_proxies()
            self.baton_location = None
            self.icommands_location = None

            logging.debug("Tear down complete")
Esempio n. 2
0
    def get_irods_server(irods_version: IrodsVersion) -> ContainerisedIrodsServer:
        """
        Gets an iRODS server of the given version.

        This server is NOT isolated between test cases. Therefore it should be treated as read-only. It should also not
        be stopped at teardown.
        :param irods_version: the iRODS version
        :return: the containerised server
        """
        global _started_irods_servers
        if irods_version not in _started_irods_servers:
            IrodsServerController = get_static_irods_server_controller(irods_version)
            atexit.register(IrodsServerController.tear_down)
            _started_irods_servers[irods_version] = IrodsServerController.start_server()
        return _started_irods_servers[irods_version]
Esempio n. 3
0
    def test_baton_can_connect_to_irods_with_settings_file(self):
        irods_server = type(self).get_irods_server(self._irods_version)

        settings_directory = create_temp_docker_mountable_directory()
        IrodsController = get_static_irods_server_controller(self._irods_version)
        # XXX: This is rather hacky - it should be possible to get the name from the iRODS controller
        if self._irods_version == IrodsVersion.v3_3_1:
            IrodsController.write_connection_settings("%s/.irodsEnv" % settings_directory, irods_server)
        else:
            IrodsController.write_connection_settings("%s/irods_environment.json" % settings_directory, irods_server)
        host_config = create_client().create_host_config(binds={
            settings_directory: {
                "bind": "/root/.irods",
                "mode": "rw"
            }
        }, links={
            irods_server.host: irods_server.host
        })

        user = irods_server.users[0]
        response = self._run(command="ils", environment={"IRODS_PASSWORD": user.password}, host_config=host_config)
        self.assertEqual(response, "/%s/home/%s:" % (user.zone, user.username))
Esempio n. 4
0
    def setup(self):
        """
        Sets up the setup: builds the baton Docker image, starts the iRODS test server (if required) and creates the
        proxies.
        """
        if self._state != TestWithBaton._SetupState.INIT:
            raise RuntimeError("Already been setup")
        self._state = TestWithBaton._SetupState.RUNNING

        docker_client = create_client()
        if self._baton_docker_build.docker_file is not None:
            # baton Docker image is to be built from a local Dockerfile
            logging.debug("Building baton Docker")
            build_baton_docker(docker_client, self._baton_docker_build)
        else:
            # Ensuring Docker image is pulled - not waiting until `docker run` to prevent Docker from polluting the
            # stderr
            if ":" in self._baton_docker_build.tag:
                repository, tag = self._baton_docker_build.tag.split(":")
            else:
                repository = self._baton_docker_build.tag
                tag = ""

            docker_image = docker_client.images("%s:%s" % (repository, tag), quiet=True)
            if len(docker_image) == 0:
                # Docker image doesn't exist locally: getting from DockerHub
                docker_client.pull(repository, tag)

        if self._irods_version_to_start:
            logging.debug("Starting iRODS test server")
            self.irods_server = get_static_irods_server_controller(self._irods_version_to_start).start_server()
            logging.debug("iRODS test server has started")
        else:
            logging.debug("Using pre-existing iRODS server")

        self._setup_proxies()

        logging.debug("Setup complete")