Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SLE15-SP5] Fixed online migration from SLE_HPC to SLES SP6+ (bsc#1220567) #653

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package/yast2-packager.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Fri Mar 8 14:08:48 UTC 2024 - Ladislav Slezák <lslezak@suse.com>

- Reimplemented the hardcoded product mapping to support also the
migration from SLE_HPC to SLES SP6+ (with the HPC module)
(bsc#1220567)
- 4.5.20

-------------------------------------------------------------------
Thu Feb 8 13:49:00 UTC 2024 - Ladislav Slezák <lslezak@suse.com>

Expand Down
4 changes: 3 additions & 1 deletion package/yast2-packager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-packager
Version: 4.5.19
Version: 4.5.20
Release: 0
Summary: YaST2 - Package Library
License: GPL-2.0-or-later
Expand Down Expand Up @@ -77,6 +77,8 @@ Requires: ruby-solv
Conflicts: yast2-core < 2.15.10
# NotEnoughMemory-related functions moved to misc.ycp import-file
Conflicts: yast2-add-on < 2.15.15
# changed API in Y2Packager::ProductUpgrade and Yast::AddOnProduct
Conflicts: yast2-registration < 4.5.9

# ensure that 'checkmedia' is on the medium
Recommends: checkmedia
Expand Down
45 changes: 37 additions & 8 deletions src/lib/y2packager/product_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class ProductUpgrade
# maps installed products to a new available base product
# rubocop:disable Layout/LineLength
MAPPING = {
# SLES12 + HPC module => SLESHPC15
# (a bit tricky, the module became a new base product!)
["SLES", "sle-module-hpc"] => "SLE_HPC",
["SLES", "SUSE-Manager-Proxy"] => "SUSE-Manager-Proxy",
["SLES", "SUSE-Manager-Server"] => "SUSE-Manager-Server",
["SLES", "SUSE-Manager-Proxy", "SUSE-Manager-Retail-Branch-Server"] => "SUSE-Manager-Retail-Branch-Server",
Expand All @@ -52,6 +49,8 @@ class ProductUpgrade
# in the src/modules/AddOnProduct.rb file, maybe it needs an update as well...
}.freeze

private_constant :MAPPING

# This maps uses a list of installed products as the key and the removed products as a value.
# All products in key have to be installed.
# It is used in special cases when the removed product is still available on the medium
Expand All @@ -65,7 +64,33 @@ class ProductUpgrade
}.freeze
# rubocop:enable Layout/LineLength

private_constant :UPGRADE_REMOVAL_MAPPING

class << self
# flag for using old (<= SLE15-SP5-) or new (>= SLE15-SP6) product mapping
attr_accessor :new_renames

def mapping
# special handling for the HPC product
product_mapping = if new_renames
{
# in SLE15-SP6+ SLE_HPC is replaced by SLES + HPC module
["SLE-HPC"] => "SLES",
["SLE_HPC"] => "SLES"
}
else
{
# SLES12 + HPC module => SLESHPC15
# (a bit tricky, the module became a new base product!)
["SLES", "sle-module-hpc"] => "SLE_HPC",
# different ID
["SLE-HPC"] => "SLE_HPC"
}
end

product_mapping.merge!(MAPPING)
end

# Find a new available base product which upgrades the installed base product.
#
# The workflow to find the new base product is:
Expand Down Expand Up @@ -117,18 +142,20 @@ def will_be_obsoleted_by(old_product_name)
installed = Y2Packager::Product.installed_products.map(&:name)
selected_products = Y2Packager::Product.with_status(:selected).map(&:name)

product_mapping = mapping

# the "sort_by(&:size).reverse" part ensures we try first the longer
# mappings (more installed products) to find more specific matches
old_products = MAPPING.keys.sort_by(&:size).reverse.find do |products|
old_products = product_mapping.keys.sort_by(&:size).reverse.find do |products|
# the product is included in the mapping key and all product mapping key
# products are installed and the replacement products are selected
products.include?(old_product_name) && (products - installed).empty? &&
selected_products.include?(MAPPING[products])
selected_products.include?(product_mapping[products])
end

return [] unless old_products

[MAPPING[old_products]]
[product_mapping[old_products]]
end

# Returns the products which are upgraded by the solver but should be actually
Expand Down Expand Up @@ -177,18 +204,20 @@ def find_by_count(available)
def find_by_mapping(available)
installed = Y2Packager::Product.installed_products

product_mapping = mapping

# sort the keys by length, try more products first
# to find the most specific upgrade, prefer the
# SLES + sle-module-hpc => SLE_HPC upgrade to plain SLES => SLES upgrade
# (if that would be in the list)
upgrade = MAPPING.keys.sort_by(&:size).reverse.find do |keys|
upgrade = product_mapping.keys.sort_by(&:size).reverse.find do |keys|
keys.all? { |name| installed.any? { |p| p.name == name } }
end

log.info("Fallback upgrade for products: #{upgrade.inspect}")
return nil unless upgrade

name = MAPPING[upgrade]
name = product_mapping[upgrade]
product = available.find { |p| p.name == name }
log.info("New product: #{product}")
product
Expand Down
35 changes: 27 additions & 8 deletions src/modules/AddOnProduct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class AddOnProductClass < Module
# SLE12 HA GEO is now included in SLE15 HA
"sle-ha-geo" => ["sle-ha"],
"SUSE_SLES_SAP" => ["SLES_SAP"],
# SLES-12 with HPC module can be replaced by SLE_HPC-15
"SLES" => ["SLE_HPC"],
# this is an internal product so far...
"SLE-HPC" => ["SLE_HPC"],
# SMT is now integrated into the base SLES
"sle-smt" => ["SLES"],
# Live patching is a module now (bsc#1074154)
Expand All @@ -52,6 +48,29 @@ class AddOnProductClass < Module
# in the src/lib/y2packager/product_upgrade.rb file, maybe it needs an update as well...
}.freeze

