From e1b8e5c625f54e374f00352d2b4e270734d777c9 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Fri, 9 May 2025 13:45:03 +0200 Subject: [PATCH] refs #1981 use zstd when creating and restoring images --- CHANGELOG.md | 6 ++++++ ogclient/lib/python3/ImageLib.py | 7 ++++++- ogclient/lib/python3/PostConfLib.py | 1 + ogclient/lib/python3/ProtocolLib.py | 4 ++-- ogclient/lib/python3/ogGlobals.py | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 727747c..f78723a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.0] - 2025-05-09 + +### Added + +- Use zstd when creating and restoring images + ## [0.8.4] - 2025-05-09 ### Added diff --git a/ogclient/lib/python3/ImageLib.py b/ogclient/lib/python3/ImageLib.py index 621924e..a99d9de 100644 --- a/ogclient/lib/python3/ImageLib.py +++ b/ogclient/lib/python3/ImageLib.py @@ -101,6 +101,8 @@ def ogCreateImageSyntax (dev, imgfile, tool='partclone', level='gzip'): 'gzip': ' | gzip -c > ', 3: ' | bzip -c > ', 'bzip': ' | bzip -c > ', + 4: ' | zstd -c > ', + 'zstd': ' | zstd -c > ', }.get (level, ' > ') #print (f'param1 ({param1}) param2 ({param2}) param3 ({param3}) imgfile ({imgfile})') @@ -150,6 +152,8 @@ def ogRestoreImageSyntax (imgfile, part, tool=None, level=None): 'gzip': ' gzip -dc ', 3: ' bzip -dc ', 'bzip': ' bzip -dc ', + 4: ' zstd -dc ', + 'zstd': ' zstd -dc ', }.get (level, '') #print (f'tool ({tool}) level ({level}) compressor ({compressor})') if compressor == '': @@ -595,7 +599,8 @@ def ogGetImageInfo (imgfile): imgdetect = False filehead = f'/tmp/{os.path.basename (imgfile)}.infohead' compressor = subprocess.run (['file', imgfile], capture_output=True, text=True).stdout.split()[1] - if compressor not in ['gzip', 'lzop']: + if 'Zstandard' == compressor: compressor = 'zstd' + if compressor not in ['gzip', 'lzop', 'zstd']: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_IMAGE, f'Image format is not valid {imgfile}') return diff --git a/ogclient/lib/python3/PostConfLib.py b/ogclient/lib/python3/PostConfLib.py index 33f17a6..473cf26 100644 --- a/ogclient/lib/python3/PostConfLib.py +++ b/ogclient/lib/python3/PostConfLib.py @@ -7,6 +7,7 @@ #*/ import os +import re import glob import subprocess diff --git a/ogclient/lib/python3/ProtocolLib.py b/ogclient/lib/python3/ProtocolLib.py index b4a17b2..98b95ec 100644 --- a/ogclient/lib/python3/ProtocolLib.py +++ b/ogclient/lib/python3/ProtocolLib.py @@ -58,7 +58,7 @@ def ogUcastSyntax (op, sess, file=None, device=None, tool=None, level=None): raise TypeError (f'argument "tool" has unsupported value "{tool}"') if level is None: raise TypeError ('missing required argument: "level"') - if level.lower() not in ['lzop', 'gzip', '0', '1']: + if level.lower() not in ['lzop', 'gzip', 'zstd']: raise TypeError (f'argument "level" has unsupported value "{level}"') elif 'SENDFILE' == op or 'RECEIVERFILE' == op: if file is None: @@ -290,7 +290,7 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None): raise TypeError (f'argument "tool" has unsupported value "{tool}"') if level is None: raise TypeError ('missing required argument: "level"') - if level.lower() not in ['lzop', 'gzip', '0', '1']: + if level.lower() not in ['lzop', 'gzip', 'zstd']: raise TypeError (f'argument "level" has unsupported value "{level}"') elif 'SENDFILE' == op or 'RECEIVERFILE' == op: if file is None: diff --git a/ogclient/lib/python3/ogGlobals.py b/ogclient/lib/python3/ogGlobals.py index f1901fd..5278c5b 100644 --- a/ogclient/lib/python3/ogGlobals.py +++ b/ogclient/lib/python3/ogGlobals.py @@ -35,7 +35,7 @@ OGLOGCOMMAND='/tmp/command.log' ACTIONCACHEFULL='NONE' #Que hacer cuando la cache no tenga espacio libre. [ NONE | FORMAT ] ] RESTOREPROTOCOLNOTCACHE=None #Que protocolo de restauracion usar en el caso de que no exista cache o no exista espacio sufiente. [NONE | UNICAST | MULTICAST].NONE retorna error IMGPROG='partclone' -IMGCOMP='lzop' +IMGCOMP='zstd' IMGEXT='img' IMGREDUCE=True #OGWINREDUCE=True #Al enviar particion reducir el sistema de archivos previamente.