Skip to content

Commit

Permalink
use DUP from ALL (FATE#319138)
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jul 7, 2015
1 parent c9aa0c8 commit 90eb79d
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 84 deletions.
4 changes: 2 additions & 2 deletions package/yast2-registration.spec
Expand Up @@ -28,8 +28,8 @@ License: GPL-2.0

# Popup.Feedback
Requires: yast2 >= 3.1.26
# fixed service removal
Requires: yast2-pkg-bindings >= 3.1.25
# "allowVendorChange" option in Pkg.SetSolverFlags()
Requires: yast2-pkg-bindings >= 3.1.26
# N_() method
Requires: yast2-ruby-bindings >= 3.1.12
Requires: rubygem(suse-connect) >= 0.2.18
Expand Down
86 changes: 59 additions & 27 deletions src/lib/registration/migration_repositories.rb
Expand Up @@ -17,67 +17,88 @@
require "registration/sw_mgmt"

module Registration
# this class activates the migration repositories
# this class activates the migration services and repositories
class MigrationRepositories
include Yast::Logger

Yast.import "Pkg"

# reset the libzypp migration setup
def self.reset
log.info "Resetting upgrade repos config"
repos = Yast::Pkg.GetUpgradeRepos()
repos.each { |repo| Yast::Pkg.RemoveUpgradeRepo(repo) }
# reset the solver
Yast::Pkg.SetSolverFlags("reset" => true)

# deselect all pre-selected packages or patches
Yast::Pkg.PkgReset
end

attr_accessor :repositories, :install_updates
attr_accessor :repositories, :services, :install_updates

def initialize
@repositories = []
@services = []
# install updates by default
@install_updates = true
end

# use the repositories from a libzypp service for the migration
# @param [String] service_name name of the service
def add_service(service_name)
service_repos = SwMgmt.service_repos(service_name)
repositories.concat(service_repos)
# does any configured service contain an update repo?
# @return [Boolean] true if at least one service repository is an update
# repository
def service_update_repo?
services_repositories.any? { |repo| repo["is_update_repo"] }
end

# is any migration repo an update repo?
# @return [Boolean] true if at least one migration repository is an update
# repository
def has_update_repo?
repositories.any? { |repo| repo["is_update_repo"] }
# configure libzypp services to allow online migration
# (used for activating the default migration setup from the registration server)
def activate_services
# disable the update repositories if not required
if !install_updates
SwMgmt.set_repos_state(services_repositories(only_updates: true), false)
end

activate_solver
end

# configure libzypp repositories to allow online migration
# (used for activating the user changes)
def activate_repositories
all_repos = Yast::Pkg.SourceGetCurrent(false)

all_repos.each do |repo|
repo_data = Yast::Pkg.SourceGeneralData(repo)

# enabled migration repositories, disable the others, change
# the status if it is different than expected
next if repositories.include?(repo) == repo_data["enabled"]

new_state_msg = repo_data["enabled"] ? "Disabling" : "Enabling"
log.info "#{new_state_msg} repository #{repo_data["alias"]}"
Yast::Pkg.SourceSetEnabled(repo, !repo_data["enabled"])
end

activate_solver
end

private

# activate the migration repositories to install the updates
def activate
def activate_solver
set_solver

repositories.each do |repo|
if repo["is_update_repo"] && !install_updates
log.info "Skipping update repository: #{repo["alias"]}"
else
log.info "Adding upgrade repo: #{repo["alias"]}"
Yast::Pkg.AddUpgradeRepo(repo["SrcId"])
end
end
# load the objects from the enabled repositories
Yast::Pkg.SourceLoad

# upgrade from all repositories
Yast::Pkg.PkgUpdateAll({})
Yast::Pkg.PkgSolve(false)

select_patches if install_updates
end

private

# set the solver flags for online migration
# @see https://fate.suse.com/319138
def set_solver
log.info "Setting the solver flag for online migration"
log.info "Setting the solver flags for online migration"
Yast::Pkg.SetSolverFlags("ignoreAlreadyRecommended" => true,
"allowVendorChange" => false)
end
Expand All @@ -87,5 +108,16 @@ def select_patches
patches_count = Yast::Pkg.ResolvablePreselectPatches(:all)
log.info "Preselected patches: #{patches_count}"
end

# evaluate migration repositories and services
# @param [Boolean] only_updates return only the update repositories
# @return [Array<Fixnum>] list of used migration repositories
def services_repositories(only_updates: false)
service_repos = services.map do |service|
SwMgmt.service_repos(service, only_updates: only_updates)
end

service_repos.flatten
end
end
end
14 changes: 5 additions & 9 deletions src/lib/registration/ui/migration_repos_selection_dialog.rb
Expand Up @@ -83,9 +83,8 @@ def dialog_content
# list of repository items
# @return [Array<Yast::Term>] content for a MultiSelectionBox widget
def repo_items
upgrade_repos = Yast::Pkg.GetUpgradeRepos
# only enabled repositories
repos = Yast::Pkg.SourceGetCurrent(true)
# all repositories
repos = Yast::Pkg.SourceGetCurrent(false)

# sort the repositories by name
repos.sort! do |x, y|
Expand All @@ -95,7 +94,7 @@ def repo_items
end

repos.map do |repo|
Item(Id(repo), repo_label(repo), upgrade_repos.include?(repo))
Item(Id(repo), repo_label(repo), Yast::Pkg.SourceGeneralData(repo)["enabled"])
end
end

Expand All @@ -117,8 +116,8 @@ def store_values

# activate the new settings
migration_repos = MigrationRepositories.new
migration_repos.repositories = selected.map { |repo| SwMgmt.repository_data(repo) }
migration_repos.activate
migration_repos.repositories = selected
migration_repos.activate_repositories
end

# run the repository management, refresh the dialog content if it
Expand All @@ -128,9 +127,6 @@ def repo_mgmt
ret = Yast::WFM.call("repositories", ["refresh-enabled"])
return :abort if ret == :abort

# load objects from the new or enabled repositories
Yast::Pkg.SourceLoad

# refresh the dialog content
Yast::UI.ChangeWidget(:repos, :Items, repo_items)

Expand Down
14 changes: 8 additions & 6 deletions src/lib/registration/ui/migration_repos_workflow.rb
Expand Up @@ -58,7 +58,9 @@ def initialize
# are added to the system
# - (optionally) user manually selects the migration repositories
# - user is asked to install also the latest updates (or to migrate to the GA version)
# - the migration repositories are marked as active for distribution upgrade (DUP)
# - "Update from ALL" is set in libzypp (uses all enabled repositories)
# - (optional step) user can manually set the migration repositories,
# the selected repositories are enabled or disabled
# - return the user input symbol (:next or :abort) to the caller
# @return [Symbol] the UI symbol
#
Expand Down Expand Up @@ -126,8 +128,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 },
"activate_migration_repos" => ->() { activate_migration_repos },
"register_migration_products" => [->() { register_migration_products }, true],
"activate_migration_repos" => [->() { activate_migration_repos }, true],
"select_migration_repos" => ->() { select_migration_repos }
}

