Skip to content

Commit 29e97cc

Browse files
authored
Merge pull request #139 from victormlg/checksumerror
ENT-12764 Fixed unhandled invalid checksum error when downloading packages
2 parents 83f67e9 + f5206b2 commit 29e97cc

File tree

5 files changed

+55
-22
lines changed

5 files changed

+55
-22
lines changed

cf_remote/aramid.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,18 @@ def _wait_for_tasks(hosts, tasks, ignore_failed, echo, echo_action, out_flag="")
250250

251251
if task.proc.args[0] == "scp":
252252
log.debug(
253-
f"Copying '{task.action}' to {task.host.user}@{task.host.host_name} over scp"
253+
"Copying '{}' to {}@{} over scp".format(
254+
task.action, task.host.user, task.host.host_name
255+
)
254256
)
255257
else:
256258
log.debug(
257-
f"Running '{task.action}' on {task.host.user}@{task.host.host_name} over {task.proc.args[0]}"
259+
"Running '{}' on {}@{} over {}".format(
260+
task.action,
261+
task.host.user,
262+
task.host.host_name,
263+
task.proc.args[0],
264+
)
258265
)
259266

260267
try:

cf_remote/commands.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
get_package_name,
3434
user_error,
3535
)
36-
from cf_remote.utils import user_error, is_package_url, print_progress_dot
36+
from cf_remote.utils import (
37+
user_error,
38+
is_package_url,
39+
print_progress_dot,
40+
ChecksumError,
41+
)
3742
from cf_remote.spawn import VM, VMRequest, Providers, AWSCredentials, GCPCredentials
3843
from cf_remote.spawn import spawn_vms, destroy_vms, dump_vms_info, get_cloud_driver
3944
from cf_remote import log
@@ -180,7 +185,11 @@ def install(
180185
if remote_download:
181186
package, hub_package, client_package = _verify_package_urls(packages)
182187
else:
183-
package, hub_package, client_package = _download_urls(packages)
188+
try:
189+
package, hub_package, client_package = _download_urls(packages)
190+
except ChecksumError as ce:
191+
log.error(ce)
192+
return 1
184193

185194
# If any of these are folders, transform them to lists of the files inside those folders:
186195
package = _maybe_packages_in_folder(package)
@@ -308,9 +317,13 @@ def _iterate_over_packages(
308317
else:
309318
for artifact in artifacts:
310319
if download:
311-
package_path = download_package(
312-
artifact.url, checksum=artifact.checksum
313-
)
320+
try:
321+
package_path = download_package(
322+
artifact.url, checksum=artifact.checksum
323+
)
324+
except ChecksumError as ce:
325+
log.error(ce)
326+
return 1
314327
if output_dir:
315328
output_dir = os.path.abspath(os.path.expanduser(output_dir))
316329
parent = os.path.dirname(output_dir)
@@ -854,7 +867,11 @@ def deploy(hubs, masterfiles):
854867
print("Found cfbs policy set: '{}'".format(masterfiles))
855868
elif masterfiles and masterfiles.startswith(("http://", "https://")):
856869
urls = [masterfiles]
857-
paths = _download_urls(urls)
870+
try:
871+
paths = _download_urls(urls)
872+
except ChecksumError as ce:
873+
log.error(ce)
874+
return 1
858875
assert len(paths) == 1
859876
masterfiles = paths[0]
860877
log.debug("Deploying downloaded: %s" % masterfiles)

cf_remote/remote.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
user_error,
1515
parse_systeminfo,
1616
parse_version,
17+
ChecksumError,
1718
)
1819
from cf_remote.ssh import ssh_sudo, ssh_cmd, scp, auto_connect
1920
from cf_remote import log
@@ -515,16 +516,20 @@ def install_host(
515516
package = packages[0]
516517

517518
if not package:
518-
package = get_package_from_host_info(
519-
data.get("package_tags"),
520-
data.get("bin"),
521-
data.get("arch"),
522-
version,
523-
hub,
524-
edition,
525-
packages,
526-
remote_download,
527-
)
519+
try:
520+
package = get_package_from_host_info(
521+
data.get("package_tags"),
522+
data.get("bin"),
523+
data.get("arch"),
524+
version,
525+
hub,
526+
edition,
527+
packages,
528+
remote_download,
529+
)
530+
except ChecksumError as ce:
531+
log.error(ce)
532+
return 1
528533

529534
if not package:
530535
log.error("Installation failed - no package found!")

cf_remote/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,7 @@ def has_unescaped_character(string, char):
279279

280280
def programmer_error(msg):
281281
sys.exit("Programmer error: " + msg)
282+
283+
284+
class ChecksumError(Exception):
285+
pass

cf_remote/web.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import hashlib
21
import os
32
import fcntl
43
import re
@@ -14,6 +13,7 @@
1413
)
1514
from cf_remote import log
1615
from cf_remote.paths import cf_remote_dir, cf_remote_packages_dir
16+
from cf_remote.utils import ChecksumError
1717

1818
SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
1919

@@ -35,7 +35,7 @@ def get_json(url):
3535
def download_package(url, path=None, checksum=None):
3636

3737
if checksum and not SHA256_RE.match(checksum):
38-
user_error(
38+
raise ChecksumError(
3939
"Invalid checksum or unsupported checksum algorithm: '%s'" % checksum
4040
)
4141

@@ -58,7 +58,7 @@ def download_package(url, path=None, checksum=None):
5858
f.seek(0)
5959
content = f.read()
6060
if checksum and is_different_checksum(checksum, content):
61-
user_error(
61+
raise ChecksumError(
6262
"Downloaded file '{}' does not match expected checksum '{}'. Please delete the file.".format(
6363
filename, checksum
6464
)
@@ -69,7 +69,7 @@ def download_package(url, path=None, checksum=None):
6969

7070
answer = urllib.request.urlopen(url).read()
7171
if checksum and is_different_checksum(checksum, answer):
72-
user_error(
72+
raise ChecksumError(
7373
"Downloaded file '{}' does not match expected checksum '{}'. Please delete the file.".format(
7474
filename, checksum
7575
)

0 commit comments

Comments
 (0)