Skip to content

Commit

Permalink
Merge pull request #215 from yast/check_registration
Browse files Browse the repository at this point in the history
Check registration status before starting online migration
  • Loading branch information
lslezak committed Sep 23, 2015
2 parents 4a1fc45 + 38040a4 commit e6ac04b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
7 changes: 7 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Sep 23 12:14:17 UTC 2015 - lslezak@suse.cz

- check whether the system is registered before running online
migration (bsc#946004)
- 3.1.154

-------------------------------------------------------------------
Mon Sep 21 13:53:12 UTC 2015 - lslezak@suse.cz

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


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

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
44 changes: 43 additions & 1 deletion src/lib/registration/ui/migration_repos_workflow.rb
Expand Up @@ -31,6 +31,7 @@ class MigrationReposWorkflow < WizardClient
include Yast::UIShortcuts

Yast.import "Sequencer"
Yast.import "Mode"

# the constructor
def initialize
Expand All @@ -44,6 +45,8 @@ def initialize

# The repositories migration workflow is:
#
# - if the system is not registered ask the user to register it first
# (otherwise abort the online migration)
# - find all installed products
# - query registered addons from the server
# - ask the registration server for the available product migrations
Expand All @@ -63,6 +66,7 @@ def run_sequence
log.info "Starting migration repositories sequence"

aliases = {
"registration_check" => [->() { registration_check }, true],
"find_products" => [->() { find_products }, true],
"load_migration_products" => [->() { load_migration_products }, true],
"select_migration_products" => ->() { select_migration_products },
Expand All @@ -85,7 +89,11 @@ def run_sequence
:manual_repo_selection

WORKFLOW_SEQUENCE = {
"ws_start" => "find_products",
"ws_start" => "registration_check",
"registration_check" => {
abort: :abort,
next: "find_products"
},
"find_products" => {
abort: :abort,
cancel: :abort,
Expand Down Expand Up @@ -125,6 +133,40 @@ def run_sequence
}
}

# check whether the system is registered, ask the user to register it
# if the system is not registered
# @return [Symbol] workflow symbol, :next if registered, :abort when not
def registration_check
return :next if Registration.is_registered?

# TRANSLATORS: a popup message with [Continue] [Cancel] buttons,
# pressing [Continue] starts the registration module, [Cancel] aborts
# the online migration
register = Yast::Popup.ContinueCancel(_("The system is not registered,\n" \
"to run the online migration you need\n" \
"to register the system first."))

return :abort unless register

register_system
end

# run the registration module to register the system
# @return [Symbol] the registration result
def register_system
# temporarily switch back to the normal mode so the registration behaves as expected
mode = Yast::Mode.mode
log.info "Setting 'normal' mode"
Yast::Mode.SetMode("normal")

ret = Yast::WFM.call("inst_scc")
log.info "Registration result: #{ret.inspect}"

log.info "Restoring #{mode.inspect} mode"
Yast::Mode.SetMode(mode)
ret
end

# find all installed products
# @return [Symbol] workflow symbol (:next or :abort)
def find_products
Expand Down
30 changes: 30 additions & 0 deletions test/migration_repos_workflow_spec.rb
Expand Up @@ -8,13 +8,43 @@
# Url of the registration server
allow(Registration::UrlHelpers).to receive(:registration_url)
allow(Registration::Addon).to receive(:find_all)
allow(Registration::Registration).to receive(:is_registered?).and_return(true)
# Load source information
allow(Yast::Pkg).to receive(:SourceLoad)
allow(Yast::Pkg).to receive(:SourceFinishAll)
allow(Yast::Pkg).to receive(:SourceRestore)
allow(Yast::Pkg).to receive(:SourceGetCurrent).and_return([])
end

context "the system is not registered" do
before do
expect(Registration::Registration).to receive(:is_registered?).and_return(false)
allow(Yast::Mode).to receive(:SetMode)
end

it "asks the user to register the system first" do
expect(Yast::Popup).to receive(:ContinueCancel).and_return(false)
subject.run_sequence
end

it "aborts when user does not want to continue" do
expect(Yast::Popup).to receive(:ContinueCancel).and_return(false)
expect(subject.run_sequence).to eq(:abort)
end

it "runs the full registration if user continues" do
expect(Yast::Popup).to receive(:ContinueCancel).and_return(true)
expect(Yast::WFM).to receive(:call).with("inst_scc")
subject.run_sequence
end

it "aborts when the registration is aborted" do
expect(Yast::Popup).to receive(:ContinueCancel).and_return(true)
expect(Yast::WFM).to receive(:call).with("inst_scc").and_return(:abort)
expect(subject.run_sequence).to eq(:abort)
end
end

context "if package management initialization succeeds" do
let(:migrations) { load_yaml_fixture("migration_to_sles12_sp1.yml") }
let(:migration_service) { load_yaml_fixture("migration_service.yml") }
Expand Down

0 comments on commit e6ac04b

Please sign in to comment.