Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix registration #338

Merged
merged 5 commits into from Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Oct 11 08:49:16 UTC 2017 - jreidinger@suse.com

- Fixed registration of autoselected extensions (bsc#1062684)
- 4.0.4

-------------------------------------------------------------------
Tue Oct 10 08:19:27 UTC 2017 - lslezak@suse.cz

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 4.0.3
Version: 4.0.4
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
22 changes: 22 additions & 0 deletions src/lib/registration/addon.rb
Expand Up @@ -80,6 +80,27 @@ def registered_not_installed
end
end

# Returns passed addons sorted with all dependencies ordered that it can be
# registered from first to last ( so no dependencies for first ).
# @param list [Array<Addon>] of addons
def registration_order(list)
to_process = list.dup
result = []

loop do
break if to_process.empty?
next_addon = to_process.find do |addon|
addon.depends_on.nil? || !to_process.include?(addon.depends_on)
end
raise "circular dependencies found in addons #{to_process.inspect}" unless next_addon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Report.Error would be probably more user friendly, but hopefully this never happens so let's make it simple...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I hope we catch it quickly in openQA when this happen, so I hope not needed. Also Report is useless as result is that it won't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that it might happen after the release, few months later... But anyway as this is really a corner case let's use this simple solution...


result << next_addon
to_process.delete(next_addon)
end

result
end

private

# create an Addon from a SUSE::Connect::Product
Expand Down Expand Up @@ -234,6 +255,7 @@ def registered?
# mark the add-on as registered
def registered
Addon.registered << self unless registered?
unselected # if register then mark as no longer selected as register is different state
end

# just internally mark the addon as NOT registered, not a real unregistration
Expand Down
7 changes: 5 additions & 2 deletions src/lib/registration/clients/inst_scc.rb
Expand Up @@ -169,7 +169,9 @@ def get_available_addons
# back returns directly to the extensions selection
def register_addons
return false if init_registration == :cancel
ret = registration_ui.register_addons(@selected_addons, @known_reg_codes)
addons = Registration::Addon.selected + Registration::Addon.auto_selected
addons = Registration::Addon.registration_order(addons)
ret = registration_ui.register_addons(addons, @known_reg_codes)
ret = :extensions if ret == :back
ret
end
Expand Down Expand Up @@ -212,7 +214,8 @@ def registration_check

# display EULAs for the selected addons
def addon_eula
::Registration::UI::AddonEulaDialog.run(@selected_addons)
new_addons = Registration::Addon.selected + Registration::Addon.auto_selected
::Registration::UI::AddonEulaDialog.run(new_addons)
end

# remember the user entered values so they can be stored to the AutoYast
Expand Down
13 changes: 13 additions & 0 deletions test/addon_spec.rb
Expand Up @@ -78,6 +78,19 @@
end
end

describe ".registration_order" do
it "returns addons sorted in the registration order" do
addons = load_yaml_fixture("sle15_addons.yaml")
sorted_addons = Registration::Addon.registration_order(addons)
expected_output = ["sle-module-basesystem", "sle-ha", "sle-we", "sle-module-legacy",
"sle-module-scripting", "sle-module-desktop-applications",
"sle-module-development-tools", "sle-module-server-applications"]

expect(addons.size).to eq sorted_addons.size
expect(sorted_addons.map(&:identifier)).to eq expected_output
end
end

describe ".selected" do
it "returns array with selected addons" do
expect(Registration::Addon.selected).to be_a(Array)
Expand Down