Expand Down Expand Up @@ -249,14 +251,14 @@ def activate_migration_repos
log.info "Activating the migration repositories"
migration_repos = ::Registration::MigrationRepositories.new
registered_services.each do |service|
migration_repos.add_service(service)
migration_repos.services << service
end

if migration_repos.has_update_repo?
if migration_repos.service_update_repo?
migration_repos.install_updates = registration_ui.install_updates?
end

migration_repos.activate
migration_repos.activate_services

manual_repo_selection ? :repo_selection : :next
end
Expand Down
17 changes: 7 additions & 10 deletions test/migration_repos_selection_dialog_test.rb
Expand Up @@ -5,21 +5,20 @@
include Yast::UIShortcuts

describe Registration::UI::MigrationReposSelectionDialog do
subject { Registration::UI::MigrationReposSelectionDialog }

describe ".run" do
before do
allow(Yast::Pkg).to receive(:GetUpgradeRepos).and_return([1, 2])
allow(Yast::Pkg).to receive(:SourceGetCurrent).and_return([0, 1, 2, 3])
allow(Yast::Pkg).to receive(:SourceGeneralData).and_return(
"name" => "name", "url" => "https://example.com")
allow(Yast::Pkg).to receive(:SourceGetCurrent).and_return([0, 1])
allow(Yast::Pkg).to receive(:SourceGeneralData).with(0).and_return(
"name" => "name", "url" => "https://example.com", "enabled" => false)
allow(Yast::Pkg).to receive(:SourceGeneralData).with(1).and_return(
"name" => "name2", "url" => "https://example2.com", "enabled" => true)

