Skip to content

Commit

Permalink
Merge pull request #202 from yast/release_target_fix
Browse files Browse the repository at this point in the history
Release target fix
  • Loading branch information
lslezak committed Aug 21, 2015
2 parents f81f631 + 3150949 commit cc26f99
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 25 deletions.
8 changes: 8 additions & 0 deletions package/yast2-registration.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Fri Aug 21 11:38:22 UTC 2015 - lslezak@suse.cz

- Fixed registering a product with POOL flavor (bsc#941402)
- Addon selection dialog - avoid possible ID duplicates when
an addon with multiple versions is displayed
- 3.1.143

-------------------------------------------------------------------
Mon Aug 17 14:40:05 UTC 2015 - igonzalezsosa@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.142
Version: 3.1.143
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
33 changes: 24 additions & 9 deletions src/lib/registration/sw_mgmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ class SwMgmt

ZYPP_DIR = "/etc/zypp"

FAKE_BASE_PRODUCT = { "name" => "SLES", "arch" => "x86_64", "version" => "12",
"release_type" => "DVD", "version_version" => "12" }
FAKE_BASE_PRODUCT = { "name" => "SLES", "arch" => "x86_64", "version" => "12-0",
"flavor" => "DVD", "version_version" => "12", "register_release" => "",
"register_target" => "sle-12-x86_64" }

OEM_DIR = "/var/lib/suseRegister/OEM"

def self.init
# false = do not allow continuing without the libzypp lock
Expand Down Expand Up @@ -145,17 +148,15 @@ def self.product_label(base_product)
end

def self.base_product_to_register
# just for debugging:
return FAKE_BASE_PRODUCT if ENV["FAKE_BASE_PRODUCT"]

base_product = find_base_product
# use FAKE_BASE_PRODUCT just for debugging
base_product = ENV["FAKE_BASE_PRODUCT"] ? FAKE_BASE_PRODUCT : find_base_product

# filter out not needed data
product_info = {
"name" => base_product["name"],
"arch" => base_product["arch"],
"version" => ::Registration::Helpers.base_version(base_product["version"]),
"release_type" => base_product["flavor"]
"version" => base_product["version_version"],
"release_type" => get_release_type(base_product)
}

log.info("Base product to register: #{product_info}")
Expand Down Expand Up @@ -449,6 +450,20 @@ def self.products_from_repo(repo_id)
end
end

private_class_method :each_repo
def self.get_release_type(product)
if product["product_line"]
oem_file = File.join(OEM_DIR, product["product_line"])

if File.exist?(oem_file)
# read only the first line
line = File.open(oem_file, &:readline)
return line.chomp if line
end
end

product["register_release"]
end

private_class_method :each_repo, :get_release_type
end
end
19 changes: 14 additions & 5 deletions src/lib/registration/ui/addon_selection_base_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def run
raise "Not implemented"
end

protected

# create widget ID for an addon
# @param [<Addon>] addon the addon
# @return [String] widget id
def addon_widget_id(addon)
"#{addon.identifier}-#{addon.version}-#{addon.arch}"
end

private

# reimplement this in a subclass
Expand Down Expand Up @@ -154,7 +163,7 @@ def addon_checkbox_element(addon)
# (%s is an extension name)
label = addon.available? ? addon.label : (_("%s (not available)") % addon.label)

CheckBox(Id(addon.identifier), Opt(:notify), label, addon_selected?(addon))
CheckBox(Id(addon_widget_id(addon)), Opt(:notify), label, addon_selected?(addon))
end

# the main event loop - handle the user in put in the dialog
Expand Down Expand Up @@ -191,14 +200,14 @@ def handle_next_button
end

# handler for changing the addon status in the main loop
# @param id [String] addon identifier
# @param id [String] addon widget id
def handle_addon_selection(id)
# check whether it's an add-on ID (checkbox clicked)
addon = @addons.find { |a| a.identifier == id }
addon = @addons.find { |a| addon_widget_id(a) == id }
return unless addon

show_addon_details(addon)
if Yast::UI.QueryWidget(Id(addon.identifier), :Value)
if Yast::UI.QueryWidget(Id(addon_widget_id(addon)), :Value)
addon.selected
else
addon.unselected
Expand All @@ -217,7 +226,7 @@ def show_addon_details(addon)
# update the enabled/disabled status in UI for dependent addons
def reactivate_dependencies
@addons.each do |addon|
Yast::UI.ChangeWidget(Id(addon.identifier), :Enabled, addon.selectable?)
Yast::UI.ChangeWidget(Id(addon_widget_id(addon)), :Enabled, addon.selectable?)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def addon_selected?(addon)
# update the enabled/disabled status in UI for dependent addons
def reactivate_dependencies
@addons.each do |addon|
Yast::UI.ChangeWidget(Id(addon.identifier), :Enabled, addon.selectable?)
Yast::UI.ChangeWidget(Id(addon_widget_id(addon)), :Enabled, addon.selectable?)
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions test/addon_selection_dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
end

it "returns `:next` if some addons are selected and user click next" do
test_addon = addon_generator
expect(Yast::UI).to receive(:UserInput).and_return(test_addon.identifier, :next)
addon = addon_generator
widget = "#{addon.identifier}-#{addon.version}-#{addon.arch}"
expect(Yast::UI).to receive(:UserInput).and_return(widget, :next)
# mock that widget is selected
expect(Yast::UI).to receive(:QueryWidget)
.with(Yast::Term.new(:id, test_addon.identifier), :Value)
.with(Yast::Term.new(:id, widget), :Value)
.and_return(true)
registration = double(activated_products: [], get_addon_list: [test_addon])
registration = double(activated_products: [], get_addon_list: [addon])
expect(subject.run(registration)).to eq :next
end
end
Expand Down
10 changes: 7 additions & 3 deletions test/registration_ui_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
let(:target_distro) { "sles-12-x86_64" }
let(:base_product) do
{
"arch" => "x86_64", "name" => "SLES", "version" => "12",
"flavor" => "DVD", "register_target" => target_distro
"arch" => "x86_64",
"flavor" => "DVD",
"name" => "SLES",
"version" => "12-0",
"version_version" => "12",
"register_target" => target_distro
}
end
let(:base_product_to_register) do
{
"arch" => "x86_64",
"name" => "SLES",
"reg_code" => "reg_code",
"release_type" => "DVD",
"release_type" => nil,
"version" => "12"
}
end
Expand Down
4 changes: 2 additions & 2 deletions test/sw_mgmt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
it "returns base product base version and release_type" do
expect(subject).to(receive(:find_base_product)
.and_return("name" => "SLES", "arch" => "x86_64",
"version" => "12.1-1.47", "flavor" => "DVD"))
"version" => "12.1-1.47", "version_version" => "12.1", "flavor" => "DVD"))

expect(subject.base_product_to_register).to eq("name" => "SLES",
"arch" => "x86_64", "version" => "12.1", "release_type" => "DVD")
"arch" => "x86_64", "version" => "12.1", "release_type" => nil)
end
end

Expand Down

0 comments on commit cc26f99

Please sign in to comment.