Skip to content

Commit

Permalink
Better handle invalid credentials (bsc#941427)
Browse files Browse the repository at this point in the history
Start the repository manager to remove the offending service/repository.
  • Loading branch information
lslezak committed Oct 3, 2016
1 parent a9267ce commit 314fd6d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
8 changes: 8 additions & 0 deletions package/yast2-registration.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Mon Oct 3 19:11:11 UTC 2016 - lslezak@suse.cz

- Better handle invalid credentials at start - start the repository
manager to allow manually removing the offending service or
repository (bsc#941427)
- 3.1.190

-------------------------------------------------------------------
Mon Oct 3 09:26:28 UTC 2016 - jreidinger@suse.com

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


Name: yast2-registration
Version: 3.1.189
Version: 3.1.190
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
15 changes: 15 additions & 0 deletions src/clients/scc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
require "yast"
require "registration/sw_mgmt"

# HTML escaping
require "cgi/util"

module Yast
class SccClient < Client
include Yast::Logger

Yast.import "CommandLine"
Yast.import "Pkg"
Yast.import "Report"
Expand All @@ -51,6 +56,16 @@ def main
::Registration::SwMgmt.init

return WFM.call("inst_scc", WFM.Args)
rescue Registration::SourceRestoreError => e
# TRANSLATORS: Error message in RichText format, %s contains the details from libzypp
Report.LongError(_("<p>The repository initialization failed. " \
"Disable (or remove) the offending service or repository " \
"in the repository manager.</p><p>Details:</p><p>%s</p>") % CGI.escapeHTML(e.message))
ret = WFM.call("repositories", WFM.Args)
log.info "repository manager result: #{ret}"
# drop all loaded repos, force complete reloading
Pkg.SourceFinishAll
retry if ret == :next
ensure
Wizard.CloseDialog
end
Expand Down
3 changes: 3 additions & 0 deletions src/lib/registration/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def initialize(msg, service)
end
end

class SourceRestoreError < PkgError
end

# generic download error
class DownloadError < RuntimeError
end
Expand Down
6 changes: 3 additions & 3 deletions src/lib/registration/sw_mgmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def self.init(load_packages = false)

raise_pkg_exception unless Pkg.TargetInitialize(Installation.destdir)
raise_pkg_exception unless Pkg.TargetLoad
raise_pkg_exception unless Pkg.SourceRestore
raise_pkg_exception(SourceRestoreError) unless Pkg.SourceRestore

raise_pkg_exception if load_packages && !Pkg.SourceLoad
end
Expand Down Expand Up @@ -499,8 +499,8 @@ def self.get_release_type(product)
product["register_release"]
end

def self.raise_pkg_exception
raise PkgError.new, Pkg.LastError
def self.raise_pkg_exception(klass = PkgError)
raise klass, Pkg.LastError
end

private_class_method :each_repo
Expand Down
11 changes: 10 additions & 1 deletion test/sw_mgmt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,23 @@
context "when the libzypp lock can be obtained" do
let(:connected) { true }

it "initializes package management" do
before do
expect(Yast::PackageCallbacks).to receive(:InitPackageCallbacks)
expect(Yast::Pkg).to receive(:TargetInitialize).and_return(true)
expect(Yast::Pkg).to receive(:TargetLoad).and_return(true)
end

it "initializes package management" do
expect(Yast::Pkg).to receive(:SourceRestore).and_return(true)

subject.init
end

it "raises SourceRestoreError exception when the repository restore fails" do
expect(Yast::Pkg).to receive(:SourceRestore).and_return(false)

expect { subject.init }.to raise_exception(Registration::SourceRestoreError)
end
end

context "when the libzypp lock cannot be obtained" do
Expand Down

0 comments on commit 314fd6d

Please sign in to comment.