-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set installation_package in SoftwareSearch queries
- Loading branch information
Showing
4 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
library/packages/src/lib/y2packager/installation_package_map.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program 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 this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast" | ||
Yast.import "Pkg" | ||
|
||
module Y2Packager | ||
# Installation packages map | ||
# | ||
# This map contains the correspondence between products and the | ||
# installation package for each product. | ||
# | ||
# The information is always read again. Reason is that that url can be invalid, | ||
# but user fix it later. This way it cache invalid result. See bsc#1086840 | ||
# ProductReader instance cache it properly, but caching for installation life-time | ||
# should be prevented. | ||
# | ||
# @return [Hash<String,String>] product name -> installation package name | ||
class InstallationPackageMap | ||
include Yast::Logger | ||
|
||
def initialize | ||
@packages_map = nil | ||
end | ||
|
||
def for(pkg_name) | ||
packages_map[pkg_name] | ||
end | ||
|
||
private | ||
|
||
def packages_map | ||
return @packages_map if @packages_map | ||
|
||
install_pkgs = Yast::Pkg.PkgQueryProvides("system-installation()") | ||
log.info "Installation packages: #{install_pkgs.inspect}" | ||
|
||
@packages_map = {} | ||
|
||
install_pkgs.each do |list| | ||
pkg_name = list.first | ||
# There can be more instances of same package in different version. | ||
# Prefer the selected or the available package, they should provide newer data | ||
# than the installed one. | ||
packages = Yast::Pkg.Resolvables({ name: pkg_name, kind: :package }, [:dependencies, :status]) | ||
package = packages.find { |p| p["status"] == :selected } || | ||
packages.find { |p| p["status"] == :available } || | ||
packages.first | ||
|
||
dependencies = package["deps"] | ||
install_provides = dependencies.find_all do |d| | ||
d["provides"]&.match(/system-installation\(\)/) | ||
end | ||
|
||
# parse product name from provides. Format of provide is | ||
# `system-installation() = <product_name>` | ||
install_provides.each do |install_provide| | ||
product_name = install_provide["provides"][/system-installation\(\)\s*=\s*(\S+)/, 1] | ||
log.info "package #{pkg_name} install product #{product_name}" | ||
@packages_map[product_name] = pkg_name | ||
end | ||
end | ||
|
||
@packages_map | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
library/packages/test/y2packager/installation_package_map_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program 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 this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../test_helper" | ||
require "y2packager/installation_package_map" | ||
|
||
describe Y2Packager::InstallationPackageMap do | ||
describe "#packages_map" do | ||
before do | ||
allow(Yast::Pkg).to receive(:PkgQueryProvides).with("system-installation()").and_return( | ||
# the first is the old product which will be removed from the system | ||
[["openSUSE-release", :CAND, :NONE], ["openSUSE-release", :CAND, :CAND]] | ||
) | ||
allow(Yast::Pkg).to receive(:Resolvables).with({ name: "openSUSE-release", kind: :package }, | ||
[:dependencies, :status]).and_return( | ||
[ | ||
{ | ||
# emulate an older system with no "system-installation()" provides | ||
"deps" => [], | ||
# put the removed product first so we can check it is skipped | ||
"status" => :removed | ||
}, | ||
{ | ||
# in reality there are many more dependencies, but they are irrelevant for this test | ||
"deps" => [{ "provides" => "system-installation() = openSUSE" }], | ||
"status" => :selected | ||
} | ||
] | ||
) | ||
end | ||
|
||
it "prefers the data from the new available product instead of the old installed one" do | ||
expect(subject.for("openSUSE")).to eq("openSUSE-release") | ||
# expect(described_class.installation_package_mapping).to eq("openSUSE" => "openSUSE-release") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters