summaryrefslogtreecommitdiffstats
path: root/src/utils/legacy.py
Commit message (Collapse)AuthorAgeFilesLines
* src: log backtrace in unhandled error casesAlejandro Sirgo Rica2024-04-031-7/+8
| | | | | | | | | | | | | | | | | | | Log an error message in known error cases and log a backtrace otherwise. Define a new error type OgError to be used in all the 'raise' blocks to define the error message to log. The exception propagates until it reaches send_internal_server_error() where the exception type is checked. If the type is OgError we log the exception message. Logs the backtrace for other types. The initial error implementation printed a backtrace everytime an error ocurred. The next iteration changed it to only print a backtrace in a very particular case but ended up omiting too much information such as syntax errors or unknown error context. The actual implementation only logs the cases we already cover in the codebase and logs a bracktrace in the others, enabling a better debugging experience.
* utils: drop ogCopyEfiBootLoader scriptAlejandro Sirgo Rica2024-03-261-10/+0
| | | | | | | | Implement a Python equivalent of ogCopyEfiBootLoader as the function copy_efi_bootloader. This function copies the contents of the folder of the EFI loader in the ESP into a ogBoot folder at the root of the partition target of an image creation. copy_efi_bootloader is a Windows only functionality.
* src: make exception messages more contextual and explicitAlejandro Sirgo Rica2024-03-211-1/+1
| | | | | | | Provide more information in exception messages as those are the source of the logging messages. Add information about paths, files or configuration related to the operation associated to the exception.
* src: centralize error logging into send_internal_server_errorAlejandro Sirgo Rica2024-03-211-14/+13
| | | | | | | | | | | | | | | | | | | | Use only the exception messages as the main resource for error messages. The previous error code had string duplication in the form of: logging.error('msg here') raise Exception('msg here') That approach also has the downside of having log duplication as it had the local logging.err() and a global logging.exception() inside send_internal_server_error capturing the exception message. The actual code only requires raising an exception with a proper error message. Improve exception messages to give more error context. Log every AssertionError as a backtrace. Use the 'raise Exception from e' syntax to modify the a previously raised exception 'e' into an exception with aditional context or different type. This also prevents the message that warns about newer exceptions being launch after an initial exception.
* utils: use returncode from subprocess in ogChangeRepo()OpenGnSys Support Team2024-02-211-4/+3
| | | | | | | ... the exception shows the samba password in the logs specify the error which tells us what has happened according to man mount(8) Return Codes.
* utils: remove repository change in restoreImageCustomOpenGnSys Support Team2024-02-151-4/+0
| | | | this is broken, it uses default uses and password, remove it.
* src: ogChangeRepo returns zero on success and -1 on errorOpenGnSys Support Team2024-02-151-7/+10
| | | | | | | | | | | | | | | | | | | | 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: improve error check in image_create and image_restoreAlejandro Sirgo Rica2024-02-141-5/+5
| | | | | | | | | cover more error cases where exceptions need to be raised. check return code in the invoked subprocess. restoreImageCustom has been intentionally left behind, it is unclear what this custom script returns on success and error.
* utils: use f-string in raise ValueError in run_lzop_partcloneinfo()OpenGnSys Support Team2023-12-151-1/+1
| | | | | | Otherwise it shows: ValueError: Unable to process image {image_path}
* live: report permissions and last update when creating imagev1.3.2-3OpenGnSys Support Team2023-12-121-0/+2
| | | | add .permissions and .lastupdate to json to report to ogserver.
* live: report image size when creating imageOpenGnSys Support Team2023-12-121-0/+1
| | | | add .size json field to report the real size of the image file.
* src: add missing copyright noticesv1.2.8Jose M. Guisado2023-04-181-0/+8
|
* legacy: improve readability of ogGetImageInfo helper functionsJose M. Guisado2023-03-101-14/+13
| | | | | | | | | | | | | | | | | | | | Change the name of the helper functions used when getting opengnsys image information (legacy ogGetImageInfo bash script). As of now the process consist of decompressing the image file with lzop and feeding that output to partclone.info. Prefer a more explicit function name rather than "process_image_*" Add comment about skipping the first two lines of partclone.info output. Usually, partclone.info starts printing out these two lines that are not related to the partclone image information: Partclone v0.3.23 http://partclone.org Showing info of image (-) As long as partclone.info output doesn't change we'll be fine, but we should not depend on human readable output. This might change in the future (i.e. adding json output format to partclone.info).
* legacy: rewrite ogGetImageInfoJose M. Guisado2023-03-021-14/+104
| | | | | | | | | | | | | | | | | | | | Rewrites this legacy script behavior using native Python code, using subprocess module when executing programs like partclone.info or lzop ogGetImageInfo is a bash script that retrieves information regarding an OpenGnsys partition image, specifically: - clonator - compressor - filesystem - datasize (size of the partition image) This rewrite only supports partclone and lzop compressed images. This is standard behavior, we have no reports of other programs or compression algorithms in use. Keep this legacy function with hungarian notation to emphasize this is still a legacy component that may be replaced in the future.
* legacy: rewrite ogChangeRepoJose M. Guisado2023-03-021-6/+52
| | | | | | | | | | | | | | | | Drop ogChangeRepo Bash script in favor of a native Python approach. Use only necessary subprocess calls instead of bringing all the logic of this function into a Bash script black box. ogChangeRepo unmounts the current OpenGnsys image samba folder (/opt/opengnsys/images) and mounts (connects to) a new directory using the new provided ip address. Keeping access mode from previous mount. If anything goes wrong when mounting the new directory, it will fallback to mounting the previous directory. If no previous OpenGnsys image samba directory is detected, this functions tries to mount the new directory anyway. In this case, it will raise CalledProcessError if something goes wrong.
* legacy: improve readability of cambiar_accessoJose M. Guisado2023-03-021-10/+10
| | | | | Expand function docstring and do not use CalledProcessError handling to return True or False. Just checking for returncode value is simpler.
* live: rewrite image_restoreJose M. Guisado2022-09-141-0/+46
| | | | | | | | Integrates image restore command into native ogClient code. Further reduces the need for external Bash scripts. After a succesful image restore, OS configuration is still using external Bash script "osConfigure/osConfigureCustom".
* image_restore: fix ogCopyEfiBootLoaderJose M. Guisado2022-09-141-3/+4
| | | | | | | | | ogCopyEfiBootloader is an invalid legacy bash function name. Rename to the correct function name 'ogCopyEfiBootLoader' and rename utility python wrapper too. Fixes: 0bd037c1a409c65fbcb01355ee0dd6dca770330e
* image_create: add legacy ogCopyEfiBootloaderJose M. Guisado2022-09-141-0/+10
| | | | | | | | | | | | | | Use legacy script that saves the Windows-specific content from the ESP to the image target filesystem. Current image restore solution from OpenGnsys scripts expect the EFI partition to be stored in the target system partition. (Only for Windows 10) For example, storing the ESP in the NTFS partition of a Windows image. Expect use of bash script ogCopyEfiBootloader until further integration is merged.
* image_create: partial integration into pythonv1.2.2Jose M. Guisado2022-08-241-0/+55
Integrates some parts of this operation into native code, eg: the md5 checksum computation. Wraps non native processes and commands using the subprocess module. For example, legacy.py stores bash commands pending integration. Supports python >=3.6, expected until more modern ogLives are put into production environments.