Skip to content

Commit

Permalink
add prefix to addon registration and register as much addons as possi…
Browse files Browse the repository at this point in the history
…ble (bnc#872481)
  • Loading branch information
jreidinger committed May 5, 2014
1 parent 960753c commit 6172f19
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
25 changes: 13 additions & 12 deletions src/clients/inst_scc.rb
Expand Up @@ -139,7 +139,7 @@ def register_base_system

base_product = ::Registration::SwMgmt.base_product_to_register
base_product["reg_code"] = reg_code
registered_services = @registration.register_products([base_product])
registered_services = @registration.register_product(base_product)

# remember the base products for later (to get the respective addons)
::Registration::Storage::BaseProduct.instance.product = base_product
Expand Down Expand Up @@ -570,21 +570,22 @@ def register_selected_addons
}
end

ret = ::Registration::SccHelpers.catch_registration_errors do
product_services = Popup.Feedback(
n_("Registering Product...", "Registering Products...", products.size),
_("Contacting the SUSE Customer Center server")) do
product_succeed = product.map do |product|
::Registration::SccHelpers.catch_registration_errors("#{product["name"]}:") do
product_service = Popup.Feedback(
# %s is name of given product
_("Registering Product %s ...") % product["name"],
_("Contacting the SUSE Customer Center server")) do

@registration.register_products(products)
end

# select repositories to use in installation (e.g. enable/disable Updates)
select_repositories(product_services) if Mode.installation
@registration.register_product(product)
end

return true
# select repositories to use in installation (e.g. enable/disable Updates)
select_repositories(product_service) if Mode.installation
end
end

return ret
return !product_succeed.include?(false) # succeed only if noone failed
end

# run the addon reg codes dialog
Expand Down
11 changes: 6 additions & 5 deletions src/lib/registration/connect_helpers.rb
Expand Up @@ -49,7 +49,8 @@ class SccHelpers
Yast.import "Popup"
Yast.import "Report"

def self.catch_registration_errors(&block)
# @param prefix[String] Prefix before error like affected product or addon
def self.catch_registration_errors(prefix = "", &block)
begin
# reset the previous SSL errors
Storage::SSLErrors.instance.reset
Expand Down Expand Up @@ -79,13 +80,13 @@ def self.catch_registration_errors(&block)
case e.response
when Net::HTTPUnauthorized, Net::HTTPUnprocessableEntity
# Error popup
report_error(_("The email address is not known or\nthe registration code is not valid."), e)
report_error(prefix + _("The email address is not known or\nthe registration code is not valid."), e)
when Net::HTTPClientError
report_error(_("Registration client error."), e)
report_error(prefix + _("Registration client error."), e)
when Net::HTTPServerError
report_error(_("Registration server error.\nRetry registration later."), e)
report_error(prefix + _("Registration server error.\nRetry registration later."), e)
else
report_error(_("Registration failed."), e)
report_error(prefix + _("Registration failed."), e)
end
false
rescue ::Registration::ServiceError => e
Expand Down
35 changes: 16 additions & 19 deletions src/lib/registration/registration.rb
Expand Up @@ -58,33 +58,30 @@ def register(email, reg_code, distro_target)
end


def register_products(products)
product_services = products.map do |product|

product_ident = {
:arch => product["arch"],
:name => product["name"],
:version => product["version"],
:release_type => product["release_type"]
}
log.info "Registering product: #{product_ident}"
def register_product(product)
product_ident = {
:arch => product["arch"],
:name => product["name"],
:version => product["version"],
:release_type => product["release_type"]
}
log.info "Registering product: #{product_ident}"

params = connect_params(:product_ident => product_ident)
params = connect_params(:product_ident => product_ident)

# use product specific reg. code (e.g. for addons)
params[:token] = product["reg_code"] if product["reg_code"]
# use product specific reg. code (e.g. for addons)
params[:token] = product["reg_code"] if product["reg_code"]

SUSE::Connect::YaST.activate_product(params)
end
product_service = SUSE::Connect::YaST.activate_product(params)

log.info "registered product_services: #{product_services.inspect}"
log.info "registered product_services: #{product_service.inspect}"

if !product_services.empty?
if product_service
credentials = SUSE::Connect::Credentials.read(SCC_CREDENTIALS)
::Registration::SwMgmt.add_services(product_services, credentials)
::Registration::SwMgmt.add_services([product_service], credentials)
end

product_services
product_service ? [product_service] : []
end

def get_addon_list
Expand Down
4 changes: 2 additions & 2 deletions test/registration_spec.rb
Expand Up @@ -32,7 +32,7 @@
end
end

describe ".register_products" do
describe ".register_product" do
it "registers the selected product and returns added zypp services" do
product = {
"arch" => "x86_64",
Expand Down Expand Up @@ -60,7 +60,7 @@
expect(SUSE::Connect::Credentials).to receive(:read)
.with(SUSE::Connect::Credentials::GLOBAL_CREDENTIALS_FILE)

service_list = Registration::Registration.new.register_products([product])
service_list = Registration::Registration.new.register_product(product)
expect(service_list).to eq([service])
end
end
Expand Down

0 comments on commit 6172f19

Please sign in to comment.