Exemple #1
0
    def test_change_not_on_rerun(self):
        run1 = ContainerRun(md5='11111111111111111111111111111111')
        run2 = ContainerRun(md5='11111111111111111111111111111111',
                            original_run=run1,
                            state=ContainerRun.COMPLETE)

        self.assertEqual(False, run2.has_changed)
Exemple #2
0
    def test_change_on_fail(self):
        """ Only report changes on successfully completed runs. """
        run1 = ContainerRun(md5='11111111111111111111111111111111')
        run2 = ContainerRun(md5='11111111111111111111111111111111',
                            original_run=run1,
                            state=ContainerRun.FAILED)

        self.assertIsNone(run2.has_changed)
Exemple #3
0
    def test_removal(self):
        run = ContainerRun(id=42, state=ContainerRun.COMPLETE)
        expected_plan = {'ContainerRuns': {run}}

        plan = run.build_removal_plan()

        self.assertEqual(expected_plan, strip_removal_plan(plan))
Exemple #4
0
 def build_run(self):
     run = ContainerRun()
     run.app = ContainerApp()
     run.app.container = Container()
     run.app.container.file = Namespace(path='/tmp/foo.simg')
     run.sandbox_path = '/tmp/box23'
     run.app.arguments.create(type=ContainerArgument.INPUT, name='in_csv')
     run.app.arguments.create(type=ContainerArgument.OUTPUT, name='out_csv')
     return run
Exemple #5
0
    def test_removal_skips_inputs(self):
        run = ContainerRun(id=42, state=ContainerRun.COMPLETE)
        dataset = Dataset(id=43)
        argument = ContainerArgument(type=ContainerArgument.INPUT)
        run.datasets.create(dataset=dataset, argument=argument)
        expected_plan = {'ContainerRuns': {run}}

        plan = run.build_removal_plan()

        self.assertEqual(expected_plan, strip_removal_plan(plan))
Exemple #6
0
    def test_build_dataset_name(self):
        run = ContainerRun(id=42)
        handler = runcontainer.Command()

        scenarios = [('example_csv', 'example_42.csv'),
                     ('example_tar_gz', 'example_42.tar.gz'),
                     ('csv', '42.csv'), ('_csv', '_42.csv'), ('_', '__42'),
                     ('no_extension', 'no_extension_42')]

        for argument_name, expected_dataset_name in scenarios:
            dataset_name = handler.build_dataset_name(run, argument_name)

            self.assertEqual(expected_dataset_name, dataset_name)
Exemple #7
0
    def test_rerun_names(self):
        expectations = [('example', 'example (rerun)'), ('', '(rerun)'),
                        ('example   ', 'example (rerun)'),
                        ('example (rerun)', 'example (rerun)'),
                        ('example (rerun) ', 'example (rerun)'),
                        ('example (rerun) weird',
                         'example (rerun) weird (rerun)')]
        run = ContainerRun()
        for name, expected_rerun_name in expectations:
            run.name = name

            rerun_name = run.get_rerun_name()

            self.assertEqual(expected_rerun_name, rerun_name)
Exemple #8
0
    def test_slurm_command_custom_memory(self):
        run = ContainerRun(pk=99)
        run.user = User(username='******')
        run.app = ContainerApp(threads=3, memory=100)
        run.app.container = Container()
        run.app.container.family = ContainerFamily(name='my container')
        run.sandbox_path = 'run23'
        expected_command = [
            'sbatch', '-J', 'r99 my container', '--parsable', '--output',
            '/tmp/kive_media/run23/logs/job%J_node%N_stdout.txt', '--error',
            '/tmp/kive_media/run23/logs/job%J_node%N_stderr.txt', '-c', '3',
            '--mem', '100', EXPECTED_MANAGE_PATH, 'runcontainer', '99'
        ]

        command = run.build_slurm_command()

        self.assertListEqual(expected_command, command)
Exemple #9
0
    def test_slurm_command_priority(self):
        run = ContainerRun(pk=99)
        run.user = User(username='******')
        run.app = ContainerApp()
        run.app.container = Container()
        run.app.container.family = ContainerFamily(name='my container')
        slurm_queues = (('low', 'kive-low'), ('medium', 'kive-medium'),
                        ('high', 'kive-high'))
        run.priority = 2
        run.sandbox_path = 'run23'
        expected_command = [
            'sbatch', '-J', 'r99 my container', '--parsable', '--output',
            '/tmp/kive_media/run23/logs/job%J_node%N_stdout.txt', '--error',
            '/tmp/kive_media/run23/logs/job%J_node%N_stderr.txt', '-c', '1',
            '--mem', '6000', '-p', 'kive-high', EXPECTED_MANAGE_PATH,
            'runcontainer', '99'
        ]

        command = run.build_slurm_command(slurm_queues)

        self.assertListEqual(expected_command, command)
Exemple #10
0
    def test_change_on_new_run(self):
        run1 = ContainerRun(md5='11111111111111111111111111111111',
                            state=ContainerRun.COMPLETE)

        self.assertIsNone(run1.has_changed)
Exemple #11
0
    def test_remove_running(self):
        run = ContainerRun(id=42, state=ContainerRun.RUNNING)

        with self.assertRaisesRegex(ValueError,
                                    r'ContainerRun id 42 is still active.'):
            run.build_removal_plan()