diff --git a/dnf5daemon-client/context.cpp b/dnf5daemon-client/context.cpp index b5428994d..32a9b8e3b 100644 --- a/dnf5daemon-client/context.cpp +++ b/dnf5daemon-client/context.cpp @@ -44,7 +44,6 @@ void Context::init_session(sdbus::IConnection & connection) { auto config = key_value_map_get>(cfg, "config", empty_options); std::filesystem::path ir{installroot.get_value()}; config["installroot"] = ir.string(); - config["cachedir"] = (ir / "var/cache/dnf").string(); for (auto & opt : setopts) { config[opt.first] = opt.second; } diff --git a/dnf5daemon-client/wrappers/dbus_goal_wrapper.cpp b/dnf5daemon-client/wrappers/dbus_goal_wrapper.cpp index de6dbf46f..95b229181 100644 --- a/dnf5daemon-client/wrappers/dbus_goal_wrapper.cpp +++ b/dnf5daemon-client/wrappers/dbus_goal_wrapper.cpp @@ -19,11 +19,50 @@ along with libdnf. If not, see . #include "dbus_goal_wrapper.hpp" +#include + +#include + namespace dnfdaemon::client { DbusGoalWrapper::DbusGoalWrapper(std::vector transaction) { - for (auto & ti : transaction) { - transaction_packages.push_back(DbusTransactionPackageWrapper(ti)); + // auxiliary map transaction_package.id -> index of package in transaction_package + // used to resolve replaces from id to DbusPackageWrapper instance + std::map transaction_packages_by_id; + + for (const auto & ti : transaction) { + auto object_type = libdnf::transaction::transaction_item_type_from_string(std::get<0>(ti)); + if (object_type == libdnf::transaction::TransactionItemType::PACKAGE) { + transaction_packages.push_back(DbusTransactionPackageWrapper(ti)); + transaction_packages_by_id.emplace( + transaction_packages.back().get_package().get_id(), transaction_packages.size() - 1); + } else if (object_type == libdnf::transaction::TransactionItemType::GROUP) { + transaction_groups.push_back(DbusTransactionGroupWrapper(ti)); + } + } + // set "replaces" for transaction_packages. Since transaction_package contains only + // id of replaced packages we must convert them to packages using transaction_packages_by_id map + for (auto & tpkg : transaction_packages) { + // ids of replaced packages are stored in "replaces" transaction item attribute + auto ti_attrs = tpkg.get_transaction_item_attrs(); + auto ti_replaces = ti_attrs.find("replaces"); + if (ti_replaces != ti_attrs.end()) { + std::vector replaces; + std::vector replaces_id = ti_replaces->second; + for (const auto & pkg_id : replaces_id) { + auto replaced_pkg_idx = transaction_packages_by_id.find(pkg_id); + if (replaced_pkg_idx != transaction_packages_by_id.end()) { + replaces.emplace_back(transaction_packages[replaced_pkg_idx->second].get_package()); + } else { + // TODO(mblaha): proper logging + // log_router.warning() + std::cerr << "Package with id \"" << pkg_id << "\" replaced by package \"" + << tpkg.get_package().get_name() << "-" << tpkg.get_package().get_evr() + << "\" not found in the transaction." << std::endl; + } + } + tpkg.set_replaces(std::move(replaces)); + } } } diff --git a/dnf5daemon-client/wrappers/dbus_package_wrapper.hpp b/dnf5daemon-client/wrappers/dbus_package_wrapper.hpp index d53b6e6a9..b22e2e614 100644 --- a/dnf5daemon-client/wrappers/dbus_package_wrapper.hpp +++ b/dnf5daemon-client/wrappers/dbus_package_wrapper.hpp @@ -38,8 +38,8 @@ class DbusPackageWrapper { std::string get_version() const { return rawdata.at("version"); } std::string get_release() const { return rawdata.at("release"); } std::string get_arch() const { return rawdata.at("arch"); } - std::string get_repo_id() const { return rawdata.at("repo"); } - std::string get_from_repo_id() const { return "TODO:from_repo"; } + std::string get_repo_id() const { return rawdata.at("repo_id"); } + std::string get_from_repo_id() const { return rawdata.at("from_repo_id"); } std::string get_nevra() const { return rawdata.at("nevra"); } std::string get_full_nevra() const { return rawdata.at("full_nevra"); } std::string get_evr() const { return rawdata.at("evr"); } diff --git a/dnf5daemon-client/wrappers/dbus_transaction_group_wrapper.hpp b/dnf5daemon-client/wrappers/dbus_transaction_group_wrapper.hpp index 85fe3ab9b..e9f17a312 100644 --- a/dnf5daemon-client/wrappers/dbus_transaction_group_wrapper.hpp +++ b/dnf5daemon-client/wrappers/dbus_transaction_group_wrapper.hpp @@ -34,19 +34,18 @@ namespace dnfdaemon::client { class DbusTransactionGroupWrapper { public: explicit DbusTransactionGroupWrapper(const dnfdaemon::DbusTransactionItem & dti) - : group(std::get<1>(dti)), - action(static_cast(std::get<0>(dti))), - // TODO(lukash) reason needs to be added to dbus - reason(libdnf::transaction::TransactionItemReason::NONE) {} + : action(libdnf::transaction::transaction_item_action_from_string(std::get<1>(dti))), + reason(libdnf::transaction::transaction_item_reason_from_string(std::get<2>(dti))), + group(std::get<4>(dti)) {} DbusGroupWrapper get_group() const { return group; } libdnf::transaction::TransactionItemAction get_action() const { return action; } libdnf::transaction::TransactionItemReason get_reason() const { return reason; } private: - DbusGroupWrapper group; libdnf::transaction::TransactionItemAction action; libdnf::transaction::TransactionItemReason reason; + DbusGroupWrapper group; }; } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp b/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp index a2e0dfa78..1e923526a 100644 --- a/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp +++ b/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp @@ -34,22 +34,26 @@ namespace dnfdaemon::client { class DbusTransactionPackageWrapper { public: explicit DbusTransactionPackageWrapper(const dnfdaemon::DbusTransactionItem & dti) - : package(std::get<1>(dti)), - action(static_cast(std::get<0>(dti))), - // TODO(lukash) reason needs to be added to dbus - reason(libdnf::transaction::TransactionItemReason::NONE) {} - - DbusPackageWrapper get_package() const { return package; } - libdnf::transaction::TransactionItemAction get_action() const { return action; } - libdnf::transaction::TransactionItemReason get_reason() const { return reason; } + : action(libdnf::transaction::transaction_item_action_from_string(std::get<1>(dti))), + reason(libdnf::transaction::transaction_item_reason_from_string(std::get<2>(dti))), + transaction_item_attrs(std::get<3>(dti)), + package(std::get<4>(dti)) {} + + DbusPackageWrapper & get_package() noexcept { return package; } + libdnf::transaction::TransactionItemAction get_action() const noexcept { return action; } + libdnf::transaction::TransactionItemReason get_reason() const noexcept { return reason; } + dnfdaemon::KeyValueMap & get_transaction_item_attrs() noexcept { return transaction_item_attrs; } // TODO(jmracek) get_replaces() is only a dummy method. In future it requires a private setter and a way how to get // data from dnf-deamon server - const std::vector get_replaces() const noexcept { return {}; } + const std::vector & get_replaces() const noexcept { return replaces; } + void set_replaces(std::vector && replaces) { this->replaces = replaces; } private: - DbusPackageWrapper package; libdnf::transaction::TransactionItemAction action; libdnf::transaction::TransactionItemReason reason; + dnfdaemon::KeyValueMap transaction_item_attrs; + DbusPackageWrapper package; + std::vector replaces; }; } // namespace dnfdaemon::client diff --git a/dnf5daemon-server/dbus.hpp b/dnf5daemon-server/dbus.hpp index d1d9ab609..b54cc7840 100644 --- a/dnf5daemon-server/dbus.hpp +++ b/dnf5daemon-server/dbus.hpp @@ -34,8 +34,12 @@ enum class RepoStatus { NOT_READY, PENDING, READY, ERROR }; enum class ResolveResult { NO_PROBLEM, WARNING, ERROR }; using DbusTransactionItem = sdbus::Struct< - unsigned int, //action - KeyValueMap>; + std::string, // libdnf::transaction::TransactionItemType + std::string, // libdnf::transaction::TransactionItemAction + std::string, // libdnf::transaction::TransactionItemReason + KeyValueMap, // other transaction item attributes - e.g. group id for REASON_CHANGE to GROUP, + // packages that are replaced by this transaction item + KeyValueMap>; // transaction object (package / group / module) using Changelog = sdbus::Struct; diff --git a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml index bdf1c91cb..8b7d8691d 100644 --- a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml +++ b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml @@ -28,7 +28,7 @@ along with libdnf. If not, see . - + diff --git a/dnf5daemon-server/group.cpp b/dnf5daemon-server/group.cpp new file mode 100644 index 000000000..53c9c367c --- /dev/null +++ b/dnf5daemon-server/group.cpp @@ -0,0 +1,56 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with libdnf. If not, see . +*/ + +#include "group.hpp" + +#include + +#include + + +// map string group attribute name to actual attribute +const std::map group_attributes{ + {"groupid", GroupAttribute::groupid}, {"name", GroupAttribute::name}, {"description", GroupAttribute::description}}; + + +dnfdaemon::KeyValueMap group_to_map( + const libdnf::comps::Group & libdnf_group, const std::vector & attributes) { + dnfdaemon::KeyValueMap dbus_group; + // add group id by default + dbus_group.emplace(std::make_pair("groupid", libdnf_group.get_groupid())); + // attributes required by client + for (auto & attr : attributes) { + auto it = group_attributes.find(attr); + if (it == group_attributes.end()) { + throw std::runtime_error(fmt::format("Group attribute '{}' not supported", attr)); + } + switch (it->second) { + case GroupAttribute::groupid: + // already added by default + break; + case GroupAttribute::name: + dbus_group.emplace(attr, libdnf_group.get_name()); + break; + case GroupAttribute::description: + dbus_group.emplace(attr, libdnf_group.get_description()); + break; + } + } + return dbus_group; +} diff --git a/dnf5daemon-server/group.hpp b/dnf5daemon-server/group.hpp new file mode 100644 index 000000000..76800fca3 --- /dev/null +++ b/dnf5daemon-server/group.hpp @@ -0,0 +1,41 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with libdnf. If not, see . +*/ + +#ifndef DNF5DAEMON_SERVER_GROUP_HPP +#define DNF5DAEMON_SERVER_GROUP_HPP + +#include "dbus.hpp" + +#include + +#include +#include + +// group attributes available to be retrieved +enum class GroupAttribute { + groupid, + name, + description + // TODO(mblaha): translated_name, translated_description, packages, reason +}; + +dnfdaemon::KeyValueMap group_to_map( + const libdnf::comps::Group & libdnf_group, const std::vector & attributes); + +#endif diff --git a/dnf5daemon-server/package.cpp b/dnf5daemon-server/package.cpp index 5a1d4c352..9bb3cb4b1 100644 --- a/dnf5daemon-server/package.cpp +++ b/dnf5daemon-server/package.cpp @@ -31,7 +31,8 @@ const std::map package_attributes{ {"version", PackageAttribute::version}, {"release", PackageAttribute::release}, {"arch", PackageAttribute::arch}, - {"repo", PackageAttribute::repo}, + {"repo_id", PackageAttribute::repo_id}, + {"from_repo_id", PackageAttribute::from_repo_id}, {"is_installed", PackageAttribute::is_installed}, {"install_size", PackageAttribute::install_size}, {"package_size", PackageAttribute::package_size}, @@ -101,9 +102,12 @@ dnfdaemon::KeyValueMap package_to_map( case PackageAttribute::arch: dbus_package.emplace(attr, libdnf_package.get_arch()); break; - case PackageAttribute::repo: + case PackageAttribute::repo_id: dbus_package.emplace(attr, libdnf_package.get_repo_id()); break; + case PackageAttribute::from_repo_id: + dbus_package.emplace(attr, libdnf_package.get_from_repo_id()); + break; case PackageAttribute::is_installed: dbus_package.emplace(attr, libdnf_package.is_installed()); break; diff --git a/dnf5daemon-server/package.hpp b/dnf5daemon-server/package.hpp index 802af92b9..1aca0553f 100644 --- a/dnf5daemon-server/package.hpp +++ b/dnf5daemon-server/package.hpp @@ -35,7 +35,8 @@ enum class PackageAttribute { version, release, arch, - repo, + repo_id, + from_repo_id, is_installed, install_size, package_size, diff --git a/dnf5daemon-server/services/goal/goal.cpp b/dnf5daemon-server/services/goal/goal.cpp index e3d860397..9b882ba8e 100644 --- a/dnf5daemon-server/services/goal/goal.cpp +++ b/dnf5daemon-server/services/goal/goal.cpp @@ -21,6 +21,7 @@ along with libdnf. If not, see . #include "callbacks.hpp" #include "dbus.hpp" +#include "group.hpp" #include "package.hpp" #include "transaction.hpp" #include "utils.hpp" @@ -29,6 +30,7 @@ along with libdnf. If not, see . #include #include #include +#include #include #include @@ -42,7 +44,7 @@ void Goal::dbus_register() { // TODO(mblaha) Adjust resolve method to accomodate also groups, environments, // and modules as part of the transaction dbus_object->registerMethod( - dnfdaemon::INTERFACE_GOAL, "resolve", "a{sv}", "a(ua{sv})u", [this](sdbus::MethodCall call) -> void { + dnfdaemon::INTERFACE_GOAL, "resolve", "a{sv}", "a(sssa{sv}a{sv})u", [this](sdbus::MethodCall call) -> void { session.get_threads_manager().handle_method(*this, &Goal::resolve, call, session.session_locale); }); dbus_object->registerMethod( @@ -78,11 +80,47 @@ sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) { auto overall_result = dnfdaemon::ResolveResult::ERROR; if (transaction.get_problems() == libdnf::GoalProblem::NO_PROBLEM) { // return the transaction only if there were no problems - std::vector attr{ - "name", "epoch", "version", "release", "arch", "repo", "package_size", "install_size", "evr", "reason"}; + std::vector pkg_attrs{ + "name", + "epoch", + "version", + "release", + "arch", + "repo_id", + "from_repo_id", + "package_size", + "install_size", + "evr", + "reason"}; for (auto & tspkg : transaction.get_transaction_packages()) { + dnfdaemon::KeyValueMap trans_item_attrs{}; + if (tspkg.get_reason_change_group_id()) { + trans_item_attrs.emplace("reason_change_group_id", *tspkg.get_reason_change_group_id()); + } + auto replaces = tspkg.get_replaces(); + if (replaces.size() > 0) { + std::vector replaces_ids{}; + for (auto & r : replaces) { + replaces_ids.emplace_back(r.get_id().id); + } + trans_item_attrs.emplace("replaces", replaces_ids); + } + dbus_transaction.push_back(dnfdaemon::DbusTransactionItem( + transaction_item_type_to_string(libdnf::transaction::TransactionItemType::PACKAGE), + transaction_item_action_to_string(tspkg.get_action()), + transaction_item_reason_to_string(tspkg.get_reason()), + trans_item_attrs, + package_to_map(tspkg.get_package(), pkg_attrs))); + } + std::vector grp_attrs{"name"}; + dnfdaemon::KeyValueMap trans_item_attrs{}; + for (auto & tsgrp : transaction.get_transaction_groups()) { dbus_transaction.push_back(dnfdaemon::DbusTransactionItem( - static_cast(tspkg.get_action()), package_to_map(tspkg.get_package(), attr))); + transaction_item_type_to_string(libdnf::transaction::TransactionItemType::GROUP), + transaction_item_action_to_string(tsgrp.get_action()), + transaction_item_reason_to_string(tsgrp.get_reason()), + trans_item_attrs, + group_to_map(tsgrp.get_group(), grp_attrs))); } // there are transactions resolved without problems but still resolve_logs // may contain some warnings / informations diff --git a/include/libdnf/base/log_event.hpp b/include/libdnf/base/log_event.hpp index be7448da0..88f66ad1b 100644 --- a/include/libdnf/base/log_event.hpp +++ b/include/libdnf/base/log_event.hpp @@ -24,6 +24,7 @@ along with libdnf. If not, see . #include "libdnf/base/goal_elements.hpp" #include "libdnf/base/solver_problems.hpp" +#include "libdnf/transaction/transaction_item_type.hpp" #include #include @@ -34,16 +35,13 @@ namespace libdnf::base { /// Contain information, hint, or a problem created during libdnf::Goal::resolve() class LogEvent { public: - /// What object type is the spec supposed to describe - enum class SpecType { PACKAGE, GROUP, ENVIRONMENT, MODULE }; - /// Public constructor LogEvent( libdnf::GoalAction action, libdnf::GoalProblem problem, const std::set & additional_data, const libdnf::GoalJobSettings & settings, - const SpecType spec_type, + const libdnf::transaction::TransactionItemType spec_type, const std::string & spec); LogEvent(libdnf::GoalProblem problem, const SolverProblems & solver_problems); ~LogEvent() = default; @@ -73,7 +71,7 @@ class LogEvent { libdnf::GoalProblem problem, const std::set & additional_data, const std::optional & settings, - const std::optional & spec_type, + const std::optional & spec_type, const std::optional & spec, const std::optional & solver_problems); @@ -82,7 +80,7 @@ class LogEvent { std::set additional_data; std::optional job_settings; - std::optional spec_type; + std::optional spec_type; std::optional spec; std::optional solver_problems; }; diff --git a/include/libdnf/transaction/transaction_item_type.hpp b/include/libdnf/transaction/transaction_item_type.hpp new file mode 100644 index 000000000..0566c304c --- /dev/null +++ b/include/libdnf/transaction/transaction_item_type.hpp @@ -0,0 +1,48 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with libdnf. If not, see . +*/ + +#ifndef LIBDNF_TRANSACTION_ITEM_TYPE_HPP +#define LIBDNF_TRANSACTION_ITEM_TYPE_HPP + +#include "libdnf/common/exception.hpp" + +#include + + +namespace libdnf::transaction { + +enum class TransactionItemType : int { PACKAGE, GROUP, ENVIRONMENT, MODULE }; + + +class InvalidTransactionItemType : public libdnf::Error { +public: + InvalidTransactionItemType(const std::string & type); + + const char * get_domain_name() const noexcept override { return "libdnf::transaction"; } + const char * get_name() const noexcept override { return "InvalidTransactionItemType"; } +}; + + +std::string transaction_item_type_to_string(TransactionItemType action); +TransactionItemType transaction_item_type_from_string(const std::string & action); + + +} // namespace libdnf::transaction + +#endif // LIBDNF_TRANSACTION_ITEM_TYPE_HPP diff --git a/libdnf/base/goal.cpp b/libdnf/base/goal.cpp index 12413e55d..fa33d5a5d 100644 --- a/libdnf/base/goal.cpp +++ b/libdnf/base/goal.cpp @@ -503,7 +503,7 @@ GoalProblem Goal::Impl::add_group_specs_to_goal(base::Transaction & transaction) action, GoalProblem::UNSUPPORTED_ACTION, settings, - base::LogEvent::SpecType::GROUP, + libdnf::transaction::TransactionItemType::GROUP, spec, {}, log_level); @@ -529,7 +529,13 @@ GoalProblem Goal::Impl::add_group_specs_to_goal(base::Transaction & transaction) } if (group_query.empty()) { transaction.p_impl->add_resolve_log( - action, GoalProblem::NOT_FOUND, settings, base::LogEvent::SpecType::GROUP, spec, {}, log_level); + action, + GoalProblem::NOT_FOUND, + settings, + libdnf::transaction::TransactionItemType::GROUP, + spec, + {}, + log_level); if (!skip_unavailable) { ret |= GoalProblem::NOT_FOUND; } @@ -604,7 +610,7 @@ std::pair Goal::Impl::add_install_to_goal( action, GoalProblem::ALREADY_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {pool.get_nevra(package_id)}, libdnf::Logger::Level::WARNING); @@ -620,7 +626,7 @@ std::pair Goal::Impl::add_install_to_goal( action, GoalProblem::NOT_FOUND_IN_REPOSITORIES, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -709,7 +715,7 @@ std::pair Goal::Impl::add_install_to_goal( action, GoalProblem::NOT_FOUND_IN_REPOSITORIES, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -784,7 +790,7 @@ std::pair Goal::Impl::add_install_to_goal( action, GoalProblem::NOT_FOUND_IN_REPOSITORIES, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -840,7 +846,7 @@ GoalProblem Goal::Impl::add_reinstall_to_goal( GoalAction::REINSTALL, GoalProblem::NOT_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -854,7 +860,7 @@ GoalProblem Goal::Impl::add_reinstall_to_goal( GoalAction::REINSTALL, GoalProblem::NOT_AVAILABLE, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -872,7 +878,7 @@ GoalProblem Goal::Impl::add_reinstall_to_goal( GoalAction::REINSTALL, GoalProblem::INSTALLED_IN_DIFFERENT_VERSION, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -885,7 +891,7 @@ GoalProblem Goal::Impl::add_reinstall_to_goal( GoalAction::REINSTALL, GoalProblem::NOT_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -895,7 +901,7 @@ GoalProblem Goal::Impl::add_reinstall_to_goal( GoalAction::REINSTALL, GoalProblem::NOT_INSTALLED_FOR_ARCHITECTURE, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -913,7 +919,7 @@ GoalProblem Goal::Impl::add_reinstall_to_goal( GoalAction::REINSTALL, GoalProblem::NOT_FOUND_IN_REPOSITORIES, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, log_level); @@ -985,7 +991,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::ALREADY_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {}, {pool.get_nevra(package_id)}, log_level); @@ -1017,7 +1023,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::NOT_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {pool.get_nevra(id)}, {}, log_level); @@ -1049,7 +1055,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::NOT_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {pool.get_nevra(id)}, {}, libdnf::Logger::Level::WARNING); @@ -1065,7 +1071,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::NOT_INSTALLED_FOR_ARCHITECTURE, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {pool.get_nevra(id)}, {}, libdnf::Logger::Level::WARNING); @@ -1079,7 +1085,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::ALREADY_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {pool.get_nevra(id)}, {pool.get_name(id) + ("." + arch)}, libdnf::Logger::Level::WARNING); @@ -1107,7 +1113,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::NOT_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {pool.get_nevra(id)}, {}, log_level); @@ -1120,7 +1126,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::NOT_INSTALLED_FOR_ARCHITECTURE, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {pool.get_nevra(id)}, {}, log_level); @@ -1136,7 +1142,7 @@ void Goal::Impl::add_rpms_to_goal(base::Transaction & transaction) { action, GoalProblem::INSTALLED_LOWEST_VERSION, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, {pool.get_nevra(id)}, {name_arch}, log_level); @@ -1231,7 +1237,7 @@ void Goal::Impl::add_up_down_distrosync_to_goal( action, GoalProblem::NOT_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, libdnf::Logger::Level::WARNING); @@ -1240,7 +1246,7 @@ void Goal::Impl::add_up_down_distrosync_to_goal( action, GoalProblem::NOT_INSTALLED_FOR_ARCHITECTURE, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, libdnf::Logger::Level::WARNING); @@ -1278,7 +1284,7 @@ void Goal::Impl::add_up_down_distrosync_to_goal( action, GoalProblem::NOT_FOUND_IN_REPOSITORIES, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {}, libdnf::Logger::Level::WARNING); @@ -1364,7 +1370,7 @@ void Goal::Impl::add_up_down_distrosync_to_goal( action, GoalProblem::INSTALLED_LOWEST_VERSION, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, spec, {name_arch}, libdnf::Logger::Level::WARNING); @@ -1513,7 +1519,7 @@ GoalProblem Goal::Impl::add_reason_change_to_goal( GoalAction::REASON_CHANGE, GoalProblem::ALREADY_INSTALLED, settings, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, pkg.get_nevra(), {libdnf::transaction::transaction_item_reason_to_string(reason)}, libdnf::Logger::Level::WARNING); @@ -1633,7 +1639,7 @@ base::Transaction Goal::resolve() { GoalAction::RESOLVE, GoalProblem::WRITE_DEBUG, {}, - base::LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, "", {abs_debug_dir}, libdnf::Logger::Level::WARNING); diff --git a/libdnf/base/log_event.cpp b/libdnf/base/log_event.cpp index 30c6bdb9e..8ca8dfcc9 100644 --- a/libdnf/base/log_event.cpp +++ b/libdnf/base/log_event.cpp @@ -33,7 +33,7 @@ LogEvent::LogEvent( libdnf::GoalProblem problem, const std::set & additional_data, const libdnf::GoalJobSettings & settings, - const SpecType spec_type, + const libdnf::transaction::TransactionItemType spec_type, const std::string & spec) : action(action), problem(problem), @@ -66,7 +66,7 @@ std::string LogEvent::to_string( libdnf::GoalProblem problem, const std::set & additional_data, const std::optional & settings, - const std::optional & spec_type, + const std::optional & spec_type, const std::optional & spec, const std::optional & solver_problems) { std::string ret; @@ -76,16 +76,16 @@ std::string LogEvent::to_string( if (action == GoalAction::REMOVE) { std::string spec_type_str; switch (*spec_type) { - case LogEvent::SpecType::PACKAGE: + case libdnf::transaction::TransactionItemType::PACKAGE: spec_type_str = _("packages"); break; - case LogEvent::SpecType::GROUP: + case libdnf::transaction::TransactionItemType::GROUP: spec_type_str = _("groups"); break; - case LogEvent::SpecType::ENVIRONMENT: + case libdnf::transaction::TransactionItemType::ENVIRONMENT: spec_type_str = _("environmental groups"); break; - case LogEvent::SpecType::MODULE: + case libdnf::transaction::TransactionItemType::MODULE: spec_type_str = _("modules"); break; } diff --git a/libdnf/base/transaction.cpp b/libdnf/base/transaction.cpp index f83635555..89bb531ca 100644 --- a/libdnf/base/transaction.cpp +++ b/libdnf/base/transaction.cpp @@ -119,7 +119,14 @@ GoalProblem Transaction::Impl::report_not_found( auto nevra_pair_reports = query.resolve_pkg_spec(pkg_spec, settings, true); if (!nevra_pair_reports.first) { // RPM was not excluded or there is no related srpm - add_resolve_log(action, GoalProblem::NOT_FOUND, settings, LogEvent::SpecType::PACKAGE, pkg_spec, {}, log_level); + add_resolve_log( + action, + GoalProblem::NOT_FOUND, + settings, + libdnf::transaction::TransactionItemType::PACKAGE, + pkg_spec, + {}, + log_level); if (settings.report_hint) { rpm::PackageQuery hints(base); if (action == GoalAction::REMOVE) { @@ -137,7 +144,7 @@ GoalProblem Transaction::Impl::report_not_found( action, GoalProblem::HINT_ICASE, settings, - LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, pkg_spec, {(*icase.begin()).get_name()}, libdnf::Logger::Level::WARNING); @@ -155,7 +162,7 @@ GoalProblem Transaction::Impl::report_not_found( action, GoalProblem::HINT_ALTERNATIVES, settings, - LogEvent::SpecType::PACKAGE, + libdnf::transaction::TransactionItemType::PACKAGE, pkg_spec, hints, libdnf::Logger::Level::WARNING); @@ -165,11 +172,25 @@ GoalProblem Transaction::Impl::report_not_found( } query.filter_repo_id({"src", "nosrc"}, sack::QueryCmp::NEQ); if (query.empty()) { - add_resolve_log(action, GoalProblem::ONLY_SRC, settings, LogEvent::SpecType::PACKAGE, pkg_spec, {}, log_level); + add_resolve_log( + action, + GoalProblem::ONLY_SRC, + settings, + libdnf::transaction::TransactionItemType::PACKAGE, + pkg_spec, + {}, + log_level); return GoalProblem::ONLY_SRC; } // TODO(jmracek) make difference between regular excludes and modular excludes - add_resolve_log(action, GoalProblem::EXCLUDED, settings, LogEvent::SpecType::PACKAGE, pkg_spec, {}, log_level); + add_resolve_log( + action, + GoalProblem::EXCLUDED, + settings, + libdnf::transaction::TransactionItemType::PACKAGE, + pkg_spec, + {}, + log_level); return GoalProblem::EXCLUDED; } @@ -177,7 +198,7 @@ void Transaction::Impl::add_resolve_log( GoalAction action, GoalProblem problem, const GoalJobSettings & settings, - const LogEvent::SpecType spec_type, + const libdnf::transaction::TransactionItemType spec_type, const std::string & spec, const std::set & additional_data, libdnf::Logger::Level log_level) { diff --git a/libdnf/base/transaction_impl.hpp b/libdnf/base/transaction_impl.hpp index 78f319ff6..676f96012 100644 --- a/libdnf/base/transaction_impl.hpp +++ b/libdnf/base/transaction_impl.hpp @@ -67,7 +67,7 @@ class Transaction::Impl { GoalAction action, GoalProblem problem, const GoalJobSettings & settings, - const LogEvent::SpecType spec_type, + const libdnf::transaction::TransactionItemType spec_type, const std::string & spec, const std::set & additional_data, libdnf::Logger::Level log_level); diff --git a/libdnf/transaction/transaction_item_type.cpp b/libdnf/transaction/transaction_item_type.cpp new file mode 100644 index 000000000..fd9069a8c --- /dev/null +++ b/libdnf/transaction/transaction_item_type.cpp @@ -0,0 +1,61 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with libdnf. If not, see . +*/ + +#include "libdnf/transaction/transaction_item_type.hpp" + +#include "utils/bgettext/bgettext-mark-domain.h" + + +namespace libdnf::transaction { + +InvalidTransactionItemType::InvalidTransactionItemType(const std::string & type) + : libdnf::Error(M_("Invalid transaction item type: {}"), type) {} + + +std::string transaction_item_type_to_string(TransactionItemType type) { + switch (type) { + case TransactionItemType::PACKAGE: + return "Package"; + case TransactionItemType::GROUP: + return "Group"; + case TransactionItemType::ENVIRONMENT: + return "Environment"; + case TransactionItemType::MODULE: + return "Module"; + } + return ""; +} + + +TransactionItemType transaction_item_type_from_string(const std::string & type) { + if (type == "Package") { + return TransactionItemType::PACKAGE; + } else if (type == "Group") { + return TransactionItemType::GROUP; + } else if (type == "Environment") { + return TransactionItemType::ENVIRONMENT; + } else if (type == "Module") { + return TransactionItemType::MODULE; + } + + throw InvalidTransactionItemType(type); +} + + +} // namespace libdnf::transaction diff --git a/test/dnf5daemon-server/support.py b/test/dnf5daemon-server/support.py index 6a6b2b1d6..f741a83dc 100644 --- a/test/dnf5daemon-server/support.py +++ b/test/dnf5daemon-server/support.py @@ -36,6 +36,19 @@ class InstallrootCase(unittest.TestCase): + def sanitize_transaction(self, resolved): + '''Prepare resolved transaction for assert''' + for object_type, action, reason, trans_item_attrs, pkg in resolved: + # id of package depends on order of the repos in the sack which varies + # between runs so we can't rely on the value + pkg.pop('id') + # also package size differs according to the builder + pkg.pop('package_size') + # TODO(mblaha): calculate correct replaces value + if "replaces" in trans_item_attrs: + trans_item_attrs.pop("replaces") + + def setUp(self): super(InstallrootCase, self).setUp() self.maxDiff = None diff --git a/test/dnf5daemon-server/test_distro_sync.py b/test/dnf5daemon-server/test_distro_sync.py index d276552d7..1d319f1b0 100644 --- a/test/dnf5daemon-server/test_distro_sync.py +++ b/test/dnf5daemon-server/test_distro_sync.py @@ -35,19 +35,18 @@ def test_distro_sync_package(self): self.iface_rpm.distro_sync(['one'], dbus.Dictionary({}, signature='sv')) resolved, errors = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv')) - - # id of package depends on order of the repos in the sack which varies - # between runs so we can't rely on the value - for action, pkg in resolved: - pkg.pop('id') - pkg.pop('package_size') + self.sanitize_transaction(resolved) self.assertCountEqual( resolved, dbus.Array([ dbus.Struct(( - dbus.UInt32(6), # action upgrade - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Upgrade'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('2-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -55,12 +54,18 @@ def test_distro_sync_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None), dbus.Struct(( - dbus.UInt32(12), # action replaced - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Replaced'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('1-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -68,7 +73,9 @@ def test_distro_sync_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('@System', variant_level=1), + dbus.String('repo_id'): dbus.String('@System', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None) ], signature=dbus.Signature('(ua{sv})')) diff --git a/test/dnf5daemon-server/test_downgrade.py b/test/dnf5daemon-server/test_downgrade.py index 3663332b7..b9a14028c 100644 --- a/test/dnf5daemon-server/test_downgrade.py +++ b/test/dnf5daemon-server/test_downgrade.py @@ -35,20 +35,19 @@ def test_downgrade_package(self): self.iface_rpm.downgrade(['one'], dbus.Dictionary({}, signature='sv')) resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv')) - - # id of package depends on order of the repos in the sack which varies - # between runs so we can't rely on the value - for action, pkg in resolved: - pkg.pop('id') - pkg.pop('package_size') + self.sanitize_transaction(resolved) self.assertEqual(result, 0) self.assertCountEqual( resolved, dbus.Array([ dbus.Struct(( - dbus.UInt32(2), # action downgrade - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Downgrade'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('1-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -56,12 +55,18 @@ def test_downgrade_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None), dbus.Struct(( - dbus.UInt32(12), # action replaced - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Replaced'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('2-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -69,7 +74,9 @@ def test_downgrade_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('@System', variant_level=1), + dbus.String('repo_id'): dbus.String('@System', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None) ], signature=dbus.Signature('(ua{sv})')) diff --git a/test/dnf5daemon-server/test_install.py b/test/dnf5daemon-server/test_install.py index 90e233a06..e041b8d88 100644 --- a/test/dnf5daemon-server/test_install.py +++ b/test/dnf5daemon-server/test_install.py @@ -26,28 +26,29 @@ def test_install_package(self): self.iface_rpm.install(['one'], dbus.Dictionary({}, signature='sv')) resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv')) - - # id of package depends on order of the repos in the sack which varies - # between runs so we can't rely on the value - for action, pkg in resolved: - pkg.pop('id') - pkg.pop('package_size') + self.sanitize_transaction(resolved) self.assertEqual(result, 0) self.assertCountEqual( resolved, dbus.Array([ dbus.Struct(( - dbus.UInt32(1), # action - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Install'), # action + dbus.String('User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), dbus.String('evr'): dbus.String('2-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), dbus.String('release'): dbus.String('1', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1), - dbus.String('version'): dbus.String('2', variant_level=1) + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('version'): dbus.String('2', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('None', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None) ], signature=dbus.Signature('(ua{sv})')) diff --git a/test/dnf5daemon-server/test_reinstall.py b/test/dnf5daemon-server/test_reinstall.py index 5e9ea6316..54af691ac 100644 --- a/test/dnf5daemon-server/test_reinstall.py +++ b/test/dnf5daemon-server/test_reinstall.py @@ -35,20 +35,19 @@ def test_reinstall_package(self): self.iface_rpm.reinstall(['one'], dbus.Dictionary({}, signature='sv')) resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv')) - - # id of package depends on order of the repos in the sack which varies - # between runs so we can't rely on the value - for action, pkg in resolved: - pkg.pop('id') - pkg.pop('package_size') + self.sanitize_transaction(resolved) self.assertEqual(result, 0) self.assertCountEqual( resolved, dbus.Array([ dbus.Struct(( - dbus.UInt32(9), # action reinstall - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Reinstall'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('1-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -56,12 +55,18 @@ def test_reinstall_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None), dbus.Struct(( - dbus.UInt32(12), # action replaced - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Replaced'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('1-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -69,7 +74,9 @@ def test_reinstall_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('@System', variant_level=1), + dbus.String('repo_id'): dbus.String('@System', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None) ], signature=dbus.Signature('(ua{sv})')), diff --git a/test/dnf5daemon-server/test_remove.py b/test/dnf5daemon-server/test_remove.py index e94248a02..47e6c3fca 100644 --- a/test/dnf5daemon-server/test_remove.py +++ b/test/dnf5daemon-server/test_remove.py @@ -35,28 +35,29 @@ def test_remove_package(self): self.iface_rpm.remove(['one'], dbus.Dictionary({}, signature='sv')) resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv')) - - # id of package depends on order of the repos in the sack which varies - # between runs so we can't rely on the value - for action, pkg in resolved: - pkg.pop('id') - pkg.pop('package_size') + self.sanitize_transaction(resolved) self.assertEqual(result, 0) self.assertCountEqual( resolved, dbus.Array([ dbus.Struct(( - dbus.UInt32(8), # action - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Remove'), # action + dbus.String('User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), dbus.String('evr'): dbus.String('1-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), dbus.String('release'): dbus.String('1', variant_level=1), - dbus.String('repo'): dbus.String('@System', variant_level=1), - dbus.String('version'): dbus.String('1', variant_level=1) + dbus.String('repo_id'): dbus.String('@System', variant_level=1), + dbus.String('version'): dbus.String('1', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None) ], signature=dbus.Signature('(ua{sv})')) diff --git a/test/dnf5daemon-server/test_repoquery.py b/test/dnf5daemon-server/test_repoquery.py index 9ee25b9f9..e46f3ee38 100644 --- a/test/dnf5daemon-server/test_repoquery.py +++ b/test/dnf5daemon-server/test_repoquery.py @@ -24,7 +24,7 @@ class RepoTest(support.InstallrootCase): def test_repoquery_all(self): # get list of all available packages - pkglist = self.iface_rpm.list({"package_attrs": ["full_nevra", "repo"]}) + pkglist = self.iface_rpm.list({"package_attrs": ["full_nevra", "repo_id"]}) # id of package depends on order of the repos in the sack which varies # between runs so we can't rely on the value for pkg in pkglist: @@ -35,27 +35,27 @@ def test_repoquery_all(self): dbus.Array([ dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:1-1.noarch', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:1-1.src', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:2-1.noarch', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:2-1.src', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('two-0:2-2.noarch', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo2', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo2', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('two-0:2-2.src', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo2', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo2', variant_level=1)}, signature=dbus.Signature('sv')), ], signature=dbus.Signature('a{sv}')) @@ -64,7 +64,7 @@ def test_repoquery_all(self): def test_repoquery_match(self): # get list of all available packages pkglist = self.iface_rpm.list({ - "package_attrs": ["full_nevra", "repo"], + "package_attrs": ["full_nevra", "repo_id"], "patterns":["one"]}) # id of package depends on order of the repos in the sack which varies # between runs so we can't rely on the value @@ -76,19 +76,19 @@ def test_repoquery_match(self): dbus.Array([ dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:1-1.noarch', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:1-1.src', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:2-1.noarch', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), dbus.Dictionary({ dbus.String('full_nevra'): dbus.String('one-0:2-1.src', variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1)}, + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1)}, signature=dbus.Signature('sv')), ], signature=dbus.Signature('a{sv}')) diff --git a/test/dnf5daemon-server/test_upgrade.py b/test/dnf5daemon-server/test_upgrade.py index 785bba6b6..dc60bb227 100644 --- a/test/dnf5daemon-server/test_upgrade.py +++ b/test/dnf5daemon-server/test_upgrade.py @@ -35,20 +35,19 @@ def test_upgrade_package(self): self.iface_rpm.upgrade(['one'], dbus.Dictionary({}, signature='sv')) resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv')) - - # id of package depends on order of the repos in the sack which varies - # between runs so we can't rely on the value - for action, pkg in resolved: - pkg.pop('id') - pkg.pop('package_size') + self.sanitize_transaction(resolved) self.assertEqual(result, 0) self.assertCountEqual( resolved, dbus.Array([ dbus.Struct(( - dbus.UInt32(6), # action upgrade - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Upgrade'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('2-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -56,12 +55,18 @@ def test_upgrade_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None), dbus.Struct(( - dbus.UInt32(12), # action replaced - dbus.Dictionary({ # package + dbus.String('Package'), # object type + dbus.String('Replaced'), # action + dbus.String('External User'), # reason + dbus.Dictionary({ # transaction item attrs + }, signature=dbus.Signature('sv')), + dbus.Dictionary({ # package dbus.String('evr'): dbus.String('1-1', variant_level=1), dbus.String('name'): dbus.String('one', variant_level=1), dbus.String('epoch'): dbus.String('0', variant_level=1), @@ -69,7 +74,9 @@ def test_upgrade_package(self): dbus.String('release'): dbus.String('1', variant_level=1), dbus.String('arch'): dbus.String('noarch', variant_level=1), dbus.String('install_size'): dbus.UInt64(0, variant_level=1), - dbus.String('repo'): dbus.String('@System', variant_level=1), + dbus.String('repo_id'): dbus.String('@System', variant_level=1), + dbus.String('from_repo_id'): dbus.String('', variant_level=1), + dbus.String('reason'): dbus.String('External User', variant_level=1), }, signature=dbus.Signature('sv'))), signature=None) ], signature=dbus.Signature('(ua{sv})'))