Skip to content

Commit

Permalink
AY: Providing a "retry" button if a request timed out. (#470)
Browse files Browse the repository at this point in the history
* AY: Providing a retry button if a request timed out.
  • Loading branch information
schubi2 committed Jan 15, 2020
1 parent 746b3d4 commit 43e8c4e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
7 changes: 7 additions & 0 deletions package/yast2-registration.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Jan 15 12:44:24 CET 2020 - schubi@suse.de

- AY: Providing a "retry" button if a request timed out.
(bsc#1159277)
- 4.2.26

-------------------------------------------------------------------
Tue Jan 14 15:04:15 UTC 2020 - Josef Reidinger <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: 4.2.25
Version: 4.2.26
Release: 0
Summary: YaST2 - Registration Module
License: GPL-2.0-only
Expand Down
24 changes: 12 additions & 12 deletions src/lib/registration/connect_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def self.catch_registration_errors(message_prefix: "",
rescue Timeout::Error => e
# Error popup
log.error "Timeout error: #{e.message}"
# FIXME: to not break existing translation, this typo should be fixed
# later after SP2: time -> timed
retry if report_error_and_retry?(message_prefix + _("Connection time out."),
retry if report_error_and_retry?(message_prefix + _("Connection timed out."),
_("Make sure that the registration server is reachable and\n" \
"the connection is reliable."))

Expand Down Expand Up @@ -158,17 +156,19 @@ def self.report_error(msg, error_message)
end

def self.details_error(msg, error_message, retry_button: false)
if Yast::Mode.auto
if Yast::Mode.auto && !retry_button
# AY mode and no retry button available
report_error(msg, error_message)
else
buttons =
if retry_button
{ retry: Yast::Label.RetryButton, cancel: Yast::Label.CancelButton }
else
:ok
end
Yast2::Popup.show(msg, details: error_message, headline: :error, buttons: buttons)
return
end

buttons =
if retry_button
{ retry: Yast::Label.RetryButton, cancel: Yast::Label.CancelButton }
else
:ok
end
Yast2::Popup.show(msg, details: error_message, headline: :error, buttons: buttons)
end

def self.report_error_and_retry?(msg, details_message)
Expand Down
11 changes: 9 additions & 2 deletions src/lib/registration/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def register(email, reg_code, distro_target)
)

log.info "Announcing system with distro_target: #{distro_target}"
login, password = SUSE::Connect::YaST.announce_system(settings, distro_target)
login = ""
password = ""
ConnectHelpers.catch_registration_errors do
login, password = SUSE::Connect::YaST.announce_system(settings, distro_target)
end
log.info "Global SCC credentials (username): #{login}"

# write the global credentials
Expand Down Expand Up @@ -210,7 +214,10 @@ def get_updates_list

log.info "Reading available updates for product: #{product["name"]}"
remote_product = SwMgmt.remote_product(product)
updates = SUSE::Connect::YaST.list_installer_updates(remote_product, connect_params)
updates = []
ConnectHelpers.catch_registration_errors do
updates = SUSE::Connect::YaST.list_installer_updates(remote_product, connect_params)
end

log.info "Updates for '#{product["name"]}' are available at '#{updates}'"
updates
Expand Down
15 changes: 6 additions & 9 deletions test/connect_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ def api_error(code: 400, headers: {}, body: {})

context "and in AutoYaST mode" do
let(:autoinst?) { true }

it "reports an error with details on timeout" do
expect(subject).to receive(:wrap_text).with("Details: #{details}", screen_width - 4)
.and_return("Details wrapped text")
expect(Yast::Report).to receive(:Error).with(
"Registration: " + _("Connection time out.") + "\n\nDetails wrapped text"
)
it "shows an error dialog with a retry and details button" do
expect(Yast2::Popup).to receive(:show)
# A retry should be provided. So no "common" AY error report.
expect(Yast::Report).not_to receive(:Error)

helpers.catch_registration_errors(message_prefix: "Registration: ") do
raise Timeout::Error
Expand All @@ -76,7 +73,7 @@ def api_error(code: 400, headers: {}, body: {})
context "and in a common installation" do
it "shows an error dialog with a retry and details button" do
expect(helpers).to receive(:report_error_and_retry?)
.with("Registration: " + _("Connection time out."), details)
.with("Registration: " + _("Connection timed out."), details)

helpers.catch_registration_errors(message_prefix: "Registration: ") do
raise Timeout::Error
Expand All @@ -85,7 +82,7 @@ def api_error(code: 400, headers: {}, body: {})

it "retries the given block if selected by the user" do
expect(helpers).to receive(:report_error_and_retry?).twice
.with("Registration: " + _("Connection time out."), details).and_return(true, false)
.with("Registration: " + _("Connection timed out."), details).and_return(true, false)

helpers.catch_registration_errors(message_prefix: "Registration: ") do
raise Timeout::Error
Expand Down
2 changes: 1 addition & 1 deletion test/migration_repos_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
.and_return([load_yaml_fixture("products_legacy_installation.yml")[1]])
expect_any_instance_of(Registration::RegistrationUI).to receive(:migration_products)
.and_return([])
expect(Yast::Report).to receive(:Error)
expect(Yast::Report).to receive(:Error).at_least(:once)

expect(subject.run).to eq(:abort)
end
Expand Down

0 comments on commit 43e8c4e

Please sign in to comment.