Skip to content

Commit

Permalink
Merge pull request #214 from yast/rollback
Browse files Browse the repository at this point in the history
Rollback registration when online migration is aborted
  • Loading branch information
lslezak committed Sep 23, 2015
2 parents 4d5f3cb + ab9d1c0 commit 4a1fc45
Show file tree
Hide file tree
Showing 46 changed files with 438 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ before_install:
# disable rvm, use system Ruby
- rvm reset
- wget https://raw.githubusercontent.com/yast/yast-devtools/master/travis-tools/travis_setup.sh
- sh ./travis_setup.sh -p "yast2-devtools yast2 yast2-slp yast2-add-on" -g bundler
- sh ./travis_setup.sh -p "yast2-devtools yast2 yast2-slp yast2-add-on yast2-update" -g bundler
script:
- rake check:pot
- rubocop
Expand Down
10 changes: 10 additions & 0 deletions package/yast2-registration.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Mon Sep 21 13:53:12 UTC 2015 - lslezak@suse.cz

- restore the original product registration when online migration
is aborted (FATE#315161)
- set the selected repository states in the manual repository
selection dialog before starting the full repository management
module
- 3.1.153

-------------------------------------------------------------------
Wed Sep 16 19:04:05 UTC 2015 - lslezak@suse.cz

Expand Down
8 changes: 5 additions & 3 deletions package/yast2-registration.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 3.1.152
Version: 3.1.153
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -32,19 +32,21 @@ Requires: yast2 >= 3.1.26
Requires: yast2-pkg-bindings >= 3.1.27
# N_() method
Requires: yast2-ruby-bindings >= 3.1.12
Requires: rubygem(suse-connect) >= 0.2.18
Requires: rubygem(suse-connect) >= 0.2.22
Requires: yast2-slp >= 3.1.2
Requires: yast2-add-on >= 3.1.8
Requires: yast2-packager >= 3.1.26
Requires: yast2-update >= 3.1.19

BuildRequires: yast2 >= 3.1.26
BuildRequires: update-desktop-files
BuildRequires: yast2-devtools >= 3.1.6
BuildRequires: rubygem(yast-rake) >= 0.1.8
BuildRequires: rubygem(rspec)
BuildRequires: rubygem(suse-connect) >= 0.2.18
BuildRequires: rubygem(suse-connect) >= 0.2.22
BuildRequires: yast2-slp >= 3.1.2
BuildRequires: yast2-packager >= 3.1.26
BuildRequires: yast2-update >= 3.1.19

BuildArch: noarch

Expand Down
23 changes: 1 addition & 22 deletions src/clients/migration_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@
# ------------------------------------------------------------------------------
#

require "yast"
require "registration/ui/migration_finish_workflow"

module Yast
class MigrationFinishClient < 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::MigrationFinishWorkflow.run
ensure
Wizard.CloseDialog unless wizard_present
end
end
end unless defined?(YaST::MigrationFinishClient)
end

Yast::MigrationFinishClient.new.main
Registration::UI::MigrationFinishWorkflow.new.main
23 changes: 1 addition & 22 deletions src/clients/migration_repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@
# ------------------------------------------------------------------------------
#

require "yast"
require "registration/ui/migration_repos_workflow"

module Yast
class MigrationReposClient < 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::MigrationReposWorkflow.run
ensure
Wizard.CloseDialog unless wizard_present
end
end
end unless defined?(YaST::MigrationReposClient)
end

Yast::MigrationReposClient.new.main
Registration::UI::MigrationReposWorkflow.new.main
17 changes: 17 additions & 0 deletions src/clients/registration_sync.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ------------------------------------------------------------------------------
# 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 "registration/ui/registration_sync_workflow"

Registration::UI::RegistrationSyncWorkflow.new.main
30 changes: 30 additions & 0 deletions src/lib/registration/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# ------------------------------------------------------------------------------
#

require "ostruct"
require "yast"
require "suse/connect"

Expand Down Expand Up @@ -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 registered products on the server with the local installed products
# (removes all registrered products on the server which are not installed in the system)
# @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)
Expand Down
34 changes: 34 additions & 0 deletions src/lib/registration/registration_ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,40 @@ def update_addons(addons, enable_updates: true)
failed_addons
end

# downgrade product registration
# @param [Hash] product libzypp product which registration will be downgraded
# @return [Array<Boolean, OpenStruct>] a pair with success flag and the
# registered remote service
def downgrade_product(product)
product_service = nil
success = ConnectHelpers.catch_registration_errors do
product_service = Yast::Popup.Feedback(
_(CONTACTING_MESSAGE),
# updating product registration, %s is a product name
_("Updating to %s ...") % SwMgmt.product_label(product)
) do
registration.downgrade_product(product)
end
end

[success, product_service]
end

# synchronize the local products with the registration server
# @param [Array<Hash>] products libzypp products to synchronize
# @return [Boolean] true on success
def synchronize_products(products)
ConnectHelpers.catch_registration_errors do
Yast::Popup.Feedback(
_(CONTACTING_MESSAGE),
# TRANSLATORS: progress label
_("Synchronizing Products...")
) do
registration.synchronize_products(products)
end
end
end

# load available addons from SCC server
# the result is cached to avoid reloading when going back and forth in the
# installation workflow
Expand Down
5 changes: 3 additions & 2 deletions src/lib/registration/sw_mgmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
require "tmpdir"
require "fileutils"
require "shellwords"
require "ostruct"

require "registration/exceptions"
require "registration/helpers"
Expand Down Expand Up @@ -135,7 +136,7 @@ def self.installed_products
# @param product [Hash] product Hash obtained from pkg-bindings
# @return [SUSE::Connect::Remote::Product] the remote product
def self.remote_product(product)
SUSE::Connect::Remote::Product.new(
OpenStruct.new(
arch: product["arch"],
identifier: product["name"],
version: product["version"],
Expand Down Expand Up @@ -477,6 +478,6 @@ def self.raise_pkg_exception
raise PkgError.new, Pkg.LastError
end

private_class_method :each_repo, :get_release_type
private_class_method :each_repo
end
end
56 changes: 3 additions & 53 deletions src/lib/registration/ui/migration_finish_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,19 @@
# ------------------------------------------------------------------------------
#

require "yast"

require "registration/repo_state"
require "registration/ui/wizard_client"

module Registration
module UI
# This class handles the workflow for finishing the online migration
class MigrationFinishWorkflow
include Yast::Logger
include Yast::I18n
include Yast::UIShortcuts

Yast.import "Report"
Yast.import "Sequencer"

# run workflow for adding the migration services
# @return [Symbol] the UI symbol
def self.run
workflow = MigrationFinishWorkflow.new
workflow.run
end

# the constructor
def initialize
textdomain "registration"
end

class MigrationFinishWorkflow < WizardClient
# Run the workflow.
# The migration finish workflow is:
# - restore the saved repository states (i.e. enable the Updates
# repositories when they were disabled during migration)
def run
run_sequence
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

WORKFLOW_SEQUENCE = {
"ws_start" => "restore_repos",
"restore_repos" => {
abort: :abort,
next: :next
}
}

# run the workflow
# @return [Symbol] the UI symbol
def run_sequence
aliases = {
"restore_repos" => ->() { restore_repos }
}

ui = Yast::Sequencer.Run(aliases, WORKFLOW_SEQUENCE)
log.info "Workflow result: #{ui}"
ui
end

# restore all saved repository states
def restore_repos
log.info "Restoring the original repository setup..."
repo_state = RepoStateStorage.instance
repo_state.read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def store_values
# run the repository management, refresh the dialog content if it
# has not been aborted
def repo_mgmt
store_values
# refresh enabled repositories so they are up-to-date
ret = Yast::WFM.call("repositories", ["refresh-enabled"])
return :abort if ret == :abort
Expand Down
Loading

0 comments on commit 4a1fc45

Please sign in to comment.