Skip to content

Commit

Permalink
Merge pull request #109 from yast/auto_packages
Browse files Browse the repository at this point in the history
Auto packages
  • Loading branch information
jreidinger committed Sep 26, 2019
2 parents a9508e2 + cb3f122 commit 40c9845
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 109 deletions.
7 changes: 7 additions & 0 deletions package/yast2-kdump.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Sep 26 12:25:08 UTC 2019 - Josef Reidinger <jreidinger@suse.com>

- 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

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-kdump.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
110 changes: 2 additions & 108 deletions src/clients/kdump_auto.rb
Original file line number Diff line number Diff line change
@@ -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 <juhliarik@suse.cz>
#
#
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(
"<UL>",
Builtins.mergestring(Builtins.maplist(Kdump.Summary) do |l|
Ops.add("<LI>", l)
end, "\n")
),
"</UL>"
)
# 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
88 changes: 88 additions & 0 deletions src/lib/kdump/clients/auto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# 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"

Yast.import "Kdump"
Yast.import "Mode"
Yast.import "Progress"
Yast.import "PackagesProposal"

module Y2Kdump
module Clients
# Client to communicate with autoyast
class Auto < ::Installation::AutoClient
def initialize
textdomain "kdump"

Yast.include self, "kdump/wizards.rb" # needed for auto sequence
end

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
Yast::Kdump.Export
end

def summary
items = Yast::Kdump.Summary.map { |s| "<li>#{s}</li>" }
"<ul>#{items.join("\n")}</ul>"
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

def packages
if Yast::Kdump.add_crashkernel_param
{
"install" => Yast::KdumpClass::KDUMP_PACKAGES,
"remove" => []
}
else
{}
end
end
end
end
end
76 changes: 76 additions & 0 deletions test/auto_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/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

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

0 comments on commit 40c9845

Please sign in to comment.