From cb6716d99721a8e475b87dc2243fb1fb589b64f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Wed, 25 May 2022 17:03:26 +0100 Subject: [PATCH 1/6] Add a test for OnlineUpdateConfiguration#{Import,Export} --- test/online_update_configuration_test.rb | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/online_update_configuration_test.rb diff --git a/test/online_update_configuration_test.rb b/test/online_update_configuration_test.rb new file mode 100644 index 0000000..1308b1d --- /dev/null +++ b/test/online_update_configuration_test.rb @@ -0,0 +1,59 @@ +# Copyright (c) [2022] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require_relative "test_helper" + +Yast.import "OnlineUpdateConfiguration" + +describe Yast::OnlineUpdateConfiguration do + before { subject.main } + + let(:profile) do + { + "enable_automatic_online_update" => true, + "skip_interactive_patches" => false, + "auto_agree_with_licenses" => true, + "use_deltarpm" => true, + "include_recommends" => false, + "update_interval" => "daily", + "category_filter" => { "category" => ["security"] } + } + end + + describe "#Import" do + + it "imports online update settings" do + subject.Import(profile) + expect(subject.enableAOU).to eq(true) + expect(subject.skipInteractivePatches).to eq(false) + expect(subject.autoAgreeWithLicenses).to eq(true) + expect(subject.use_deltarpm).to eq(true) + expect(subject.includeRecommends).to eq(false) + expect(subject.updateInterval).to eq(:daily) + expect(subject.currentCategories).to eq(["security"]) + end + end + + describe "#Export" do + it "exports online update settings" do + subject.Import(profile) + expect(subject.Export).to eq(profile) + end + end +end From 0bdd195c79f98d987beac4ea32063ea520384b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Wed, 25 May 2022 18:00:38 +0100 Subject: [PATCH 2/6] Export the category_filter with a single nesting level --- src/modules/OnlineUpdateConfiguration.rb | 21 ++++++++++----- test/online_update_configuration_test.rb | 33 +++++++++++++++++++----- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/modules/OnlineUpdateConfiguration.rb b/src/modules/OnlineUpdateConfiguration.rb index 87b6d2a..4e81e5c 100644 --- a/src/modules/OnlineUpdateConfiguration.rb +++ b/src/modules/OnlineUpdateConfiguration.rb @@ -588,11 +588,8 @@ def Import(settings) @includeRecommends ) @use_deltarpm = settings.fetch('use_deltarpm', @use_deltarpm) - @currentCategories = Convert.convert( - Ops.get(settings, ["category_filter", "category"], @currentCategories), - :from => "any", - :to => "list " - ) + + @currentCategories = get_category_filter(settings["category_filter"]) getInterval = Ops.get_string(settings, "update_interval", "") @@ -604,7 +601,6 @@ def Import(settings) true end - # Write() def Write SCR.Write( @@ -665,7 +661,7 @@ def Export @updateInterval, :name ), - "category_filter" => { "category" => @currentCategories } + "category_filter" => @currentCategories } end @@ -694,6 +690,17 @@ def Export publish :function => :Import, :type => "boolean (map)" publish :function => :Write, :type => "boolean ()" publish :function => :Export, :type => "map ()" + + private + + def get_category_filter(category_filter) + return category_filter if category_filter.is_a?(Array) + + return category_filter.fetch("category", []) if category_filter.is_a?(Hash) + + [] + end + end OnlineUpdateConfiguration = OnlineUpdateConfigurationClass.new diff --git a/test/online_update_configuration_test.rb b/test/online_update_configuration_test.rb index 1308b1d..974acda 100644 --- a/test/online_update_configuration_test.rb +++ b/test/online_update_configuration_test.rb @@ -29,25 +29,37 @@ "enable_automatic_online_update" => true, "skip_interactive_patches" => false, "auto_agree_with_licenses" => true, - "use_deltarpm" => true, - "include_recommends" => false, + "use_deltarpm" => false, + "include_recommends" => true, "update_interval" => "daily", - "category_filter" => { "category" => ["security"] } + "category_filter" => ["security"] } end describe "#Import" do - it "imports online update settings" do subject.Import(profile) expect(subject.enableAOU).to eq(true) expect(subject.skipInteractivePatches).to eq(false) expect(subject.autoAgreeWithLicenses).to eq(true) - expect(subject.use_deltarpm).to eq(true) - expect(subject.includeRecommends).to eq(false) + expect(subject.use_deltarpm).to eq(false) + expect(subject.includeRecommends).to eq(true) expect(subject.updateInterval).to eq(:daily) expect(subject.currentCategories).to eq(["security"]) end + + context "when an empty profile is given" do + it "keeps the default values" do + subject.Import({}) + expect(subject.enableAOU).to eq(false) + expect(subject.skipInteractivePatches).to eq(true) + expect(subject.autoAgreeWithLicenses).to eq(false) + expect(subject.use_deltarpm).to eq(true) + expect(subject.includeRecommends).to eq(false) + expect(subject.updateInterval).to eq(:weekly) + expect(subject.currentCategories).to eq([]) + end + end end describe "#Export" do @@ -55,5 +67,14 @@ subject.Import(profile) expect(subject.Export).to eq(profile) end + + context "when it uses the old format for category_filter" do + it "sets the categories filter" do + subject.Import( + profile.merge("category_filter" => { "category" => ["security"]}) + ) + expect(subject.currentCategories).to eq(["security"]) + end + end end end From 4e446107c26a68bb7db121e4acba1756ded0ced7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Thu, 26 May 2022 07:51:57 +0100 Subject: [PATCH 3/6] Bump version and update changes file --- package/yast2-online-update-configuration.changes | 7 +++++++ package/yast2-online-update-configuration.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/yast2-online-update-configuration.changes b/package/yast2-online-update-configuration.changes index 6ec83a1..ae1067b 100644 --- a/package/yast2-online-update-configuration.changes +++ b/package/yast2-online-update-configuration.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu May 26 06:42:47 UTC 2022 - Imobach Gonzalez Sosa + +- Reduce nesting in the "category_filter" section of the AutoYaST + profile (bsc#1198848). The old (nested) format is still accepted. +- 4.3.3 + ------------------------------------------------------------------- Thu Aug 20 13:25:49 UTC 2020 - David Diaz diff --git a/package/yast2-online-update-configuration.spec b/package/yast2-online-update-configuration.spec index 63cd580..abdac62 100644 --- a/package/yast2-online-update-configuration.spec +++ b/package/yast2-online-update-configuration.spec @@ -16,7 +16,7 @@ # Name: yast2-online-update-configuration -Version: 4.3.2 +Version: 4.3.3 Release: 0 Group: System/YaST License: GPL-2.0 From 5f6508012d8742435de808141e4b116a5f2ce587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Thu, 26 May 2022 09:42:26 +0100 Subject: [PATCH 4/6] Allow category or listentry in the AutoYaST profile --- src/autoyast-rnc/online_update_configuration.rnc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/autoyast-rnc/online_update_configuration.rnc b/src/autoyast-rnc/online_update_configuration.rnc index 34bd448..5b50b92 100644 --- a/src/autoyast-rnc/online_update_configuration.rnc +++ b/src/autoyast-rnc/online_update_configuration.rnc @@ -26,4 +26,4 @@ include_recommends = element include_recommends { BOOLEAN } use_deltarpm = element use_deltarpm { BOOLEAN } update_interval = element update_interval { STRING } category_filter = element category_filter { LIST, category* } -category = element category { STRING } +category = element (category | listentry) { STRING } From 54b34e0324c8e69108d3d09e914637b5460fe4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Thu, 26 May 2022 13:13:17 +0100 Subject: [PATCH 5/6] Update from code review --- src/modules/OnlineUpdateConfiguration.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/modules/OnlineUpdateConfiguration.rb b/src/modules/OnlineUpdateConfiguration.rb index 4e81e5c..5265fa7 100644 --- a/src/modules/OnlineUpdateConfiguration.rb +++ b/src/modules/OnlineUpdateConfiguration.rb @@ -694,11 +694,14 @@ def Export private def get_category_filter(category_filter) - return category_filter if category_filter.is_a?(Array) - - return category_filter.fetch("category", []) if category_filter.is_a?(Hash) - - [] + case category_filter + when Array + category_filter + when Hash + category_filter.fetch("category", []) + else + [] + end end end From 10dffea18b45bf8e7d0ae75051802e16004e4527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Thu, 26 May 2022 15:56:10 +0100 Subject: [PATCH 6/6] Support the old category_filter format in validation --- src/autoyast-rnc/online_update_configuration.rnc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/autoyast-rnc/online_update_configuration.rnc b/src/autoyast-rnc/online_update_configuration.rnc index 5b50b92..6871840 100644 --- a/src/autoyast-rnc/online_update_configuration.rnc +++ b/src/autoyast-rnc/online_update_configuration.rnc @@ -13,7 +13,7 @@ online_update_configuration = auto_agree_with_licenses? & include_recommends? & update_interval? & - category_filter? & + (category_filter | nested_category_filter)? & use_deltarpm? ) } @@ -25,5 +25,12 @@ auto_agree_with_licenses = element auto_agree_with_licenses { BOOLEAN } include_recommends = element include_recommends { BOOLEAN } use_deltarpm = element use_deltarpm { BOOLEAN } update_interval = element update_interval { STRING } + category_filter = element category_filter { LIST, category* } category = element (category | listentry) { STRING } + +# Support for the old category_filter format (bsc#1198848) +nested_category_filter = element category_filter { + MAP, + element category { LIST, category* } + }