diff options
-rw-r--r-- | lib/facter.rb | 67 | ||||
-rw-r--r-- | lib/facter/memory.rb | 2 | ||||
-rw-r--r-- | lib/facter/processor.rb | 4 | ||||
-rw-r--r-- | tests/tc_simple.rb | 58 |
4 files changed, 66 insertions, 65 deletions
diff --git a/lib/facter.rb b/lib/facter.rb index 57711f5..5feee20 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -218,7 +218,7 @@ class Facter return end - # insert resolves in order of number of tags + # insert resolves in order of number of confinements inserted = false @resolves.each_with_index { |r,index| if resolve.length > r.length @@ -239,7 +239,7 @@ class Facter end # Iterate across all of the fact resolution mechanisms and yield each in - # turn. These are inserted in order of most tags. + # turn. These are inserted in order of most confinements. def each @resolves.each { |r| yield r } end @@ -322,9 +322,10 @@ class Facter end # An actual fact resolution mechanism. These are largely just chunks of - # code, with optional tags restricting the mechanisms to only working on - # specific systems. Note that the tags are always ANDed, so any tags - # specified must all be true for the resolution to be suitable. + # code, with optional confinements restricting the mechanisms to only working on + # specific systems. Note that the confinements are always ANDed, so any + # confinements specified must all be true for the resolution to be + # suitable. class Resolution attr_accessor :interpreter, :code, :name, :fact @@ -369,13 +370,13 @@ class Facter # Create a new resolution mechanism. def initialize(name) @name = name - @tags = [] + @confines = [] @value = nil end - # Return the number of tags. + # Return the number of confines. def length - @tags.length + @confines.length end # Set our code for returning a value. @@ -401,11 +402,11 @@ class Facter def suitable? unless defined? @suitable @suitable = true - if @tags.length == 0 + if @confines.length == 0 return true end - @tags.each { |tag| - unless tag.true? + @confines.each { |confine| + unless confine.true? @suitable = false end } @@ -414,15 +415,15 @@ class Facter return @suitable end - # Add a new tag to the resolution mechanism. - def tag(*args) + # Add a new confine to the resolution mechanism. + def confine(*args) if args[0].is_a? Hash args[0].each do |fact, values| - @tags.push Tag.new(fact,*values) + @confines.push Confine.new(fact,*values) end else fact = args.shift - @tags.push Tag.new(fact,*args) + @confines.push Confine.new(fact,*args) end end @@ -458,7 +459,7 @@ class Facter # A restricting tag for fact resolution mechanisms. The tag must be true # for the resolution mechanism to be suitable. - class Tag + class Confine attr_accessor :fact, :op, :value # Add the tag. Requires the fact name, an operator, and the value @@ -548,13 +549,13 @@ class Facter Facter.add("OperatingSystem") do #obj.os = "Linux" - tag("kernel","SunOS") + confine("kernel","SunOS") setcode do "Solaris" end end Facter.add("OperatingSystem") do #obj.os = "Linux" - tag("kernel","Linux") + confine("kernel","Linux") setcode do if FileTest.exists?("/etc/debian_version") "Debian" @@ -577,11 +578,11 @@ class Facter Facter.add("HardwareModel") do setcode 'uname -m' - #tag("operatingsystem","SunOS") + #confine("operatingsystem","SunOS") end Facter.add("Architecture") do - tag("operatingsystem","Debian") + confine("operatingsystem","Debian") setcode do model = Facter.hardwaremodel case model @@ -749,16 +750,16 @@ class Facter Facter.add("UniqueId") do setcode 'hostid', '/bin/sh' - tag("operatingsystem","Solaris") + confine("operatingsystem","Solaris") end Facter.add("HardwareISA") do setcode 'uname -p', '/bin/sh' - tag("operatingsystem","Solaris") + confine("operatingsystem","Solaris") end Facter.add("MacAddress") do - tag("operatingsystem","Solaris") + confine("operatingsystem","Solaris") setcode do ether = nil output = %x{/sbin/ifconfig -a} @@ -771,7 +772,7 @@ class Facter end Facter.add("MacAddress") do - tag("Kernel","Darwin") + confine("Kernel","Darwin") setcode do ether = nil output = %x{/sbin/ifconfig} @@ -787,7 +788,7 @@ class Facter end end Facter.add("IPAddress") do - tag("Kernel","Darwin") + confine("Kernel","Darwin") setcode do ip = nil output = %x{/sbin/ifconfig} @@ -806,22 +807,22 @@ class Facter end end Facter.add("Hostname") do - tag("Kernel","Darwin") - tag("KernelRelease","R7") + confine("Kernel","Darwin") + confine("KernelRelease","R7") setcode do %x{/usr/sbin/scutil --get LocalHostName} end end Facter.add("IPHostnumber") do - tag("Kernel","Darwin") - tag("KernelRelease","R6") + confine("Kernel","Darwin") + confine("KernelRelease","R6") setcode do %x{/usr/sbin/scutil --get LocalHostName} end end Facter.add("IPHostnumber") do - tag("Kernel","Darwin") - tag("KernelRelease","R6") + confine("Kernel","Darwin") + confine("KernelRelease","R6") setcode do ether = nil output = %x{/sbin/ifconfig} @@ -838,12 +839,12 @@ class Facter end Facter.add("ps") do - tag("operatingsystem","FreeBSD", "NetBSD", "OpenBSD", "Darwin") + confine("operatingsystem","FreeBSD", "NetBSD", "OpenBSD", "Darwin") setcode do 'ps -auxwww' end end Facter.add("id") do - tag("operatingsystem","Linux") + confine("operatingsystem","Linux") setcode "whoami" end diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index 47f98f7..405d61e 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -50,7 +50,7 @@ end :SwapSize => "SwapTotal", :SwapFree => "SwapFree"}.each do |fact, name| Facter.add(fact) do - tag "kernel", "Linux" + confine :kernel => :linux setcode do Facter::Memory.meminfo_number(name) end diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb index bbb476c..2753806 100644 --- a/lib/facter/processor.rb +++ b/lib/facter/processor.rb @@ -31,13 +31,13 @@ end Facter.add("ProcessorCount") do setcode do - processor_list.length + processor_list.length.to_s end end processor_list.each_with_index do |desc, i| Facter.add("Processor#{i}") do - tag :kernel => "Linux" + confine :kernel => :linux setcode do desc end diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb index a293c78..ee815dd 100644 --- a/tests/tc_simple.rb +++ b/tests/tc_simple.rb @@ -40,7 +40,7 @@ class TestFacter < Test::Unit::TestCase assert(Facter.version =~ /^[0-9]+(\.[0-9]+)*$/ ) end - def test_notags_sh + def test_noconfines_sh assert_nothing_raised { Facter.add("testing") do setcode "echo yup" @@ -50,7 +50,7 @@ class TestFacter < Test::Unit::TestCase assert_equal("yup", Facter["testing"].value) end - def test_notags + def test_noconfines assert_nothing_raised { Facter.add("testing") do setcode { "foo" } @@ -60,47 +60,47 @@ class TestFacter < Test::Unit::TestCase assert_equal("foo", Facter["testing"].value) end - def test_onetruetag + def test_onetrueconfine assert_nothing_raised { Facter.add("required") { setcode { "foo" } } Facter.add("testing") { setcode { "bar" } - tag("required","foo") + confine("required","foo") } } assert_equal("bar", Facter["testing"].value) end - def test_onefalsetag + def test_onefalseconfine assert_nothing_raised { Facter.add("required") { setcode { "foo" } } Facter.add("testing") { setcode { "bar" } - tag("required","bar") + confine("required","bar") } } assert_equal(nil, Facter["testing"].value) end - def test_recursivetags + def test_recursiveconfines # This will try to autoload "required", which will fail, so the # fact will be marked as unsuitable. assert_nothing_raised { Facter.add("testing") { setcode { "bar" } - tag("required","foo") + confine("required","foo") } } assert_nothing_raised { Facter.add("required") do setcode { "foo" } - tag("testing","bar") + confine("testing","bar") end } @@ -110,15 +110,15 @@ class TestFacter < Test::Unit::TestCase def test_multipleresolves assert_nothing_raised { Facter.add("funtest") { - setcode { "untagged" } + setcode { "unconfineged" } } Facter.add("funtest") { - setcode { "tagged" } - tag("operatingsystem", Facter["operatingsystem"].value) + setcode { "confineged" } + confine("operatingsystem", Facter["operatingsystem"].value) } } - assert_equal("tagged", Facter["funtest"].value) + assert_equal("confineged", Facter["funtest"].value) end def test_upcase @@ -176,7 +176,7 @@ class TestFacter < Test::Unit::TestCase def test_adding2 assert_nothing_raised() { Facter.add("bootest") { - tag("operatingsystem", Facter["operatingsystem"].value) + confine("operatingsystem", Facter["operatingsystem"].value) setcode "echo bootest" } } @@ -190,8 +190,8 @@ class TestFacter < Test::Unit::TestCase Facter.add("bahtest") { #obj.os = Facter["operatingsystem"].value #obj.release = Facter["operatingsystemrelease"].value - tag("operatingsystem", Facter["operatingsystem"].value) - tag("operatingsystemrelease", + confine("operatingsystem", Facter["operatingsystem"].value) + confine("operatingsystemrelease", Facter["operatingsystemrelease"].value) setcode "echo bahtest" } @@ -206,8 +206,8 @@ class TestFacter < Test::Unit::TestCase Facter.add("failure") { #obj.os = Facter["operatingsystem"].value #obj.release = "FakeRelease" - tag("operatingsystem", Facter["operatingsystem"].value) - tag("operatingsystemrelease", "FakeRelease") + confine("operatingsystem", Facter["operatingsystem"].value) + confine("operatingsystemrelease", "FakeRelease") setcode "echo failure" } } @@ -404,42 +404,42 @@ some random stuff end end - def test_tag_as_array_and_hash + def test_confine_as_array_and_hash assert_nothing_raised { Facter.add("myfact") do - tag "kernel", Facter.kernel + confine "kernel", Facter.kernel setcode do "yep" end end } - assert_equal("yep", Facter.myfact, "Did not get tagged goal") + assert_equal("yep", Facter.myfact, "Did not get confineged goal") # now try it as a hash assert_nothing_raised { Facter.add("hashfact") do - tag "kernel" => Facter.kernel + confine "kernel" => Facter.kernel setcode do "hashness" end end } - assert_equal("hashness", Facter.hashfact, "Did not get tagged goal") + assert_equal("hashness", Facter.hashfact, "Did not get confineged goal") # now with multiple values assert_nothing_raised { Facter.add("hashfact2") do - tag :kernel => ["nosuchkernel", Facter.kernel] + confine :kernel => ["nosuchkernel", Facter.kernel] setcode do "multihash" end end } - assert_equal("multihash", Facter.hashfact2, "Did not get multivalue tag") + assert_equal("multihash", Facter.hashfact2, "Did not get multivalue confine") end def test_strings_or_symbols assert_nothing_raised { Facter.add("symbol1") do - tag :kernel => Facter.kernel + confine :kernel => Facter.kernel setcode do "yep1" end end } @@ -447,10 +447,10 @@ some random stuff assert_equal("yep1", Facter.symbol1, "Did not get symbol fact") end - def test_tag_case_insensitivity + def test_confine_case_insensitivity assert_nothing_raised { Facter.add :casetest1 do - tag :kernel => Facter.kernel.downcase + confine :kernel => Facter.kernel.downcase setcode do "yep1" end end } @@ -459,7 +459,7 @@ some random stuff assert_nothing_raised { Facter.add :casetest2 do - tag :kernel => Facter.kernel.upcase + confine :kernel => Facter.kernel.upcase setcode do "yep2" end end } |