Skip to content

Commit

Permalink
fix in -or- rules operator
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Jan 19, 2016
1 parent e63fc7e commit eef6e83
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/modules/AutoInstallRules.rb
Expand Up @@ -466,13 +466,14 @@ def Read
rls.reject! {|r| r=="result"}
rls.push("result")
end
op = Ops.get_string(ruleset, "operator", "and")
rls.reject! {|r| r=="op"}
Builtins.y2milestone("Orderes Rules: %1", rls)
Builtins.foreach(rls) do |rule|
ruledef = ruleset.fetch( rule, {} )
Builtins.y2milestone("Rule: %1", rule)
Builtins.y2milestone("Ruledef: %1", ruledef)
match = Ops.get_string(ruledef, "match", "undefined")
op = Ops.get_string(ruledef, "operator", "and")
matchtype = Ops.get_string(ruledef, "match_type", "exact")
easy_rules = [
"hostname",
Expand Down Expand Up @@ -822,7 +823,6 @@ def Read
@tomerge
)
end

nil
end

Expand Down
61 changes: 61 additions & 0 deletions test/AutoInstallRules_test.rb
Expand Up @@ -114,6 +114,67 @@
end
end

describe "#Rules XML" do
it "Reading rules with -or- operator" do
expect(Yast::XML).to receive(:XMLToYCPFile).and_return(
{ "rules"=>[{
"hostaddress"=>{"match"=>"10.69.57.43",
"match_type"=>"exact"},
"mac"=>{"match"=>"000c2903d288",
"match_type"=>"exact"},
"operator"=>"or",
"result"=>{"profile"=>"machine12.xml"}}]
}
)
expect(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash_output"),
"if ( [ \"$hostaddress\" = \"10.69.57.43\" ] ) || ( [ \"$mac\" = \"000c2903d288\" ] ); then exit 0; else exit 1; fi",
{"hostaddress"=>"192.168.1.1", "mac"=>""}
)
.and_return({"stdout"=>"", "exit"=>0, "stderr"=>""})

subject.Read
end

it "Reading rules with -and- operator" do
expect(Yast::XML).to receive(:XMLToYCPFile).and_return(
{ "rules"=>[{
"hostaddress"=>{"match"=>"10.69.57.43",
"match_type"=>"exact"},
"mac"=>{"match"=>"000c2903d288",
"match_type"=>"exact"},
"operator"=>"and",
"result"=>{"profile"=>"machine12.xml"}}]
}
)
expect(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash_output"),
"if ( [ \"$hostaddress\" = \"10.69.57.43\" ] ) && ( [ \"$mac\" = \"000c2903d288\" ] ); then exit 0; else exit 1; fi",
{"hostaddress"=>"192.168.1.1", "mac"=>""}
)
.and_return({"stdout"=>"", "exit"=>0, "stderr"=>""})

subject.Read
end

it "Reading rules with default operator" do
expect(Yast::XML).to receive(:XMLToYCPFile).and_return(
{ "rules"=>[{
"hostaddress"=>{"match"=>"10.69.57.43",
"match_type"=>"exact"},
"mac"=>{"match"=>"000c2903d288",
"match_type"=>"exact"},
"result"=>{"profile"=>"machine12.xml"}}]
}
)
expect(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash_output"),
"if ( [ \"$hostaddress\" = \"10.69.57.43\" ] ) && ( [ \"$mac\" = \"000c2903d288\" ] ); then exit 0; else exit 1; fi",
{"hostaddress"=>"192.168.1.1", "mac"=>""}
)
.and_return({"stdout"=>"", "exit"=>0, "stderr"=>""})

subject.Read
end
end

describe "#Host ID" do
let(:wicked_output_path) { File.join(root_path, 'test', 'fixtures', 'output', 'wicked_output') }
it "returns host IP in hex format (initial Stage)" do
Expand Down

0 comments on commit eef6e83

Please sign in to comment.