22979496db
Resolves: RHEL-49670
108 lines
3.7 KiB
Diff
108 lines
3.7 KiB
Diff
From 6157248a5035a7752115143d8d29773384c1db3f Mon Sep 17 00:00:00 2001
|
|
From: Joseph Marrero <jmarrero@redhat.com>
|
|
Date: Tue, 16 Jul 2024 15:48:41 -0400
|
|
Subject: [PATCH 2/4] Update ostree/bootc host system check.
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Upstream commit: 6120fe52511775b60b6031d4169988c025610ab5
|
|
|
|
This changes the is_container() func for _is_bootc_host()
|
|
and updates the logic and message. This should detect on
|
|
all ostree and bootc hosts to date that are not using
|
|
bootc usroverlay or ostree admin unlock for development
|
|
purposes.
|
|
|
|
Resolves: https://issues.redhat.com/browse/RHEL-49670
|
|
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
---
|
|
dnf/cli/cli.py | 11 +++++------
|
|
dnf/util.py | 33 ++++++++-------------------------
|
|
2 files changed, 13 insertions(+), 31 deletions(-)
|
|
|
|
diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py
|
|
index 1fd0e96c3..8521dd351 100644
|
|
--- a/dnf/cli/cli.py
|
|
+++ b/dnf/cli/cli.py
|
|
@@ -214,13 +214,12 @@ class BaseCli(dnf.Base):
|
|
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'.
|
|
+ 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`.
|
|
""")
|
|
- logger.info(_container_msg)
|
|
+ logger.info(_bootc_host_msg)
|
|
raise CliError(_("Operation aborted."))
|
|
|
|
if self._promptWanted():
|
|
diff --git a/dnf/util.py b/dnf/util.py
|
|
index 9909f8fea..e8f587a03 100644
|
|
--- a/dnf/util.py
|
|
+++ b/dnf/util.py
|
|
@@ -33,13 +33,11 @@ import errno
|
|
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
|
|
@@ -635,30 +633,15 @@ def _name_unset_wrapper(input_name):
|
|
return input_name if input_name else _("<name-unset>")
|
|
|
|
|
|
-def is_container():
|
|
+def _is_bootc_host():
|
|
"""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
|
|
+ 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)
|
|
--
|
|
2.46.2
|
|
|