def step_impl(context, history_range=None): if history_range is None: history_range = "list" cmd = " ".join(context.dnf.get_cmd(context) + ["history", history_range]) run_in_context(context, cmd) assert_history_list(context, context.cmd_stdout)
def step_impl(context): check_context_table(context, ["Package", "Reason"]) cmd = context.dnf.get_cmd(context) + [ "repoquery --qf '%{name}-%{evr}.%{arch},%{reason}' --installed" ] run_in_context(context, " ".join(cmd)) expected = [[p, r] for p, r in context.table] found = sorted( [r.split(",") for r in context.cmd_stdout.strip().split('\n')]) if found != expected: print_lines_diff(expected, found) raise AssertionError("Package reasons mismatch")
def step_impl(context): check_context_table(context, ["Action", "Package"]) cmd = " ".join(context.dnf.get_cmd(context) + ["history", "userinstalled"]) run_in_context(context, cmd) for action, package in context.table: if action == 'match': if package not in context.cmd_stdout: raise AssertionError( '[history] package "{0}" not matched as userinstalled.'.format(package)) elif action == 'not match': if package in context.cmd_stdout: raise AssertionError( '[history] package "{0}" matched as userinstalled.'.format(package)) else: raise ValueError('Invalid action "{0}".'.format(action))
def when_I_execute_dnf_with_args(context, args): """ Creates an unpriviged user if it doesn't exist (therefore the test is destructive!). Runs the dnf command under this user. """ # create a regular user for the test if it doesn't exist run_in_context(context, 'id -u testuser || useradd testuser', can_fail=False) cmd = " ".join(context.dnf.get_cmd(context)) cmd += " " + args.format(context=context) context.dnf["rpmdb_pre"] = get_rpmdb_rpms(context.dnf.installroot) # escape the quotes so that we can wrap the command in `su` cmd = cmd.replace('"', '\\"') run_in_context(context, 'su testuser -c "' + cmd + '"', can_fail=True)
def generate_repodata(context, repo): repo_replaced = repo.replace("$releasever", context.dnf.releasever) if repo_replaced in context.repos: return args = "--no-database --simple-md-filenames --revision=1550000000" groups_filename = os.path.join(context.dnf.fixturesdir, "specs", repo_replaced, "comps.xml") if os.path.isfile(groups_filename): args += " --groupfile " + groups_filename target_path = os.path.join(context.scenario.repos_location, repo_replaced) run_in_context(context, "createrepo_c %s %s" % (args, target_path)) repodata_path = os.path.join(target_path, "repodata") updateinfo_filename = os.path.join(context.dnf.fixturesdir, "specs", repo_replaced, "updateinfo.xml") if os.path.isfile(updateinfo_filename): run_in_context( context, "modifyrepo_c %s %s" % (updateinfo_filename, repodata_path)) modules_filename = os.path.join(context.dnf.fixturesdir, "specs", repo_replaced, "modules.yaml") if os.path.isfile(modules_filename): run_in_context( context, "modifyrepo_c --mdtype=modules %s %s" % (modules_filename, repodata_path)) context.repos[repo_replaced] = True
def generate_repodata(context, repo, extra_args=None, explicit=False, can_fail=False, expected_exit_code=None): repo_subst = repo.replace("$releasever", context.dnf.releasever) repo_info = get_repo_info(context, repo) if repo_subst in context.repos and not extra_args and not ( explicit and repo_info.copied): return args = "--no-database --simple-md-filenames --revision=1550000000" groups_filename = os.path.join(context.dnf.fixturesdir, "specs", repo_subst, "comps.xml") if os.path.isfile(groups_filename): args += " --groupfile " + groups_filename if extra_args is not None: args += " " + extra_args target_path = repo_info.get_substituted_path(context) if not os.path.isdir(target_path): os.makedirs(target_path) run_in_context(context, "createrepo_c %s '%s'" % (args, target_path), can_fail, expected_exit_code) repodata_path = os.path.join(target_path, "repodata") updateinfo_filename = os.path.join(context.dnf.fixturesdir, "specs", repo_subst, "updateinfo.xml") if os.path.isfile(updateinfo_filename): run_in_context( context, "modifyrepo_c %s '%s'" % (updateinfo_filename, repodata_path)) modules_filename = os.path.join(context.dnf.fixturesdir, "specs", repo_subst, "modules.yaml") if os.path.isfile(modules_filename): run_in_context( context, "modifyrepo_c --mdtype=modules %s '%s'" % (modules_filename, repodata_path)) if not repo_info.copied: context.repos[repo_subst] = True
def when_I_execute_dnf_automatic_with_args(context, args): cmd = "dnf-automatic" cmd += " " + args.format(context=context) context.dnf["rpmdb_pre"] = get_rpmdb_rpms(context.dnf.installroot) run_in_context(context, cmd, can_fail=True)
def when_I_execute_rpm_on_host_with_args(context, args): cmd = "rpm" cmd += " " + args.format(context=context) run_in_context(context, cmd, can_fail=True)
def when_I_execute_rpm_with_args(context, args): cmd = "rpm --root=" + context.dnf.installroot cmd += " " + args.format(context=context) run_in_context(context, cmd, can_fail=True)
def when_I_execute_microdnf_with_args(context, args): cmd = " ".join(context.dnf.get_microdnf_cmd(context)) cmd += " " + args.format(context=context) context.dnf["rpmdb_pre"] = get_rpmdb_rpms(context.dnf.installroot) run_in_context(context, cmd, can_fail=True)
def when_I_execute_sqliterepo_c_in_directory(context, arguments, directory): target_path = prepend_installroot(context, directory) run_in_context(context, "sqliterepo_c " + arguments.format(context=context), cwd=target_path, can_fail=True)
def when_I_execute_command(context, command): run_in_context(context, command.format(context=context))
def when_I_execute_command_in_directory(context, command, directory): run_in_context(context, command.format(context=context), cwd=directory.format(context=context))
def parsed_history_info(context, spec): cmd = " ".join(context.dnf.get_cmd(context) + ["history", "info", spec]) run_in_context(context, cmd) return parse_history_info(context.cmd_stdout.splitlines())