-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2019 SUSE LLC, All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# ------------------------------------------------------------------------------ | ||
|
||
require "yast" | ||
|
||
require "y2packager/product_location" | ||
require "y2packager/repomd_downloader" | ||
|
||
Yast.import "InstURL" | ||
|
||
module Y2Packager | ||
# This class scans the installation medium type. | ||
class MediumType | ||
extend Yast::Logger | ||
|
||
# Type of the installation medium | ||
# | ||
# @return [Symbol] Symbol describing the medium, one of `:offline`, | ||
# `:online` or `:standard` | ||
def self.type | ||
@type ||= detect_medium_type | ||
end | ||
|
||
# Is the medium an online installation medium? (SLE Online) | ||
# The online installation medium contains no repository | ||
# or a repository without any base product. | ||
def self.online? | ||
type == :online | ||
end | ||
|
||
# Is the medium an offline installation medium? (SLE Offline) | ||
# The offline installation medium contains several installation repositories. | ||
# (At least one base product and one module/extension, usually there are | ||
# several base products and many modules/extensions.) | ||
def self.offline? | ||
type == :offline | ||
end | ||
|
||
# Is the medium an standard installation medium? (openSUSE Leap) | ||
# The standard installation medium contains a single repository | ||
# with at least one base product. (Usually there is only one base product.) | ||
def self.standard? | ||
type == :standard | ||
end | ||
|
||
############################################################################################## | ||
|
||
# | ||
# Detect the medium type. | ||
# | ||
# @return [Symbol] Symbol describing the medium, one of `:offline`, | ||
# `:online` or `:standard` | ||
def self.detect_medium_type | ||
url = Yast::InstURL.installInf2Url("") | ||
|
||
raise "The installation URL is not set" if url.nil? || url.empty? | ||
|
||
# scan the number of the products in the media.1/products file | ||
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 repositories)") | ||
return :offline | ||
end | ||
|
||
# scan the available base products on the medium | ||
base_products = Y2Packager::ProductLocation.scan(url).select { |p| p.details&.base } | ||
|
||
if base_products.empty? | ||
log.info("Detected medium type: online (no base product found on the medium)") | ||
:online | ||
else | ||
log.info("Detected medium type: standard (found #{base_products.size} base products)") | ||
:standard | ||
end | ||
end | ||
|
||
private_class_method :detect_medium_type | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require_relative "test_helper" | ||
require "y2packager/medium_type" | ||
|
||
describe Y2Packager::MediumType do | ||
Yast.import "Pkg" | ||
|
||
let(:repo_url) { "http://example.com/repo" } | ||
|
||
before do | ||
allow(Yast::InstURL).to receive (:installInf2Url).and_return(repo_url) | ||
end | ||
|
||
describe "#type" do | ||
it "raises an exception when the installation URL is nil" do | ||
|
||
end | ||
|
||
it "raises an exception when the installation URL is empty" do | ||
|
||
end | ||
end | ||
end |