Skip to content

Commit

Permalink
revert caching back, the latest connect includes show_product()
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jun 16, 2014
1 parent 324101e commit 808b788
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 32 deletions.
26 changes: 21 additions & 5 deletions src/clients/inst_scc.rb
Expand Up @@ -154,9 +154,6 @@ def register_base_system
base_product_data["reg_code"] = reg_code
registered_service = @registration.register_product(base_product_data, email)
options.base_registered = true
# remember the available extensions
log.info "Extensions for the base product: #{registered_service.product.extensions}"
::Registration::Addon.cache_addons(registered_service.product.extensions)

registered_service
end
Expand Down Expand Up @@ -322,12 +319,13 @@ def select_repositories(product_service)

# run the addon selection dialog
def select_addons
get_available_addons # FIXME just to fill cache with popup

# FIXME workaround to reference between old way and new storage in Addon metaclass
@selected_addons = Registration::Addon.selected
::Registration::Storage::InstallationOptions.instance.selected_addons = @selected_addons

available_addons = ::Registration::Storage::Cache.instance.available_addons
Registration::UI::AddonSelectionDialog.run(available_addons)
Registration::UI::AddonSelectionDialog.run(@registration)
end


Expand Down Expand Up @@ -390,6 +388,24 @@ def addon_regcodes_dialog_content(addons)
)
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
# cache the available addons
init_registration

@available_addons = Popup.Feedback(
_(CONTACTING_MESSAGE),
_("Loading Available Add-on Products and Extensions...")) do

Registration::Addon.find_all(@registration)
end

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

# handle user input in the addon reg codes dialog
def handle_register_addons_dialog(addons_with_codes)
continue_buttons = [:next, :back, :close, :abort]
Expand Down
13 changes: 5 additions & 8 deletions src/lib/registration/addon.rb
Expand Up @@ -24,9 +24,12 @@
module Registration
class Addon
class << self
def find_all
def find_all(registration)
return @cached_addons if @cached_addons
raise "Uninitialized addon cache, missing Addon.cache_addons call"
pure_addons = registration.get_addon_list
@cached_addons = pure_addons.reduce([]) do |res, addon|
res.concat(create_addon_with_deps(addon))
end
end

def registered
Expand All @@ -37,12 +40,6 @@ def selected
@selected ||= []
end

def cache_addons(pure_addons)
@cached_addons = pure_addons.reduce([]) do |res, addon|
res.concat(create_addon_with_deps(addon))
end
end

private

def create_addon_with_deps(root)
Expand Down
19 changes: 19 additions & 0 deletions src/lib/registration/registration.rb
Expand Up @@ -71,6 +71,25 @@ def upgrade_product(product)
end
end

def get_addon_list
# extensions for base product
base_product = ::Registration::SwMgmt.find_base_product

log.info "Reading available addons for product: #{base_product["name"]}"

remote_product = SUSE::Connect::Remote::Product.new(
:arch => base_product["arch"],
:identifier => base_product["name"],
:version => base_product["version"],
:release_type => base_product["release_type"]
)

params = connect_params({})
addons = SUSE::Connect::YaST.show_product(remote_product, params)
# ignore the base product "addon"
addons.reject{ |a| a.identifier == base_product["name"] }
end

def self.is_registered?
SUSE::Connect::System.registered?
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/registration/storage.rb
Expand Up @@ -48,7 +48,7 @@ def initialize
end
end

class Cache < Struct.new(:first_run, :registered_addons,
class Cache < Struct.new(:available_addons, :first_run, :registered_addons,
:reg_url, :reg_url_cached)

include Singleton
Expand Down
10 changes: 5 additions & 5 deletions src/lib/registration/ui/addon_selection_dialog.rb
Expand Up @@ -20,14 +20,14 @@ class AddonSelectionDialog
Yast.import "Wizard"

# create a new dialog for accepting importing a SSL certificate and run it
def self.run
dialog = AddonSelectionDialog.new
def self.run(registration)
dialog = AddonSelectionDialog.new(registration)
dialog.run
end

def initialize
def initialize(registration)
textdomain "registration"
@addons = Addon.find_all
@addons = Addon.find_all(registration)
log.info "Available addons: #{@addons}"
end

Expand Down Expand Up @@ -120,7 +120,7 @@ def addon_checkbox(addon, extra_spacing)
def addon_checkbox_element(addon)
CheckBox(Id(addon.identifier),
Opt(:notify),
addon.friendly_name || addon.name,
addon.label,
addon.selected? || addon.registered?)
end

Expand Down
12 changes: 6 additions & 6 deletions test/addon_selection_dialog_test.rb
Expand Up @@ -20,14 +20,14 @@
describe ".run" do
it "returns response from addon selection according to pressed button" do
expect(Yast::UI).to receive(:UserInput).and_return(:abort)
Registration::Addon.cache_addons([])
expect(subject.run).to eq :abort
registration = double(:get_addon_list => [])
expect(subject.run(registration)).to eq :abort
end

it "returns `:skip` if no addon is selected and user click next" do
expect(Yast::UI).to receive(:UserInput).and_return(:next)
Registration::Addon.cache_addons([])
expect(subject.run).to eq :skip
registration = double(:get_addon_list => [])
expect(subject.run(registration)).to eq :skip
end

it "returns `:next` if some addons are selected and user click next" do
Expand All @@ -37,8 +37,8 @@
expect(Yast::UI).to receive(:QueryWidget).
with(Yast::Term.new(:id, test_addon.identifier), :Value).
and_return(true)
Registration::Addon.cache_addons([test_addon])
expect(subject.run).to eq :next
registration = double(:get_addon_list => [test_addon])
expect(subject.run(registration)).to eq :next
end
end
end
13 changes: 6 additions & 7 deletions test/addon_spec.rb
Expand Up @@ -19,23 +19,23 @@
it "find all addons for current base product" do
prod1 = addon_generator
prod2 = addon_generator
registration = double(:get_addon_list => [prod1, prod2])

Registration::Addon.cache_addons([prod1, prod2])
expect(Registration::Addon.find_all.size).to be 2
expect(Registration::Addon.find_all(registration).size).to be 2
end

it "find even dependend products" do
prod1 = addon_with_child_generator
registration = double(:get_addon_list => [prod1])

Registration::Addon.cache_addons([prod1])
expect(Registration::Addon.find_all.size).to be 2
expect(Registration::Addon.find_all(registration).size).to be 2
end

it "sets properly dependencies between addons" do
prod1 = addon_with_child_generator
registration = double(:get_addon_list => [prod1])

Registration::Addon.cache_addons([prod1])
addons = Registration::Addon.find_all
addons = Registration::Addon.find_all(registration)
expect(addons.any? {|addon| addon.children.size == 1}).to be_true
expect(addons.any?(&:depends_on)).to be_true
end
Expand Down Expand Up @@ -116,5 +116,4 @@
end
end


end

0 comments on commit 808b788

Please sign in to comment.