def test_removal(self): app = ContainerApp(id=42) expected_plan = {'ContainerApps': {app}} plan = app.build_removal_plan() self.assertEqual(expected_plan, strip_removal_plan(plan))
def test_removal_with_linked_runs(self): """ One run's output is used as another's input, watch for dups. """ app = ContainerApp(id=42) run1 = app.runs.create(id=43, state=ContainerRun.COMPLETE) dataset = Dataset.objects.create(id=44) run_dataset1 = run1.datasets.create( id=45, run=run1, dataset=dataset, argument=ContainerArgument(type=ContainerArgument.OUTPUT)) run2 = app.runs.create(id=46, state=ContainerRun.COMPLETE) run_dataset2 = run2.datasets.create( id=47, run=run2, dataset=dataset, argument=ContainerArgument(type=ContainerArgument.INPUT)) dataset.containers.add(run_dataset1) dataset.containers.add(run_dataset2) expected_plan = { 'ContainerApps': {app}, 'ContainerRuns': {run1, run2}, 'Datasets': {dataset} } plan = app.build_removal_plan() self.assertEqual(expected_plan, strip_removal_plan(plan))
def test_removal_with_linked_runs(self): """ One run's output is used as another's input, watch for dups. """ app = ContainerApp(id=42) run1 = app.runs.create(id=43, state=ContainerRun.COMPLETE) dataset = Dataset.objects.create(id=44) run_dataset1 = run1.datasets.create( id=45, run=run1, dataset=dataset, argument=ContainerArgument(type=ContainerArgument.OUTPUT)) run2 = app.runs.create(id=46, state=ContainerRun.COMPLETE) run_dataset2 = run2.datasets.create( id=47, run=run2, dataset=dataset, argument=ContainerArgument(type=ContainerArgument.INPUT)) dataset.containers.add(run_dataset1) dataset.containers.add(run_dataset2) expected_plan = {'ContainerApps': {app}, 'ContainerRuns': {run1, run2}, 'Datasets': {dataset}} plan = app.build_removal_plan() self.assertEqual(expected_plan, strip_removal_plan(plan))
def test_write_optional(self): app = ContainerApp() expected_outputs = '--greetings_csv names_csv' app.write_outputs(expected_outputs) outputs = app.outputs self.assertEqual(expected_outputs, outputs)
def test_write_inputs_divider(self): app = ContainerApp() expected_inputs = '--greetings_csv* -- names_csv' app.write_inputs(expected_inputs) inputs = app.inputs self.assertEqual(expected_inputs, inputs)
def test_removal_with_run(self): app = ContainerApp(id=42) run = app.runs.create(id=43, state=ContainerRun.COMPLETE) expected_plan = {'ContainerApps': {app}, 'ContainerRuns': {run}} plan = app.build_removal_plan() self.assertEqual(expected_plan, strip_removal_plan(plan))
def test_write_output_multiple(self): app = ContainerApp() expected_outputs = 'greetings_csv/ names_csv' app.write_outputs(expected_outputs) outputs = app.outputs self.assertEqual(expected_outputs, outputs)
def test_write_input_multiple(self): app = ContainerApp() expected_inputs = 'greetings_csv* names_csv' app.write_inputs(expected_inputs) inputs = app.inputs self.assertEqual(expected_inputs, inputs)
def test_display_default(self): app = ContainerApp(name='') # default app app.container = Container(tag='v1.0') app.container.family = ContainerFamily(name='Splines') expected_display_name = 'Splines:v1.0' display_name = app.display_name self.assertEqual(expected_display_name, display_name)
def test_display_name(self): app = ContainerApp(name='reticulate') app.container = Container(tag='v1.0') app.container.family = ContainerFamily(name='Splines') expected_display_name = 'Splines:v1.0 / reticulate' display_name = app.display_name app_str = str(app) self.assertEqual(expected_display_name, display_name) self.assertEqual(expected_display_name, app_str)
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
def setUp(self): self.mock_viewset(ContainerAppViewSet) super(ContainerAppApiMockTests, self).setUp() patcher = mocked_relations(Container, ContainerFamily) patcher.start() self.addCleanup(patcher.stop) self.list_path = reverse("containerapp-list") self.list_view, _, _ = resolve(self.list_path) self.detail_pk = 43 self.detail_path = reverse("containerapp-detail", kwargs={'pk': self.detail_pk}) self.detail_view, _, _ = resolve(self.detail_path) self.my_user = User(pk=1000) User.objects.add(self.my_user) my_kive_user = KiveUser(pk=self.my_user.pk, username='******') KiveUser.objects.add(my_kive_user) other_user = User(pk=1001) User.objects.add(other_user) other_kive_user = KiveUser(pk=other_user.pk) KiveUser.objects.add(other_kive_user) my_container = Container.objects.create(id=100, user=my_kive_user) my_container.family = ContainerFamily.objects.create() other_container = Container.objects.create(id=101, user=other_kive_user) archive = ContainerApp(pk=42, name='archive', description='impressive') compress = ContainerApp(pk=43, name='compress') backup = ContainerApp(pk=44, name='backup') distribute = ContainerApp(pk=45, name='distribute') archive.container = compress.container = backup.container = my_container distribute.container = other_container ContainerApp.objects.add(archive, compress, backup, distribute)
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)
def test_optional_arguments(self): app = ContainerApp() app.arguments.create(name='greetings_csv', position=1, type=ContainerArgument.INPUT) app.arguments.create(name='names_csv', type=ContainerArgument.INPUT) app.arguments.create(name='messages_csv', position=1, type=ContainerArgument.OUTPUT) expected_inputs = '--names_csv greetings_csv' expected_outputs = 'messages_csv' inputs = app.inputs outputs = app.outputs self.assertEqual(expected_inputs, inputs) self.assertEqual(expected_outputs, outputs)
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)
def test_multiple_arguments(self): app = ContainerApp() app.arguments.create(name='greetings_csv', position=1, type=ContainerArgument.INPUT) app.arguments.create(name='names_csv', position=2, allow_multiple=True, type=ContainerArgument.INPUT) app.arguments.create(name='messages_csv', position=1, type=ContainerArgument.OUTPUT, allow_multiple=True) expected_inputs = 'greetings_csv names_csv*' expected_outputs = 'messages_csv/' inputs = app.inputs outputs = app.outputs self.assertEqual(expected_inputs, inputs) self.assertEqual(expected_outputs, outputs)
def test_write_arguments_bad_name(self): app = ContainerApp() with self.assertRaisesRegexp(ValueError, r'Invalid argument name: @greetings_csv'): app.write_outputs('@greetings_csv names_csv')
def test_write_output_bad_multiple(self): app = ContainerApp() with self.assertRaisesRegexp(ValueError, r'Invalid argument name: greetings_csv*'): app.write_outputs('greetings_csv* names_csv')
def test_write_output_bad_multiple(self): app = ContainerApp() with self.assertRaisesRegex(ValueError, r'Invalid argument name: greetings_csv*'): app.write_outputs('greetings_csv* names_csv')
def test_write_arguments_bad_name(self): app = ContainerApp() with self.assertRaisesRegex(ValueError, r'Invalid argument name: @greetings_csv'): app.write_outputs('@greetings_csv names_csv')