Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd326e7
commit d438b08
Showing
4 changed files
with
255 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require "yast" | ||
|
||
module Installation | ||
# Abstract class that simplify writting auto clients for autoyast. | ||
# It provides single entry point and abstract methods, that all proposal clients | ||
# need to implement. | ||
# @example how to run client | ||
# require "installation/example_auto" | ||
# ::Installation::ExampleAuto.run | ||
# | ||
# @see for example client in installation bootloader_auto.rb | ||
# @see http://users.suse.com/~ug/autoyast_doc/devel/ar01s05.html for configuration and some old documenation | ||
class AutoClient < Yast::Client | ||
include Yast::Logger | ||
|
||
# Entry point for calling client. Only part needed in client rb file. | ||
# @return response from abstract methods | ||
def self.run | ||
self.new.run | ||
end | ||
|
||
# Dispatches to abstract method based on passed Arguments to client | ||
def run | ||
func, param = Yast::WFM.Args | ||
log.info "Called #{self.class}.run with #{func} and params #{param}" | ||
|
||
case func | ||
when "Import" | ||
import(param) | ||
when "Export" | ||
export | ||
when "Summary" | ||
summary | ||
when "Reset" | ||
reset | ||
when "Change" | ||
change | ||
when "Write" | ||
write | ||
when "Packages" | ||
packages | ||
when "Read" | ||
read | ||
else | ||
raise "Invalid action for auto client '#{func.inspect}'" | ||
end | ||
end | ||
|
||
protected | ||
|
||
# Abstract method to import data from autoyast profile | ||
# @param [Map] data from autoyast | ||
# @return true if succeed | ||
def import(data) | ||
raise NotImplementedError, "Calling abstract method 'import'" | ||
end | ||
|
||
# Abstract method to return configuration map for autoyast | ||
# @return [Map] autoyast data | ||
def export | ||
raise NotImplementedError, "Calling abstract method 'export'" | ||
end | ||
|
||
# Abstract method to provide brief summary of configuration. | ||
# @return [String] description in richtext format | ||
def summary | ||
raise NotImplementedError, "Calling abstract method 'summary'" | ||
end | ||
|
||
# Abstract method to reset configuration to default state. | ||
# @return [Map] returns empty map or default values. TODO it looks like it doesn't matter | ||
def reset | ||
raise NotImplementedError, "Calling abstract method 'reset'" | ||
end | ||
|
||
# Abstract method to start widget sequence to modify configuration | ||
# @return [Symbol] returns sequence symbol from widget | ||
def change | ||
raise NotImplementedError, "Calling abstract method 'change'" | ||
end | ||
|
||
|
||
# Abstract method to write settings to target. | ||
# @return true if succeed | ||
def write | ||
raise NotImplementedError, "Calling abstract method 'write'" | ||
end | ||
|
||
# Optional abstract method to get list of methods needed for configuration. | ||
# Default implementation return empty list | ||
# @return [Array<String>] list of required packages | ||
def packages | ||
log.info "#{self.class} do not implement packages, return default." | ||
|
||
[] | ||
end | ||
|
||
# Abstract method to read settings from target. It is used to initialize configuration | ||
# from current system for further represent in autoyast profile. | ||
# @return ignored | ||
def read | ||
raise NotImplementedError, "Calling abstract method 'write'" | ||
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
TESTS = \ | ||
asciifile_test.rb \ | ||
auto_client_test.rb \ | ||
finish_client_test.rb \ | ||
hooks_test.rb \ | ||
linuxrc_test.rb \ | ||
|
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,148 @@ | ||
#! /usr/bin/env rspec | ||
|
||
require_relative "test_helper" | ||
|
||
require "installation/auto_client" | ||
|
||
class TestAuto < ::Installation::AutoClient | ||
def import(args) | ||
args.empty? ? "import" : args | ||
end | ||
|
||
["export", "summary", "reset", "change", "write", "packages", "read"].each do |m| | ||
define_method(m.to_sym) { m } | ||
end | ||
end | ||
|
||
describe ::Installation::AutoClient do | ||
subject { ::TestAuto } | ||
describe ".run" do | ||
it "raise exception if unknown first argument is passed" do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Unknown", {}]) | ||
expect{::Installation::AutoClient.run}.to raise_error | ||
end | ||
|
||
context "first client argument is Import" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Import", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method import" do | ||
expect(subject.run).to eq "import" | ||
end | ||
|
||
it "passes argument hash to abstract method" do | ||
test_params = { :a => :b, :c => :d } | ||
allow(Yast::WFM).to receive(:Args).and_return(["Import", test_params]) | ||
|
||
expect(subject.run).to eq test_params | ||
end | ||
|
||
it "raise NotImplementedError exception if abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
context "first client argument is Export" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Export", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method export" do | ||
expect(subject.run).to eq "export" | ||
end | ||
|
||
it "raise NotImplementedError exception if abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
context "first client argument is Summary" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Summary", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method summary" do | ||
expect(subject.run).to eq "summary" | ||
end | ||
|
||
it "raise NotImplementedError exception if abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
context "first client argument is Reset" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Reset", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method reset" do | ||
expect(subject.run).to eq "reset" | ||
end | ||
|
||
it "raise NotImplementedError exception if abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
context "first client argument is Change" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Change", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method change" do | ||
expect(subject.run).to eq "change" | ||
end | ||
|
||
it "raise NotImplementedError exception if abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
context "first client argument is Write" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Write", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method write" do | ||
expect(subject.run).to eq "write" | ||
end | ||
|
||
it "raise NotImplementedError exception if abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
context "first client argument is Read" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Read", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method read" do | ||
expect(subject.run).to eq "read" | ||
end | ||
|
||
it "raise NotImplementedError exception if abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to raise_error(NotImplementedError) | ||
end | ||
end | ||
|
||
context "first client argument is Packages" do | ||
before do | ||
allow(Yast::WFM).to receive(:Args).and_return(["Packages", {}]) | ||
end | ||
|
||
it "dispatch call to abstract method packages" do | ||
expect(subject.run).to eq "packages" | ||
end | ||
|
||
it "just log if optional abstract method not defined" do | ||
expect{::Installation::AutoClient.run}.to_not raise_error | ||
end | ||
|
||
it "returns empty array if optional abstract method not defined" do | ||
expect(::Installation::AutoClient.run).to eq [] | ||
end | ||
end | ||
end | ||
end |