From b04d2868fb34aa4216dd09ccb71d4dcd3c580bf4 Mon Sep 17 00:00:00 2001 From: Ruairidh MacLeod Date: Fri, 15 Nov 2024 14:21:24 +0000 Subject: [PATCH] don't return early in install loop --- roles/hicservices_rdmp/tasks/deploy_rdmp_cli.py | 11 +++++++---- roles/hicservices_rdmp/tasks/main.yaml | 3 ++- .../smi_isidentifiable/tasks/deploy_isidentifiable.py | 11 +++++++---- roles/smi_isidentifiable/tasks/main.yaml | 3 ++- roles/smi_smiservices/tasks/deploy_smiservices.py | 11 +++++++---- roles/smi_smiservices/tasks/main.yaml | 3 ++- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/roles/hicservices_rdmp/tasks/deploy_rdmp_cli.py b/roles/hicservices_rdmp/tasks/deploy_rdmp_cli.py index c4a0077..d390277 100755 --- a/roles/hicservices_rdmp/tasks/deploy_rdmp_cli.py +++ b/roles/hicservices_rdmp/tasks/deploy_rdmp_cli.py @@ -19,13 +19,14 @@ def main() -> int: parser.add_argument("versions", type=json.loads) args = parser.parse_args() + rc = 0 for version, version_data in args.versions.items(): install_dir = f"{args.install_root}/v{version}" if os.path.isdir(install_dir): print(f"{install_dir} already exists") - return 0 + continue os.mkdir(install_dir) with tempfile.TemporaryDirectory() as tempdir: @@ -35,7 +36,7 @@ def main() -> int: f"Checksum format not supported: {p['checksum']}", file=sys.stderr, ) - return 1 + return 2 package_name = p["name"].replace("", version) url = f"{args.base_url}/v{version}/{package_name}" @@ -51,7 +52,7 @@ def main() -> int: f"Expected {expected_sha256}, got {file_sha256}" ) print(err, file=sys.stderr) - return 1 + return 2 package_ext = package_path.split(".")[-1] if package_ext == "xz": @@ -75,7 +76,9 @@ def main() -> int: assert len(rdmp_cli_dir) == 1, f"Expected only one match: {rdmp_cli_dir}" shutil.copytree(rdmp_cli_dir[0], f"{install_dir}/rdmp-cli") - return 0 + rc = 1 + + return rc if __name__ == "__main__": diff --git a/roles/hicservices_rdmp/tasks/main.yaml b/roles/hicservices_rdmp/tasks/main.yaml index e118fa0..94fb162 100644 --- a/roles/hicservices_rdmp/tasks/main.yaml +++ b/roles/hicservices_rdmp/tasks/main.yaml @@ -14,7 +14,8 @@ {{ hicservices_rdmp_base_dir }} \ '{{ hicservices_rdmp_versions | to_json }}' register: deploy_result - changed_when: deploy_result.rc != 0 + changed_when: deploy_result.rc == 1 + failed_when: deploy_result.rc > 1 - name: Set rdmp-cli permissions ansible.builtin.file: diff --git a/roles/smi_isidentifiable/tasks/deploy_isidentifiable.py b/roles/smi_isidentifiable/tasks/deploy_isidentifiable.py index 860c9ea..e0e628e 100755 --- a/roles/smi_isidentifiable/tasks/deploy_isidentifiable.py +++ b/roles/smi_isidentifiable/tasks/deploy_isidentifiable.py @@ -19,13 +19,14 @@ def main() -> int: parser.add_argument("versions", type=json.loads) args = parser.parse_args() + rc = 0 for version, version_data in args.versions.items(): install_dir = f"{args.install_root}/v{version}" if os.path.isdir(install_dir): print(f"{install_dir} already exists") - return 0 + continue os.mkdir(install_dir) with tempfile.TemporaryDirectory() as tempdir: @@ -35,7 +36,7 @@ def main() -> int: f"Checksum format not supported: {p['checksum']}", file=sys.stderr, ) - return 1 + return 2 package_name = p["name"].replace("", version) url = f"{args.base_url}/v{version}/{package_name}" @@ -50,7 +51,7 @@ def main() -> int: f"Checksum error. Expected {expected_md5}, got {file_md5}", file=sys.stderr, ) - return 1 + return 2 package_ext = package_path.split(".")[-1] if package_ext == "gz": @@ -83,7 +84,9 @@ def main() -> int: for f in glob.glob(f"{tempdir}/*.{ext}"): shutil.copy2(f, f"{install_dir}/") - return 0 + rc = 1 + + return rc if __name__ == "__main__": diff --git a/roles/smi_isidentifiable/tasks/main.yaml b/roles/smi_isidentifiable/tasks/main.yaml index ce07678..727715f 100644 --- a/roles/smi_isidentifiable/tasks/main.yaml +++ b/roles/smi_isidentifiable/tasks/main.yaml @@ -14,4 +14,5 @@ {{ smi_isidentifiable_base_dir }} \ '{{ smi_isidentifiable_versions | to_json }}' register: deploy_result - changed_when: deploy_result.rc != 0 + changed_when: deploy_result.rc == 1 + failed_when: deploy_result.rc > 1 diff --git a/roles/smi_smiservices/tasks/deploy_smiservices.py b/roles/smi_smiservices/tasks/deploy_smiservices.py index 804374c..37832a8 100755 --- a/roles/smi_smiservices/tasks/deploy_smiservices.py +++ b/roles/smi_smiservices/tasks/deploy_smiservices.py @@ -20,13 +20,14 @@ def main() -> int: parser.add_argument("versions", type=json.loads) args = parser.parse_args() + rc = 0 for version, version_data in args.versions.items(): install_dir = f"{args.install_root}/v{version}" if os.path.isdir(install_dir): print(f"{install_dir} already exists") - return 0 + continue os.mkdir(install_dir) with tempfile.TemporaryDirectory() as tempdir: @@ -36,7 +37,7 @@ def main() -> int: f"Checksum format not supported: {p['checksum']}", file=sys.stderr, ) - return 1 + return 2 package_name = p["name"].replace("", version) url = f"{args.base_url}/v{version}/{package_name}" @@ -51,7 +52,7 @@ def main() -> int: f"Checksum error. Expected {expected_md5}, got {file_md5}", file=sys.stderr, ) - return 1 + return 2 package_ext = package_path.split(".")[-1] if package_ext == "tgz": @@ -88,7 +89,9 @@ def main() -> int: ctp_jar = f"{tempdir}/ctpanonymiser-1.0.0/CTPAnonymiser-portable-1.0.0.jar" shutil.copy2(ctp_jar, f"{install_dir}/CTPAnonymiser.jar") - return 0 + rc = 1 + + return rc if __name__ == "__main__": diff --git a/roles/smi_smiservices/tasks/main.yaml b/roles/smi_smiservices/tasks/main.yaml index 388e7dc..c4f3d19 100644 --- a/roles/smi_smiservices/tasks/main.yaml +++ b/roles/smi_smiservices/tasks/main.yaml @@ -14,4 +14,5 @@ {{ smi_smiservices_base_dir }} \ '{{ smi_smiservices_versions | to_json }}' register: deploy_result - changed_when: deploy_result.rc != 0 + changed_when: deploy_result.rc == 0 + failed_when: deploy_result.rc > 1