From af58c49ec9a73d960bc30a7b1f3f12b02da6deca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Thu, 1 Feb 2018 21:22:52 +0100 Subject: [PATCH] Support for the SLE11 migration --- .../clients/inst_migration_repos.rb | 19 ++-------- src/lib/registration/registration.rb | 6 +--- .../ui/migration_repos_workflow.rb | 9 +++-- test/inst_migration_repos_spec.rb | 13 ------- test/registration_spec.rb | 35 ++++--------------- 5 files changed, 17 insertions(+), 65 deletions(-) diff --git a/src/lib/registration/clients/inst_migration_repos.rb b/src/lib/registration/clients/inst_migration_repos.rb index 572db7333..a7b13171c 100644 --- a/src/lib/registration/clients/inst_migration_repos.rb +++ b/src/lib/registration/clients/inst_migration_repos.rb @@ -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 diff --git a/src/lib/registration/registration.rb b/src/lib/registration/registration.rb index 479cd0a59..9875dbece 100644 --- a/src/lib/registration/registration.rb +++ b/src/lib/registration/registration.rb @@ -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? diff --git a/src/lib/registration/ui/migration_repos_workflow.rb b/src/lib/registration/ui/migration_repos_workflow.rb index 1d8515874..fa664455d 100644 --- a/src/lib/registration/ui/migration_repos_workflow.rb +++ b/src/lib/registration/ui/migration_repos_workflow.rb @@ -36,6 +36,7 @@ class MigrationReposWorkflow < WizardClient Yast.import "Stage" Yast.import "SourceDialogs" Yast.import "Linuxrc" + Yast.import "Installation" # the constructor def initialize @@ -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}" @@ -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? diff --git a/test/inst_migration_repos_spec.rb b/test/inst_migration_repos_spec.rb index dcfadbf12..9d8213a93 100644 --- a/test/inst_migration_repos_spec.rb +++ b/test/inst_migration_repos_spec.rb @@ -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 diff --git a/test/registration_spec.rb b/test/registration_spec.rb index 589a74164..171a66a5a 100644 --- a/test/registration_spec.rb +++ b/test/registration_spec.rb @@ -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) @@ -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