Skip to content

Commit

Permalink
Merge pull request #526 from yast/medium_detection
Browse files Browse the repository at this point in the history
Improved medium type detection
  • Loading branch information
lslezak committed Jul 10, 2020
2 parents 2b36fa2 + a9295aa commit 45eae79
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
@@ -1,5 +1,5 @@
container:
image: registry.opensuse.org/yast/head/containers/yast-ruby:latest
image: registry.opensuse.org/yast/sle-15/sp2/containers/yast-ruby

Rubocop_task:
container:
Expand Down
8 changes: 8 additions & 0 deletions package/yast2-packager.changes
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Fri Jul 10 07:14:05 UTC 2020 - Ladislav Slezák <lslezak@suse.cz>

- Improve medium type detection, do not report Online medium
when the /media.1/products file is missing in the repository,
SMT does not mirror this file (bsc#1173336)
- 4.2.63

-------------------------------------------------------------------
Mon Apr 20 11:46:59 UTC 2020 - Josef Reidinger <jreidinger@suse.com>

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


Name: yast2-packager
Version: 4.2.62
Version: 4.2.63
Release: 0
Summary: YaST2 - Package Library
License: GPL-2.0-or-later
Expand Down
7 changes: 0 additions & 7 deletions src/lib/y2packager/medium_type.rb
Expand Up @@ -105,13 +105,6 @@ def detect_medium_type
downloader = Y2Packager::RepomdDownloader.new(url)
product_repos = downloader.product_repos

# the online medium should not contain any repository
# TODO: how to detect an invalid installation URL or a broken medium??
if product_repos.empty?
log.info("Detected medium type: online (no repository on the medium)")
return :online
end

# the offline medium contains several modules and extensions
if product_repos.size > 1
log.info("Detected medium type: offline (found #{product_repos.size} product repos)")
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2packager/product_location.rb
Expand Up @@ -60,7 +60,7 @@ def self.scan(url, base_product = nil, force_scan = false)

pool = Y2Packager::SolvablePool.new

repomd_files = downloader.primary_xmls
repomd_files = downloader.primary_xmls(force_scan)
return [] if repomd_files.empty?

repomd_files.each do |repomd|
Expand Down
18 changes: 15 additions & 3 deletions src/lib/y2packager/repomd_downloader.rb
Expand Up @@ -48,6 +48,9 @@ def product_repos
#
# Returns the downloaded primary.xml.gz file(s) from the repository.
#
# @param force [Boolean] Force scanning the repositories even when
# the /media.1/products file is missing, default `false`
#
# @note For remote repositories (http://, ftp://, ...) the files are downloaded
# to a temporary directory (/var/tmp/...), but for the local repositories
# or mountable repositories (dir://, dvd://) it directly points to the original files!
Expand All @@ -61,12 +64,21 @@ def product_repos
# @return [Array<String>] List of paths pointing to the downloaded primary.xml.gz files,
# returns an empty list if the URL or the repository is not valid.
#
def primary_xmls
return [] if product_repos.empty?
def primary_xmls(force = false)
# first check if there are any products defined in /media.1/products
repos = product_repos

if repos.empty?
return [] unless force

# if `force` is true then scan the repository at the root anyway,
# the repository name is ignored later so it can be any string
repos = { "Root Repository" => "/" }
end

# add a temporary repository for downloading the files via libzypp
src = Yast::Pkg.RepositoryAdd("base_urls" => [url])
product_repos.map do |(_name, dir)|
repos.map do |(_name, dir)|
# download the repository index file (repomd.xml)
repomd_file = Yast::Pkg.SourceProvideFile(src, 1, File.join(dir, "repodata/repomd.xml"))

Expand Down
19 changes: 12 additions & 7 deletions test/medium_type_test.rb
Expand Up @@ -24,13 +24,6 @@
expect { described_class.type }.to raise_exception(/The installation URL is not set/)
end

it "returns :online if no repository is found on the medium" do
expect_any_instance_of(Y2Packager::RepomdDownloader)
.to receive(:product_repos).and_return([])

expect(described_class.type).to eq(:online)
end

it "returns :offline if at least two repositories are found on the medium" do
expect_any_instance_of(Y2Packager::RepomdDownloader)
.to receive(:product_repos).and_return(
Expand All @@ -43,6 +36,18 @@
expect(described_class.type).to eq(:offline)
end

context "missing media.1/products on the installation medium" do
before do
expect_any_instance_of(Y2Packager::RepomdDownloader)
.to receive(:product_repos).and_return([])
end

it "returns :online if the repository does not contain any base product" do
expect(Y2Packager::ProductLocation).to receive(:scan).and_return([])
expect(described_class.type).to eq(:online)
end
end

context "only one repository on the installation medium" do
before do
expect_any_instance_of(Y2Packager::RepomdDownloader)
Expand Down

0 comments on commit 45eae79

Please sign in to comment.