Skip to content

Commit

Permalink
Revert "Update ostree/bootc host system check."
Browse files Browse the repository at this point in the history
This reverts commit 734aab7 because
it breaks "dnf --installroot".
Related: https://issues.redhat.com/browse/RHEL-49670
  • Loading branch information
ppisar committed Aug 14, 2024
1 parent 66ae26f commit 9079c98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
11 changes: 6 additions & 5 deletions dnf/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
33 changes: 25 additions & 8 deletions dnf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -633,15 +635,30 @@ def _name_unset_wrapper(input_name):
return input_name if input_name else _("<name-unset>")


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)

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

0 comments on commit 9079c98

Please sign in to comment.