summaryrefslogtreecommitdiffstats
path: root/src/utils/tiptorrent.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/tiptorrent.py')
-rw-r--r--src/utils/tiptorrent.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/utils/tiptorrent.py b/src/utils/tiptorrent.py
index d46b1c7..18c4df7 100644
--- a/src/utils/tiptorrent.py
+++ b/src/utils/tiptorrent.py
@@ -33,11 +33,9 @@ def tip_fetch_csum(tip_addr, image_name):
with urllib.request.urlopen(f'{url}') as resp:
r = resp.readline().rstrip().decode('utf-8')
except urllib.error.URLError as e:
- logging.warning('URL error when fetching checksum: {e.reason}')
- raise e
+ raise urllib.error.URLError(f'URL error when fetching checksum: {e.reason}') from e
except urllib.error.HTTPError as e:
- logging.warning(f'HTTP Error when fetching checksum: {e.reason}')
- raise e
+ raise urllib.error.URLError(f'HTTP Error when fetching checksum: {e.reason}') from e
return r
@@ -48,8 +46,7 @@ def tip_write_csum(image_name):
image_path = f'/opt/opengnsys/cache/opt/opengnsys/images/{image_name}.img'
if not os.path.exists(image_path):
- logging.error('Invalid image path')
- raise ValueError('Invalid image path for tiptorrent checksum writing')
+ raise RuntimeError(f'Invalid image path {image_path} for tiptorrent checksum writing')
filename = image_path + ".full.sum"
csum = _compute_md5(image_path)
@@ -65,8 +62,7 @@ def tip_check_csum(tip_addr, image_name):
logging.info(f'Verifying checksum for {image_name}.img, please wait...')
image_path = f'/opt/opengnsys/cache/opt/opengnsys/images/{image_name}.img'
if not os.path.exists(image_path):
- logging.error('Invalid image path')
- raise ValueError('Invalid image path for tiptorrent image csum comparison')
+ raise RuntimeError(f'Invalid image path {image_path} for tiptorrent image csum comparison')
cache_csum = _compute_md5(image_path)
remote_csum = tip_fetch_csum(tip_addr, image_name)
@@ -88,15 +84,13 @@ def tip_client_get(tip_addr, image_name):
stdout=logfile,
cwd='/opt/opengnsys/cache/opt/opengnsys/images/')
proc.communicate()
- except:
- logging.exception('Exception when running tiptorrent client GET subprocess')
- raise ValueError('Unexpected error running tiptorrent subprocess')
+ except OSError as e:
+ raise OSError('Unexpected error running tiptorrent subprocess: {e}') from e
finally:
logfile.close()
if proc.returncode != 0:
- logging.error(f'Error fetching image {image_name} via tiptorrent')
- raise ValueError('Tiptorrent download failed')
+ raise RuntimeError(f'Error fetching image {image_name} via tiptorrent')
else:
logging.info('Calculating checksum...')
logging.info('*DO NOT REBOOT OR POWEROFF* the client during this time')