Esempio n. 1
0
 def create_executable_template(command: str):
     commands_builder = CommandsBuilder(
         command, image=self._image_with_compatible_icommands,
         get_path_arguments_to_mount=IrodsBaseExecutablesController._GET_POSITIONAL_ARGUMENTS_TO_MOUNT,
         mounts=self._run_container_commands_builder.mounts,
         other_docker=self._run_container_commands_builder.other_docker)
     return Executable(commands_builder, False)
Esempio n. 2
0
 def test_create_executable_commands_with_no_running_container(self):
     commands_builder = CommandsBuilder("echo",
                                        image=UBUNTU_IMAGE_TO_TEST_WITH,
                                        executable_arguments=[_CONTENT])
     commands = self.controller.create_executable_commands(
         Executable(commands_builder, False))
     out, error = self._run_commands(commands)
     self.assertEqual(_CONTENT, out)
Esempio n. 3
0
    def test_create_executable_commands_with_positional_parameter_needing_mounting_for_read(
            self):
        _, read_file = self._temp_manager.create_temp_file()
        with open(read_file, "w") as file:
            file.write(_CONTENT)

        commands_builder = CommandsBuilder(
            "cat",
            image=UBUNTU_IMAGE_TO_TEST_WITH,
            get_path_arguments_to_mount=_CAT_MOUNTED_ARGUMENT_PARSER)
        commands = self.controller.create_executable_commands(
            Executable(commands_builder, False))
        out, error = self._run_commands(commands, [read_file])
        self.assertEqual(_CONTENT, out)
Esempio n. 4
0
 def create_simple_executable_commands(
         self,
         containerised_executable: str,
         executable_arguments=CLI_ARGUMENTS) -> str:
     """
     TODO
     :param containerised_executable:
     :param executable_arguments:
     :return:
     """
     containerised_executable = containerised_executable.replace('"', '\\"')
     to_execute = CommandsBuilder(
         executable=containerised_executable,
         container=self._cached_container_name,
         executable_arguments=[executable_arguments])
     return self.create_executable_commands(Executable(to_execute, True))
Esempio n. 5
0
    def test_create_executable_commands_with_named_parameters_needing_mounting(
            self):
        with tempfile.TemporaryDirectory(
                dir=MOUNTABLE_TEMP_DIRECTORY) as temp_directory:
            commands_builder = CommandsBuilder(
                "touch",
                image=UBUNTU_IMAGE_TO_TEST_WITH,
                get_path_arguments_to_mount=_TOUCH_MOUNTED_ARGUMENT_PARSER,
                mounts={temp_directory: temp_directory})
            commands = self.persistent_run_controller.create_executable_commands(
                Executable(commands_builder, False))

            test_file = os.path.join(temp_directory, "test-file")
            _, reference = self._temp_manager.create_temp_file()
            os.utime(reference, (0, 0))
            self._run_commands(commands, ["-r", reference, test_file])
            self.assertEqual(0.0, os.path.getmtime(test_file))
Esempio n. 6
0
    def test_create_executable_commands_with_positional_parameter_needing_mounting_for_write(
            self):
        with tempfile.TemporaryDirectory(
                dir=MOUNTABLE_TEMP_DIRECTORY) as temp_directory:
            file_locations = [
                os.path.join(temp_directory, str(uuid4())) for _ in range(5)
            ]
            commands_builder = CommandsBuilder(
                "touch",
                image=UBUNTU_IMAGE_TO_TEST_WITH,
                get_path_arguments_to_mount=_TOUCH_MOUNTED_ARGUMENT_PARSER)
            commands = self.controller.create_executable_commands(
                Executable(commands_builder, False))
            self._run_commands(commands, file_locations)

            for location in file_locations:
                self.assertTrue(os.path.exists(location))
Esempio n. 7
0
    def _register_named_executables(self):
        """
        Registers the executables that can be written by this controller.
        """
        for icommand in IrodsBaseExecutablesController._ICOMMAND_EXECUTABLES - {"iget", "iput"}:
            self.named_executables[icommand] = Executable(CommandsBuilder(icommand), True)

        def create_executable_template(command: str):
            commands_builder = CommandsBuilder(
                command, image=self._image_with_compatible_icommands,
                get_path_arguments_to_mount=IrodsBaseExecutablesController._GET_POSITIONAL_ARGUMENTS_TO_MOUNT,
                mounts=self._run_container_commands_builder.mounts,
                other_docker=self._run_container_commands_builder.other_docker)
            return Executable(commands_builder, False)

        # Note: if `-` is the second positional argument with `iget`, `-` is suspected as a file, relative to the
        # current directory. This leads to an unnecessary mount and the use of `-w` to change the working directory.
        self.named_executables["iget"] = create_executable_template("iget")
        self.named_executables["iput"] = create_executable_template("iput")
Esempio n. 8
0
from useintest.executables.builders import CommandsBuilder
from useintest.executables.common import get_all_path_like_arguments_for_mounting
from useintest.executables.controllers import DefinedExecutablesControllerTypeBuilder
from useintest.executables.models import Executable

Samtools1_3_1ExecutablesController = DefinedExecutablesControllerTypeBuilder(
    "Samtools1_3_1ExecutablesController",
    {
        "samtools":
        Executable(
            CommandsBuilder(
                image="comics/samtools:1.3.1",
                executable="samtools",
                # There are so many ways in which Samtools accepts file paths that the creation of a parser for it would
                # be a massive task. Instead, we'll overzealously bind mount anything that looks like a file path.
                get_path_arguments_to_mount=
                get_all_path_like_arguments_for_mounting),
            False)
    }).build()

SamtoolsExecutablesController = Samtools1_3_1ExecutablesController

samtools_executable_controllers = {Samtools1_3_1ExecutablesController}