Skip to content

Commit

Permalink
small refactoring - share the common code
Browse files Browse the repository at this point in the history
between the standard and Autoyast client
  • Loading branch information
lslezak committed Aug 29, 2014
1 parent 354fe46 commit 6ac6c9f
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 196 deletions.
123 changes: 27 additions & 96 deletions src/clients/inst_scc.rb
Expand Up @@ -35,6 +35,7 @@
require "registration/storage"
require "registration/url_helpers"
require "registration/registration"
require "registration/registration_ui"
require "registration/ui/addon_eula_dialog"
require "registration/ui/addon_selection_dialog"
require "registration/ui/addon_reg_codes_dialog"
Expand Down Expand Up @@ -136,42 +137,13 @@ def register_base_system

next if init_registration == :cancel

success = ::Registration::ConnectHelpers.catch_registration_errors do
base_product = ::Registration::SwMgmt.find_base_product
distro_target = base_product["register_target"]

if !::Registration::Registration.is_registered?
log.info "Registering system, distro_target: #{distro_target}"

Popup.Feedback(_(CONTACTING_MESSAGE),
_("Registering the System...")) do

@registration.register(email, reg_code, distro_target)
end
end

if !options.base_registered
# then register the product(s)
product_service = Popup.Feedback(_(CONTACTING_MESSAGE),
_("Registering %s ...") % ::Registration::SwMgmt.base_product_label(base_product)
) do

base_product_data = ::Registration::SwMgmt.base_product_to_register
base_product_data["reg_code"] = reg_code
registered_service = @registration.register_product(base_product_data, email)
options.base_registered = true

registered_service
end

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

return :next
end
# TODO FIXME use @registration_ui instead of @registration everywhere
registration_ui = ::Registration::RegistrationUI.new(@registration)
success = registration_ui.register_system_and_base_product(email, reg_code,
register_base_product: !options.base_registered, enable_updates: install_updates?)

if success
options.base_registered = true
# save the config if running in installed system
# (in installation/upgrade it's written in _finish client)
::Registration::Helpers.write_config if Mode.normal
Expand Down Expand Up @@ -199,28 +171,8 @@ def register_base_system
def refresh_base_product
return false if init_registration == :cancel

upgraded = ::Registration::ConnectHelpers.catch_registration_errors(show_update_hint: true) do
# then register the product(s)
base_product = ::Registration::SwMgmt.base_product_to_register
product_services = Popup.Feedback(
_(CONTACTING_MESSAGE),
# updating base product registration, %s is a new base product name
_("Updating to %s ...") % ::Registration::SwMgmt.base_product_label(
::Registration::SwMgmt.find_base_product)
) do
@registration.upgrade_product(base_product)
end

# select repositories to use in installation (e.g. enable/disable Updates)
select_repositories(product_services)
end

if !upgraded
log.info "Registration upgrade failed, removing the credentials to register from scratch"
::Registration::Helpers.reset_registration_status
end

upgraded
registration_ui = ::Registration::RegistrationUI.new(@registration)
registration_ui.update_base_product(enable_updates: install_updates?)
end

def refresh_addons
Expand All @@ -233,32 +185,11 @@ def refresh_addons
return :cancel
end

# find addon updates
addons_to_update = ::Registration::SwMgmt.find_addon_updates(addons)

failed_addons = addons_to_update.reject do |addon_to_update|
::Registration::ConnectHelpers.catch_registration_errors do
# then register the product(s)
product_services = Popup.Feedback(
_(CONTACTING_MESSAGE),
# updating registered addon/extension, %s is an extension name
_("Updating to %s ...") % addon_to_update.label
) do
@registration.upgrade_product(addon_to_update)
end

# mark as registered
addon_to_update.registered
registration_ui = ::Registration::RegistrationUI.new(@registration)
failed_addons = registration_ui.update_addons(addons, enable_updates: install_updates?)

select_repositories(product_services)
end
end

if !failed_addons.empty?
log.warn "Failed addons: #{failed_addons}"
# if update fails preselest the addon for full registration
failed_addons.each(&:selected)
end
# if update fails preselest the addon for full registration
failed_addons.each(&:selected)

:next
end
Expand Down Expand Up @@ -373,12 +304,11 @@ def show_scc_credentials_dialog
end
end

def select_repositories(product_service)
options = ::Registration::Storage::InstallationOptions.instance
def install_updates?
# ask only at installation/update
return true unless Mode.installation || Mode.update

# added update repositories
updates = ::Registration::SwMgmt.service_repos(product_service, only_updates: true)
log.info "Found update repositories: #{updates.size}"
options = ::Registration::Storage::InstallationOptions.instance

# not set yet?
if options.install_updates.nil?
Expand All @@ -388,7 +318,15 @@ def select_repositories(product_service)
"on-line updates during installation?"))
end

::Registration::SwMgmt.set_repos_state(updates, options.install_updates)
options.install_updates
end

def select_repositories(product_service)
# added update repositories
updates = ::Registration::SwMgmt.service_repos(product_service, only_updates: true)
log.info "Found update repositories: #{updates.size}"

::Registration::SwMgmt.set_repos_state(updates, install_updates?)
end

# run the addon selection dialog
Expand All @@ -411,15 +349,8 @@ def get_available_addons
# cache the available addons
return :cancel if init_registration == :cancel

