Skip to content

Commit

Permalink
Merge 3bd87e7 into 532f643
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jun 7, 2021
2 parents 532f643 + 3bd87e7 commit 4309ff5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Expand Up @@ -64,3 +64,8 @@ Style/VariableName:
- src/lib/**/*.rb
Exclude:
- src/lib/installation/clients/*.rb

Style/PredicateName:
Exclude:
# mocked Registration.is_registered?
- test/lib/upgrade_repo_manager_test.rb
9 changes: 9 additions & 0 deletions package/yast2-installation.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Mon Jun 7 13:19:09 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

- Better evaluate the old and new repositories during upgrade,
do not preselect new repositories for removal if they
accidentally use the same repository as already present in
the system (bsc#1185822)
- 4.3.39

-------------------------------------------------------------------
Thu Apr 29 09:21:31 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.3.38
Version: 4.3.39
Release: 0
Group: System/YaST
License: GPL-2.0-only
Expand Down
52 changes: 51 additions & 1 deletion src/lib/installation/upgrade_repo_manager.rb
Expand Up @@ -25,6 +25,7 @@ module Installation
# and using them in the new upgraded system.
class UpgradeRepoManager
include Yast::Logger
extend Yast::Logger

# @return [Array<Y2Packager::Repository>] The old repositories
attr_reader :repositories
Expand Down Expand Up @@ -52,7 +53,12 @@ def self.create_from_old_repositories
current_repos = Y2Packager::Repository.all
stored_repos = Y2Packager::OriginalRepositorySetup.instance.repositories
stored_repo_aliases = stored_repos.map(&:repo_alias)
old_repos = current_repos.select { |r| stored_repo_aliases.include?(r.repo_alias) }
reg_urls = registration_urls

old_repos = current_repos.select do |r|
stored_repo_aliases.include?(r.repo_alias) &&
!reg_urls.include?(base_url(r.raw_url.uri))
end

current_services = Y2Packager::Service.all
stored_services = Y2Packager::OriginalRepositorySetup.instance.services
Expand Down Expand Up @@ -158,5 +164,49 @@ def update_urls
repo.url = url
end
end

# Collect the repository URLs for all registered products and addons,
# If the system is not registered or the yast2-registration package is not
# installed then it return an empty list.
#
# @return [Array<URI>] list of simplified URLs
# @see .base_url
def self.registration_urls
require "registration/registration"
require "registration/registration_ui"
require "registration/url_helpers"

return [] unless Registration::Registration.is_registered?

registration = Registration::Registration.new(Registration::UrlHelpers.registration_url)
registration_ui = Registration::RegistrationUI.new(registration)
activations = registration_ui.activated_products

activations.map(&:repositories).flatten.map { |repo| base_url(repo["url"]) }
rescue LoadError
# the registration package is not available in the openSUSE installer
# or during RPM build
log.info("Registration package not available")
[]
end

# Remove some URL parts to allow less strict comparison:
# - remove the query parameter, the locally saved SCC repositories have
# an unique hash attached as a query parameter, the activated products
# result does not contain that
# - ignore the trailing slash, it is not important for comparing repositories
#
# @param repo_url [String, URI] the input URL
# @return [URI] simplified URL
def self.base_url(repo_url)
uri = repo_url.is_a?(URI) ? repo_url.dup : URI(repo_url)
uri.query = nil
# do NOT use the bang method here (delete_suffix!), it would modify
# the original URL although the .dup is used above!
uri.path = uri.path.delete_suffix("/")
uri
end

private_class_method :registration_urls, :base_url
end
end
15 changes: 15 additions & 0 deletions test/lib/upgrade_repo_manager_test.rb
Expand Up @@ -3,6 +3,20 @@
require_relative "../test_helper"
require "installation/upgrade_repo_manager"

begin
# check if the registration package is present, it might not be available during RPM build
require "registration/registration"
rescue LoadError
# mock the Registration class if missing
module Registration
class Registration
def self.is_registered?
false
end
end
end
end

describe Installation::UpgradeRepoManager do
let(:repo1) do
Y2Packager::Repository.new(repo_id: 1, repo_alias: "test1",
Expand Down Expand Up @@ -122,6 +136,7 @@
allow(Y2Packager::Repository).to receive(:all).and_return([repo1, repo2])
expect(Y2Packager::OriginalRepositorySetup.instance).to receive(:repositories)
.and_return([repo1, repo2])
allow(Registration::Registration).to receive(:is_registered?).and_return(false)
end

it "initializes the UpgradeRepoManager from the stored old repositories" do
Expand Down

0 comments on commit 4309ff5

Please sign in to comment.