Skip to content

Commit

Permalink
merged with master
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Jan 11, 2018
2 parents 0e933d1 + 9cb627d commit bcab600
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 269 deletions.
9 changes: 8 additions & 1 deletion package/autoyast2.changes
@@ -1,8 +1,15 @@
-------------------------------------------------------------------
Wed Jan 10 17:20:25 CET 2018 - schubi@suse.de
Wed Jan 10 17:20:25 UTC 2018 - schubi@suse.de

- Merging products before package evaluation starts.
(bnc#1075182)
- 4.0.19

-------------------------------------------------------------------
Wed Jan 10 14:23:07 UTC 2018 - igonzalezsosa@suse.com

- Fix initialization to copy the profile to /tmp/profile again
(bsc#1075334)
- 4.0.18

-------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Expand Up @@ -22,7 +22,7 @@
%endif

Name: autoyast2
Version: 4.0.18
Version: 4.0.19
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
3 changes: 2 additions & 1 deletion src/clients/inst_autoinit.rb
Expand Up @@ -18,6 +18,7 @@ def main
Yast.import "Installation"
Yast.import "AutoInstall"
Yast.import "AutoinstConfig"
Yast.import "AutoinstFunctions"
Yast.import "AutoinstGeneral"
Yast.import "ProfileLocation"
Yast.import "AutoInstallRules"
Expand Down Expand Up @@ -107,7 +108,7 @@ def main
WFM.CallFunction("fcoe-client_auto", ["Write"])
end

if !AutoinstConfig.selected_product
if !AutoinstFunctions.selected_product
Report.Error(_("No base product selected"))

return :abort
Expand Down
153 changes: 0 additions & 153 deletions src/modules/AutoinstConfig.rb
Expand Up @@ -34,9 +34,6 @@ def main
Yast.import "Stage"
Yast.import "Label"
Yast.import "Report"
Yast.import "Profile"
Yast.import "AutoinstFunctions"
Yast.import "Pkg"

Yast.include self, "autoinstall/xml.rb"

Expand Down Expand Up @@ -231,38 +228,6 @@ def setProposalList(l)
nil
end

# Checking the environment the installed system
# to run a second stage if it is needed.
#
# @return [String] empty String or error messsage about missing packages.
def check_second_stage_environment
error = ""
return error unless AutoinstFunctions.second_stage_required?

missing_packages = Profile.needed_second_stage_packages.select do |p|
!Pkg.IsSelected(p)
end
unless missing_packages.empty?
log.warn "Second stage cannot be run due missing packages: #{missing_packages}"
# TRANSLATORS: %s will be replaced by a package list
error = format(_("AutoYaST cannot run second stage due to missing packages \n%s.\n"),
missing_packages.join(", "))
unless registered?
if Profile.current["suse_register"] &&
Profile.current["suse_register"]["do_registration"] == true
error << _("The registration has failed. " \
"Please check your registration settings in the AutoYaST configuration file.")
log.warn "Registration has been called but has failed."
else
error << _("You have not registered your system. " \
"Missing packages can be added by configuring the registration in the AutoYaST configuration file.")
log.warn "Registration is not configured at all."
end
end
end
error
end

# Searches for 'autoyast' via SLP and returns the full URL of
# the profile. If more providers are found, user is asked to
# select one.
Expand Down Expand Up @@ -563,41 +528,6 @@ def MainHelp
main_help
end

# Tries to find a base product if could be identified from the AY profile
#
# There are several ways how can base product be defined in the profile
# 1) explicitly
# 2) impllicitly according to software selection
# 3) if not set explicitly and just one product is available on media - use it
#
# @return [Y2Packager::Product] a base product or nil
def selected_product
return @selected_product if @selected_product

profile = Profile.current
product = identify_product_by_selection(profile)

# user asked for a product which is not available -> exit, not found
return nil if product.nil? && base_product_name(profile)

@selected_product = if product
log.info("selected_product - found explicitly defined base product: #{product.inspect}")
product
elsif (product = identify_product_by_patterns(profile))
log.info("selected_product - base product identified by patterns: #{product.inspect}")
product
elsif (product = identify_product_by_packages(profile))
log.info("selected_product - base product identified by packages: #{product.inspect}")
product
else
# last instance
base_products = Y2Packager::Product.available_base_products
base_products.first if base_products.size == 1
end

@selected_product
end

# Profile path during installation
#
# @return [String] Path
Expand Down Expand Up @@ -669,89 +599,6 @@ def profile_backup_path
publish :function => :AutoinstConfig, :type => "void ()"
publish :function => :MainHelp, :type => "string ()"
publish :function => :check_second_stage_environment, :type => "string ()"

private

# Determine whether the system is registered
#
# @return [Boolean]
def registered?
require "registration/registration"
Registration::Registration.is_registered?
rescue LoadError
false
end

# Reads base product name from the profile
#
# FIXME: Currently it returns first found product name. It should be no
# problem since this section was unused in AY installation so far.
# However, it might be needed to add a special handling for multiple
# poducts in the future. At least we can filter out products which are
# not base products.
#
# @param profile [Hash] AutoYaST profile
# @return [String] product name
def base_product_name(profile)
software = profile.fetch("software", {})
software.fetch("products", []).first
end

# Tries to identify a base product according to the condition in block
#
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product
base_products = Y2Packager::Product.available_base_products

products = base_products.select do |product|
yield(product)
end

return products.first if products.size == 1
nil
end

# Try to find base product according to patterns in profile
#
# searching for patterns like "sles-base-32bit"
#
# @param [Hash] profile - a hash representation of AY profile
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_patterns(profile)
software = profile.fetch("software", {})

identify_product do |product|
software.fetch("patterns", []).any? { |p| p =~ /#{product.name.downcase}-.*/ }
end
end

# Try to find base product according to packages selection in profile
#
# searching for packages like "sles-release"
#
# @param [Hash] profile - a hash representation of AY profile
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_packages(profile)
software = profile.fetch("software", {})

identify_product do |product|
software.fetch("packages", []).any? { |p| p =~ /#{product.name.downcase}-release/ }
end
end

# Try to identify base product using user's selection in profile
#
# @param [Hash] profile - a hash representation of AY profile
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_selection(profile)
identify_product do |product|
product.short_name == base_product_name(profile)
end
end
end

AutoinstConfig = AutoinstConfigClass.new
Expand Down
154 changes: 154 additions & 0 deletions src/modules/AutoinstFunctions.rb
@@ -1,13 +1,17 @@
module Yast
# Helper methods to be used on autoinstallation.
class AutoinstFunctionsClass < Module
include Yast::Logger

def main
textdomain "installation"

Yast.import "Stage"
Yast.import "Mode"
Yast.import "AutoinstConfig"
Yast.import "ProductControl"
Yast.import "Profile"
Yast.import "Pkg"
end

# Determines if the second stage should be executed
Expand All @@ -29,6 +33,156 @@ def second_stage_required?
ProductControl.RunRequired("continue", Mode.mode)
end
end

# Checking the environment the installed system
# to run a second stage if it is needed.
#
# @return [String] empty String or error messsage about missing packages.
def check_second_stage_environment
error = ""
return error unless second_stage_required?

missing_packages = Profile.needed_second_stage_packages.select do |p|
!Pkg.IsSelected(p)
end
unless missing_packages.empty?
log.warn "Second stage cannot be run due missing packages: #{missing_packages}"
# TRANSLATORS: %s will be replaced by a package list
error = format(_("AutoYaST cannot run second stage due to missing packages \n%s.\n"),
missing_packages.join(", "))
unless registered?
if Profile.current["suse_register"] &&
Profile.current["suse_register"]["do_registration"] == true
error << _("The registration has failed. " \
"Please check your registration settings in the AutoYaST configuration file.")
log.warn "Registration has been called but has failed."
else
error << _("You have not registered your system. " \
"Missing packages can be added by configuring the registration in the AutoYaST configuration file.")
log.warn "Registration is not configured at all."
end
end
end
error
end

# Tries to find a base product if could be identified from the AY profile
#
# There are several ways how can base product be defined in the profile
# 1) explicitly
# 2) impllicitly according to software selection
# 3) if not set explicitly and just one product is available on media - use it
#
# @return [Y2Packager::Product] a base product or nil
def selected_product
return @selected_product if @selected_product

profile = Profile.current
product = identify_product_by_selection(profile)

# user asked for a product which is not available -> exit, not found
return nil if product.nil? && base_product_name(profile)

@selected_product = if product
log.info("selected_product - found explicitly defined base product: #{product.inspect}")
product
elsif (product = identify_product_by_patterns(profile))
log.info("selected_product - base product identified by patterns: #{product.inspect}")
product
elsif (product = identify_product_by_packages(profile))
log.info("selected_product - base product identified by packages: #{product.inspect}")
product
else
# last instance
base_products = Y2Packager::Product.available_base_products
base_products.first if base_products.size == 1
end

@selected_product
end

private

# Determine whether the system is registered
#
# @return [Boolean]
def registered?
require "registration/registration"
Registration::Registration.is_registered?
rescue LoadError
false
end

# Tries to identify a base product according to the condition in block
#
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product
base_products = Y2Packager::Product.available_base_products

products = base_products.select do |product|
yield(product)
end

return products.first if products.size == 1
nil
end

# Try to find base product according to patterns in profile
#
# searching for patterns like "sles-base-32bit"
#
# @param [Hash] profile - a hash representation of AY profile
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_patterns(profile)
software = profile.fetch("software", {})

identify_product do |product|
software.fetch("patterns", []).any? { |p| p =~ /#{product.name.downcase}-.*/ }
end
end

# Try to find base product according to packages selection in profile
#
# searching for packages like "sles-release"
#
# @param [Hash] profile - a hash representation of AY profile
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_packages(profile)
software = profile.fetch("software", {})

identify_product do |product|
software.fetch("packages", []).any? { |p| p =~ /#{product.name.downcase}-release/ }
end
end

# Try to identify base product using user's selection in profile
#
# @param [Hash] profile - a hash representation of AY profile
# @return [Y2Packager::Product] a product if exactly one product matches
# the criteria, nil otherwise
def identify_product_by_selection(profile)
identify_product do |product|
product.short_name == base_product_name(profile)
end
end

# Reads base product name from the profile
#
# FIXME: Currently it returns first found product name. It should be no
# problem since this section was unused in AY installation so far.
# However, it might be needed to add a special handling for multiple
# poducts in the future. At least we can filter out products which are
# not base products.
#
# @param profile [Hash] AutoYaST profile
# @return [String] product name
def base_product_name(profile)
software = profile.fetch("software", {})
software.fetch("products", []).first
end
end

AutoinstFunctions = AutoinstFunctionsClass.new
Expand Down

0 comments on commit bcab600

Please sign in to comment.