Skip to content

Commit

Permalink
Handle going back, tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 16, 2018
1 parent 4e8e36b commit 22a3800
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
File renamed without changes.
32 changes: 25 additions & 7 deletions src/lib/registration/ui/offline_migration_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class OfflineMigrationWorkflow
include Yast::I18n
include Yast::Logger

Yast.import "GetInstArgs"
Yast.import "Packages"

# the constructor
def initialize
textdomain "registration"
Expand All @@ -37,15 +40,26 @@ def initialize
def main
log.info "Starting offline migration sequence"

ui = migration_repos
if Yast::GetInstArgs.going_back
log.info("Going back")

if ui == :rollback
rollback
# always go back in the upgrade workflow, maybe the user just selected
# a wrong partition to upgrade
ui = :back
if Registration.is_registered?
log.info("Restoring the previous registration")
rollback
end

return :back
end

# run the main registration migration
ui = migration_repos

rollback if ui == :rollback

# go back in the upgrade workflow after rollback or abort,
# maybe the user justelected a wrong partition to upgrade
ui = :back if ui == :abort || ui == :rollback

log.info "Offline migration result: #{ui}"
ui
end
Expand All @@ -54,10 +68,14 @@ def main

def rollback
Yast::WFM.CallFunction("registration_sync")
# the rollback removes the initial installation repository with
# the base product, initialize it again
Yast::Packages.init_called = false
Yast::Packages.Init
end

def migration_repos
Yast::WFM.CallFunction("migration_repos", [{ "enable_back" => true }])
Yast::WFM.CallFunction("inst_migration_repos", [{ "enable_back" => true }])
end
end
end
Expand Down
13 changes: 7 additions & 6 deletions test/offline_migration_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

describe Registration::UI::OfflineMigrationWorkflow do
describe "#main" do
it "runs the 'migration_repos' client" do
expect(Yast::WFM).to receive(:CallFunction).with("migration_repos", anything)
it "runs the 'inst_migration_repos' client" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_migration_repos", anything)
subject.main
end

it "returns the 'migration_repos' result" do
expect(Yast::WFM).to receive(:CallFunction).with("migration_repos", anything).and_return(:foo)
it "returns the 'inst_migration_repos' result" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_migration_repos", anything)
.and_return(:foo)
expect(subject.main).to eq(:foo)
end

context "the 'migration_repos' client returns :rollback" do
context "the 'inst_migration_repos' client returns :rollback" do
before do
expect(Yast::WFM).to receive(:CallFunction).with("migration_repos", anything)
expect(Yast::WFM).to receive(:CallFunction).with("inst_migration_repos", anything)
.and_return(:rollback)
allow(Yast::WFM).to receive(:CallFunction).with("registration_sync")
end
Expand Down

0 comments on commit 22a3800

Please sign in to comment.