Skip to content

Commit

Permalink
Decrease the priority of the initial DVD installation repository (bsc…
Browse files Browse the repository at this point in the history
…#1071742)

To prefer the packages from the other DVD media. Avoid media
changes between the "Packages" and the "Installer" DVDs.

- 4.0.28
  • Loading branch information
lslezak committed Jan 11, 2018
1 parent 968b17e commit 57e9f8a
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 1 deletion.
9 changes: 9 additions & 0 deletions package/yast2-packager.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Thu Jan 11 11:54:47 UTC 2018 - lslezak@suse.cz

- Decrease the priority of the initial DVD installation repository
to prefer the packages from the other DVD media (avoid media
changes between the "Packages" and the "Installer" DVDs)
(bsc#1071742)
- 4.0.28

-------------------------------------------------------------------
Tue Jan 9 14:48:08 UTC 2018 - lslezak@suse.cz

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


Name: yast2-packager
Version: 4.0.27
Version: 4.0.28
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
70 changes: 70 additions & 0 deletions src/modules/Packages.rb
Expand Up @@ -4,6 +4,7 @@
# html_escape()
require "erb"
require "fileutils"
require "uri"

# Yast namespace
module Yast
Expand Down Expand Up @@ -2146,6 +2147,10 @@ def Proposal(force_reset, reinit, _simple)
Label(_("Evaluating package selection..."))
)

# Optionally adjust the priority of the initial installation repository
# to prefer the packages from the other DVD media (bsc#1071742)
adjust_repo_priority

Builtins.y2milestone(
"Packages::Proposal: force_reset %1, reinit %2, lang '%3'",
force_reset,
Expand Down Expand Up @@ -2775,6 +2780,71 @@ def pkg_will_be_installed(tag)
log.info("#{tag} will #{ret ? "" : "not "}be installed")
ret
end

# the default libzypp repository priority
DEFAULT_PRIORITY = 99

# Adjust the priority of the initial installation repository. (bsc#1071742)
#
# The initial repository priority is decreased (a higher number used!) to
# prefer the packages from the other media to avoid unecessary media changes
# for the same packages present on multiple media only if:
# - The initial repository is volatile (CD or DVD)
# - If all repositories are local (CD, DVD, HDD, USB...)
# - If there is at least one more volatile (CD or DVD) repository
#
# Otherwise it does not make sense (installing from DVD without any
# addon, installing from DVD + network addon, installing from USB + a DVD
# addon).
#
# If there is a remote addon then the priority cannot be changed
# because that would break the DVD/network preference set by the
# "download_media_prefer_download" libzypp option.
def adjust_repo_priority
# all enabled repositories
enabled_repos = Pkg.SourceGetCurrent(true)
# just a sanity check, should not happen (TM)
return if enabled_repos.empty?

# all enabled repositories are local (CD, DVD, HDD, USB...)
all_local = true
# number of volatile media (CD or DVD)
volatile_media = 0

enabled_repos.each do |repo|
url = Pkg.SourceGeneralData(repo)["url"]
next if url.nil? || url.empty?
scheme = URI(url).scheme
all_local &= Pkg.UrlSchemeIsLocal(scheme)
volatile_media += 1 if Pkg.UrlSchemeIsVolatile(scheme)
end

repo_id = enabled_repos.first
repo_priority = Pkg.SourceGeneralData(repo_id)["priority"]
repo_url = Pkg.SourceGeneralData(repo_id)["url"]
repo_volatile = repo_url.empty? ? false : Pkg.UrlSchemeIsVolatile(URI(repo_url).scheme)

log.info("All installation repositories are local: #{all_local}")
log.info("Installing from volatile medium: #{repo_volatile}")
log.info("Number of volatile media: #{volatile_media}")

# puts("All installation repositories are local: #{all_local}")
# puts("Installing from volatile medium: #{repo_volatile}")
# puts("Number of volatile media: #{volatile_media}")

# change the priority only if:
# - installing from CD or DVD
# - all repositories are local, no remote repository is used
# - at least one CD or DVD addon is used
if repo_volatile && all_local && volatile_media > 1
# decrease the priority (the higher number the lower priority!)
Pkg.SourceSetPriority(repo_id, repo_priority + 1) if repo_priority == DEFAULT_PRIORITY
# set the default if not set (e.g. reset after going back and adding
# a remote repository or removing all other repositories)
elsif repo_priority != DEFAULT_PRIORITY
Pkg.SourceSetPriority(repo_id, DEFAULT_PRIORITY)
end
end
end

Packages = PackagesClass.new
Expand Down
93 changes: 93 additions & 0 deletions test/packages_test.rb
Expand Up @@ -1403,4 +1403,97 @@ def product(properties = {})
expect { URI.parse(@base_url.value) }.to_not raise_error
end
end

describe "#adjust_repo_priority" do
before do
expect(Yast::Pkg).to receive(:SourceGetCurrent).with(true).and_return(repos.keys)
repos.each do |id, data|
expect(Yast::Pkg).to receive(:SourceGeneralData).with(id).and_return(data).at_least(:once)
end
end

# define the common repository cases
let(:volatile_repo) { { "url" => "dvd:///", "priority" => 99 } }
let(:local_repo) { { "url" => "hd:///", "priority" => 99 } }
let(:remote_repo) { { "url" => "http:///example.com/repo", "priority" => 99 } }

# share the testing scenarios
shared_examples "keeps priority" do
it "does not change the priority" do
expect(Yast::Pkg).to_not receive(:SourceSetPriority)
subject.send(:adjust_repo_priority)
end
end

shared_examples "sets priority" do |repo, prio|
it "changes the priority" do
expect(Yast::Pkg).to receive(:SourceSetPriority).with(repo, prio)
subject.send(:adjust_repo_priority)
end
end

# no priority change scenarios

context "installing from a DVD without any addon" do
let(:repos) { { 0 => volatile_repo } }
it_behaves_like "keeps priority"
end

context "installing from a DVD with a remote addon" do
let(:repos) { { 0 => volatile_repo, 1 => remote_repo } }
it_behaves_like "keeps priority"
end

context "installing from a DVD with a USB addon" do
let(:repos) { { 0 => volatile_repo, 1 => local_repo } }
it_behaves_like "keeps priority"
end

context "installing from a DVD with an USB and a remote addon" do
let(:repos) { { 0 => volatile_repo, 1 => local_repo, 2 => remote_repo } }
it_behaves_like "keeps priority"
end

context "installing from a DVD with a DVD and a remote addon" do
let(:repos) { { 0 => volatile_repo, 1 => volatile_repo, 2 => remote_repo } }
it_behaves_like "keeps priority"
end

context "installing from a remote repo without any addon" do
let(:repos) { { 0 => remote_repo } }
it_behaves_like "keeps priority"
end

context "installing from a remote repo with a remote addon" do
let(:repos) { { 0 => remote_repo, 1 => remote_repo } }
it_behaves_like "keeps priority"
end

context "installing from a remote repo with a DVD addon" do
let(:repos) { { 0 => remote_repo, 1 => volatile_repo } }
it_behaves_like "keeps priority"
end

context "installing from a remote repo with 2 DVD addons" do
let(:repos) { { 0 => remote_repo, 1 => volatile_repo, 2 => volatile_repo } }
it_behaves_like "keeps priority"
end

# priority changed scenarios

context "installing from a DVD with a DVD addon" do
let(:repos) { { 0 => volatile_repo, 1 => volatile_repo } }
it_behaves_like "sets priority", 0, 100
end

context "installing from a DVD with 2 DVD addons" do
let(:repos) { { 0 => volatile_repo, 1 => volatile_repo, 2 => volatile_repo } }
it_behaves_like "sets priority", 0, 100
end

context "installing from a DVD with an USB and a DVD addon" do
let(:repos) { { 0 => volatile_repo, 1 => local_repo, 2 => volatile_repo } }
it_behaves_like "sets priority", 0, 100
end
end
end

0 comments on commit 57e9f8a

Please sign in to comment.