Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
- initialize the connection object when reading addons (otherwise a "nil" bug
  appears when going back in the installation workflow)
- cache the registration server URL (to use the same server when going back)
- added "nil" check for long product description
- typo in a logger call
- 3.1.45
  • Loading branch information
lslezak committed May 5, 2014
1 parent 6e378ac commit 9e1a837
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
12 changes: 12 additions & 0 deletions package/yast2-registration.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
-------------------------------------------------------------------
Mon May 5 15:54:04 UTC 2014 - lslezak@suse.cz

- initialize the connection object when reading addons
(otherwise a "nil" bug appears when going back in the
installation workflow)
- cache the registration server URL (to use the same server when
going back)
- added "nil" check for long product description
- typo in a logger call
- 3.1.45

-------------------------------------------------------------------
Mon May 5 15:34:47 UTC 2014 - 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.44
Version: 3.1.45
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
13 changes: 10 additions & 3 deletions src/clients/inst_scc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def register_base_system
# reset the user input in case an exception is raised
ret = nil

url = ::Registration::Helpers.registration_url
@registration = ::Registration::Registration.new(url)
init_registration

::Registration::SccHelpers.catch_registration_errors do
distro_target = ::Registration::SwMgmt.find_base_product["register_target"]
Expand Down Expand Up @@ -456,7 +455,7 @@ def addon_regcode_items(addons)

addons.each do |addon|
label = addon.short_name
label << " (#{addon.long_name})" unless addon.long_name.empty?
label << " (#{addon.long_name})" if addon.long_name && !addon.long_name.empty?

box[box.size] = MinWidth(REG_CODE_WIDTH, InputField(Id(addon.product_ident), label,
@known_reg_codes.fetch(addon.product_ident, "")))
Expand Down Expand Up @@ -570,6 +569,8 @@ def register_selected_addons
}
end

init_registration

product_succeed = product.map do |product|
::Registration::SccHelpers.catch_registration_errors("#{product["name"]}:") do
product_service = Popup.Feedback(
Expand Down Expand Up @@ -736,6 +737,12 @@ def start_workflow
log.info "Starting scc sequence"
Sequencer.Run(aliases, sequence)
end

def init_registration
url = ::Registration::Helpers.registration_url
@registration = ::Registration::Registration.new(url)
end

end unless defined?(InstSccClient)
end

Expand Down
28 changes: 22 additions & 6 deletions src/lib/registration/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require "yast"
require "uri"

require "registration/storage"

module Registration

class Helpers
Expand Down Expand Up @@ -70,14 +72,28 @@ def self.language
# for details
# @return [String,nil] registration URL, nil means use the default
def self.registration_url
# cache the URL to use the same server for all operations
cache = ::Registration::Storage::Cache.instance
return cache.reg_url if cache.reg_url

# TODO FIXME: handle autoyast mode as well, currently it is handled in scc_auto client
return reg_url_at_upgrade if Yast::Mode.update
return reg_url_at_installation if Yast::Mode.installation
return reg_url_at_runnig_system if Yast::Mode.normal
# see https://github.com/yast/yast-yast2/blob/master/library/general/src/modules/Mode.rb#L105
url = case Yast::Mode.mode
when "installation"
reg_url_at_installation
when "normal"
reg_url_at_runnig_system
when "update"
reg_url_at_upgrade
else
log.warn "Unknown mode: #{Yast::Mode.mode}, using default URL"
# use the default
nil
end

log.warn "Unknown mode: #{Mode.mode} using default URL"
# no custom URL, use the default
nil
# cache the URL
::Registration::Storage::Cache.instance.reg_url = url
url
end

# convert service URL to plain URL, remove the SLP service prefix
Expand Down
2 changes: 1 addition & 1 deletion src/lib/registration/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def initialize
end
end

class Cache < Struct.new(:available_addons)
class Cache < Struct.new(:available_addons, :reg_url)
include Singleton
end

Expand Down
2 changes: 1 addition & 1 deletion src/lib/registration/sw_mgmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def self.each_repo(repo_aliases, &block)
if repo
yield(repo)
else
log.warning "Repository '#{repo_alias}' was not found, skipping"
log.warn "Repository '#{repo_alias}' was not found, skipping"
end
end
end
Expand Down
11 changes: 5 additions & 6 deletions test/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
stub_const("Yast::Mode", yast_mode)
stub_const("Yast::Linuxrc", yast_linuxrc)
stub_const("Yast::WFM", yast_wfm)
# reset the cache befor each test
::Registration::Storage::Cache.instance.reg_url = nil
end

context "at installation" do
before do
allow(yast_mode).to receive(:installation).and_return(true)
allow(yast_mode).to receive(:update).and_return(false)
allow(yast_mode).to receive(:normal).and_return(false)
allow(yast_mode).to receive(:mode).and_return("installation")
end

context "no local registration server is announced via SLP" do
Expand Down Expand Up @@ -65,9 +65,8 @@

context "at installed system" do
before do
allow(yast_mode).to receive(:normal).and_return(true)
allow(yast_mode).to receive(:update).and_return(false)
allow(yast_mode).to receive(:installation).and_return(false)
allow(yast_mode).to receive(:mode).and_return("normal")

# FIXME: stub SLP service discovery, later add config file reading
expect(yast_wfm).to receive(:call).with("discover_registration_services").and_return(nil)
end
Expand Down

0 comments on commit 9e1a837

Please sign in to comment.