Skip to content

Commit

Permalink
Input dataset MD5s are now tested when a run is launched, as part of #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Liang committed Feb 22, 2019
1 parent 8b446c1 commit 5aaad54
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 12 additions & 0 deletions kive/container/management/commands/runcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def run_container(self, run):
stdout_path = os.path.join(logs_path, 'stdout.txt')
stderr_path = os.path.join(logs_path, 'stderr.txt')

for input_cd in run.datasets.filter(argument__type=ContainerArgument.INPUT):
input_dataset = input_cd.dataset
current_md5 = input_dataset.compute_md5()
if current_md5 != input_dataset.MD5_checksum:
raise ValueError(
"Dataset with pk={} has an inconsistent checksum (original {}; current {})".format(
input_dataset.pk,
input_dataset.MD5_checksum,
current_md5
)
)

container_to_run = run.app.container
container_to_run.validate_md5()
if not container_to_run.is_singularity():
Expand Down
26 changes: 24 additions & 2 deletions kive/container/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,23 @@ def test_run(self):
dataset_groups = list(output_dataset.groups_allowed.values_list('name'))
self.assertEqual(expected_groups, dataset_groups)

def test_run_input_bad_md5(self):
run = ContainerRun.objects.get(name='fixture run')
everyone = Group.objects.get(name='Everyone')
run.groups_allowed.clear()
run.groups_allowed.add(everyone)

# Tamper with the file.
input_containerdataset = run.datasets.get(
argument__type=ContainerArgument.INPUT,
argument__position=1
)
input_dataset = input_containerdataset.dataset
input_dataset.dataset_file.save("tampered", ContentFile(b"foo"), save=True)

with self.assertRaises(ValueError):
call_command('runcontainer', str(run.id))

def test_run_bad_md5(self):
run = ContainerRun.objects.get(name='fixture run')
everyone = Group.objects.get(name='Everyone')
Expand Down Expand Up @@ -1699,8 +1716,13 @@ def test_run_multistep_archive(self):
run.app = container.apps.create(memory=200, threads=1)
run.app.write_inputs('pairs_csv')
run.app.write_outputs('summary_csv')
pairs_dataset = Dataset.objects.create(user=run.user, name='pairs.csv')
pairs_dataset.dataset_file.save('pairs.csv', ContentFile(pairs_text))
pairs_dataset = Dataset.create_dataset(
file_path=None,
user=run.user,
file_handle=ContentFile(pairs_text, name="pairs.csv")
)
# pairs_dataset = Dataset.objects.create(user=run.user, name='pairs.csv')
# pairs_dataset.dataset_file.save('pairs.csv', ContentFile(pairs_text))
run_input = run.datasets.get()
run_input.dataset = pairs_dataset
run_input.argument = run.app.arguments.get(type=ContainerArgument.INPUT)
Expand Down

0 comments on commit 5aaad54

Please sign in to comment.