Skip to content

Commit

Permalink
Merge pull request #48 from yast/merge_SP1
Browse files Browse the repository at this point in the history
[master] Workarounds for the openSUSE => SLES migration
  • Loading branch information
lslezak committed May 31, 2019
2 parents 486338d + 7596660 commit afeea3c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
10 changes: 10 additions & 0 deletions package/yast2-migration.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Thu May 30 14:08:16 UTC 2019 - Ladislav Slezák <lslezak@suse.cz>

- Fixes for the openSUSE Leap => SLES migration (jsc#SLE-7006)
- Enable the openSUSE => SUSE vendor change
- Disable all other repositories (esp. the default OSS and
non-OSS repositories) which could collide with the new SLES
repositories
- 4.1.2

-------------------------------------------------------------------
Thu Nov 29 09:15:35 UTC 2018 - lslezak@suse.cz

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-migration.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-migration
Version: 4.1.1
Version: 4.1.2
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
48 changes: 46 additions & 2 deletions src/lib/migration/main_workflow.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------
# Copyright (c) 2015 SUSE LLC, All Rights Reserved.
# Copyright (c) 2015-2019 SUSE LLC, All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
Expand All @@ -26,6 +26,7 @@
Yast.import "Report"
Yast.import "Pkg"
Yast.import "Installation"
Yast.import "OSRelease"
Yast.import "PackageCallbacks"

require "migration/finish_dialog"
Expand All @@ -47,6 +48,14 @@ class MainWorkflow
"--cleanup-algorithm=number --print-number --userdata important=yes " \
"--description=\"%{description}\"".freeze

# a temporary vendor configuration file
VENDOR_FILE = "/etc/zypp/vendors.d/YaST_openSUSE_migration.conf".freeze

# content of the vendor configuation file,
# make the "openSUSE" and "SUSE" vendors equal, allow to change
# the vendor from "openSUSE" to "SUSE"
VENDOR_CONTENT = "[main]\nvendors=openSUSE,SUSE\n".freeze

def self.run
workflow = new
workflow.run
Expand All @@ -60,13 +69,14 @@ def run
Yast::Wizard.CreateDialog
Yast::Sequencer.Run(aliases, WORKFLOW_SEQUENCE)
ensure
vendor_cleanup
Yast::Wizard.CloseDialog
end
end

private

# remeber the "pre" snapshot id (needed for the "post" snapshot)
# remember the "pre" snapshot id (needed for the "post" snapshot)
attr_accessor :pre_snapshot

WORKFLOW_SEQUENCE = {
Expand Down Expand Up @@ -184,6 +194,7 @@ def rollback
end

def repositories
prepare_repos
Yast::WFM.CallFunction("migration_repos", [{ "enable_back" => false }])
end

Expand Down Expand Up @@ -319,7 +330,11 @@ def restart_yast(step)
:restart
end

# Initialize the package manager (libzypp)
def init_pkg_mgmt
# the vendor configuration file must be created *before* initializing libzypp
vendor_init

# display progress when refreshing repositories
Yast::PackageCallbacks.InitPackageCallbacks

Expand All @@ -332,5 +347,34 @@ def init_pkg_mgmt

ret
end

# Enable the openSUSE => SUSE vendor change when migrating from
# an openSUSE distribution to SLE.
def vendor_init
File.write(VENDOR_FILE, VENDOR_CONTENT) if opensuse?
end

# Remove the vendor configuration file
def vendor_cleanup
File.delete(VENDOR_FILE) if File.exist?(VENDOR_FILE)
end

# Prepare the repositories for the online migration.
# This mainly activates some workarounds in the openSUSE => SLE migration
def prepare_repos
return unless opensuse?

# disable all enabled repositories, the migration only removes (upgrades)
# the repositories from the registration server (SCC), all other repositories
# (like the default OSS and non-OSS repos) would collide with the new SLES repos
Yast::Pkg.SourceGetCurrent(true).each { |r| Yast::Pkg.SourceSetEnabled(r, false) }
end

# Running in an openSUSE distribution?
#
# @return [Boolean] True if running in an openSUSE distribution, false otherwise
def opensuse?
Yast::OSRelease.id.match?(/opensuse/i)
end
end
end
25 changes: 25 additions & 0 deletions test/main_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def mock_client(name, res)
allow(Yast::Pkg).to receive(:TargetLoad).and_return(true)
allow(Yast::Pkg).to receive(:SourceRestore).and_return(true)
allow(Yast::Pkg).to receive(:SourceLoad).and_return(true)
allow(Yast::OSRelease).to receive(:id).and_return("sles")
allow(File).to receive(:delete).with(Migration::MainWorkflow::VENDOR_FILE)
end

it "pass workflow sequence to Yast sequencer" do
Expand Down Expand Up @@ -154,5 +156,28 @@ def mock_client(name, res)

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

context "in openSUSE Leap" do
before do
allow(Yast::OSRelease).to receive(:id).and_return("opensuse-leap")
allow(File).to receive(:write).with(Migration::MainWorkflow::VENDOR_FILE, anything)
allow(Yast::Pkg).to receive(:SourceGetCurrent).and_return([])
allow(Yast::Pkg).to receive(:SourceSetEnabled)
end

it "writes the vendor config file" do
expect(File).to receive(:write).with(Migration::MainWorkflow::VENDOR_FILE,
Migration::MainWorkflow::VENDOR_CONTENT)

::Migration::MainWorkflow.run
end

it "disables all current repositories" do
expect(Yast::Pkg).to receive(:SourceGetCurrent).and_return([42])
expect(Yast::Pkg).to receive(:SourceSetEnabled).with(42, false)

::Migration::MainWorkflow.run
end
end
end
end

0 comments on commit afeea3c

Please sign in to comment.