From 48f6a41838759294ee29d3c8e76b601addecdeb5 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 3 Apr 2025 14:10:15 +0200 Subject: [PATCH 01/19] refs #1801 fix invocation to ogCheckIpAddress --- CHANGELOG.md | 18 ++++++++++++++++++ ogclient/interfaceAdm/CrearImagen.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29ceb4a..7b265a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ 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.3.1] - 2025-04-03 + +### Fixed + +- Fixed invocation to ogCheckIpAddress in interfaceAdm/CrearImagen.py + +## [0.3.0] - 2025-04-03 + +### Removed + +- Removed burg and rsync 3.1 + +## [0.2.6] - 2025-03-31 + +### Fixed + +- Restore qt4 browser + ## [0.2.5] - 2025-03-31 ### Fixed diff --git a/ogclient/interfaceAdm/CrearImagen.py b/ogclient/interfaceAdm/CrearImagen.py index ea2b096..2ab2b58 100755 --- a/ogclient/interfaceAdm/CrearImagen.py +++ b/ogclient/interfaceAdm/CrearImagen.py @@ -66,7 +66,7 @@ repo = arg_repo if not repo: repo = 'REPO' if repo == ogGetIpAddress(): repo = 'CACHE' # Si es una ip y es distinta a la del recurso samba cambiamos de REPO. -if 'REPO' == repo or StringLib.ogCheckIpAddress (repo): +if 'REPO' == repo or ogCheckIpAddress (repo): # Si falla el cambio -> salimos con error repositorio no valido if not ogChangeRepo (repo): ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, repo) -- 2.40.1 From 5e9fb86f9f7dd0a357825c38b42b0f4bd289b6bd Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Mon, 7 Apr 2025 10:53:29 +0200 Subject: [PATCH 02/19] refs #1802 fix functions/ogCopyFile args handling --- CHANGELOG.md | 6 ++++++ ogclient/functions/ogCopyFile | 3 +++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b265a8..aa3ac2f 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.3.2] - 2025-04-07 + +### Fixed + +- Handle invalid number of arguments pass to functions/ogCopyFile + ## [0.3.1] - 2025-04-03 ### Fixed diff --git a/ogclient/functions/ogCopyFile b/ogclient/functions/ogCopyFile index 04f1784..f65663b 100755 --- a/ogclient/functions/ogCopyFile +++ b/ogclient/functions/ogCopyFile @@ -55,6 +55,9 @@ elif 6 == len (sys.argv): args = parser.parse_args() src = { 'container': args.src_container, 'file': args.src_file } dst = { 'disk': args.dst_disk, 'par': args.dst_par, 'file': args.dst_file } +else: + ogHelp ('ogCopyFile', 'ogCopyFile [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target', ['ogCopyFile REPO newfile.txt 1 2 /tmp/newfile.txt']) + sys.exit (1) ret = ogCopyFile (src, dst) if ret is not None: -- 2.40.1 From 6cbe28272f14d420dd5de5e3865ad452db9d4d67 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 9 Apr 2025 11:24:49 +0200 Subject: [PATCH 03/19] refs #1872 always kill browser before exiting --- CHANGELOG.md | 6 ++++++ ogclient/interfaceAdm/Configurar.py | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa3ac2f..f0f69ac 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.3.3] - 2025-04-09 + +### Fixed + +- Kill coproc'ed browser in all execution branches in Configurar.py + ## [0.3.2] - 2025-04-07 ### Fixed diff --git a/ogclient/interfaceAdm/Configurar.py b/ogclient/interfaceAdm/Configurar.py index 0b24360..ab74291 100755 --- a/ogclient/interfaceAdm/Configurar.py +++ b/ogclient/interfaceAdm/Configurar.py @@ -75,8 +75,11 @@ for item in tbprm: elif 'tch' == k: tch = v # Error si no se define el parámetro de disco (dis). -if dis is None: sys.exit (ogGlobals.OG_ERR_FORMAT) -if tch is None: tch = '0' +if dis is None: + coproc.kill() + sys.exit (ogGlobals.OG_ERR_FORMAT) +if tch is None: + tch = '0' # Toma valores de distribución de particiones, separados por "%". tbp = [] # Valores de configuración (parámetros para ogCreatePartitions) @@ -111,6 +114,7 @@ for item in tbprm: if tam is None: missing_params.append ('tam') if missing_params: print (f'partition data ({item}) missing required parameters ({' '.join (missing_params)})') + coproc.kill() sys.exit (1) # Componer datos de particionado. @@ -150,6 +154,7 @@ if 'CACHE' in sparam: rc = SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch) if rc: SystemLib.ogRaiseError (['log', 'session'], ogGlobals.OG_ERR_CACHE, f'initCache failed') + coproc.kill() sys.exit (1) # Definir particionado. -- 2.40.1 From 782e5c8978f3a26bfd8c51d47d25ff8a42fdc8fc Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 9 Apr 2025 17:20:03 +0200 Subject: [PATCH 04/19] refs #1874 fix usage of ogEcho --- CHANGELOG.md | 6 ++++ ogclient/lib/python3/FileSystemLib.py | 47 +++++---------------------- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0f69ac..b5bd97b 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.3.4] - 2025-04-09 + +### Fixed + +- Fixed usage of ogEcho in FileSystemLib + ## [0.3.3] - 2025-04-09 ### Fixed diff --git a/ogclient/lib/python3/FileSystemLib.py b/ogclient/lib/python3/FileSystemLib.py index 987ec7e..d30684a 100644 --- a/ogclient/lib/python3/FileSystemLib.py +++ b/ogclient/lib/python3/FileSystemLib.py @@ -286,12 +286,7 @@ def ogGetFsSize (disk, par, unit='KB'): elif unit.upper() == "TB": factor = 1024 * 1024 * 1024 elif unit.upper() != "KB": - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_FORMAT, - f"{unit} != {{ KB, MB, GB, TB }}" - ) - return + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f"{unit} != {{ KB, MB, GB, TB }}") return # Obtener el tamaño del sistema de archivo (si no está formateado; tamaño = 0). mnt = ogMount (disk, par) @@ -331,11 +326,7 @@ def ogGetFsType(disk, part): try: subprocess.run(["zfs", "mount", PART]) except FileNotFoundError: - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_NOTEXEC, - 'zfs' - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTEXEC, 'zfs') return out = subprocess.run(["mount"], capture_output=True, text=True).stdout.splitlines() for line in out: @@ -344,11 +335,7 @@ def ogGetFsType(disk, part): break if not TYPE: - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_NOTFOUND, - f'{disk} {part}' - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{disk} {part}') return # Componer valores correctos. @@ -592,11 +579,7 @@ def ogMountFs (disk, par): try: rc = subprocess.run(['mount', dev, mntdir, '-o', 'force,remove_hiberfile'], check=True).returncode except subprocess.CalledProcessError: - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_PARTITION, - f"{disk}, {par}" - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f"{disk}, {par}") return if 0 == rc: @@ -605,26 +588,18 @@ def ogMountFs (disk, par): try: subprocess.run (['ntfsfix', '-d', par], check=True) except subprocess.CalledProcessError: - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_PARTITION, - f"{disk, par}" - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f"{disk, par}") #return else: try: subprocess.run (['mount', par, mntdir, '-o', 'ro'], check=True) except subprocess.CalledProcessError: - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_PARTITION, - f"{disk, par}" - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f"{disk, par}") #return # Aviso de montaje de solo lectura. if ogIsReadonly(disk, par): - SystemLib.ogEcho("warning", f'ogMountFs: {ogGlobals.lang.MSG_MOUNTREADONLY}: "{disk}, {par}"') + SystemLib.ogEcho ([], "warning", f'ogMountFs: {ogGlobals.lang.MSG_MOUNTREADONLY}: "{disk}, {par}"') else: # Montar sistema de archivos ZFS (un ZPOOL no comienza por "/"). subprocess.run(['zfs', 'mount', dev]) @@ -809,18 +784,14 @@ def ogUnmountFs(disk, par): if MNTDIR: # Error si la particion está bloqueada. if ogIsLocked (disk, par): - SystemLib.ogRaiseError ( - [], - ogGlobals.OG_ERR_LOCKED, - f"{ogGlobals.lang.MSG_PARTITION}, {disk} {par}" - ) + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_LOCKED, f"{ogGlobals.lang.MSG_PARTITION}, {disk} {par}") return # Desmontar y borrar punto de montaje. try: subprocess.run(["umount", PART], check=True) except subprocess.CalledProcessError: - SystemLib.ogEcho("warning", f'ogUnmountFs: {ogGlobals.lang.MSG_DONTUNMOUNT}: "{disk}, {par}"') + SystemLib.ogEcho ([], "warning", f'ogUnmountFs: {ogGlobals.lang.MSG_DONTUNMOUNT}: "{disk}, {par}"') try: os.rmdir(MNTDIR) except: -- 2.40.1 From e76fe57b1be92e97bd2efc7fae01f43018e88fbb Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 9 Apr 2025 17:34:29 +0200 Subject: [PATCH 05/19] refs #1874 fix syntax --- CHANGELOG.md | 6 ++++++ ogclient/lib/python3/FileSystemLib.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5bd97b..2dc7271 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.3.5] - 2025-04-09 + +### Fixed + +- Fixed syntax + ## [0.3.4] - 2025-04-09 ### Fixed diff --git a/ogclient/lib/python3/FileSystemLib.py b/ogclient/lib/python3/FileSystemLib.py index d30684a..1b5a5be 100644 --- a/ogclient/lib/python3/FileSystemLib.py +++ b/ogclient/lib/python3/FileSystemLib.py @@ -286,7 +286,8 @@ def ogGetFsSize (disk, par, unit='KB'): elif unit.upper() == "TB": factor = 1024 * 1024 * 1024 elif unit.upper() != "KB": - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f"{unit} != {{ KB, MB, GB, TB }}") return + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f"{unit} != {{ KB, MB, GB, TB }}") + return # Obtener el tamaño del sistema de archivo (si no está formateado; tamaño = 0). mnt = ogMount (disk, par) -- 2.40.1 From a1493a827e9eeac5420087c7ae7bbd92d17efae7 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 9 Apr 2025 17:47:51 +0200 Subject: [PATCH 06/19] refs #1876 change check and improve debug msg --- ogclient/lib/python3/FileSystemLib.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ogclient/lib/python3/FileSystemLib.py b/ogclient/lib/python3/FileSystemLib.py index 1b5a5be..1067ddc 100644 --- a/ogclient/lib/python3/FileSystemLib.py +++ b/ogclient/lib/python3/FileSystemLib.py @@ -692,7 +692,8 @@ def ogReduceFs (disk, par): break elif type == 'NTFS': ogUnmount (disk, par) - nr_lines = subprocess.run (['ntfsresize', '-fi', PART], capture_output=True, text=True).stdout.splitlines() + ntfsresize_out = subprocess.run (['ntfsresize', '-fi', PART], capture_output=True, text=True).stdout + nr_lines = ntfsresize_out.splitlines() maxsize = None size = None for l in nr_lines: @@ -702,12 +703,10 @@ def ogReduceFs (disk, par): size = l.split()[4] size = int ((int (size) * 1.1 / 1024 + 1) * 1024) - if not maxsize and not size: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'{disk},{par}') + if not maxsize or not size: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'{disk},{par} ({ntfsresize_out})') return None - import time - extrasize = 0 retval = 1 while retval != 0 and size+extrasize < maxsize: -- 2.40.1 From 44511c79a0bcf73dd672df52b86656bb69f843ad Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 9 Apr 2025 18:36:11 +0200 Subject: [PATCH 07/19] refs #1876 change check and improve debug msg --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dc7271..df519fe 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.3.6] - 2025-04-09 + +### Fixed + +- Fixed ogReduceFs + ## [0.3.5] - 2025-04-09 ### Fixed -- 2.40.1 From bbaa6578e101de617d681c849232b70895da0934 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 10 Apr 2025 08:11:04 +0200 Subject: [PATCH 08/19] refs #1878 makes writable Samba export in ogclient --- etc/samba/smb-ogclient.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/samba/smb-ogclient.conf b/etc/samba/smb-ogclient.conf index a7c3422..34d5496 100644 --- a/etc/samba/smb-ogclient.conf +++ b/etc/samba/smb-ogclient.conf @@ -1,7 +1,7 @@ [ogclient] comment = OpenGnsys Client browseable = no - writeable = no + writeable = yes locking = no path = /opt/opengnsys/ogclient guest ok = no -- 2.40.1 From 1f92f549944807fb49ed16e8c61086039fc888ea Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 10 Apr 2025 09:41:08 +0200 Subject: [PATCH 09/19] refs #1878 update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df519fe..46b173f 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.4.0] - 2025-04-10 + +### Changed + +- Make /opt/opengnsys writable in clients, just like it used to be + ## [0.3.6] - 2025-04-09 ### Fixed -- 2.40.1 From 2c18e6981f05c98938e57b8adf0a036504299774 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 10 Apr 2025 13:32:48 +0200 Subject: [PATCH 10/19] refs #1879 negate rc to the shell --- CHANGELOG.md | 6 ++++++ ogclient/scripts/restoreImage.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46b173f..476e917 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.4.1] - 2025-04-10 + +### Fixed + +- restoreImage.py: return negated rc to the shell + ## [0.4.0] - 2025-04-10 ### Changed diff --git a/ogclient/scripts/restoreImage.py b/ogclient/scripts/restoreImage.py index a5f0ff6..961b971 100644 --- a/ogclient/scripts/restoreImage.py +++ b/ogclient/scripts/restoreImage.py @@ -114,5 +114,5 @@ t = time.time() - t0 SystemLib.ogEcho (['log', 'session'], None, f'[100] Duracion de la operacion {int (t/60)}m {int (t%60)}s') # Código de salida del comando prinicpal de restauración. -sys.exit (retval) +sys.exit (not retval) ## negated for the shell -- 2.40.1 From 697c60f8122614bf9b3aafe38062c4c8671485c0 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 10 Apr 2025 16:21:59 +0200 Subject: [PATCH 11/19] Publish in nightlys --- Jenkins/Jenkinsfile-deb-pkg | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Jenkins/Jenkinsfile-deb-pkg b/Jenkins/Jenkinsfile-deb-pkg index 2f78603..157ae91 100644 --- a/Jenkins/Jenkinsfile-deb-pkg +++ b/Jenkins/Jenkinsfile-deb-pkg @@ -48,7 +48,18 @@ pipeline { } } } - + stage('Generate Changelog (Nightly)'){ + when { + branch 'main' + } + steps { + script { + def devName = params.DEV_NAME ? params.DEV_NAME : env.DEFAULT_DEV_NAME + def devEmail = params.DEV_EMAIL ? params.DEV_EMAIL : env.DEFAULT_DEV_EMAIL + generateDebianChangelog(env.BUILD_DIR, devName, devEmail,"nightly") + } + } + } stage('Build') { steps { script { @@ -71,6 +82,19 @@ pipeline { } } } + stage ('Publish to Debian Repository (Nightly)') { + when { + branch 'main' + } + agent { label 'debian-repo' } + steps { + script { + // Construir el patrón de versión esperado en el nombre del paquete + def versionPattern = "-${env.BUILD_NUMBER}~nightly" + publicarEnAptly('/var/tmp/opengnsys/debian-repo/ogclient', 'nightly', versionPattern) + } + } + } } post { always { -- 2.40.1 From 0179d106e909c1d2894f6634b23099235cd4a2c1 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 15 Apr 2025 16:54:06 +0200 Subject: [PATCH 12/19] refs #1838 log to /var/log instead of the shared /opt/opengnsys/log --- CHANGELOG.md | 6 +++ ogclient/lib/python3/SystemLib.py | 62 +++++++++++++++++++++++-------- ogclient/lib/python3/ogGlobals.py | 5 ++- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 476e917..ad1cf43 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.5.0] - 2025-04-15 + +### Changed + +- Log to /var/log/clone-engine.log and clone-engine.json.log + ## [0.4.1] - 2025-04-10 ### Fixed diff --git a/ogclient/lib/python3/SystemLib.py b/ogclient/lib/python3/SystemLib.py index 3b0b0ab..d86b635 100644 --- a/ogclient/lib/python3/SystemLib.py +++ b/ogclient/lib/python3/SystemLib.py @@ -3,6 +3,7 @@ import datetime from zoneinfo import ZoneInfo import sys import os +import json import shutil import inspect import glob @@ -20,6 +21,7 @@ import StringLib def _logtype2logfile (t): if 'log' == t.lower(): return ogGlobals.OGLOGFILE + if 'jsonlog' == t.lower(): return ogGlobals.OGJSONLOGFILE elif 'command' == t.lower(): return ogGlobals.OGLOGCOMMAND elif 'session' == t.lower(): return ogGlobals.OGLOGSESSION else: raise Exception (f'unknown log type ({t})') @@ -35,24 +37,40 @@ def ogEcho (logtypes, loglevel, msg): logfiles = ['/dev/stdout'] if type (logtypes) is list: for l in logtypes: - logfiles.append (_logtype2logfile (l)) + if 'log' == l: + logfiles.append (_logtype2logfile ('log')) + logfiles.append (_logtype2logfile ('jsonlog')) + else: + logfiles.append (_logtype2logfile (l)) else: ## string - logfiles.append (_logtype2logfile (logtypes)) + if 'log' == logtypes: + logfiles.append (_logtype2logfile ('log')) + logfiles.append (_logtype2logfile ('jsonlog')) + else: + logfiles.append (_logtype2logfile (logtypes)) if loglevel is None or 'help' == loglevel: if ogGlobals.DEBUG.lower() != "no": logfiles.append (ogGlobals.OGLOGFILE) + logfiles.append (ogGlobals.OGJSONLOGFILE) for f in logfiles: with open (f, 'a') as fd: - fd.write (msg + '\n') + if ogGlobals.OGJSONLOGFILE == f: + fd.write (json.dumps ({'message':msg}) + '\n') + else: + fd.write (msg + '\n') return if 'info' == loglevel or 'warning' == loglevel or 'error' == loglevel: - DATETIME = datetime.datetime.now(ZoneInfo(ogGlobals.TZ)).strftime("%F %T %Z") + DATETIME = datetime.datetime.now (ZoneInfo (ogGlobals.TZ)).strftime ('%F %T %Z') + DATETIME_json = datetime.datetime.now (ZoneInfo (ogGlobals.TZ)).strftime ('%Y-%m-%d %H:%M:%S') for f in logfiles: with open (f, 'a') as fd: - fd.write (f"OpenGnsys {loglevel} {DATETIME} {msg}\n") + if ogGlobals.OGJSONLOGFILE == f: + fd.write (json.dumps ({'timestamp':DATETIME_json, 'severity':loglevel, 'message':msg}) + '\n') + else: + fd.write (f"OpenGnsys {loglevel} {DATETIME} {msg}\n") else: raise Exception (f'unknown loglevel ({loglevel})') @@ -75,10 +93,18 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs): if type (logtypes) is list: for l in logtypes: logtypes = list (map (lambda x: x.lower(), logtypes)) - logfiles.append (_logtype2logfile (l)) + if 'log' == l: + logfiles.append (_logtype2logfile ('log')) + logfiles.append (_logtype2logfile ('jsonlog')) + else: + logfiles.append (_logtype2logfile (l)) else: ## string logtypes = logtypes.lower() - logfiles.append (_logtype2logfile (logtypes)) + if 'log' == logtypes: + logfiles.append (_logtype2logfile ('log')) + logfiles.append (_logtype2logfile ('jsonlog')) + else: + logfiles.append (_logtype2logfile (logtypes)) if not fun: ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, 'no function provided') @@ -103,7 +129,6 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs): # ## redirect stdout only # eval $COMMAND | tee -a $FILES - import time sout = serr = '' if 'command' in logtypes: os.unlink (ogGlobals.OGLOGCOMMAND) @@ -121,14 +146,19 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs): if sout or serr or ('True' != rc_str and 'False' != rc_str and 'None' != rc_str): for f in logfiles: with open (f, 'a') as fd: - if sout: fd.write (f'{sout}\n') - if serr: fd.write (f'{serr}\n') - if rc_str: fd.write (f'{rc_str}\n') - #fd.write (f"ogExecAndLog: {fun.__name__} rc:\n{rc_str}\n") - #if sout: fd.write (f"ogExecAndLog: {fun.__name__} stdout:\n{sout}\n") - #else: fd.write (f"ogExecAndLog: {fun.__name__} stdout: (none)\n") - #if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n") - #else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n") + if ogGlobals.OGJSONLOGFILE == f: + if sout: fd.write (json.dumps ({'message':sout}) + '\n') + if serr: fd.write (json.dumps ({'message':serr}) + '\n') + if rc_str: fd.write (json.dumps ({'message':rc_str}) + '\n') + else: + if sout: fd.write (f'{sout}\n') + if serr: fd.write (f'{serr}\n') + if rc_str: fd.write (f'{rc_str}\n') + #fd.write (f"ogExecAndLog: {fun.__name__} rc:\n{rc_str}\n") + #if sout: fd.write (f"ogExecAndLog: {fun.__name__} stdout:\n{sout}\n") + #else: fd.write (f"ogExecAndLog: {fun.__name__} stdout: (none)\n") + #if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n") + #else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n") return rc diff --git a/ogclient/lib/python3/ogGlobals.py b/ogclient/lib/python3/ogGlobals.py index 7e978fc..cf3f10e 100644 --- a/ogclient/lib/python3/ogGlobals.py +++ b/ogclient/lib/python3/ogGlobals.py @@ -88,8 +88,9 @@ OGPYFUNCS = os.path.join (OPENGNSYS, 'functions') OGSCRIPTS = os.path.join (OPENGNSYS, 'scripts') OGIMG = os.path.join (OPENGNSYS, 'images') OGCAC = os.path.join (OPENGNSYS, 'cache') -OGLOG = os.path.join (OPENGNSYS, 'log') -OGLOGFILE = f'{OGLOG}/{ip}.log' +OGLOG = os.path.join ('var', 'log') +OGLOGFILE = f'{OGLOG}/clone-engine.log' +OGJSONLOGFILE = f'{OGLOG}/clone-engine.json.log' DEBUG = 'yes' _path = os.environ['PATH'] + ':/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:/opt/oglive/rootfs/opt/drbl/sbin' os.environ['PATH'] = ':'.join ([OGSCRIPTS, _path, OGAPI, OGBIN]) -- 2.40.1 From 46238456cbe4165d5646f9acda39a54d0e36f234 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 15 Apr 2025 16:55:45 +0200 Subject: [PATCH 13/19] refs #1838 log to /var/log instead of the shared /opt/opengnsys/log --- ogclient/lib/python3/ogGlobals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ogclient/lib/python3/ogGlobals.py b/ogclient/lib/python3/ogGlobals.py index cf3f10e..beb3d97 100644 --- a/ogclient/lib/python3/ogGlobals.py +++ b/ogclient/lib/python3/ogGlobals.py @@ -88,7 +88,7 @@ OGPYFUNCS = os.path.join (OPENGNSYS, 'functions') OGSCRIPTS = os.path.join (OPENGNSYS, 'scripts') OGIMG = os.path.join (OPENGNSYS, 'images') OGCAC = os.path.join (OPENGNSYS, 'cache') -OGLOG = os.path.join ('var', 'log') +OGLOG = '/var/log' OGLOGFILE = f'{OGLOG}/clone-engine.log' OGJSONLOGFILE = f'{OGLOG}/clone-engine.json.log' DEBUG = 'yes' -- 2.40.1 From bf85cb1fed896be469830044627902456addd989 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 15 Apr 2025 17:03:31 +0200 Subject: [PATCH 14/19] refs #1916 move ogGetIpAddress to NetLib --- CHANGELOG.md | 6 ++++++ ogclient/lib/python3/NetLib.py | 24 +++++++++++++++++++++++- ogclient/lib/python3/ogGlobals.py | 27 --------------------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad1cf43..18e8db1 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.6.0] - 2025-04-15 + +### Changed + +- ogGetIpAddress() is no longer required in ogGlobals--move it back into NetLib + ## [0.5.0] - 2025-04-15 ### Changed diff --git a/ogclient/lib/python3/NetLib.py b/ogclient/lib/python3/NetLib.py index a6cacc4..438d72d 100644 --- a/ogclient/lib/python3/NetLib.py +++ b/ogclient/lib/python3/NetLib.py @@ -142,7 +142,29 @@ def ogGetHostname(): #@note Usa las variables utilizadas por el initrd "/etc/net-ethX.conf #*/ ## def ogGetIpAddress(): - return ogGlobals.ogGetIpAddress() + if "IPV4ADDR" in os.environ: + ip = os.environ["IPV4ADDR"] + if '/' in ip: ip = ip.split ('/')[0] + return ip + + extra_args = [] + if "DEVICE" in os.environ: + extra_args = [ "dev", os.environ["DEVICE"] ] + ipas = subprocess.run (['ip', '-json', 'address', 'show', 'up'] + extra_args, capture_output=True, text=True).stdout + + ipasj = json.loads (ipas) + addresses = [] + for e in ipasj: + if 'lo' == e['ifname']: continue + if 'addr_info' not in e: continue + addrs = e['addr_info'] + for a in addrs: + if 'inet' != a['family']: continue + addresses.append ({ 'local': a['local'], 'prefixlen': a['prefixlen'] }) + + if 1 != len (addresses): + raise Exception ('more than one local IP address found') + return addresses[0] #/** diff --git a/ogclient/lib/python3/ogGlobals.py b/ogclient/lib/python3/ogGlobals.py index beb3d97..c212c9e 100644 --- a/ogclient/lib/python3/ogGlobals.py +++ b/ogclient/lib/python3/ogGlobals.py @@ -6,33 +6,6 @@ import os.path import locale import importlib.util -## required for defining OGLOGFILE -def ogGetIpAddress(): - if "IPV4ADDR" in os.environ: - ip = os.environ["IPV4ADDR"] - if '/' in ip: ip = ip.split ('/')[0] - return ip - - extra_args = [] - if "DEVICE" in os.environ: - extra_args = [ "dev", os.environ["DEVICE"] ] - ipas = subprocess.run (['ip', '-json', 'address', 'show', 'up'] + extra_args, capture_output=True, text=True).stdout - - ipasj = json.loads (ipas) - addresses = [] - for e in ipasj: - if 'lo' == e['ifname']: continue - if 'addr_info' not in e: continue - addrs = e['addr_info'] - for a in addrs: - if 'inet' != a['family']: continue - addresses.append ({ 'local': a['local'], 'prefixlen': a['prefixlen'] }) - - if 1 != len (addresses): - raise Exception ('more than one local IP address found') - return addresses[0] -ip = ogGetIpAddress() - def load_lang (name): global lang if name in sys.modules: -- 2.40.1 From e20bd46edb3379f1e241db033581faff9cc65da1 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 15 Apr 2025 17:06:34 +0200 Subject: [PATCH 15/19] refs #1914 fix a couple of bugs --- CHANGELOG.md | 6 ++++++ ogclient/lib/python3/ImageLib.py | 2 ++ ogclient/scripts/deployImage.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18e8db1..64f5aea 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.6.1] - 2025-04-15 + +### Fixed + +- Fixed capturing of partclone output and management of return value + ## [0.6.0] - 2025-04-15 ### Changed diff --git a/ogclient/lib/python3/ImageLib.py b/ogclient/lib/python3/ImageLib.py index 5cfcbaf..621924e 100644 --- a/ogclient/lib/python3/ImageLib.py +++ b/ogclient/lib/python3/ImageLib.py @@ -512,6 +512,8 @@ def ogRestoreImage (repo, imgpath, disk, par): rc = None try: p = subprocess.run (program, shell=True, capture_output=True, text=True) + print (p.stdout) + print (p.stderr) rc = p.returncode if not rc: SystemLib.ogRaiseError ([], ogGlobalsOG_ERR_IMAGE, f'{imgfile}, {disk}, {par}') diff --git a/ogclient/scripts/deployImage.py b/ogclient/scripts/deployImage.py index e5a2ec2..4070fb4 100755 --- a/ogclient/scripts/deployImage.py +++ b/ogclient/scripts/deployImage.py @@ -145,6 +145,10 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): SystemLib.ogEcho (['log', 'session'], None, f'[55] {ogGlobals.lang.MSG_HELP_ogRestoreImage}: restoreImage {params}') retval = subprocess.run (['restoreImage.py'] + params).returncode + ## turn shell's success into python success (without ending up with True or False) + if retval: retval = 0 + else: retval = 1 + # Mostrar resultados. resumerestoreimage = subprocess.run (['grep', '--max-count', '1', 'Total Time:', ogGlobals.OGLOGCOMMAND], capture_output=True, text=True).stdout SystemLib.ogEcho (['log', 'session'], None, f' [ ] {resumerestoreimage} ') -- 2.40.1 From c76fd8388a1d0c0015302396613ce85363643c39 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 15 Apr 2025 17:16:48 +0200 Subject: [PATCH 16/19] refs #1908 remove refs to OGLOG --- CHANGELOG.md | 6 ++++++ ogclient/lib/python3/ogGlobals.py | 5 ++--- ogclient/scripts/listHardwareInfo.py | 2 +- ogclient/scripts/listSoftwareInfo.py | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64f5aea..1ec917e 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.7.0] - 2025-04-15 + +### Removed + +- Removed references to ogGlobals.OGLOG in python code + ## [0.6.1] - 2025-04-15 ### Fixed diff --git a/ogclient/lib/python3/ogGlobals.py b/ogclient/lib/python3/ogGlobals.py index c212c9e..f1901fd 100644 --- a/ogclient/lib/python3/ogGlobals.py +++ b/ogclient/lib/python3/ogGlobals.py @@ -61,9 +61,8 @@ OGPYFUNCS = os.path.join (OPENGNSYS, 'functions') OGSCRIPTS = os.path.join (OPENGNSYS, 'scripts') OGIMG = os.path.join (OPENGNSYS, 'images') OGCAC = os.path.join (OPENGNSYS, 'cache') -OGLOG = '/var/log' -OGLOGFILE = f'{OGLOG}/clone-engine.log' -OGJSONLOGFILE = f'{OGLOG}/clone-engine.json.log' +OGLOGFILE = '/var/log/clone-engine.log' +OGJSONLOGFILE = '/var/log/clone-engine.json.log' DEBUG = 'yes' _path = os.environ['PATH'] + ':/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:/opt/oglive/rootfs/opt/drbl/sbin' os.environ['PATH'] = ':'.join ([OGSCRIPTS, _path, OGAPI, OGBIN]) diff --git a/ogclient/scripts/listHardwareInfo.py b/ogclient/scripts/listHardwareInfo.py index d702212..5993f07 100755 --- a/ogclient/scripts/listHardwareInfo.py +++ b/ogclient/scripts/listHardwareInfo.py @@ -21,7 +21,7 @@ if len (sys.argv) > 1: #SERVERLOGDIR = unused # Fichero de listado: hard-IP -HARDFILE = f'{ogGlobals.OGLOG}/hard-{ogGetIpAddress()}' +HARDFILE = f'/tmp/hard-{ogGetIpAddress()}' out = ogListHardwareInfo() with open (HARDFILE, 'w') as fd: fd.write (out) diff --git a/ogclient/scripts/listSoftwareInfo.py b/ogclient/scripts/listSoftwareInfo.py index 1c2756e..f92cdbd 100755 --- a/ogclient/scripts/listSoftwareInfo.py +++ b/ogclient/scripts/listSoftwareInfo.py @@ -18,7 +18,7 @@ prog = os.path.basename (sys.argv[0]) def main (disk, par, reduced): ip = NetLib.ogGetIpAddress() - softfile = f'{ogGlobals.OGLOG}/soft-{ip}-{disk}-{par}' + softfile = f'/tmp/soft-{ip}-{disk}-{par}' software_list = InventoryLib.ogListSoftware (disk, par) if reduced: -- 2.40.1 From bd056438a1cf020881a999de0e9e71ca11678f44 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 15 Apr 2025 17:56:27 +0200 Subject: [PATCH 17/19] refs #1918 fix getConfiguration.py --- CHANGELOG.md | 6 ++++++ ogclient/interfaceAdm/getConfiguration.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec917e..9b783e4 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.7.1] - 2025-04-15 + +### Fixed + +- getConfiguration.py: don't fail if NTFS filesystems are mounted ro + ## [0.7.0] - 2025-04-15 ### Removed diff --git a/ogclient/interfaceAdm/getConfiguration.py b/ogclient/interfaceAdm/getConfiguration.py index 960fe7a..29d4ec4 100755 --- a/ogclient/interfaceAdm/getConfiguration.py +++ b/ogclient/interfaceAdm/getConfiguration.py @@ -74,4 +74,5 @@ else: # Borramos marcas de arranque de Windows for f in glob.glob ('/mnt/*/ogboot.*') + glob.glob ('/mnt/*/*/ogboot.*'): - os.unlink (f) + try: os.unlink (f) + except: pass -- 2.40.1 From 842dbf48c21dd3018838317396b7581525a2facc Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Mon, 21 Apr 2025 12:48:47 +0200 Subject: [PATCH 18/19] refs #1912 fix a couple of rc --- CHANGELOG.md | 6 ++++++ ogclient/lib/python3/DiskLib.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b783e4..75468e5 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.7.2] - 2025-04-21 + +### Fixed + +- Have the partitioning functions return a meaningful rc + ## [0.7.1] - 2025-04-15 ### Fixed diff --git a/ogclient/lib/python3/DiskLib.py b/ogclient/lib/python3/DiskLib.py index 7cb0c45..1213358 100644 --- a/ogclient/lib/python3/DiskLib.py +++ b/ogclient/lib/python3/DiskLib.py @@ -179,7 +179,7 @@ def ogCreatePartitions (disk, parts): p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True) subprocess.run (['partprobe', DISK]) if CACHESIZE: CacheLib.ogMountCache() - return True + return not p.returncode #/** @@ -285,7 +285,7 @@ def ogCreateGptPartitions (disk, parts): p = subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK], capture_output=True, text=True) subprocess.run (['partprobe', DISK]) if CACHESIZE: CacheLib.ogMountCache() - return True + return not p.returncode #/** -- 2.40.1 From c3e86b7dc079e6fb3ecd797d6544ec25af87aa18 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 23 Apr 2025 13:58:51 +0200 Subject: [PATCH 19/19] refs #1925 send /stopped on poweroff or restart --- CHANGELOG.md | 6 ++++++ ogclient/interfaceAdm/Apagar.py | 3 +++ ogclient/interfaceAdm/Reiniciar.py | 3 +++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75468e5..c45ab03 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.8.0] - 2025-04-23 + +### Added + +- Have the oglive agent send /stopped on poweroff or restart + ## [0.7.2] - 2025-04-21 ### Fixed diff --git a/ogclient/interfaceAdm/Apagar.py b/ogclient/interfaceAdm/Apagar.py index 25545f3..b89c3cc 100755 --- a/ogclient/interfaceAdm/Apagar.py +++ b/ogclient/interfaceAdm/Apagar.py @@ -2,6 +2,9 @@ import os import sys +import time +os.system ('pkill -f OGAgent') +time.sleep (3) os.system ('poweroff') sys.exit (0) diff --git a/ogclient/interfaceAdm/Reiniciar.py b/ogclient/interfaceAdm/Reiniciar.py index 0cbeedc..ceaa589 100755 --- a/ogclient/interfaceAdm/Reiniciar.py +++ b/ogclient/interfaceAdm/Reiniciar.py @@ -2,6 +2,9 @@ import os import sys +import time +os.system ('pkill -f OGAgent') +time.sleep (3) os.system ('reboot') sys.exit (0) -- 2.40.1