Skip to content

Commit

Permalink
Support for the SLE11 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 2, 2018
1 parent 6634495 commit af58c49
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 65 deletions.
19 changes: 2 additions & 17 deletions src/lib/registration/clients/inst_migration_repos.rb
Expand Up @@ -42,23 +42,8 @@ def set_target_path
destdir = Yast::Installation.destdir || "/"
return if destdir == "/"

log.info("Setting SUSEConnect target directory: #{destdir}")
SUSE::Connect::System.filesystem_root = destdir

# copy the old config from the upgraded system to inst-sys
# to correctly work in the SMT case
# FIXME: this should not be needed, it should be possible to read
# the config from the /mnt directly...
target_path = SUSE::Connect::YaST::DEFAULT_CONFIG_FILE
source_path = File.join(destdir, target_path)

if File.exist?(source_path)
log.info("Copying #{source_path} -> #{target_path}")
::FileUtils.cp(source_path, target_path)
elsif File.exist?(target_path)
log.info("Removing #{target_path}...")
::FileUtils.rm(target_path)
end
# copy the old NCC/SCC credentials
SwMgmt.copy_old_credentials(destdir)
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions src/lib/registration/registration.rb
Expand Up @@ -208,11 +208,7 @@ def get_updates_list

# Full path to the SCC credentials file.
def self.credentials_path
# Use /mnt only at upgrade, during installation /mnt is not yet mounted
# at the registration step, the credentials are later copied to
# the target system
prefix = (Yast::Stage.initial && Yast::Mode.update) ? Yast::Installation.destdir : "/"
File.join(prefix, SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE
end

def self.is_registered?
Expand Down
9 changes: 7 additions & 2 deletions src/lib/registration/ui/migration_repos_workflow.rb
Expand Up @@ -36,6 +36,7 @@ class MigrationReposWorkflow < WizardClient
Yast.import "Stage"
Yast.import "SourceDialogs"
Yast.import "Linuxrc"
Yast.import "Installation"

# the constructor
def initialize
Expand Down Expand Up @@ -215,7 +216,10 @@ def find_products
return :abort
end

merge_registered_addons
# do not read addons when upgrading from an NCC based system (SLE11)
ncc_file = File.join(Yast::Installation.destdir,
SUSE::Connect::YaST::DEFAULT_CREDENTIALS_DIR, "NCCcredentials")
merge_registered_addons unless File.exist?(ncc_file)

log.info "Products to migrate: #{products}"

Expand Down Expand Up @@ -293,7 +297,8 @@ def load_migration_products_offline
release_type: nil
)

log.info "Loading offline migration products from the server..."
log.info "Loading offline migrations for target product: #{remote_product.inspect}"
log.info "Installed products: #{products.inspect}"
self.migrations = registration_ui.offline_migration_products(products, remote_product)

if migrations.empty?
Expand Down
13 changes: 0 additions & 13 deletions test/inst_migration_repos_spec.rb
Expand Up @@ -6,23 +6,10 @@

describe Registration::Clients::InstMigrationRepos do
before do
allow(SUSE::Connect::System).to receive(:filesystem_root=)
allow(Yast::Installation).to receive(:destdir).and_return("/")
allow(Yast::WFM).to receive(:call)
end

it "passes the target path to SUSEConnect" do
destdir = "/foo"
expect(Yast::Installation).to receive(:destdir).and_return(destdir).at_least(:once)
expect(SUSE::Connect::System).to receive(:filesystem_root=).with(destdir)
subject.main
end

it "does not pass the path if it is \"/\"" do
expect(SUSE::Connect::System).to_not receive(:filesystem_root=)
subject.main
end

it "runs the standard \"migration_repos\" client" do
expect(Yast::WFM).to receive(:call).with("migration_repos")
subject.main
Expand Down
35 changes: 7 additions & 28 deletions test/registration_spec.rb
Expand Up @@ -77,20 +77,6 @@
expect(registered_service).to eq(service)
end

it "honors the target system prefix at upgrade" do
expect(Yast::Mode).to receive(:update).and_return(true)
expect(Yast::Stage).to receive(:initial).and_return(true)
expect(Yast::Installation).to receive(:destdir).and_return(destdir)

expect(File).to receive(:exist?).with(/\A#{Regexp.escape(destdir)}\//)
.and_return(true)

expect(File).to receive(:read).with(/\A#{Regexp.escape(destdir)}\//)
.and_return("username=SCC_foo\npassword=bar")

subject.send(yast_method, product)
end

it "does not add the target system prefix if not at upgrade" do
allow(Yast::Mode).to receive(:update).and_return(false)
allow(Yast::Stage).to receive(:initial).and_return(false)
Expand Down Expand Up @@ -279,23 +265,16 @@
end

describe ".is_registered?" do
let(:destdir) { "/foo" }

it "honors the target system prefix at upgrade" do
expect(Yast::Mode).to receive(:update).and_return(true)
expect(Yast::Stage).to receive(:initial).and_return(true)
expect(Yast::Installation).to receive(:destdir).and_return(destdir)
expect(File).to receive(:exist?).with(/\A#{Regexp.escape(destdir)}/)
Registration::Registration.is_registered?
it "returns true if the global credentials file exists" do
expect(File).to receive(:exist?).with(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
.and_return(true)
expect(Registration::Registration.is_registered?).to eq(true)
end

it "does not add the prefix if not at upgrade" do
allow(Yast::Mode).to receive(:update).and_return(false)
allow(Yast::Stage).to receive(:initial).and_return(false)
expect(Yast::Installation).to_not receive(:destdir)
it "returns false if the global credentials file exists" do
expect(File).to receive(:exist?).with(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
Registration::Registration.is_registered?
.and_return(false)
expect(Registration::Registration.is_registered?).to eq(false)
end

end
end

0 comments on commit af58c49

Please sign in to comment.