Codebase list facter / 97927e3
Merge branch 'ticket/master/7670' Nick Lewis 12 years ago
10 changed file(s) with 69 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
+0
-31
accecptance/tests/ticket_7039_facter_multiple_facts_one_file.rb less more
0 test_name "#7039: Facter having issue handling multiple facts in a single file"
1
2 fact_file= %q{
3 Facter.add(:test_fact1) do
4 setcode do
5 "test fact 1"
6 end
7 end
8
9 Facter.add(:test_fact2) do
10 setcode do
11 "test fact 2"
12 end
13 end
14 }
15
16 agent1=agents.first
17 step "Agent: Create fact file with multiple facts"
18 create_remote_file(agent1, '/tmp/test_facts.rb', fact_file )
19
20 step "Agent: Verify test_fact1 from /tmp/test_facts.rb"
21 on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact1") do
22 fail_test "Fact 1 not returned by facter --puppet test_fact1" unless
23 stdout.include? 'test fact 1'
24 end
25
26 step "Agent: Verify test_fact2 from /tmp/test_facts.rb"
27 on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact2") do
28 fail_test "Fact 1 not returned by facter --puppet test_fact2" unless
29 stdout.include? 'test fact 2'
30 end
0 test_name "#7670: Facter should properly detect operatingsystem on Ubuntu after a clear"
1
2 script_contents = <<-OS_DETECT
3 require 'facter'
4 Facter['operatingsystem'].value
5 Facter.clear
6 exit Facter['operatingsystem'].value == 'Ubuntu'
7 OS_DETECT
8
9 script_name = "/tmp/facter_os_detection_test_#{$$}"
10
11 agents.each do |agent|
12 next unless agent['platform'].include? 'ubuntu'
13
14 create_remote_file(agent, script_name, script_contents)
15
16 on(agent, "ruby #{script_name}")
17 end
0 test_name "#7039: Facter having issue handling multiple facts in a single file"
1
2 fact_file= %q{
3 Facter.add(:test_fact1) do
4 setcode do
5 "test fact 1"
6 end
7 end
8
9 Facter.add(:test_fact2) do
10 setcode do
11 "test fact 2"
12 end
13 end
14 }
15
16 agent1=agents.first
17 step "Agent: Create fact file with multiple facts"
18 create_remote_file(agent1, '/tmp/test_facts.rb', fact_file )
19
20 step "Agent: Verify test_fact1 from /tmp/test_facts.rb"
21 on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact1") do
22 fail_test "Fact 1 not returned by facter --puppet test_fact1" unless
23 stdout.include? 'test fact 1'
24 end
25
26 step "Agent: Verify test_fact2 from /tmp/test_facts.rb"
27 on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact2") do
28 fail_test "Fact 1 not returned by facter --puppet test_fact2" unless
29 stdout.include? 'test fact 2'
30 end
99 names = argv
1010
1111 # Create the facts hash that is printed to standard out.
12 # Pre-load all of the facts, since we can have multiple facts
13 # per file, and since we can't know ahead of time which file a
14 # fact will be in, we'll need to load every file.
15 facts = Facter.to_hash
1612 unless names.empty?
1713 facts = {}
1814 names.each do |name|
2420 end
2521 end
2622 end
23
24 # Print everything if they didn't ask for specific facts.
25 facts ||= Facter.to_hash
2726
2827 # Print the facts as YAML and exit
2928 if options[:yaml]
6565 def fact(name)
6666 name = canonize(name)
6767
68 # Try to load the fact if necessary
6869 loader.load(name) unless @facts[name]
6970
70 return @facts[name]
71 # Try HARDER
72 loader.load_all unless @facts[name]
73
74 @facts[name]
7175 end
7276
7377 # Flush all cached values.
1717
1818 # Ensure that we don't accidentally cache between test cases.
1919 config.before :each do
20 Facter::Util::Loader.any_instance.stubs(:load_all)
2021 Facter.clear
2122 end
2223 end
22 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
33
44 require 'facter'
5 require 'facter/util/ip'
56
67 describe "Per Interface IP facts" do
7 before do
8 Facter.loadfacts
9 end
10
118 it "should replace the ':' in an interface list with '_'" do
129 # So we look supported
1310 Facter.fact(:kernel).stubs(:value).returns("SunOS")
1411
15 Facter::Util::IP.expects(:get_interfaces).returns %w{eth0:1 eth1:2}
12 Facter::Util::IP.stubs(:get_interfaces).returns %w{eth0:1 eth1:2}
1613 Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2}
1714 end
1815 end
55
66 describe "Memory facts" do
77 before do
8 Facter.loadfacts
8 # We need these facts loaded, but they belong to a file with a
9 # different name, so load the file explicitly.
10 Facter.collection.loader.load(:memory)
911 end
1012
1113 after do
3333
3434 it "should identify Oracle VM as OVS" do
3535 Facter.fact(:kernel).stubs(:value).returns("Linux")
36 Facter.stubs(:value).with(:lsbdistid).returns(nil)
3637 FileTest.stubs(:exists?).returns false
3738
3839 FileTest.expects(:exists?).with("/etc/ovs-release").returns true
4344
4445 it "should identify VMWare ESX" do
4546 Facter.fact(:kernel).stubs(:value).returns("Linux")
47 Facter.stubs(:value).with(:lsbdistid).returns(nil)
4648 FileTest.stubs(:exists?).returns false
4749
4850 FileTest.expects(:exists?).with("/etc/vmware-release").returns true
1818
1919
2020 describe Facter::Util::Loader do
21 before :each do
22 Facter::Util::Loader.any_instance.unstub(:load_all)
23 end
24
2125 def with_env(values)
2226 old = {}
2327 values.each do |var, value|