Skip to content

Commit

Permalink
Initial support for the SLE15 offline migration (fate#323163)
Browse files Browse the repository at this point in the history
- 4.0.18
  • Loading branch information
Gilson Souza authored and lslezak committed Jan 26, 2018
1 parent a4a87ab commit b72c636
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
6 changes: 6 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jan 26 15:59:19 UTC 2018 - lslezak@suse.cz

- Initial support for the SLE15 offline migration (fate#323163)
- 4.0.18

-------------------------------------------------------------------
Tue Jan 16 12:39:14 UTC 2018 - lslezak@suse.cz

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


Name: yast2-registration
Version: 4.0.17
Version: 4.0.18
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
22 changes: 19 additions & 3 deletions src/lib/registration/clients/inst_migration_repos.rb
Expand Up @@ -39,10 +39,26 @@ def main

# Pass the target directory to SUSEConnect
def set_target_path
return if Yast::Installation.destdir == "/"
destdir = Yast::Installation.destdir
return if destdir.nil? || destdir == "/"

log.info("Setting SUSEConnect target directory: #{Yast::Installation.destdir}")
SUSE::Connect::System.filesystem_root = Yast::Installation.destdir
log.info("Setting SUSEConnect target directory: #{destdir}")
SUSE::Connect::System.filesystem_root = destdir

# copy the old config from the upgraded system to inst-sys
# to correctly work in the SMT case
# FIXME: this should not be needed, it should be possible to read
# the config from the /mnt directly...
target_path = SUSE::Connect::YaST::DEFAULT_CONFIG_FILE
source_path = File.join(destdir, target_path)

if File.exist?(source_path)
log.info("Copying #{source_path} -> #{target_path}")
::FileUtils.cp(source_path, target_path)
elsif File.exist?(target_path)
log.info("Removing #{target_path}...")
::FileUtils.rm(target_path)
end
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions src/lib/registration/registration.rb
Expand Up @@ -167,6 +167,18 @@ def migration_products(installed_products)
migrations
end

def offline_migration_products(installed_products, target_base_product)
log.info "Offline migration for: #{target_base_product}."
migration_paths = []
ConnectHelpers.catch_registration_errors do
migration_paths = SUSE::Connect::YaST
.system_offline_migrations(installed_products, target_base_product)
end

log.info "Received possible migrations paths: #{migration_paths}"
migration_paths
end

# Get the list of updates for a base product or self_update_id if defined
#
# @return [Array<String>] List of URLs of updates repositories.
Expand Down
12 changes: 12 additions & 0 deletions src/lib/registration/registration_ui.rb
Expand Up @@ -198,6 +198,18 @@ def migration_products(products)
end
end

# According to the official SUSE terminology, "online" refers to a running
# system and (offline) to a system that is not running. It's NOT about the
# network connectivity
def offline_migration_products(products, base_product)
Yast::Popup.Feedback(
_(CONTACTING_MESSAGE),
_("Loading Migration Products...")
) do
registration.offline_migration_products(products, base_product)
end
end

# Register the selected addons, asks for reg. codes if required, known_reg_codes
# @param selected_addons [Array<Addon>] list of addons selected for registration,
# successfully registered addons are removed from the list
Expand Down
71 changes: 69 additions & 2 deletions src/lib/registration/ui/migration_repos_workflow.rb
Expand Up @@ -33,6 +33,7 @@ class MigrationReposWorkflow < WizardClient

Yast.import "Sequencer"
Yast.import "Mode"
Yast.import "Stage"
Yast.import "SourceDialogs"
Yast.import "Linuxrc"

Expand Down Expand Up @@ -114,6 +115,7 @@ def run_sequence
"load_migration_products" => {
abort: :abort,
cancel: :abort,
empty: :back,
next: "select_migration_products"
},
"select_migration_products" => {
Expand Down Expand Up @@ -188,6 +190,11 @@ def register_system
def not_installed_products_check
SwMgmt.init(true)

# FIXME: do the check also at offline upgrade?
# Currently it reads the addons for the new SLES15 which is not
# registered yet and fails.
return :next if Yast::Stage.initial

Addon.find_all(registration)

UI::NotInstalledProductsDialog.run
Expand Down Expand Up @@ -240,10 +247,22 @@ def merge_registered_addons
products.concat(addons)
end

# load migration products for the installed products from the registration server
# load migration products for the installed products from the registration server,
# loads online or offline migrations depending on the system state
# @return [Symbol] workflow symbol (:next or :abort)
def load_migration_products
log.info "Loading migration products from server"
if Yast::Stage.initial && Yast::Mode.update
load_migration_products_offline
else
load_migration_products_online
end
end

# load migration products for the installed products from the registration server
# for the currently running system (online migration)
# @return [Symbol] workflow symbol (:next or :abort)
def load_migration_products_online
log.info "Loading online migration products from the server..."
self.migrations = registration_ui.migration_products(products)

if migrations.empty?
Expand All @@ -255,6 +274,37 @@ def load_migration_products
:next
end

# load migration products for the installed products from the registration server
# on a system that is not running (offline migration)
# @return [Symbol] workflow symbol (:next or :abort)
def load_migration_products_offline
base_product = upgraded_base_product
if !base_product
# TRANSLATORS: Error message
Yast::Report.Error(_("Cannot find a base product to upgrade."))
return :empty
end

remote_product = OpenStruct.new(
arch: base_product.arch.to_s,
identifier: base_product.name,
version: base_product.version,
# FIXME: not supported by Y2Packager::Product yet
release_type: nil
)

log.info "Loading offline migration products from the server..."
self.migrations = registration_ui.offline_migration_products(products, remote_product)

if migrations.empty?
# TRANSLATORS: Error message
Yast::Report.Error(_("No migration product found."))
return :empty
end

:next
end

# run the migration target selection dialog
# @return [Symbol] workflow symbol (:next or :abort)
def select_migration_products
Expand Down Expand Up @@ -483,6 +533,23 @@ def media_upgrade(registered)
"using the previous product. The packages from the registration " \
"repositories can conflict with the new packages.</p>")
end

def upgraded_base_product
# temporarily run the update mode to let the solver select the product for upgrade
# (this will correctly handle possible product renames)
Yast::Pkg.PkgUpdateAll({})
product = Y2Packager::Product.selected_base

# restore the initial status, the package update will be turned on later again
Yast::Pkg.PkgReset
changed = Yast::Pkg.ResolvableProperties("", :package, "").select do |p|
p["status"] != :available || p["status"] != :installed
end
changed.each { |p| Yast::Pkg.PkgNeutral(p["name"]) }

log.info("Upgraded base product: #{product.inspect}")
product
end
end
end
end

0 comments on commit b72c636

Please sign in to comment.