# check the displayed content
expect(Yast::Wizard).to receive(:SetContents) do |_title, content, _help, _back, _next|
term = content.nested_find do |t|
t.respond_to?(:value) && t.value == :MultiSelectionBox &&
t.params[3].include?(Item(Id(0), "name (https://example.com)", false)) &&
t.params[3].include?(Item(Id(1), "name (https://example.com)", true))
t.params[3].include?(Item(Id(1), "name2 (https://example2.com)", true))
end

expect(term).to_not eq(nil)
Expand All @@ -38,9 +37,8 @@
expect(Yast::UI).to receive(:QueryWidget).with(:repos, :SelectedItems).and_return([1])
# resets the repositories
expect(Registration::MigrationRepositories).to receive(:reset)
allow(Registration::SwMgmt).to receive(:repository_data)
# activates the new config
expect_any_instance_of(Registration::MigrationRepositories).to receive(:activate)
expect_any_instance_of(Registration::MigrationRepositories).to receive(:activate_repositories)

expect(subject.run).to eq(:next)
end
Expand All @@ -51,7 +49,6 @@
expect(Yast::WFM).to receive(:call).with("repositories", ["refresh-enabled"])
.and_return(:next)

expect(Yast::Pkg).to receive(:SourceLoad)
expect(Yast::UI).to receive(:ChangeWidget)

expect(subject.run).to eq(:abort)
Expand Down
26 changes: 23 additions & 3 deletions test/migration_repos_workflow_spec.rb
Expand Up @@ -54,7 +54,7 @@
expect_any_instance_of(Registration::Registration).to receive(:upgrade_product)
.and_return(migration_service)

expect_any_instance_of(Registration::MigrationRepositories).to receive(:activate)
expect_any_instance_of(Registration::MigrationRepositories).to receive(:activate_services)
end

it "registers the selected migration products" do
Expand All @@ -74,12 +74,12 @@
expect(subject.run).to eq(:next)
end

it "does not install updates if required" do
it "does not install updates if not required" do
set_success_expectations

# an update available
expect_any_instance_of(Registration::MigrationRepositories).to \
receive(:has_update_repo?).and_return(true)
receive(:service_update_repo?).and_return(true)
# user requestes skipping updates
expect_any_instance_of(Registration::RegistrationUI).to receive(:install_updates?)
.and_return(false)
Expand Down Expand Up @@ -108,6 +108,26 @@

expect(subject.run).to eq(:abort)
end

it "reports error and aborts when registering the migration products fails" do
# installed SLES12
expect(Registration::SwMgmt).to receive(:installed_products)
.and_return([load_yaml_fixture("products_legacy_installation.yml")[1]])

expect_any_instance_of(Registration::RegistrationUI).to receive(:migration_products)
.and_return(migrations)

# user selected a migration and pressed [Next]
expect_any_instance_of(Registration::UI::MigrationSelectionDialog).to receive(:run)
.and_return(:next)
expect_any_instance_of(Registration::UI::MigrationSelectionDialog).to \
receive(:selected_migration).and_return(migrations.first)

expect_any_instance_of(Registration::Registration).to receive(:upgrade_product)
.and_raise("Registration failed")

expect(subject.run).to eq(:abort)
end
end
end
end

0 comments on commit 90eb79d

Please sign in to comment.