From b3afe6359eed78509ce76316469c5b89a95b4e76 Mon Sep 17 00:00:00 2001 From: emlys <43770515+emlys@users.noreply.github.com> Date: Wed, 26 Jun 2019 10:24:33 -0700 Subject: [PATCH 1/3] Checker workflow fails as expected when checksums do not match * set exit code to 1 on failure dockstore/dockstore#2340 --- .travis.yml | 20 ++++++++++++++ checker-fail-cwl.json | 7 +++++ checker/bin/check_md5sum | 54 ++++++++++++++++++++------------------ checker/md5sum-checker.cwl | 2 +- checker/md5sum-checker.wdl | 2 +- md5sum-fail-wdl.json | 4 +++ test.py | 27 +++++++++++++++++++ 7 files changed, 88 insertions(+), 28 deletions(-) create mode 100644 .travis.yml create mode 100644 checker-fail-cwl.json create mode 100644 md5sum-fail-wdl.json create mode 100644 test.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..adcf9b3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +sudo: required + +services: + - docker + +language: python + +python: + - "3.6" + +before_install: + # Download Cromwell + - wget -O $TRAVIS_BUILD_DIR/cromwell-42.jar https://github.com/broadinstitute/cromwell/releases/download/42/cromwell-42.jar; + - curl -o requirements.txt "https://dockstore.org/api/metadata/runner_dependencies?client_version=1.6.0&python_version=3" + +install: + - pip install -r requirements.txt + +script: + - python -m unittest discover -s . \ No newline at end of file diff --git a/checker-fail-cwl.json b/checker-fail-cwl.json new file mode 100644 index 0000000..9812490 --- /dev/null +++ b/checker-fail-cwl.json @@ -0,0 +1,7 @@ +{ + "input_file": { + "class": "File", + "path": "md5sum.input" + }, + "expected_md5": "not a matching md5sum" +} \ No newline at end of file diff --git a/checker/bin/check_md5sum b/checker/bin/check_md5sum index 4c12b76..bf8c9f8 100644 --- a/checker/bin/check_md5sum +++ b/checker/bin/check_md5sum @@ -6,39 +6,41 @@ import json import sys import os + def main(): - parser = argparse.ArgumentParser(description='Checks to see if a given file contains a certain string and then returns a JSON.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('--input-file', type=str, help='file input') - parser.add_argument('--md5', type=str, help='expected md5') - args = parser.parse_args() + parser = argparse.ArgumentParser(description='Checks to see if a given file contains a certain string and then returns a JSON.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('--input-file', type=str, help='file input') + parser.add_argument('--md5', type=str, help='expected md5') + args = parser.parse_args() + + result_code = check_file(args.input_file, args.md5) - result = check_file(args.input_file, args.md5) + results_file = open("results.json", "w") + if result_code == 0: + results_file.write('{ "overall" : true, "steps" : { "md5sum_check" : true } }') + else: + results_file.write('{ "overall" : false, "steps" : { "md5sum_check" : false } }') + results_file.close() - results_file = open("results.json", "w") - if (result == 0): - results_file.write('{ "overall" : true, "steps" : { "md5sum_check" : true } }') - else: - results_file.write('{ "overall" : false, "steps" : { "md5sum_check" : false } }') - results_file.close() + log_file = open("log.txt", "w") + log_file.write("") + log_file.close() - log_file = open("log.txt", "w") - log_file.write("") - log_file.close() + sys.exit(result_code) - # correct way to do this? - return(result) def check_file(input_file, md5): - file = open(input_file, "r") - contents = file.read() - contents = contents.rstrip() - print ("FILE CONTENTS: "+contents) - if (contents == md5): - print("Contents match") - return(0) - else: - print("Contents DO NOT match") - return(1) + file = open(input_file, "r") + contents = file.read() + contents = contents.rstrip() + print("FILE CONTENTS: "+contents) + if contents == md5: + print("Contents match") + return 0 + else: + print("Contents DO NOT match") + return 1 + if __name__ == "__main__": main() diff --git a/checker/md5sum-checker.cwl b/checker/md5sum-checker.cwl index c90549e..da0b186 100644 --- a/checker/md5sum-checker.cwl +++ b/checker/md5sum-checker.cwl @@ -7,7 +7,7 @@ cwlVersion: v1.0 requirements: - class: DockerRequirement - dockerPull: quay.io/agduncan94/checker-md5sum + dockerPull: quay.io/dockstore-testing/md5sum-checker:feature_emlys_DOC-654 - class: InlineJavascriptRequirement hints: diff --git a/checker/md5sum-checker.wdl b/checker/md5sum-checker.wdl index 7ad8eb7..dc7ff95 100644 --- a/checker/md5sum-checker.wdl +++ b/checker/md5sum-checker.wdl @@ -7,6 +7,6 @@ task checkerTask { } runtime { - docker: "quay.io/agduncan94/checker-md5sum" + docker: "quay.io/dockstore-testing/md5sum-checker:feature_emlys_DOC-654" } } diff --git a/md5sum-fail-wdl.json b/md5sum-fail-wdl.json new file mode 100644 index 0000000..98d8f05 --- /dev/null +++ b/md5sum-fail-wdl.json @@ -0,0 +1,4 @@ +{ + "checkerWorkflow.inputFile": "md5sum.input", + "checkerWorkflow.expectedMd5sum": "not a real md5sum" +} diff --git a/test.py b/test.py new file mode 100644 index 0000000..8b49eaa --- /dev/null +++ b/test.py @@ -0,0 +1,27 @@ +import subprocess +import unittest + + +class TestMd5sumChecker(unittest.TestCase): + # For each workflow, verify that it succeeds when the input file's md5sum matches and fails when it does not + def test_cwl_success(self): + process = subprocess.call(["cwltool", "checker-workflow-wrapping-tool.cwl", "checker-input-cwl.json"]) + self.assertEqual(process, 0) + + def test_cwl_failure(self): + process = subprocess.call(["cwltool", "checker-workflow-wrapping-tool.cwl", "checker-fail-cwl.json"]) + self.assertEqual(process, 1) + + def test_wdl_success(self): + process = subprocess.call(["java", "-jar", "cromwell-42.jar", "run", "checker-workflow-wrapping-workflow.wdl", + "-i", "md5sum-wdl.json"]) + self.assertEqual(process, 0) + + def test_wdl_failure(self): + process = subprocess.call(["java", "-jar", "cromwell-42.jar", "run", "checker-workflow-wrapping-workflow.wdl", + "-i", "md5sum-fail-wdl.json"]) + self.assertEqual(process, 1) + + +if __name__ == '__main__': + unittest.main() From 761499a8329b367d37eb83d180fb762e04ada97f Mon Sep 17 00:00:00 2001 From: emlys <43770515+emlys@users.noreply.github.com> Date: Fri, 28 Jun 2019 11:18:51 -0700 Subject: [PATCH 2/3] updated to version 1.0.0 (#4) * updated to version 1.0.0 * replacing test docker image with local version --- .travis.yml | 5 +++++ checker/md5sum-checker.cwl | 2 +- checker/md5sum-checker.wdl | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index adcf9b3..98e1c7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,9 @@ install: - pip install -r requirements.txt script: + - docker build -t test-image -f checker/Dockerfile checker + - >- + sed 's/dockerPull:.*/dockerPull: test-image:latest/g' checker/md5sum-checker.cwl + - >- + sed 's/docker:.*/docker: "test-image:latest"/g' checker/md5sum-checker.wdl - python -m unittest discover -s . \ No newline at end of file diff --git a/checker/md5sum-checker.cwl b/checker/md5sum-checker.cwl index da0b186..16887ac 100644 --- a/checker/md5sum-checker.cwl +++ b/checker/md5sum-checker.cwl @@ -7,7 +7,7 @@ cwlVersion: v1.0 requirements: - class: DockerRequirement - dockerPull: quay.io/dockstore-testing/md5sum-checker:feature_emlys_DOC-654 + dockerPull: quay.io/dockstore-testing/md5sum-checker:1.0.0 - class: InlineJavascriptRequirement hints: diff --git a/checker/md5sum-checker.wdl b/checker/md5sum-checker.wdl index dc7ff95..637e782 100644 --- a/checker/md5sum-checker.wdl +++ b/checker/md5sum-checker.wdl @@ -7,6 +7,6 @@ task checkerTask { } runtime { - docker: "quay.io/dockstore-testing/md5sum-checker:feature_emlys_DOC-654" + docker: "quay.io/dockstore-testing/md5sum-checker:1.0.0" } } From 329a291b2d349b19e94dc456b547c7d38834596a Mon Sep 17 00:00:00 2001 From: garyluu Date: Tue, 10 Sep 2019 15:34:38 -0400 Subject: [PATCH 3/3] Move inputs files --- md5sum/md5sum-input-cwl.json | 2 +- md5sum/md5sum-wdl.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/md5sum/md5sum-input-cwl.json b/md5sum/md5sum-input-cwl.json index c6e6b7b..a254306 100644 --- a/md5sum/md5sum-input-cwl.json +++ b/md5sum/md5sum-input-cwl.json @@ -1,6 +1,6 @@ { "input_file": { "class": "File", - "path": "md5sum.input" + "path": "../md5sum.input" } } diff --git a/md5sum/md5sum-wdl.json b/md5sum/md5sum-wdl.json index 4ed090c..125237c 100644 --- a/md5sum/md5sum-wdl.json +++ b/md5sum/md5sum-wdl.json @@ -1,3 +1,3 @@ { - "ga4ghMd5.inputFile": "md5sum.input" + "ga4ghMd5.inputFile": "../md5sum.input" }