From 2c762c475386b0eb322e685716219750e3dc3dd4 Mon Sep 17 00:00:00 2001 From: andre161292 Date: Sat, 25 Feb 2023 10:58:04 +0100 Subject: [PATCH] Added support for openSUSE MicroOS (#5998) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(zypper): Added condition to check for transactional-update binary to support microos closes #5615 * style(changelog): Made zypper-change uppercase Co-authored-by: Felix Fontein * fix(zypper): Removed check for /var/lib/misc/transactional-update.state * feat(zypper): Aligned transactional-update checks with zypper's * refactor(zypper): Removed dependency to psutil and made use of parsing /proc/mount * refactor(zypper): Removed need for regex, plus small refactoring --------- Co-authored-by: André Dörscheln Co-authored-by: Felix Fontein --- .../5615-zypper-transactional-update.yml | 2 ++ plugins/modules/zypper.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/5615-zypper-transactional-update.yml diff --git a/changelogs/fragments/5615-zypper-transactional-update.yml b/changelogs/fragments/5615-zypper-transactional-update.yml new file mode 100644 index 0000000000..5eb6bb8405 --- /dev/null +++ b/changelogs/fragments/5615-zypper-transactional-update.yml @@ -0,0 +1,2 @@ +bugfixes: + - "zypper - make package managing work on readonly filesystem of openSUSE MicroOS (https://github.com/ansible-collections/community.general/pull/5615)." diff --git a/plugins/modules/zypper.py b/plugins/modules/zypper.py index 775ff0fd6e..9ba5555e20 100644 --- a/plugins/modules/zypper.py +++ b/plugins/modules/zypper.py @@ -519,8 +519,21 @@ def repo_refresh(m): return retvals +def get_fs_type_and_readonly_state(mount_point): + with open('/proc/mounts', 'r') as file: + for line in file.readlines(): + fields = line.split() + path = fields[1] + if path == mount_point: + fs = fields[2] + opts = fields[3] + return fs, 'ro' in opts.split(',') + return None + + def transactional_updates(): - return os.path.exists('/var/lib/misc/transactional-update.state') + return os.path.exists('/usr/sbin/transactional-update') and get_fs_type_and_readonly_state('/') == ('btrfs', True) + # =========================================== # Main control flow