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.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/utils/tiptorrent.py b/src/utils/tiptorrent.py
index 18c4df7..83ca052 100644
--- a/src/utils/tiptorrent.py
+++ b/src/utils/tiptorrent.py
@@ -13,6 +13,7 @@ import shlex
import shutil
import subprocess
import urllib.request
+from src.log import OgError
def _compute_md5(path, bs=2**20):
m = hashlib.md5()
@@ -33,9 +34,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:
- raise urllib.error.URLError(f'URL error when fetching checksum: {e.reason}') from e
+ raise OgError(f'URL error when fetching checksum: {e.reason}') from e
except urllib.error.HTTPError as e:
- raise urllib.error.URLError(f'HTTP Error when fetching checksum: {e.reason}') from e
+ raise OgError(f'HTTP Error when fetching checksum: {e.reason}') from e
return r
@@ -46,7 +47,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):
- raise RuntimeError(f'Invalid image path {image_path} for tiptorrent checksum writing')
+ raise OgError(f'Invalid image path {image_path} for tiptorrent checksum writing')
filename = image_path + ".full.sum"
csum = _compute_md5(image_path)
@@ -62,7 +63,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):
- raise RuntimeError(f'Invalid image path {image_path} for tiptorrent image csum comparison')
+ raise OgError(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)
@@ -85,12 +86,12 @@ def tip_client_get(tip_addr, image_name):
cwd='/opt/opengnsys/cache/opt/opengnsys/images/')
proc.communicate()
except OSError as e:
- raise OSError('Unexpected error running tiptorrent subprocess: {e}') from e
+ raise OgError('Unexpected error running tiptorrent subprocess: {e}') from e
finally:
logfile.close()
if proc.returncode != 0:
- raise RuntimeError(f'Error fetching image {image_name} via tiptorrent')
+ raise OgError(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')