Merge branch 'ticket/master/7670'
Nick Lewis
12 years ago
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
|
9 | 9 |
names = argv
|
10 | 10 |
|
11 | 11 |
# 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
|
16 | 12 |
unless names.empty?
|
17 | 13 |
facts = {}
|
18 | 14 |
names.each do |name|
|
|
24 | 20 |
end
|
25 | 21 |
end
|
26 | 22 |
end
|
|
23 |
|
|
24 |
# Print everything if they didn't ask for specific facts.
|
|
25 |
facts ||= Facter.to_hash
|
27 | 26 |
|
28 | 27 |
# Print the facts as YAML and exit
|
29 | 28 |
if options[:yaml]
|
65 | 65 |
def fact(name)
|
66 | 66 |
name = canonize(name)
|
67 | 67 |
|
|
68 |
# Try to load the fact if necessary
|
68 | 69 |
loader.load(name) unless @facts[name]
|
69 | 70 |
|
70 | |
return @facts[name]
|
|
71 |
# Try HARDER
|
|
72 |
loader.load_all unless @facts[name]
|
|
73 |
|
|
74 |
@facts[name]
|
71 | 75 |
end
|
72 | 76 |
|
73 | 77 |
# Flush all cached values.
|
17 | 17 |
|
18 | 18 |
# Ensure that we don't accidentally cache between test cases.
|
19 | 19 |
config.before :each do
|
|
20 |
Facter::Util::Loader.any_instance.stubs(:load_all)
|
20 | 21 |
Facter.clear
|
21 | 22 |
end
|
22 | 23 |
end
|
2 | 2 |
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3 | 3 |
|
4 | 4 |
require 'facter'
|
|
5 |
require 'facter/util/ip'
|
5 | 6 |
|
6 | 7 |
describe "Per Interface IP facts" do
|
7 | |
before do
|
8 | |
Facter.loadfacts
|
9 | |
end
|
10 | |
|
11 | 8 |
it "should replace the ':' in an interface list with '_'" do
|
12 | 9 |
# So we look supported
|
13 | 10 |
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
14 | 11 |
|
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}
|
16 | 13 |
Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2}
|
17 | 14 |
end
|
18 | 15 |
end
|
5 | 5 |
|
6 | 6 |
describe "Memory facts" do
|
7 | 7 |
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)
|
9 | 11 |
end
|
10 | 12 |
|
11 | 13 |
after do
|
33 | 33 |
|
34 | 34 |
it "should identify Oracle VM as OVS" do
|
35 | 35 |
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
36 |
Facter.stubs(:value).with(:lsbdistid).returns(nil)
|
36 | 37 |
FileTest.stubs(:exists?).returns false
|
37 | 38 |
|
38 | 39 |
FileTest.expects(:exists?).with("/etc/ovs-release").returns true
|
|
43 | 44 |
|
44 | 45 |
it "should identify VMWare ESX" do
|
45 | 46 |
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
47 |
Facter.stubs(:value).with(:lsbdistid).returns(nil)
|
46 | 48 |
FileTest.stubs(:exists?).returns false
|
47 | 49 |
|
48 | 50 |
FileTest.expects(:exists?).with("/etc/vmware-release").returns true
|
18 | 18 |
|
19 | 19 |
|
20 | 20 |
describe Facter::Util::Loader do
|
|
21 |
before :each do
|
|
22 |
Facter::Util::Loader.any_instance.unstub(:load_all)
|
|
23 |
end
|
|
24 |
|
21 | 25 |
def with_env(values)
|
22 | 26 |
old = {}
|
23 | 27 |
values.each do |var, value|
|