Skip to content

Commit

Permalink
Restore the repository setup after going back
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 16, 2018
1 parent 4f397bc commit 60dcfa3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
36 changes: 32 additions & 4 deletions src/lib/registration/ui/offline_migration_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class OfflineMigrationWorkflow

Yast.import "GetInstArgs"
Yast.import "Packages"
Yast.import "Installation"
Yast.import "Wizard"
Yast.import "Pkg"

# the constructor
def initialize
Expand All @@ -40,15 +43,21 @@ def initialize
def main
log.info "Starting offline migration sequence"

# display an empty dialog just to hide the content of the previous step
Yast::Wizard.ClearContents

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

if Registration.is_registered?
log.info("Restoring the previous registration")
rollback
restore_installation_repos
end

return :back
else
backup_installation_repos
end

# run the main registration migration
Expand All @@ -68,15 +77,34 @@ 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

if Yast::Stage.initial && File.exist?(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
log.info("Removing #{SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE}...")
File.delete(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
end
end

def migration_repos
Yast::WFM.CallFunction("inst_migration_repos", [{ "enable_back" => true }])
end

def backup_installation_repos
ids = Yast::Pkg.SourceGetCurrent(false)
@@repos_backup = ids.map { |r| Yast::Pkg.SourceGeneralData(r) }
end

def restore_installation_repos
return unless @@repos_backup
Yast::Pkg.SourceFinishAll
Yast::Pkg.TargetFinish
Yast::Pkg.TargetInitialize("/")

@@repos_backup.each { |r| Yast::Pkg.RepositoryAdd(r) }

Yast::Pkg.SourceLoad
Yast::Pkg.TargetFinish
Yast::Pkg.TargetInitialize(Yast::Installation.destdir)
end
end
end
end
1 change: 1 addition & 0 deletions src/lib/registration/ui/registration_sync_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RegistrationSyncWorkflow < WizardClient
Yast.import "Pkg"
Yast.import "Update"
Yast.import "Installation"
Yast.import "Stage"

# the constructor
def initialize
Expand Down
2 changes: 1 addition & 1 deletion test/inst_migration_repos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

it "runs the standard \"migration_repos\" client" do
expect(Yast::WFM).to receive(:call).with("migration_repos")
expect(Yast::WFM).to receive(:call).with("migration_repos", anything)
subject.main
end
end
6 changes: 6 additions & 0 deletions test/offline_migration_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

describe Registration::UI::OfflineMigrationWorkflow do
describe "#main" do
before do
allow(Yast::Wizard).to receive(:SetContents)
allow(Yast::Packages).to receive(:init_called=)
allow(Yast::Packages).to receive(:Initialize)
end

it "runs the 'inst_migration_repos' client" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_migration_repos", anything)
subject.main
Expand Down

0 comments on commit 60dcfa3

Please sign in to comment.