@available_addons = Popup.Feedback(
_(CONTACTING_MESSAGE),
_("Loading Available Extensions and Modules...")) do

Registration::Addon.find_all(@registration)
end

::Registration::Storage::Cache.instance.available_addons = @available_addons
@available_addons
registration_ui = ::Registration::RegistrationUI.new(@registration)
@available_addons = registration_ui.get_available_addons
end

# register all selected addons
Expand Down
108 changes: 8 additions & 100 deletions src/clients/scc_auto.rb
Expand Up @@ -169,8 +169,7 @@ def write
import_certificate(@config.reg_server_cert)
end

register_base_product
register_addons
register_base_product && register_addons
end

return false unless ret
Expand All @@ -195,13 +194,6 @@ def auto_packages
ret
end

# TODO: share this?
def disable_update_repos(product_service)
update_repos = ::Registration::SwMgmt.service_repos(product_service, only_updates: true)
log.info "Disabling #{update_repos.size} update repositories: #{update_repos}"
::Registration::SwMgmt.set_repos_state(update_repos, false)
end

# find registration server via SLP
# @retun [String,nil] URL of the server, nil on error
def find_slp_server
Expand Down Expand Up @@ -249,6 +241,7 @@ def update_registration
url = ::Registration::UrlHelpers.registration_url
log.info "Updating registration using URL: #{url}"
@registration = ::Registration::Registration.new(url)
@registration_ui = ::Registration::RegistrationUI.new(@registration)

# the old system was not registered
return false unless prepare_update
Expand All @@ -263,30 +256,8 @@ def update_registration
# TODO FIXME: share these methods with inst_scc.rb

def register_base_product
base_product = ::Registration::SwMgmt.find_base_product
distro_target = base_product["register_target"]

if !::Registration::Registration.is_registered?
log.info "Registering system, distro_target: #{distro_target}"

Popup.Feedback(_(CONTACTING_MESSAGE),
_("Registering the System...")) do

@registration.register(@config.email, @config.reg_code, distro_target)
end
end

# register the base product
product_service = Popup.Feedback(_(CONTACTING_MESSAGE),
_("Registering %s ...") % ::Registration::SwMgmt.base_product_label(base_product)
) do

base_product_data = ::Registration::SwMgmt.base_product_to_register
base_product_data["reg_code"] = @config.reg_code
@registration.register_product(base_product_data, @config.email)
end

disable_update_repos(product_service) if !@config.install_updates
@registration_ui.register_system_and_base_product(@config.email, @config.reg_code,
enable_updates: @config.install_updates)
end

def register_addons
Expand All @@ -302,8 +273,7 @@ def register_addons

::Registration::Storage::Cache.instance.addon_services << product_service


disable_update_repos(product_service) if !@config.install_updates
@registration_ui.disable_update_repos(product_service) if !@config.install_updates
end

# install the new products
Expand All @@ -319,79 +289,17 @@ def prepare_update

# @return [Boolean] true on success
def update_base_product
upgraded = ::Registration::ConnectHelpers.catch_registration_errors(show_update_hint: true) do
# then register the product(s)
base_product = ::Registration::SwMgmt.base_product_to_register
product_service = Popup.Feedback(
_(CONTACTING_MESSAGE),
# updating base product registration, %s is a new base product name
_("Updating to %s ...") % ::Registration::SwMgmt.base_product_label(
::Registration::SwMgmt.find_base_product)
) do
@registration.upgrade_product(base_product)
end

# select repositories to use in installation (e.g. enable/disable Updates)
disable_update_repos(product_service) if !@config.install_updates
end

if !upgraded
log.info "Registration upgrade failed, removing the credentials to register from scratch"
::Registration::Helpers.reset_registration_status
end

upgraded
@registration_ui.update_base_product(enable_updates: @config.install_updates)
end

# @return [Boolean] true on success
def update_addons
addons = get_available_addons

# find addon updates
addons_to_update = ::Registration::SwMgmt.find_addon_updates(addons)

failed_addons = addons_to_update.reject do |addon_to_update|
::Registration::ConnectHelpers.catch_registration_errors do
# then register the product(s)
product_service = Popup.Feedback(
_(CONTACTING_MESSAGE),
# updating registered addon/extension, %s is an extension name
_("Updating to %s ...") % addon_to_update.label
) do
@registration.upgrade_product(addon_to_update)
end

::Registration::Storage::Cache.instance.addon_services << product_service

# select repositories to use in installation (e.g. enable/disable Updates)
disable_update_repos(product_service) if !@config.install_updates
end
end

# install the new upgraded products
::Registration::SwMgmt.select_addon_products

log.error "Failed addons: #{failed_addons}" unless failed_addons.empty?
addons = @registration_ui.get_available_addons

failed_addons = @registration_ui.update_addons(addons, enable_updates: @config.install_updates)
failed_addons.empty?
end

# load available addons from SCC server
# the result is cached to avoid reloading when going back and forth in the
# installation workflow
def get_available_addons
available_addons = Popup.Feedback(
_(CONTACTING_MESSAGE),
_("Loading Available Extensions and Modules...")) do

Registration::Addon.find_all(@registration)
end

::Registration::Storage::Cache.instance.available_addons = available_addons
available_addons
end


end unless defined?(SccAutoClient)
end

Expand Down

0 comments on commit 6ac6c9f

Please sign in to comment.