From c759a586fbdbb7836e54e0fa8650b29b6db479b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 6 Aug 2024 12:48:37 +0200 Subject: [PATCH 1/3] Revert "Update bootc hosts message to point to bootc --help" This reverts commit 6461b97ef7c2f51fcd1377442cc4b3ce30675c61 because it breaks "dnf --installroot". Related: https://issues.redhat.com/browse/RHEL-49670 --- dnf/cli/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py index 99af9069b9..8521dd3518 100644 --- a/dnf/cli/cli.py +++ b/dnf/cli/cli.py @@ -217,7 +217,7 @@ def do_transaction(self, display=()): if dnf.util._is_bootc_host(): _bootc_host_msg = _(""" *** Error: system is configured to be read-only; for more -*** information run `bootc --help`. +*** information run `bootc status` or `ostree admin status`. """) logger.info(_bootc_host_msg) raise CliError(_("Operation aborted.")) From f6d25a8a3bd8c9c7c21e41220f0916c78a12025b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 6 Aug 2024 12:49:10 +0200 Subject: [PATCH 2/3] Revert "Update ostree/bootc host system check." This reverts commit 734aab779bfd6c1792dd17528b30215a715fa898 because it breaks "dnf --installroot". Related: https://issues.redhat.com/browse/RHEL-49670 --- dnf/cli/cli.py | 11 ++++++----- dnf/util.py | 33 +++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py index 8521dd3518..1fd0e96c3a 100644 --- a/dnf/cli/cli.py +++ b/dnf/cli/cli.py @@ -214,12 +214,13 @@ def do_transaction(self, display=()): elif 'test' in self.conf.tsflags: logger.info(_("{prog} will only download packages, install gpg keys, and check the " "transaction.").format(prog=dnf.util.MAIN_PROG_UPPER)) - if dnf.util._is_bootc_host(): - _bootc_host_msg = _(""" -*** Error: system is configured to be read-only; for more -*** information run `bootc status` or `ostree admin status`. + if dnf.util.is_container(): + _container_msg = _(""" +*** This system is managed with ostree. Changes to the system +*** made with dnf will be lost with the next ostree-based update. +*** If you do not want to lose these changes, use 'rpm-ostree'. """) - logger.info(_bootc_host_msg) + logger.info(_container_msg) raise CliError(_("Operation aborted.")) if self._promptWanted(): diff --git a/dnf/util.py b/dnf/util.py index e68dd57332..9909f8fea5 100644 --- a/dnf/util.py +++ b/dnf/util.py @@ -33,11 +33,13 @@ import functools import hawkey import itertools +import json import locale import logging import os import pwd import shutil +import subprocess import sys import tempfile import time @@ -633,15 +635,30 @@ def _name_unset_wrapper(input_name): return input_name if input_name else _("") -def _is_bootc_host(): +def is_container(): """Returns true is the system is managed as an immutable container, false otherwise. If msg is True, a warning message is displayed for the user. """ - ostree_booted = '/run/ostree-booted' - usr = '/usr/' - # Check if usr is writtable and we are in a running ostree system. - # We want this code to return true only when the system is in locked state. If someone ran - # bootc overlay or ostree admin unlock we would want normal DNF path to be ran as it will be - # temporary changes (until reboot). - return os.path.isfile(ostree_booted) and not os.access(usr, os.W_OK) \ No newline at end of file + + bootc = '/usr/bin/bootc' + ostree = '/sysroot/ostree' + + if os.path.isfile(bootc) and os.access(bootc, os.X_OK): + p = subprocess.Popen([bootc, "status", "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (out, err) = p.communicate() + + if p.returncode == 0: + # check the output of 'bootc status' + j = json.loads(out) + + # XXX: the API from bootc status is evolving + status = j.get("status", "") + kind = j.get("kind", "") + + if kind.lower() == "bootchost" and bool(status.get("isContainer", None)): + return True + elif os.path.isdir(ostree): + return True + + return False \ No newline at end of file From 7c3660b9aad68523e38899b40b4bdf198787be73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 6 Aug 2024 12:49:11 +0200 Subject: [PATCH 3/3] Revert "Add detection for ostree-based systems and warn users about losing changes" This reverts commit d100c8d717cb6fbd6ba9e16028a56b140275bc8b because it breaks "dnf --installroot". Related: https://issues.redhat.com/browse/RHEL-49670 --- dnf/cli/cli.py | 9 --------- dnf/util.py | 31 ------------------------------- 2 files changed, 40 deletions(-) diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py index 1fd0e96c3a..0c4f4c6ad9 100644 --- a/dnf/cli/cli.py +++ b/dnf/cli/cli.py @@ -214,15 +214,6 @@ def do_transaction(self, display=()): elif 'test' in self.conf.tsflags: logger.info(_("{prog} will only download packages, install gpg keys, and check the " "transaction.").format(prog=dnf.util.MAIN_PROG_UPPER)) - if dnf.util.is_container(): - _container_msg = _(""" -*** This system is managed with ostree. Changes to the system -*** made with dnf will be lost with the next ostree-based update. -*** If you do not want to lose these changes, use 'rpm-ostree'. -""") - logger.info(_container_msg) - raise CliError(_("Operation aborted.")) - if self._promptWanted(): if self.conf.assumeno or not self.output.userconfirm(): raise CliError(_("Operation aborted.")) diff --git a/dnf/util.py b/dnf/util.py index 9909f8fea5..16c5bc89c1 100644 --- a/dnf/util.py +++ b/dnf/util.py @@ -33,13 +33,11 @@ import functools import hawkey import itertools -import json import locale import logging import os import pwd import shutil -import subprocess import sys import tempfile import time @@ -633,32 +631,3 @@ def _tsi_or_pkg_nevra_cmp(item1, item2): def _name_unset_wrapper(input_name): # returns for everything that evaluates to False (None, empty..) return input_name if input_name else _("") - - -def is_container(): - """Returns true is the system is managed as an immutable container, - false otherwise. If msg is True, a warning message is displayed - for the user. - """ - - bootc = '/usr/bin/bootc' - ostree = '/sysroot/ostree' - - if os.path.isfile(bootc) and os.access(bootc, os.X_OK): - p = subprocess.Popen([bootc, "status", "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (out, err) = p.communicate() - - if p.returncode == 0: - # check the output of 'bootc status' - j = json.loads(out) - - # XXX: the API from bootc status is evolving - status = j.get("status", "") - kind = j.get("kind", "") - - if kind.lower() == "bootchost" and bool(status.get("isContainer", None)): - return True - elif os.path.isdir(ostree): - return True - - return False \ No newline at end of file