Skip to content

Commit

Permalink
behave: remove dnf5 if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Jan 24, 2024
1 parent 43e02e6 commit 0101b7c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion behave/features/steps/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
# pylint: disable=missing-function-docstring,function-redefined


def _first_int(string, max_lines=20):
for line in string.split("\n")[:max_lines]:
if not line:
continue
first_word = line.split()[0]
if first_word.isdigit():
return first_word
raise Exception("unexpected dnf history output")


def add_cleanup_last_transaction(context):
# TODO: DNF5 support https://github.com/rpm-software-management/dnf5/issues/140
dnf = ["sudo", "/usr/bin/dnf-3", "-y", "history"]
_, out, _ = run(dnf + ["list"])
transaction_id = _first_int(out)
def _revert_transaction(_context):
cmd = dnf + ["undo", transaction_id]
assert_that(run(cmd)[0], equal_to(0))
context.add_cleanup(_revert_transaction, context)

@given(u'an unique mock namespace')
def step_impl(context):
print("using uniqueext {}".format(context.uniqueext))
Expand All @@ -39,7 +59,14 @@ def step_impl(context, package, state):
is_installed = bool(not is_installed)

if "not" in state:
assert_that(is_installed, equal_to(False))
if not is_installed:
return # nothing to do

# Remove the package and schedule its removal
cmd = ["sudo", "dnf", "-y", "remove", package]
assert_that(run(cmd)[0], equal_to(0))
# schedule removal
add_cleanup_last_transaction(context)
return

if is_installed:
Expand Down

0 comments on commit 0101b7c

Please sign in to comment.