From 410225a100a85f76d256342dec98b178fc16a150 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Fri, 23 May 2025 12:26:46 +0200 Subject: [PATCH 1/3] Removed unused library Signed-off-by: Victor Moene --- cf_remote/web.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cf_remote/web.py b/cf_remote/web.py index 3f7ae3c..fc3fa17 100644 --- a/cf_remote/web.py +++ b/cf_remote/web.py @@ -1,4 +1,3 @@ -import hashlib import os import fcntl import re From 529745f612d587b18fb9add460b623d472d4b425 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Fri, 23 May 2025 12:25:47 +0200 Subject: [PATCH 2/3] Fixed unhandled invalid checksum error when downloading package Ticket: ENT-12764 Signed-off-by: Victor Moene --- cf_remote/commands.py | 29 +++++++++++++++++++++++------ cf_remote/remote.py | 25 +++++++++++++++---------- cf_remote/utils.py | 4 ++++ cf_remote/web.py | 7 ++++--- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/cf_remote/commands.py b/cf_remote/commands.py index 06e0f80..62517f8 100644 --- a/cf_remote/commands.py +++ b/cf_remote/commands.py @@ -33,7 +33,12 @@ get_package_name, user_error, ) -from cf_remote.utils import user_error, is_package_url, print_progress_dot +from cf_remote.utils import ( + user_error, + is_package_url, + print_progress_dot, + ChecksumError, +) from cf_remote.spawn import VM, VMRequest, Providers, AWSCredentials, GCPCredentials from cf_remote.spawn import spawn_vms, destroy_vms, dump_vms_info, get_cloud_driver from cf_remote import log @@ -180,7 +185,11 @@ def install( if remote_download: package, hub_package, client_package = _verify_package_urls(packages) else: - package, hub_package, client_package = _download_urls(packages) + try: + package, hub_package, client_package = _download_urls(packages) + except ChecksumError as ce: + log.error(ce) + return 1 # If any of these are folders, transform them to lists of the files inside those folders: package = _maybe_packages_in_folder(package) @@ -308,9 +317,13 @@ def _iterate_over_packages( else: for artifact in artifacts: if download: - package_path = download_package( - artifact.url, checksum=artifact.checksum - ) + try: + package_path = download_package( + artifact.url, checksum=artifact.checksum + ) + except ChecksumError as ce: + log.error(ce) + return 1 if output_dir: output_dir = os.path.abspath(os.path.expanduser(output_dir)) parent = os.path.dirname(output_dir) @@ -854,7 +867,11 @@ def deploy(hubs, masterfiles): print("Found cfbs policy set: '{}'".format(masterfiles)) elif masterfiles and masterfiles.startswith(("http://", "https://")): urls = [masterfiles] - paths = _download_urls(urls) + try: + paths = _download_urls(urls) + except ChecksumError as ce: + log.error(ce) + return 1 assert len(paths) == 1 masterfiles = paths[0] log.debug("Deploying downloaded: %s" % masterfiles) diff --git a/cf_remote/remote.py b/cf_remote/remote.py index 88b97d7..bf58ec1 100644 --- a/cf_remote/remote.py +++ b/cf_remote/remote.py @@ -14,6 +14,7 @@ user_error, parse_systeminfo, parse_version, + ChecksumError, ) from cf_remote.ssh import ssh_sudo, ssh_cmd, scp, auto_connect from cf_remote import log @@ -515,16 +516,20 @@ def install_host( package = packages[0] if not package: - package = get_package_from_host_info( - data.get("package_tags"), - data.get("bin"), - data.get("arch"), - version, - hub, - edition, - packages, - remote_download, - ) + try: + package = get_package_from_host_info( + data.get("package_tags"), + data.get("bin"), + data.get("arch"), + version, + hub, + edition, + packages, + remote_download, + ) + except ChecksumError as ce: + log.error(ce) + return 1 if not package: log.error("Installation failed - no package found!") diff --git a/cf_remote/utils.py b/cf_remote/utils.py index 0dde62f..6a74917 100644 --- a/cf_remote/utils.py +++ b/cf_remote/utils.py @@ -279,3 +279,7 @@ def has_unescaped_character(string, char): def programmer_error(msg): sys.exit("Programmer error: " + msg) + + +class ChecksumError(Exception): + pass diff --git a/cf_remote/web.py b/cf_remote/web.py index fc3fa17..9f786a1 100644 --- a/cf_remote/web.py +++ b/cf_remote/web.py @@ -13,6 +13,7 @@ ) from cf_remote import log from cf_remote.paths import cf_remote_dir, cf_remote_packages_dir +from cf_remote.utils import ChecksumError SHA256_RE = re.compile(r"^[0-9a-f]{64}$") @@ -34,7 +35,7 @@ def get_json(url): def download_package(url, path=None, checksum=None): if checksum and not SHA256_RE.match(checksum): - user_error( + raise ChecksumError( "Invalid checksum or unsupported checksum algorithm: '%s'" % checksum ) @@ -57,7 +58,7 @@ def download_package(url, path=None, checksum=None): f.seek(0) content = f.read() if checksum and is_different_checksum(checksum, content): - user_error( + raise ChecksumError( "Downloaded file '{}' does not match expected checksum '{}'. Please delete the file.".format( filename, checksum ) @@ -68,7 +69,7 @@ def download_package(url, path=None, checksum=None): answer = urllib.request.urlopen(url).read() if checksum and is_different_checksum(checksum, answer): - user_error( + raise ChecksumError( "Downloaded file '{}' does not match expected checksum '{}'. Please delete the file.".format( filename, checksum ) From f5206b2421cacb02886e6db6acf97082bf1f6717 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Wed, 4 Jun 2025 12:35:44 +0200 Subject: [PATCH 3/3] Fixed unsupported string formatting Signed-off-by: Victor Moene --- cf_remote/aramid.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cf_remote/aramid.py b/cf_remote/aramid.py index cfac5a4..01f54a4 100644 --- a/cf_remote/aramid.py +++ b/cf_remote/aramid.py @@ -250,11 +250,18 @@ def _wait_for_tasks(hosts, tasks, ignore_failed, echo, echo_action, out_flag="") if task.proc.args[0] == "scp": log.debug( - f"Copying '{task.action}' to {task.host.user}@{task.host.host_name} over scp" + "Copying '{}' to {}@{} over scp".format( + task.action, task.host.user, task.host.host_name + ) ) else: log.debug( - f"Running '{task.action}' on {task.host.user}@{task.host.host_name} over {task.proc.args[0]}" + "Running '{}' on {}@{} over {}".format( + task.action, + task.host.user, + task.host.host_name, + task.proc.args[0], + ) ) try: