From 0fc7f8f33eecad34976ae14617c736bf78eb3b0e Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Wed, 14 Feb 2024 22:10:30 +0100 Subject: src: ogChangeRepo returns zero on success and -1 on error do not return the returncode, instead return an integer. do not use except CalledProcessError as e: it causes a another exception while handling exception. Remount the original image repository. it should be possible to simplify this further by: - stacking mounts, no need to umount initial repo and mount it again when switching to the new repo, because remount back initial repo might fail (!) - use check=False and simply check for x.returncode --- src/utils/legacy.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/utils') diff --git a/src/utils/legacy.py b/src/utils/legacy.py index a272e4c..437dbfd 100644 --- a/src/utils/legacy.py +++ b/src/utils/legacy.py @@ -192,15 +192,18 @@ def ogChangeRepo(ip, smb_user='opengnsys', smb_pass='og'): else: umount(mntdir) + err = 0 cmd = f'mount.cifs -o {mode},username={smb_user},password={smb_pass} {new_name} /opt/opengnsys/images' try: result = subprocess.run(shlex.split(cmd), check=True) - except CalledProcessError as e: - logging.error(f'Error mounting new image directory: {e}') - cmd = f'mount.cifs -o {mode},username={smb_user},password={smb_pass} {orig_name} /opt/opengnsys/images' - result = subprocess.run(shlex.split(cmd), check=True) - finally: - return result + except: + err = -1 + logging.error(f'Error mounting {new_name} in /opt/opengnsys/images') + + cmd = f'mount.cifs -o {mode},username={smb_user},password={smb_pass} {orig_name} /opt/opengnsys/images' + subprocess.run(shlex.split(cmd)) + + return err def restoreImageCustom(repo_ip, image_name, disk, partition, method): @@ -210,7 +213,7 @@ def restoreImageCustom(repo_ip, image_name, disk, partition, method): logging.error('Invalid restoreImageCustom invocation') raise ValueError('Error: restoreImageCustom not found') - if ogChangeRepo(repo).returncode != 0: + if ogChangeRepo(repo) != 0: logging.error('ogChangeRepo could not change repository to %s', repo) raise ValueError(f'Error: Cannot change repository to {repo}') -- cgit v1.2.3-18-g5258