Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Sep 21, 2015
1 parent 464da5e commit 6fe54d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
44 changes: 33 additions & 11 deletions src/lib/registration/ui/registration_sync_workflow.rb
Expand Up @@ -20,17 +20,19 @@

module Registration
module UI
# This class handles the workflow for finishing the online migration
# 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 workflow for adding the migration services
# @return [Symbol] the UI symbol
# run the registration synchronization
# @return [Symbol] the UI symbol (:next on sucess, :abort on error)
def self.run
workflow = RegistrationSyncWorkflow.new
workflow.run
Expand All @@ -44,7 +46,8 @@ def initialize
self.registration_ui = RegistrationUI.new(registration)
end

# run the registration rollback
# run the registration synchronization
# @return [Symbol] the UI symbol (:next on sucess, :abort on error)
def run
rollback
rescue => e
Expand All @@ -59,22 +62,41 @@ def run
attr_accessor :registration_ui

# restore the registration status
# @return [Symbol] :next on sucess, :abort on error
def rollback
log.info "Restoring the original registration status..."
# reset the package status (reset the product states from "upgrading"
# to "installed")
Yast::Pkg.ResolvableNeutral("", :product, false)
log.info "Restoring the original repository and registration status..."

# 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)

# load the installed products
Yast::Pkg.TargetLoad
products = SwMgmt.installed_products

# downgrade all installed products
return :abort unless downgrade_products(products)

# reload the repositories to synchronize the changes
Yast::Pkg.SourceFinishAll
Yast::Pkg.SourceRestore

# synchronize all installed products (remove additional registrations at the server)
registration_ui.synchronize_products(products) ? :next : :abort
end

# downgrade product registrations (restore the original status before upgrading)
# @return [Boolean] true on success
def downgrade_products(products)
products.each do |product|
product["release_type"] = SwMgmt.get_release_type(product)
success, _service = registration_ui.downgrade_product(product)
return :abort unless success
return false unless success
end

# synchronize all installed products (remove additional registrations at the server)
registration_ui.synchronize_products(products) ? :next : :abort
true
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions test/registration_sync_workflow_spec.rb
Expand Up @@ -5,13 +5,18 @@
describe Registration::UI::RegistrationSyncWorkflow do
describe "#run" do
before do
allow(Yast::Pkg).to receive(:SourceFinishAll)
allow(Yast::Pkg).to receive(:TargetFinish)
allow(Yast::Pkg).to receive(:TargetInitialize)
allow(Yast::Pkg).to receive(:TargetLoad)
allow(Yast::Pkg).to receive(:SourceRestore)
allow(Registration::UrlHelpers).to receive(:registration_url)
allow(Yast::Pkg).to receive(:ResolvableNeutral)
allow(Registration::SwMgmt).to receive(:get_release_type)
end

it "downgrades to the installed products and synchronizes the products on the server" do
it "restores repositories, downgrades registration and synchronizes the products" do
installed_sles = load_yaml_fixture("products_legacy_installation.yml")[1]
expect(Yast::Update).to receive(:restore_backup)
expect(Registration::SwMgmt).to receive(:installed_products).and_return([installed_sles])
expect_any_instance_of(Registration::RegistrationUI).to receive(:downgrade_product)
.with(installed_sles).and_return([true, nil])
Expand Down

0 comments on commit 6fe54d1

Please sign in to comment.