private_constant :DEFAULT_PRODUCT_RENAMES

attr_accessor :new_renames

def default_product_renames
# special handling for the HPC product
product_mapping = if new_renames
{
# in SLE15-SP6+ SLE_HPC is replaced by SLES + HPC module
"SLE-HPC" => ["SLES"],
"SLE_HPC" => ["SLES"]
}
else
{
# in SLE15 SP5 (or older) the SLES + HPC module is upgraded to SLE_HPC
"SLES" => ["SLE_HPC"],
"SLE-HPC" => ["SLE_HPC"]
}
end

product_mapping.merge!(DEFAULT_PRODUCT_RENAMES)
end

# @return [Hash] Product renames added externally through the #add_rename method
attr_accessor :external_product_renames
private :external_product_renames, :external_product_renames=
Expand Down Expand Up @@ -2015,7 +2034,7 @@ def missing_upgrades

# handle the product renames, if a renamed product was installed
# replace it with the new product so the new product is preselected
DEFAULT_PRODUCT_RENAMES.each do |k, v|
default_product_renames.each do |k, v|
next unless installed_addons.include?(k)

installed_addons.delete(k)
Expand Down Expand Up @@ -2106,12 +2125,12 @@ def renamed_by_libzypp?(old_name, new_name)

# Determine whether a product rename is included in the fallback map
#
# @see DEFAULT_PRODUCT_RENAMES
# @see default_product_renames
# @see #renamed_at?
def renamed_by_default?(old_name, new_name)
log.info "Search #{old_name} -> #{new_name} rename in default map: " \
"#{DEFAULT_PRODUCT_RENAMES.inspect}"
renamed_at?(DEFAULT_PRODUCT_RENAMES, old_name, new_name)
"#{default_product_renames.inspect}"
renamed_at?(default_product_renames, old_name, new_name)
end

# Determine whether a product rename is present on a given hash
Expand Down
Loading