Skip to content

Commit

Permalink
activate the migration repositories ("dup --from")
Browse files Browse the repository at this point in the history
added some error handling
  • Loading branch information
lslezak committed Jun 18, 2015
1 parent 118e420 commit 7684044
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 12 deletions.
66 changes: 66 additions & 0 deletions src/lib/registration/migration_repositories.rb
@@ -0,0 +1,66 @@

# ------------------------------------------------------------------------------
# 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/sw_mgmt"

module Registration
# this class displays and runs the dialog with addon selection
class MigrationRepositories
include Yast::Logger

Yast.import "Pkg"

attr_accessor :repositories, :install_updates

def initialize
self.repositories = []
end

def reset
self.repositories = []

log.info "Resetting upgrade repos config"
repos = Yast::Pkg.GetUpgradeRepos()
repos.each { |repo| Yast::Pkg.RemoveUpgradeRepo(repo) }
end

def add_repo(id)
repositories << id
end

def add_service(service_name)
service_repos = SwMgmt.service_repos(service_name)
repositories.concat(service_repos)
end

def activate
# be compatible with "zypper dup --from"
log.info "Disabling recommended packages for already installed packages"
Yast::Pkg.SetSolverFlags("ignoreAlreadyRecommended" => true)

log.info "Adding upgrade repos: #{repositories.map { |repo| repo["alias"] }}"
repositories.each { |repo| Yast::Pkg.AddUpgradeRepo(repo["SrcId"]) }

Yast::Pkg.PkgSolve(false)

return unless install_updates

# preselect all applicable patches (except optional ones)
patches_count = Yast::Pkg.ResolvablePreselectPatches(:all)
log.info "Preselected patches: #{patches_count}"
end
end
end
8 changes: 6 additions & 2 deletions src/lib/registration/registration.rb
Expand Up @@ -127,9 +127,13 @@ def activated_products
# @return [Array<Array<SUSE::Connect::Remote::Product>>] list of possible migrations
def migration_products(installed_products)
log.info "Loading migration products for: #{installed_products}"
migrations = SUSE::Connect::YaST.system_migrations(installed_products)
log.info "Received system migrations: #{migrations}"
migrations = []

ConnectHelpers.catch_registration_errors do
migrations = SUSE::Connect::YaST.system_migrations(installed_products)
end

log.info "Received system migrations: #{migrations}"
migrations
end

Expand Down
27 changes: 25 additions & 2 deletions src/lib/registration/ui/migration_repos_workflow.rb
Expand Up @@ -3,6 +3,7 @@

require "registration/registration"
require "registration/registration_ui"
require "registration/migration_repositories"
require "registration/sw_mgmt"
require "registration/ui/migration_selection_dialog"

Expand Down Expand Up @@ -82,6 +83,11 @@ def run
next: "register_migration_products"
},
"register_migration_products" => {
abort: :abort,
cancel: :abort,
next: "activate_migration_repos"
},
"activate_migration_repos" => {
abort: :abort,
cancel: :abort,
next: :next
Expand All @@ -93,7 +99,8 @@ def run_sequence
"find_products" => [->() { find_products }, true],
"load_migration_products" => [->() { load_migration_products }, true],
"select_migration_products" => ->() { select_migration_products },
"register_migration_products" => ->() { register_migration_products }
"register_migration_products" => ->() { register_migration_products },
"activate_migration_repos" => ->() { activate_migration_repos }
}

ui = Yast::Sequencer.Run(aliases, WORKFLOW_SEQUENCE)
Expand Down Expand Up @@ -162,13 +169,29 @@ def register_migration_products
_("Registering Migration Products...")) do
selected_migration.each do |product|
log.info "Registering migration product #{product}"
registered_services << registration.upgrade_product(product)

upgraded = ConnectHelpers.catch_registration_errors do
registered_services << registration.upgrade_product(product)
end

return :abort unless upgraded
end
end

log.info "Registered services: #{registered_services}"
:next
end

def activate_migration_repos
migration_repos = ::Registration::MigrationRepositories.new

registered_services.each do |service|
migration_repos.add_service(service)
end

migration_repos.activate
:next
end
end
end
end
12 changes: 4 additions & 8 deletions test/migration_repos_workflow_spec.rb
Expand Up @@ -18,14 +18,14 @@
expect(Registration::SwMgmt).to receive(:init).and_return(false)
expect(Yast::Pkg).to receive(:LastError).and_return(msg)

expect(subject.run).to eq(error: true, error_msg: msg)
expect(subject.run).to eq(:abort)
end

it "handles any exception raised and reports an error" do
msg = "Something failed..."
expect(Yast::Sequencer).to receive(:Run).and_raise(msg)

expect(subject.run).to eq(error: true, error_msg: msg)
expect(subject.run).to eq(:abort)
end

context "if package management initialization succeeds" do
Expand All @@ -51,15 +51,11 @@
expect_any_instance_of(Registration::Registration).to receive(:upgrade_product)
.and_return(migration_service)

allow(Registration::SwMgmt).to receive(:service_repos).and_return([])
expect_any_instance_of(Registration::MigrationRepositories).to receive(:activate)
end

it "registers the selected migration products" do
ret = subject.run
# no error reported
expect(ret).to_not have_key(:aborted)
expect(ret).to_not have_key(:error)
expect(ret[:success]).to eq(true)
expect(subject.run).to eq(:next)
end
end
end
Expand Down

0 comments on commit 7684044

Please sign in to comment.