-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore the original product registration when online migration is aborted
- Loading branch information
Showing
12 changed files
with
325 additions
and
9 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
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
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
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,38 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2015 SUSE LLC | ||
# | ||
# 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 "registration/ui/registration_sync_workflow" | ||
|
||
module Yast | ||
class RegistrationSyncClient < Client | ||
Yast.import "Wizard" | ||
|
||
def main | ||
textdomain "registration" | ||
|
||
# create the Wizard dialog if needed | ||
wizard_present = Wizard.IsWizardDialog | ||
Wizard.CreateDialog unless wizard_present | ||
|
||
begin | ||
::Registration::UI::RegistrationSyncWorkflow.run | ||
ensure | ||
Wizard.CloseDialog unless wizard_present | ||
end | ||
end | ||
end unless defined?(YaST::RegistrationSyncClient) | ||
end | ||
|
||
Yast::RegistrationSyncClient.new.main |
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
# ------------------------------------------------------------------------------ | ||
# | ||
|
||
require "ostruct" | ||
require "yast" | ||
require "suse/connect" | ||
|
||
|
@@ -85,6 +86,35 @@ def upgrade_product(product) | |
end | ||
end | ||
|
||
# downgrade product registration | ||
# used when restoring the original registration after aborted migration | ||
# @param [Hash] product libzypp product to which the registration should be downgraded | ||
def downgrade_product(product) | ||
service_for_product(product) do |product_ident, params| | ||
log.info "Downgrading product: #{product}" | ||
service = SUSE::Connect::YaST.downgrade_product(product_ident, params) | ||
log.info "Downgrade product result: #{service}" | ||
|
||
service | ||
end | ||
end | ||
|
||
# synchronize the registedred products on the server with the local installed products | ||
This comment has been minimized.
Sorry, something went wrong. |
||
# (removes all o registrered products) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lslezak
Author
Member
|
||
# @param [Array<Hash>] products list of installed libzypp products | ||
def synchronize_products(products) | ||
remote_products = products.map do |product| | ||
OpenStruct.new( | ||
arch: product["arch"], | ||
identifier: product["name"], | ||
version: product["version_version"], | ||
release_type: product["release_type"] | ||
) | ||
end | ||
log.info "Synchronizing products: #{remote_products}" | ||
SUSE::Connect::YaST.synchronize(remote_products) | ||
end | ||
|
||
# @param [String] target_distro new target distribution | ||
# @return [OpenStruct] SCC response | ||
def update_system(target_distro = nil) | ||
|
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
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
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
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,110 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2015 SUSE LLC | ||
# | ||
# 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 "registration/registration_ui" | ||
require "registration/sw_mgmt" | ||
require "registration/url_helpers" | ||
|
||
module Registration | ||
module UI | ||
# This class handles synchronizing the repositories/services after abort | ||
class RegistrationSyncWorkflow | ||
include Yast::Logger | ||
include Yast::I18n | ||
include Yast::UIShortcuts | ||
|
||
Yast.import "Report" | ||
Yast.import "Pkg" | ||
Yast.import "Update" | ||
Yast.import "Installation" | ||
|
||
# run the registration synchronization | ||
# @return [Symbol] the UI symbol (:next on sucess, :abort on error) | ||
def self.run | ||
workflow = RegistrationSyncWorkflow.new | ||
workflow.run | ||
end | ||
|
||
# the constructor | ||
def initialize | ||
textdomain "registration" | ||
|
||
registration = Registration.new(UrlHelpers.registration_url) | ||
self.registration_ui = RegistrationUI.new(registration) | ||
end | ||
|
||
# run the registration synchronization | ||
# @return [Symbol] the UI symbol (:next on sucess, :abort on error) | ||
def run | ||
rollback | ||
rescue => e | ||
log.error "Caught error: #{e.class}: #{e.message.inspect}, #{e.backtrace}" | ||
# TRANSLATORS: error message, %s are details | ||
Yast::Report.Error(_("Internal error: %s") % e.message) | ||
return :abort | ||
end | ||
|
||
private | ||
|
||
attr_accessor :registration_ui | ||
|
||
# restore the registration status | ||
# @return [Symbol] :next on sucess, :abort on error | ||
def rollback | ||
log.info "Restoring the original repository and registration status..." | ||
|
||
restore_repos | ||
|
||
# load the installed products | ||
Yast::Pkg.TargetLoad | ||
products = SwMgmt.installed_products | ||
|
||
# downgrade all installed products | ||
return :abort unless downgrade_products(products) | ||
|
||
reload_repos | ||
|
||
# synchronize all installed products (remove additional registrations at the server) | ||
registration_ui.synchronize_products(products) ? :next : :abort | ||
end | ||
|
||
# restore the repositpories from the backup archive | ||
def restore_repos | ||
# finish the sources and the target to reload the repositories from the backup | ||
Yast::Pkg.SourceFinishAll | ||
Yast::Pkg.TargetFinish | ||
Yast::Update.restore_backup | ||
Yast::Pkg.TargetInitialize(Yast::Installation.destdir) | ||
end | ||
|
||
# reload the repositories to synchronize the changes | ||
def reload_repos | ||
Yast::Pkg.SourceFinishAll | ||
Yast::Pkg.SourceRestore | ||
end | ||
|
||
# downgrade product registrations (restore the original status before upgrading) | ||
# @return [Boolean] true on success | ||
def downgrade_products(products) | ||
products.all? do |product| | ||
product["release_type"] = SwMgmt.get_release_type(product) | ||
success, _service = registration_ui.downgrade_product(product) | ||
success | ||
end | ||
end | ||
end | ||
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
Oops, something went wrong.
typo registedred -> registered