Skip to content

Commit

Permalink
rollback only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Sep 22, 2015
1 parent 9d6791b commit 92025ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
18 changes: 5 additions & 13 deletions src/lib/migration/main_workflow.rb
Expand Up @@ -83,16 +83,17 @@ def run
next: "online_update"
},
"online_update" => {
abort: "restore",
abort: :abort,
restart: "restart_after_update",
next: "repositories"
},
"restart_after_update" => {
restart: :restart
},
"repositories" => {
abort: "restore",
next: "proposals"
abort: :abort,
rollback: "rollback",
next: "proposals"
},
"proposals" => {
abort: "rollback",
Expand All @@ -106,9 +107,6 @@ def run
abort: :abort,
next: "restart_after_migration"
},
"restore" => {
abort: :abort
},
"restart_after_migration" => {
restart: :restart
},
Expand All @@ -134,7 +132,6 @@ def aliases
"create_backup" => ->() { create_backup },
"online_update" => ->() { online_update },
"restart_after_update" => ->() { restart_yast(:restart_after_update) },
"restore" => ->() { restore_state },
"rollback" => ->() { rollback },
"perform_migration" => ->() { perform_migration },
"proposals" => ->() { proposals },
Expand Down Expand Up @@ -181,14 +178,9 @@ def online_update
:restart
end

def restore_state
Yast::Update.restore_backup

:abort
end

def rollback
Yast::WFM.CallFunction("registration_sync")
:abort
end

def repositories
Expand Down
13 changes: 8 additions & 5 deletions test/main_workflow_test.rb
Expand Up @@ -40,10 +40,10 @@ def mock_client(name, res)
mock_client("inst_kickoff", :next)
mock_client("inst_rpmcopy", :next)
mock_client("migration_finish", :next)
mock_client("registration_sync", :next)

allow(Yast::Update).to receive(:clean_backup)
allow(Yast::Update).to receive(:create_backup)
allow(Yast::Update).to receive(:restore_backup)

allow(Yast::SCR).to receive(:Execute).with(bash_path, /snapper .*list-configs/)
.and_return(cmd_success)
Expand Down Expand Up @@ -74,12 +74,15 @@ def mock_client(name, res)
expect(::Migration::MainWorkflow.run).to eq :restart
end

it "restores repositories when clicking on Cancel" do
expect(Yast::Update).to receive(:clean_backup)
expect(Yast::Update).to receive(:create_backup)
expect(Yast::Update).to receive(:restore_backup)
it "aborts without rollback when the migration selection is aborted" do
mock_client(["migration_repos", [{ "enable_back" => false }]], :abort)

expect(::Migration::MainWorkflow.run).to eq :abort
end

it "rolls back the registration after registering migration products" do
mock_client(["migration_proposals", [{ "hide_export" => true }]], :abort)
expect(Yast::WFM).to receive(:CallFunction).with("registration_sync")

expect(::Migration::MainWorkflow.run).to eq :abort
end
Expand Down

0 comments on commit 92025ea

Please sign in to comment.