-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from yast/auto_packages
Auto packages
- Loading branch information
Showing
5 changed files
with
174 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |