From e8a2903ca5f6504ea038fe155478925a26237416 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 25 Sep 2019 12:37:24 +0200 Subject: [PATCH 1/6] convert auto client from ycp client to object based client --- src/clients/kdump_auto.rb | 110 +--------------------------------- src/lib/kdump/clients/auto.rb | 74 +++++++++++++++++++++++ 2 files changed, 76 insertions(+), 108 deletions(-) create mode 100644 src/lib/kdump/clients/auto.rb diff --git a/src/clients/kdump_auto.rb b/src/clients/kdump_auto.rb index f37b648..9177222 100644 --- a/src/clients/kdump_auto.rb +++ b/src/clients/kdump_auto.rb @@ -1,109 +1,3 @@ -# encoding: utf-8 +require "kdump/clients/auto" -# File: -# kdump_auto.ycp -# -# Module: -# Kdump installation and configuration -# -# Summary: -# Kdump autoinstallation preparation -# -# Authors: -# Jozef Uhliarik -# -# -module Yast - class KdumpAutoClient < Client - def main - Yast.import "UI" - textdomain "kdump" - - Builtins.y2milestone("----------------------------------------") - Builtins.y2milestone("kdump auto started") - - Yast.import "Kdump" - Yast.import "Mode" - Yast.import "Progress" - - Yast.include self, "kdump/wizards.rb" - - @progress_orig = Progress.set(false) - - @ret = nil - @func = "" - @param = {} - - # Check arguments - if Ops.greater_than(Builtins.size(WFM.Args), 0) && - Ops.is_string?(WFM.Args(0)) - @func = Convert.to_string(WFM.Args(0)) - if Ops.greater_than(Builtins.size(WFM.Args), 1) && - Ops.is_map?(WFM.Args(1)) - @param = Convert.to_map(WFM.Args(1)) - end - end - Builtins.y2debug("func=%1", @func) - Builtins.y2debug("param=%1", @param) - - if @func == "Import" - @ret = Kdump.Import(@param) - # Create a summary - # return string - elsif @func == "Summary" - @ret = Ops.add( - Ops.add( - "" - ) - # did configuration changed - # return boolean - elsif @func == "GetModified" - @ret = Kdump.GetModified - # set configuration as changed - # return boolean - elsif @func == "SetModified" - Kdump.SetModified - @ret = true - # Reset configuration - # return map or list - elsif @func == "Reset" - Kdump.Import({}) - @ret = {} - # Change configuration - # return symbol (i.e. `finish || `accept || `next || `cancel || `abort) - elsif @func == "Change" - @ret = KdumpAutoSequence() - return deep_copy(@ret) - # Return configuration data - # return map or list - elsif @func == "Export" - @ret = Kdump.Export - # Write configuration data - # return boolean - elsif @func == "Write" - @ret = Kdump.Write - elsif @func == "Read" - @ret = Kdump.Read - else - Builtins.y2error("unknown function: %1", @func) - @ret = false - end - Progress.set(@progress_orig) - - Builtins.y2debug("ret=%1", @ret) - Builtins.y2milestone("kdump_auto finished") - Builtins.y2milestone("----------------------------------------") - - deep_copy(@ret) - - # EOF - end - end -end - -Yast::KdumpAutoClient.new.main +Y2Kdump::Clients::Auto.run diff --git a/src/lib/kdump/clients/auto.rb b/src/lib/kdump/clients/auto.rb new file mode 100644 index 0000000..421e59d --- /dev/null +++ b/src/lib/kdump/clients/auto.rb @@ -0,0 +1,74 @@ +# encoding: utf-8 + +# ------------------------------------------------------------------------------ +# Copyright (c) 2019 SUSE LLC +# +# 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. +# +# ------------------------------------------------------------------------------ + +require "installation/auto_client" + +module Y2Kdump + module Clients + # Client to communicate with autoyast + class Auto < ::Installation::AutoClient + def initialize + textdomain "kdump" + + Yast.import "Kdump" + Yast.import "Mode" + Yast.import "Progress" + + Yast.include self, "kdump/wizards.rb" # needed for auto sequence + end + + def import(profile) + Yast::Kdump.Import(profile) + end + + def export + Yast::Kdump.Export + end + + def summary + items = Yast::Kdump.Summary.map { |s| "
  • #{s}
  • " } + "" + end + + def modified? + Yast::Kdump.GetModified + end + + def modified + Yast::Kdump.SetModified + end + + def reset + Yast::Kdump.Import({}) + end + + def change + KdumpAutoSequence() + end + + def write + progress_orig = Yast::Progress.set(false) + Yast::Kdump.Write + Yast::Progress.set(progress_orig) + end + + def read + progress_orig = Yast::Progress.set(false) + Yast::Kdump.Read + Yast::Progress.set(progress_orig) + end + end + end +end From 66211e92edc9dcb1bfcc8e0e9e02359d5e399299 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 25 Sep 2019 13:43:26 +0200 Subject: [PATCH 2/6] add test for new auto client --- src/lib/kdump/clients/auto.rb | 8 +++--- test/auto_test.rb | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 test/auto_test.rb diff --git a/src/lib/kdump/clients/auto.rb b/src/lib/kdump/clients/auto.rb index 421e59d..68db0f7 100644 --- a/src/lib/kdump/clients/auto.rb +++ b/src/lib/kdump/clients/auto.rb @@ -15,6 +15,10 @@ require "installation/auto_client" +Yast.import "Kdump" +Yast.import "Mode" +Yast.import "Progress" + module Y2Kdump module Clients # Client to communicate with autoyast @@ -22,10 +26,6 @@ class Auto < ::Installation::AutoClient def initialize textdomain "kdump" - Yast.import "Kdump" - Yast.import "Mode" - Yast.import "Progress" - Yast.include self, "kdump/wizards.rb" # needed for auto sequence end diff --git a/test/auto_test.rb b/test/auto_test.rb new file mode 100644 index 0000000..189c514 --- /dev/null +++ b/test/auto_test.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env rspec + +require_relative "./test_helper" + +require "kdump/clients/auto" + +describe Y2Kdump::Clients::Auto do + describe "#import" do + it "imports given hash" do + expect(Yast::Kdump).to receive(:Import).with({}) + subject.import({}) + end + end + + describe "#export" do + it "returns hash" do + expect(subject.export).to be_a ::Hash + end + end + + describe "#summary" do + it "returns a string" do + expect(subject.summary).to be_a ::String + end + end + + describe "#modified" do + it "sets modified flag" do + subject.modified + expect(subject.modified?).to eq true + end + end + + describe "#reset" do + it "import empty data" do + expect(Yast::Kdump).to receive(:Import).with({}) + subject.reset + end + end + + describe "#read" do + it "reads system kdump settings" do + expect(Yast::Kdump).to receive(:Read) + subject.read + end + end + + describe "#write" do + it "writes settings to system" do + expect(Yast::Kdump).to receive(:Write) + subject.write + end + end +end From 0d2ec38840611bb01b0aed9d9f11b15dc12a6198 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Wed, 25 Sep 2019 13:53:20 +0200 Subject: [PATCH 3/6] implement returning list of packages --- src/lib/kdump/clients/auto.rb | 11 +++++++++++ test/auto_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/lib/kdump/clients/auto.rb b/src/lib/kdump/clients/auto.rb index 68db0f7..c774ae4 100644 --- a/src/lib/kdump/clients/auto.rb +++ b/src/lib/kdump/clients/auto.rb @@ -69,6 +69,17 @@ def read Yast::Kdump.Read Yast::Progress.set(progress_orig) end + + def packages + if Yast::Kdump.add_crashkernel_param + { + "install" => Yast::KdumpClass::KDUMP_PACKAGES, + "remove" => [] + } + else + {} + end + end end end end diff --git a/test/auto_test.rb b/test/auto_test.rb index 189c514..572bc88 100644 --- a/test/auto_test.rb +++ b/test/auto_test.rb @@ -51,4 +51,26 @@ subject.write end end + + describe "#packages" do + before do + allow(Yast::Kdump).to receive(:add_crashkernel_param).and_return(enabled) + end + + context "kdump is enabled" do + let(:enabled) { true } + + it "returns list of packages to install" do + expect(subject.packages).to eq({ "install" => ["kexec-tools", "kdump"], "remove" => [] }) + end + end + + context "kdump is disabled" do + let(:enabled) { false } + + it "returns empty list" do + expect(subject.packages).to eq({}) + end + end + end end From 0962e72bce0d4de565b1725e20f807883ef9a8f3 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 26 Sep 2019 09:23:51 +0200 Subject: [PATCH 4/6] add to first stage proposal required packages in import --- src/lib/kdump/clients/auto.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/kdump/clients/auto.rb b/src/lib/kdump/clients/auto.rb index c774ae4..c4bc5f4 100644 --- a/src/lib/kdump/clients/auto.rb +++ b/src/lib/kdump/clients/auto.rb @@ -18,6 +18,7 @@ Yast.import "Kdump" Yast.import "Mode" Yast.import "Progress" +Yast.import "PackagesProposal" module Y2Kdump module Clients @@ -31,6 +32,8 @@ def initialize def import(profile) Yast::Kdump.Import(profile) + # add packages needed to proposal, as it is needed already in first stage (bsc#1149208) + Yast::PackagesProposal.AddResolvables("yast2-kdump", :package, packages["install"]) end def export From 17123a30524fb89621626ee9867ba692d403adca Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 26 Sep 2019 14:25:57 +0200 Subject: [PATCH 5/6] Changes --- package/yast2-kdump.changes | 7 +++++++ package/yast2-kdump.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/yast2-kdump.changes b/package/yast2-kdump.changes index 244bb84..7bbba58 100644 --- a/package/yast2-kdump.changes +++ b/package/yast2-kdump.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Sep 26 12:25:08 UTC 2019 - Josef Reidinger + +- fix installing kdump to first stage when kdump enabled in + AutoYaST (bsc#1149208) +- 4.2.5 + ------------------------------------------------------------------- Wed Aug 28 09:52:34 CEST 2019 - schubi@suse.de diff --git a/package/yast2-kdump.spec b/package/yast2-kdump.spec index 522383c..059a4d7 100644 --- a/package/yast2-kdump.spec +++ b/package/yast2-kdump.spec @@ -17,7 +17,7 @@ Name: yast2-kdump -Version: 4.2.4 +Version: 4.2.5 Release: 0 Summary: Configuration of kdump License: GPL-2.0-only From cb3f1220debb3117106f2703dcae59659f4628e9 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 26 Sep 2019 15:40:55 +0200 Subject: [PATCH 6/6] fix rubocop --- test/auto_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/auto_test.rb b/test/auto_test.rb index 572bc88..ee42c72 100644 --- a/test/auto_test.rb +++ b/test/auto_test.rb @@ -61,7 +61,7 @@ let(:enabled) { true } it "returns list of packages to install" do - expect(subject.packages).to eq({ "install" => ["kexec-tools", "kdump"], "remove" => [] }) + expect(subject.packages).to eq("install" => ["kexec-tools", "kdump"], "remove" => []) end end