Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and enable tests for transaction replay #1525

Merged
merged 20 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d0bf5ed
Add support for reason change in transaction table checking
kontura Jul 17, 2023
0fb73d0
replay.feature: convert reasons to dnf5 format
kontura Aug 24, 2023
f46eab7
Add missing dnf5 format for: Removing environmental groups
kontura Aug 24, 2023
b14d6ac
Add step for checking system state of groups
kontura Jul 1, 2024
464b200
Add step for checking system state of environments
kontura Jul 1, 2024
53a42a2
Replace comps history db checks with system state checks
kontura Jul 2, 2024
3322bcc
Replace `History info should match` with `transaction items for trans…
kontura Jul 2, 2024
651d95a
replay.feature: upgrade action to dnf5 format
kontura Jul 2, 2024
07b2b19
replay.feature: update to dnf5 format, syntax and usage
kontura Jul 2, 2024
2f0eb00
replay.feature: update test for reason change of missing pkg
kontura Jul 2, 2024
10146fd
replay.feature: when a group is removed its packages are cleaned up
kontura Jul 2, 2024
47615fc
replay.feature: packaged pulled in by a group have reason Group
kontura Jul 2, 2024
a40e11e
replay.feature: use Dependency for testing reason change and remove
kontura Jul 2, 2024
c1d438b
replay.feature: fix a bad test, the reason is user
kontura Jul 2, 2024
421aaf8
replay.feature: replace `unknown` reason with `User`
kontura Jul 2, 2024
d2cbdb8
replay.feature: disable invalid test
kontura Jul 2, 2024
cb13af7
replay.feature: add failing test to track expected behavior
kontura Jul 2, 2024
662c697
replay-validation.feature: update for dnf5 and enable it
kontura Jul 2, 2024
26975be
replay-errors.feature: update for dnf5 and enable it
kontura Jul 2, 2024
f7927b9
Add test for replay group install without package_types
kontura Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions dnf-behave-tests/dnf/steps/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,60 +79,6 @@ def step_impl(context, history_range=None):
assert_history_list(context, context.cmd_stdout)


#TODO(amatej): This should be removed once the step is no longer used in transaction-sr/replay.feature.
# The step is duplicate of 'dnf5 transaction items for transaction "last" are'.
@behave.then('History info should match')
@behave.then('History info "{spec}" should match')
def step_impl(context, spec=None):
IN = ['Description',]
ACTIONS = [
'Install',
'Upgrade',
'Downgrade',
'Reinstall',
'Remove',
'Replaced',
'Reason Change',
'Enable',
'Disable',
'Reset',
]

check_context_table(context, ["Key", "Value"])

if spec is None:
spec = ""
h_info = parsed_history_info(context, spec)

expected_actions = []
for key, value in context.table:
if key in h_info:
if key in IN and value in h_info[key]:
continue
elif value == h_info[key]:
continue
else:
raise AssertionError(
'[history] {0} "{1}" not matched by "{2}".'.format(
key, h_info[key], value))
elif key in ACTIONS:
expected_actions.append([key, value])
else:
raise AssertionError('[history] key "{0}" not found.'.format(key))

found_actions = []
for a in h_info[None]:
action = a.split()

if action[0:2] == ["Reason", "Change"]:
found_actions.append(["Reason Change", action[2]])
else:
found_actions.append(action[0:2])

if expected_actions != found_actions:
print_lines_diff(expected_actions, found_actions)
raise AssertionError("History actions mismatch")

@behave.then('History info rpmdb version changed')
def step_impl(context, spec=""):
h_info = parsed_history_info(context, spec)
Expand Down
7 changes: 7 additions & 0 deletions dnf-behave-tests/dnf/steps/lib/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"Installing environmental groups": "env-install",
"Installing Environment Groups": "env-install",
"Removing Environment Groups": "env-remove",
"Removing environmental groups": "env-remove",
"Upgrading Environment Groups": "env-upgrade",
"Upgrading environmental groups": "env-upgrade",
"Installing module profiles": "module-profile-install",
Expand All @@ -62,6 +63,7 @@
"Switching module streams": "module-stream-switch",
"Disabling modules": "module-disable",
"Resetting modules": "module-reset",
"Changing reason": "changing-reason",
}


Expand Down Expand Up @@ -305,6 +307,11 @@ def parse_transaction_table_dnf5(context, lines):
nevra = "{0[name]}-{0[evr]}.{0[arch]}".format(match_dict)
rpm = RPM(nevra)
result[result_action].add(rpm)
if action == "changing-reason":
# Drop line that describes how the reason was changed, eg: User -> Dependency.
# Currently we do not record how the reason was changed, it can be checked by
# step: "dnf5 transaction items for transaction "last" are"
lines.pop(0)

return result

Expand Down
75 changes: 75 additions & 0 deletions dnf-behave-tests/dnf/steps/system_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,78 @@ def package_state_is(context):

if fail:
raise AssertionError("System state mismatch")


@behave.then('group state is')
def group_state_is(context):
"""
Checks packages and userinstalled state in groups system state groups.toml.
For that, the table in context has to contain group id.
"""
check_context_table(context, ["id", "package_types", "packages", "userinstalled"])

found_groups = []
with open(os.path.join(context.dnf.installroot, "usr/lib/sysimage/libdnf5/groups.toml")) as f:
for k, v in toml.load(f)["groups"].items():
pkg_types = v["package_types"]
pkg_types.sort()
pkgs = v["packages"]
pkgs.sort()
found_groups.append((k, ', '.join(pkg_types), ', '.join(pkgs), str(v["userinstalled"])))
found_groups.sort()

expected_groups = []
for group_id, package_types, packages, userinstalled in context.table:
p_types = package_types.split(',')
p_types = list(map(str.strip, p_types))
p_types.sort()
p = packages.split(',')
p = list(map(str.strip, p))
p.sort()
expected_groups.append((group_id, ', '.join(p_types), ', '.join(p), str(userinstalled)))

expected_groups.sort()

fail = False
if expected_groups != found_groups:
print("groups.toml system state differs from expected:")
print_lines_diff(expected_groups, found_groups)
fail = True

if fail:
raise AssertionError("Group system state mismatch")


@behave.then('environment state is')
def environment_state_is(context):
"""
Checks groups in environments system state environments.toml.
For that, the table in context has to contain environment id.
"""
check_context_table(context, ["id", "groups"])

found_environments = []
with open(os.path.join(context.dnf.installroot, "usr/lib/sysimage/libdnf5/environments.toml")) as f:
for k, v in toml.load(f)["environments"].items():
groups = v["groups"]
groups.sort()
found_environments.append((k, ', '.join(groups)))
found_environments.sort()

expected_environments = []
for env_id, groups in context.table:
g = groups.split(',')
g = list(map(str.strip, g))
g.sort()
expected_environments.append((env_id, ', '.join(g)))

expected_environments.sort()

fail = False
if expected_environments != found_environments:
print("environments.toml system state differs from expected:")
print_lines_diff(expected_environments, found_environments)
fail = True

if fail:
raise AssertionError("Environment system state mismatch")
2 changes: 1 addition & 1 deletion dnf-behave-tests/dnf/steps/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def check_rpmdb_transaction(context, mode):
if action.startswith("remove-"):
action = "remove"

if action in ["broken"] or action in ["conflict"]:
if action in ["broken", "conflict", "changing-reason"]:
continue
for nevra in nevras.split(", "):
if action.startswith('group-') or action.startswith('env-') or action.startswith('module-'):
Expand Down
Loading
Loading