summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-05-27 11:59:25 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-05-30 17:22:23 +0200
commit9a5e83ea1abfd8e22d8531d343ffd2c85d95b351 (patch)
treefa0745f79874aaec98d49c4c5ed43048c81e4afc
parentdd003e688fad500bb40210d64b7b96e1ea63b8fa (diff)
src: stop using hardcoded paths to cache image directory
Use the constant OG_CACHE_IMAGE_PATH from cache.py to obtain the location of the directory where images are stored. This way the path can be changed from one single point.
-rw-r--r--src/live/ogOperations.py9
-rw-r--r--src/utils/tiptorrent.py8
2 files changed, 8 insertions, 9 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index e8a3b40..485b4d7 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -39,7 +39,6 @@ from src.log import OgError
OG_SHELL = '/bin/bash'
-OG_CACHE_PATH = '/opt/opengnsys/cache/opt/opengnsys/images'
class OgLiveOperations:
def __init__(self, config):
@@ -181,7 +180,7 @@ class OgLiveOperations:
Implies a unicast transfer. Does not use tiptorrent.
"""
src = f'/opt/opengnsys/images/{image_name}.img'
- dst = f'/opt/opengnsys/cache/opt/opengnsys/images/{image_name}.img'
+ dst = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
try:
r = shutil.copy(src, dst)
tip_write_csum(image_name)
@@ -194,7 +193,7 @@ class OgLiveOperations:
raise OgError(f'Cannot change repository to {repo}')
if cache:
- image_path = f'/opt/opengnsys/cache/opt/opengnsys/images/{name}.img'
+ image_path = f'{OG_CACHE_IMAGE_PATH}{name}.img'
if (not os.path.exists(image_path) or
not tip_check_csum(repo, name)):
self._copy_image_to_cache(name)
@@ -203,10 +202,10 @@ class OgLiveOperations:
self._restore_image(image_path, devpath)
def _restore_image_tiptorrent(self, repo, name, devpath):
- if not os.path.exists(OG_CACHE_PATH):
+ if not os.path.exists(OG_CACHE_IMAGE_PATH):
raise OgError('No cache partition is mounted')
- image_path = f'/opt/opengnsys/cache/opt/opengnsys/images/{name}.img'
+ image_path = f'{OG_CACHE_IMAGE_PATH}{name}.img'
try:
if (not os.path.exists(image_path) or not tip_check_csum(repo, name)):
tip_client_get(repo, name)
diff --git a/src/utils/tiptorrent.py b/src/utils/tiptorrent.py
index 9715b21..d3e95f4 100644
--- a/src/utils/tiptorrent.py
+++ b/src/utils/tiptorrent.py
@@ -14,7 +14,7 @@ import shutil
import subprocess
import urllib.request
from src.log import OgError
-from src.utils.cache import mount_cache
+from src.utils.cache import *
def _compute_md5(path, bs=2**20):
m = hashlib.md5()
@@ -45,7 +45,7 @@ def tip_write_csum(image_name):
if not mount_cache():
raise OgError(f'Failed to checksum {image_name}: cache partition is not available')
- image_path = f'/opt/opengnsys/cache/opt/opengnsys/images/{image_name}.img'
+ image_path = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
if not os.path.exists(image_path):
raise OgError(f'Invalid image path {image_path} for tiptorrent checksum writing')
@@ -65,7 +65,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'
+ image_path = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
if not os.path.exists(image_path):
raise OgError(f'Invalid image path {image_path} for tiptorrent image csum comparison')
@@ -93,7 +93,7 @@ def tip_client_get(tip_addr, image_name):
try:
proc = subprocess.Popen(shlex.split(cmd),
stdout=logfile,
- cwd='/opt/opengnsys/cache/opt/opengnsys/images/')
+ cwd=OG_CACHE_IMAGE_PATH)
proc.communicate()
except OSError as e:
raise OgError('Unexpected error running tiptorrent subprocess: {e}') from e