summaryrefslogtreecommitdiffstats
path: root/src/live/ogOperations.py
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-03-27 17:25:53 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-04-01 13:44:17 +0200
commit1aba9d09236233e19d6145992c28e94afbd8758b (patch)
treee4e602ac78b3ac32c1596c299717e8542cdd0e40 /src/live/ogOperations.py
parent474183ab71aadd5b150b5d0a8acf0eae56e43ee2 (diff)
Revert "live: improve lzop and partclone error handling"
This reverts commit 57787dab5499a38915b5e2f702844553abd2ea2a. Read from stderr is blocking if no data is available, revert this patch since ogClient hangs indefinitely in lzop invocations due to races in process execution through Popen.
Diffstat (limited to 'src/live/ogOperations.py')
-rw-r--r--src/live/ogOperations.py73
1 files changed, 27 insertions, 46 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 6703041..cfe05f6 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -190,28 +190,14 @@ class OgLiveOperations:
if not os.path.exists(image_path):
raise RuntimeError(f'Image not found at {image_path} during image restore')
- proc_lzop = subprocess.Popen(cmd_lzop,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- proc_pc = subprocess.Popen(cmd_pc,
- stdin=proc_lzop.stdout,
- stderr=subprocess.PIPE)
-
- pc_stderr = proc_pc.communicate()[1]
- lzop_stderr = proc_lzop.stderr.read()
- proc_lzop.poll() # update returncode
-
with open('/tmp/command.log', 'wb', 0) as logfile:
- logfile.write(lzop_stderr)
- logfile.write(pc_stderr)
-
- if proc_lzop.returncode != 0:
- raise OSError(f'lzop subprocess failed: {lzop_stderr.decode("utf-8")}')
-
- if proc_pc.returncode != 0:
- raise OSError(f'partclone subprocess failed: {pc_stderr.decode("utf-8")}')
-
- logging.info('Image restore successful')
+ proc_lzop = subprocess.Popen(cmd_lzop,
+ stdout=subprocess.PIPE)
+ proc_pc = subprocess.Popen(cmd_pc,
+ stdin=proc_lzop.stdout,
+ stderr=logfile)
+ proc_lzop.stdout.close()
+ proc_pc.communicate()
def _ogbrowser_clear_logs(self):
logfiles = ['/tmp/command.log', '/tmp/session.log']
@@ -465,37 +451,32 @@ class OgLiveOperations:
if ogReduceFs(disk, partition) == -1:
raise ValueError(f'Failed to shrink {fstype} filesystem in {padev}')
+ cmd1 = shlex.split(f'partclone.{fstype} -I -C --clone -s {padev} -O -')
+ cmd2 = shlex.split(f'lzop -1 -fo {image_path}')
+
+ logfile = open('/tmp/command.log', 'wb', 0)
+
if os.path.exists(image_path) and backup:
shutil.move(image_path, f'{image_path}.ant')
+ p1 = Popen(cmd1, stdout=PIPE, stderr=logfile)
+ p2 = Popen(cmd2, stdin=p1.stdout)
+ p1.stdout.close()
+
logging.info(f'Creating image at {image_path} from {padev} using {fstype}')
logging.info('*DO NOT REBOOT OR POWEROFF* the client during this time')
- cmd_pc = shlex.split(f'partclone.{fstype} -I -C --clone -s {padev} -O -')
- cmd_lzop = shlex.split(f'lzop -1 -fo {image_path}')
-
- proc_pc = subprocess.Popen(cmd_pc,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- proc_lzop = subprocess.Popen(cmd_lzop,
- stdin=proc_pc.stdout,
- stderr=subprocess.PIPE)
-
- lzop_stderr = proc_lzop.communicate()[1]
- pc_stderr = proc_pc.stderr.read()
- proc_pc.poll() # update returncode
-
- with open('/tmp/command.log', 'wb', 0) as logfile:
- logfile.write(pc_stderr)
- logfile.write(lzop_stderr)
-
- if proc_pc.returncode != 0:
- raise OSError(f'partclone subprocess failed: {pc_stderr.decode("utf-8")}')
-
- if proc_lzop.returncode != 0:
- raise OSError(f'lzop subprocess failed: {lzop_stderr.decode("utf-8")}')
-
- logging.info('Image creation successful')
+ try:
+ retdata = p2.communicate()
+ except OSError as e:
+ raise OSError(f'Unexpected error when running partclone and lzop commands: {e}') from e
+ finally:
+ logfile.close()
+ p2.terminate()
+ p1.poll()
+
+ logging.info(f'partclone process exited with code {p1.returncode}')
+ logging.info(f'lzop process exited with code {p2.returncode}')
ogExtendFs(disk, partition)