Skip to content

Commit

Permalink
drop Pkg.ResolvableProperties (#54)
Browse files Browse the repository at this point in the history
* drop Pkg.ResolvableProperties
  • Loading branch information
schubi2 committed Nov 22, 2019
1 parent fcc38fa commit f908bf2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 19 deletions.
8 changes: 8 additions & 0 deletions package/yast2-migration.changes
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Tue Nov 19 12:00:26 CET 2019 - schubi@suse.de

- Using Y2Packager::Resolvable.any? and Y2Packager::Resolvable.find
in order to decrease the required memory (bsc#1132650,
bsc#1140037).
- 4.2.4

-------------------------------------------------------------------
Mon Oct 28 09:54:49 UTC 2019 - José Iván López González <jlopez@suse.com>

Expand Down
5 changes: 3 additions & 2 deletions package/yast2-migration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-migration
Version: 4.2.3
Version: 4.2.4
Release: 0
Summary: YaST2 - Online migration
Group: System/YaST
Expand All @@ -38,7 +38,8 @@ BuildRequires: yast2-update
BuildRequires: update-desktop-files

Requires: yast2 >= 3.1.130
Requires: yast2-packager
# product_update_summary, product_update_warning
Requires: yast2-packager >= 4.2.33
Requires: yast2-pkg-bindings
Requires: yast2-ruby-bindings
# new rollback client
Expand Down
9 changes: 5 additions & 4 deletions src/lib/migration/proposal_client.rb
Expand Up @@ -15,6 +15,7 @@

require "installation/proposal_client"
require "migration/repository_checker"
require "y2packager/resolvable"

module Migration
# The proposal client for online migration
Expand Down Expand Up @@ -45,7 +46,7 @@ def make_proposal(_attrs)
# recalculate the disk space usage data
SpaceCalculation.GetPartitionInfo

products = Pkg.ResolvableProperties("", :product, "")
products = Y2Packager::Resolvable.find(kind: :product)

ret = {
"preformatted_proposal" => product_summary(products),
Expand Down Expand Up @@ -92,7 +93,7 @@ def description
# check the current products for possible issues, add product warnings
# to the proposal summary
# @param [Hash] proposal the proposal summary (the value is modified)
# @param [Array<Hash>] products list of the current products (from libzypp)
# @param [Array<Y2Packager::Resolvable>] products list of the current products
def add_warnings(proposal, products)
package_warnings = Packages.product_update_warning(products)
repo_warnings = check_repositories(products)
Expand All @@ -112,7 +113,7 @@ def add_warnings(proposal, products)
end

# create a product summary for migration proposal
# @param [Array<Hash>] products the current libzypp products
# @param [Array<Y2Packager::Resolvable>] products the current libzypp products
# @return [String] product summary text (RichText)
def product_summary(products)
summary_text = Packages.product_update_summary(products).map do |item|
Expand All @@ -123,7 +124,7 @@ def product_summary(products)
end

# check for obsolete repositories
# @param [Array<Hash>] products the current libzypp products
# @param [Array<Y2Packager::Resolvable>] products the current libzypp products
# @return [Hash] warning for the proposal summary, an empty Hash is returned
# if everything is OK
def check_repositories(products)
Expand Down
18 changes: 10 additions & 8 deletions src/lib/migration/repository_checker.rb
Expand Up @@ -19,14 +19,15 @@
# ------------------------------------------------------------------------------

require "yast"
require "y2packager/resolvable"

module Migration
# Check for possible repository issues in the libzypp products
class RepositoryChecker
include Yast::Logger

# constructor
# @param [Array<Hash>] products list of products from pkg-bindings
# @param [Array<Y2Packager::Resolvable>] products list of products
def initialize(products)
@products = products
end
Expand All @@ -35,7 +36,7 @@ def initialize(products)
# (an upgrade is available for them)
# return [Array<Fixnum>] repositories providing obsolete products
def obsolete_product_repos
old_repos = obsolete_available_products.map { |product| product["source"] }
old_repos = obsolete_available_products.map(&:source)

# make sure the system repo or invalid values are filtered out
# (related to gh#yast/yast-registration#198)
Expand All @@ -53,7 +54,7 @@ def obsolete_product_repos
attr_accessor :products

# get the available obsolete products
# @return [Array<Hash>] obsolete products
# @return [Array<Y2Packager::Resolvable>] obsolete products
def obsolete_available_products
obsolete_products = []

Expand All @@ -73,9 +74,9 @@ def obsolete_available_products

# select the products with the specified status
# @param [Symbol] status required status of the products
# @return [Array<Hash>] list of libzypp products
# @return [Array<Y2Packager::Resolvable>] list of libzypp products
def select_products(status)
products.select { |product| product["status"] == status }
products.select { |product| product.status == status }
end

# Does a product upgrade another product?
Expand All @@ -86,9 +87,10 @@ def product_upgrade?(new_product, old_product)
# use Gem::Version internally for a proper version string comparison
# TODO: check also "provides" to handle product renames (should not happen
# in SP migration, but anyway...)
old_product["name"] == new_product["name"] &&
(Gem::Version.new(old_product["version_version"]) <
Gem::Version.new(new_product["version_version"]))
# TODO: use Pkg.CompareVersions()
old_product.name == new_product.name &&
(Gem::Version.new(old_product.version_version) <
Gem::Version.new(new_product.version_version))
end
end
end
3 changes: 3 additions & 0 deletions test/data/sles12_migration_products.yml
@@ -1,5 +1,6 @@
---
- arch: x86_64
kind: :product
category: base
description: |-
SUSE Linux Enterprise offers a comprehensive
Expand Down Expand Up @@ -42,6 +43,7 @@
version_version: '12'
- arch: x86_64
category: addon
kind: :product
description: |-
SUSE Linux Enterprise offers a comprehensive
suite of products built on a single code base.
Expand Down Expand Up @@ -83,6 +85,7 @@
version_version: '12.1'
- arch: x86_64
category: addon
kind: :product
description: |-
SUSE Linux Enterprise offers a comprehensive
suite of products built on a single code base.
Expand Down
18 changes: 14 additions & 4 deletions test/migration_proposal_client_test.rb
Expand Up @@ -47,6 +47,11 @@

describe "#make_proposal" do
let(:msg) { "Product <b>Foo</b> will be installed" }
let(:products) do
load_yaml_data("sles12_migration_products.yml").map do |p|
Y2Packager::Resolvable.new(p)
end
end

before do
expect(Yast::Pkg).to receive(:PkgSolve)
Expand All @@ -55,23 +60,28 @@
expect(Yast::SpaceCalculation).to receive(:GetPartitionInfo)
expect(Yast::Packages).to receive(:product_update_summary)
.and_return([msg])
expect(Yast::Pkg).to receive(:ResolvableProperties).with("", :product, "")
.and_return(load_yaml_data("sles12_migration_products.yml"))
expect(Y2Packager::Resolvable).to receive(:find).with(kind: :product)
.and_return(products)
expect(Yast::Pkg).to receive(:SourceGeneralData).with(0)
.and_return("name" => "Repo")
end

it "returns a map with proposal details" do
expect(Yast::Packages).to receive(:product_update_warning).and_return({})
proposal = subject.make_proposal({})

expect(proposal).to include("help", "preformatted_proposal")
expect(proposal["preformatted_proposal"]).to include(msg)
end

it "returns a warning when an obsoleted repository is present" do
warning_string = "warning string"
expect(Yast::Packages).to receive(:product_update_warning).and_return(
"warning_level" => :warning,
"warning" => warning_string
)
proposal = subject.make_proposal({})
expect(proposal["warning"]).to include("Repository <b>Repo</b> is obsolete " \
"and should be excluded from migration")
expect(proposal["warning"]).to include(warning_string)
expect(proposal["warning_level"]).to eq(:warning)
end
end
Expand Down
5 changes: 4 additions & 1 deletion test/repository_checker_test.rb
Expand Up @@ -24,7 +24,10 @@

describe Migration::RepositoryChecker do
subject do
Migration::RepositoryChecker.new(load_yaml_data("sles12_migration_products.yml"))
products = load_yaml_data("sles12_migration_products.yml").map do |p|
Y2Packager::Resolvable.new(p)
end
Migration::RepositoryChecker.new(products)
end

describe "#obsolete_product_repos" do
Expand Down

0 comments on commit f908bf2

Please sign in to comment.