Skip to content

Commit

Permalink
Merge pull request #389 from mchf/fate325541-disable-dvd-repo
Browse files Browse the repository at this point in the history
Disable cd / dvd repositories when installation is over
  • Loading branch information
mchf committed Nov 20, 2018
2 parents c838393 + f946af4 commit 2ed3eab
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 14 deletions.
7 changes: 7 additions & 0 deletions package/yast2-packager.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Nov 19 07:27:24 UTC 2018 - mfilka@suse.com

- fate#325541
- disabling CD / DVD repositories according to control file setup
- 4.1.15

-------------------------------------------------------------------
Fri Nov 16 13:29:45 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.1.14
Version: 4.1.15
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
31 changes: 26 additions & 5 deletions src/lib/packager/clients/pkg_finish.rb
Expand Up @@ -102,6 +102,19 @@ def write

private

# Checks if given source repo should be disabled
#
# Currently CD / DVD repositories are disabled after installation, when
# enabled in control file
#
# @param source [Symbol] if :cd or :dvd then control file is checked if the
# repo should be disabled
# @return [Boolean] true if the repo should be disabled
def disable_media_repo?(source)
return false if ![:cd, :dvd].include?(source)
ProductFeatures.GetBooleanFeature("software", "disable_media_repo")
end

# Backup old sources
#
# During upgrade, old sources are reinitialized
Expand Down Expand Up @@ -164,14 +177,22 @@ def disable_local_repos
end

uncovered = repo.products.reject { |p| products_whitelist.include?(p) }
if uncovered.empty?
disable = if disable_media_repo?(repo.scheme)
log.info("Repo #{repo.repo_id} (#{repo.name}) is at CD / DVD; disabling")
true
elsif uncovered.empty?
log.info("Repo #{repo.repo_id} (#{repo.name}) will be disabled because products " \
"are present in other repositories")
repo.disable!
disabled << repo
"are present in other repositories")
true
else
log.info("Repo #{repo.repo_id} (#{repo.name}) cannot be disabled because these " \
"products are not available through other repos: #{uncovered.map(&:name)}")
"products are not available through other repos: #{uncovered.map(&:name)}")
false
end

if disable
repo.disable!
disabled << repo
end
end
end
Expand Down
51 changes: 43 additions & 8 deletions test/pkg_finish_test.rb
Expand Up @@ -22,6 +22,9 @@
before do
allow(Yast::WFM).to receive(:Args).and_return(args)
allow(::Y2Packager::Repository).to receive(:enabled).and_return(repositories)
allow(Yast::ProductFeatures)
.to receive(:GetBooleanFeature)
.and_call_original
allow(Yast::ProductFeatures).to receive(:GetBooleanFeature)
.with("software", "minimalistic_libzypp_config")
.and_return(minimalistic_libzypp_config)
Expand Down Expand Up @@ -77,19 +80,24 @@
end

context "given some local repository" do
let(:repositories) { [local_repo, remote_repo] }
let(:repositories) { [local_repo, local_dvd_repo, remote_repo] }
let(:base_products) { [sles_product, sled_product] }

let(:local_repo) do
Y2Packager::Repository.new(repo_id: 1, name: "SLE-12-SP2-0", enabled: true,
url: URI("cd://dev/sr0"), autorefresh: false)
url: URI("hd:/?devices=/dev/sda"), autorefresh: false)
end

let(:remote_repo) do
Y2Packager::Repository.new(repo_id: 2, name: "SLE-12-SP2-Pool", enabled: true,
url: URI("http://download.suse.com/sle-12-sp2"), autorefresh: true)
end

let(:local_dvd_repo) do
Y2Packager::Repository.new(repo_id: 3, name: "SLE-15-SP1-0", enabled: true,
url: URI("dvd:///?devices=/dev/sr0"), autorefresh: false)
end

let(:sles_product) do
instance_double(Y2Packager::Product, name: "SLES", installed?: true)
end
Expand All @@ -104,6 +112,7 @@

before do
allow(local_repo).to receive(:products).and_return([sles_product, sled_product])
allow(local_dvd_repo).to receive(:products).and_return([sles_product, sled_product])
end

context "if installed base products are available through other repos" do
Expand All @@ -117,14 +126,40 @@
end
end

context "if installed base products are not available through other repos" do
before do
allow(remote_repo).to receive(:products).and_return([])
context "when control file option disable_media_repo is enabled" do
before(:each) do
allow(Yast::ProductFeatures)
.to receive(:GetBooleanFeature)
.with("software", "disable_media_repo")
.and_return(true)
end

it "does not disable the local repository" do
expect(local_repo).to_not receive(:disable!)
client.run
context "dvd repo is disabled even if base products aren't available using other repos" do
before do
allow(remote_repo).to receive(:products).and_return([])
end

it "disables the local repository if set in the control file" do
expect(local_dvd_repo).to receive(:disable!)

client.run
end
end

context "if installed base products are not available through other repos" do
before do
allow(remote_repo).to receive(:products).and_return([])
end

it "disables local dvd repo" do
expect(local_dvd_repo).to receive(:disable!)
client.run
end

it "does not disable the local repository if not CD / DVD" do
expect(local_repo).to_not receive(:disable!)
client.run
end
end
end

Expand Down

0 comments on commit 2ed3eab

Please sign in to comment.