facter 1.5.8 → 1.5.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (119) hide show
  1. data/CHANGELOG +94 -0
  2. data/INSTALL +1 -1
  3. data/README +1 -1
  4. data/README.rst +3 -3
  5. data/Rakefile +9 -6
  6. data/bin/facter +18 -123
  7. data/conf/redhat/facter.spec +21 -3
  8. data/conf/solaris/pkginfo +2 -2
  9. data/install.rb +18 -10
  10. data/lib/facter.rb +27 -1
  11. data/lib/facter/application.rb +123 -0
  12. data/lib/facter/arp.rb +28 -0
  13. data/lib/facter/ec2.rb +32 -11
  14. data/lib/facter/hardwareisa.rb +1 -1
  15. data/lib/facter/id.rb +2 -9
  16. data/lib/facter/interfaces.rb +1 -1
  17. data/lib/facter/ipaddress.rb +2 -33
  18. data/lib/facter/ipaddress6.rb +68 -0
  19. data/lib/facter/lsb.rb +5 -5
  20. data/lib/facter/lsbmajdistrelease.rb +1 -1
  21. data/lib/facter/macaddress.rb +4 -14
  22. data/lib/facter/manufacturer.rb +9 -0
  23. data/lib/facter/memory.rb +110 -6
  24. data/lib/facter/netmask.rb +1 -1
  25. data/lib/facter/operatingsystem.rb +17 -2
  26. data/lib/facter/operatingsystemrelease.rb +34 -0
  27. data/lib/facter/processor.rb +8 -5
  28. data/lib/facter/selinux.rb +37 -4
  29. data/lib/facter/uniqueid.rb +1 -1
  30. data/lib/facter/util/#uptime.rb# +64 -0
  31. data/lib/facter/util/ip.rb +23 -15
  32. data/lib/facter/util/loader.rb +2 -2
  33. data/lib/facter/util/macaddress.rb +28 -0
  34. data/lib/facter/util/manufacturer.rb +39 -2
  35. data/lib/facter/util/memory.rb +43 -0
  36. data/lib/facter/util/netmask.rb +1 -1
  37. data/lib/facter/util/resolution.rb +7 -0
  38. data/lib/facter/util/uptime.rb +11 -1
  39. data/lib/facter/util/virtual.rb +13 -2
  40. data/lib/facter/util/vlans.rb +2 -2
  41. data/lib/facter/util/xendomains.rb +10 -0
  42. data/lib/facter/virtual.rb +45 -13
  43. data/lib/facter/xendomains.rb +10 -0
  44. data/spec/fixtures/ifconfig/bsd_ifconfig_all_with_multiple_interfaces +18 -0
  45. data/spec/fixtures/ifconfig/centos_5_5 +17 -0
  46. data/spec/fixtures/ifconfig/centos_5_5_eth0 +8 -0
  47. data/spec/fixtures/ifconfig/darwin_10_3_0 +26 -0
  48. data/spec/fixtures/ifconfig/darwin_10_3_0_en0 +6 -0
  49. data/spec/fixtures/ifconfig/darwin_10_6_4 +28 -0
  50. data/spec/fixtures/ifconfig/darwin_10_6_4_en1 +6 -0
  51. data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack +8 -0
  52. data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack_en1 +7 -0
  53. data/spec/fixtures/ifconfig/darwin_9_8_0 +26 -0
  54. data/spec/fixtures/ifconfig/darwin_9_8_0_en0 +6 -0
  55. data/spec/fixtures/ifconfig/darwin_ifconfig_all_with_multiple_interfaces +23 -0
  56. data/spec/fixtures/ifconfig/fedora_10 +36 -0
  57. data/spec/fixtures/ifconfig/fedora_10_eth0 +9 -0
  58. data/spec/fixtures/ifconfig/fedora_13 +18 -0
  59. data/spec/fixtures/ifconfig/fedora_13_eth0 +9 -0
  60. data/spec/fixtures/ifconfig/fedora_8 +38 -0
  61. data/spec/fixtures/ifconfig/fedora_8_eth0 +9 -0
  62. data/spec/fixtures/ifconfig/freebsd_6_0 +12 -0
  63. data/spec/fixtures/ifconfig/linux_ifconfig_all_with_multiple_interfaces +19 -0
  64. data/spec/fixtures/ifconfig/open_solaris_10 +12 -0
  65. data/spec/fixtures/ifconfig/open_solaris_b132 +20 -0
  66. data/spec/fixtures/ifconfig/sunos_ifconfig_all_with_multiple_interfaces +10 -0
  67. data/spec/fixtures/ifconfig/ubuntu_7_04 +38 -0
  68. data/spec/fixtures/ifconfig/ubuntu_7_04_eth0 +9 -0
  69. data/spec/fixtures/netstat/centos_5_5 +5 -0
  70. data/spec/fixtures/netstat/darwin_10_3_0 +35 -0
  71. data/spec/fixtures/netstat/darwin_10_6_4 +29 -0
  72. data/spec/fixtures/netstat/darwin_10_6_6_dualstack +34 -0
  73. data/spec/fixtures/netstat/darwin_9_8_0 +28 -0
  74. data/spec/fixtures/netstat/fedora_10 +7 -0
  75. data/spec/fixtures/netstat/open_solaris_10 +16 -0
  76. data/spec/fixtures/netstat/open_solaris_b132 +17 -0
  77. data/spec/fixtures/netstat/ubuntu_7_04 +7 -0
  78. data/spec/fixtures/uptime/kstat_boot_time +1 -0
  79. data/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest +37 -0
  80. data/spec/fixtures/virtual/proc_self_status/vserver_2_1/host +36 -0
  81. data/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest +39 -0
  82. data/spec/fixtures/virtual/proc_self_status/vserver_2_3/host +39 -0
  83. data/spec/integration/{facter.rb → facter_spec.rb} +1 -1
  84. data/spec/spec_helper.rb +8 -3
  85. data/spec/unit/data/debian_kfreebsd_ifconfig +40 -0
  86. data/spec/unit/data/hpux_netstat_all_interfaces +3 -6
  87. data/spec/unit/data/selinux_sestatus +6 -0
  88. data/spec/unit/data/xendomains +4 -0
  89. data/spec/unit/{facter.rb → facter_spec.rb} +28 -1
  90. data/spec/unit/id_spec.rb +27 -0
  91. data/spec/unit/{interfaces.rb → interfaces_spec.rb} +1 -1
  92. data/spec/unit/ipaddress6_spec.rb +36 -0
  93. data/spec/unit/memory_spec.rb +45 -0
  94. data/spec/unit/{operatingsystem.rb → operatingsystem_spec.rb} +22 -8
  95. data/spec/unit/operatingsystemrelease_spec.rb +49 -0
  96. data/spec/unit/selinux_spec.rb +89 -0
  97. data/spec/unit/{uptime.rb → uptime_spec.rb} +4 -4
  98. data/spec/unit/util/{collection.rb → collection_spec.rb} +1 -1
  99. data/spec/unit/util/{confine.rb → confine_spec.rb} +1 -1
  100. data/spec/unit/util/{fact.rb → fact_spec.rb} +1 -1
  101. data/spec/unit/util/{ip.rb → ip_spec.rb} +47 -12
  102. data/spec/unit/util/{loader.rb → loader_spec.rb} +51 -1
  103. data/spec/unit/util/macaddress_spec.rb +68 -0
  104. data/spec/unit/util/{macosx.rb → macosx_spec.rb} +1 -1
  105. data/spec/unit/util/{manufacturer.rb → manufacturer_spec.rb} +15 -4
  106. data/spec/unit/util/{resolution.rb → resolution_spec.rb} +1 -1
  107. data/spec/unit/util/uptime_spec.rb +73 -0
  108. data/spec/unit/util/{virtual.rb → virtual_spec.rb} +37 -3
  109. data/spec/unit/util/{vlans.rb → vlans_spec.rb} +1 -1
  110. data/spec/unit/util/xendomains_spec.rb +23 -0
  111. data/spec/unit/virtual_spec.rb +196 -0
  112. metadata +149 -98
  113. data/spec/Rakefile +0 -18
  114. data/spec/unit/data/hpux_ifconfig +0 -3
  115. data/spec/unit/data/hpux_netscan +0 -4
  116. data/spec/unit/operatingsystemrelease.rb +0 -39
  117. data/spec/unit/selinux.rb +0 -48
  118. data/spec/unit/util/uptime.rb +0 -53
  119. data/spec/unit/virtual.rb +0 -71
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
4
 
5
5
  require 'facter'
6
6
 
@@ -9,31 +9,45 @@ describe "Operating System fact" do
9
9
  before do
10
10
  Facter.clear
11
11
  end
12
-
12
+
13
13
  after do
14
14
  Facter.clear
15
15
  end
16
-
16
+
17
17
  it "should default to the kernel name" do
18
18
  Facter.fact(:kernel).stubs(:value).returns("Nutmeg")
19
19
 
20
20
  Facter.fact(:operatingsystem).value.should == "Nutmeg"
21
21
  end
22
-
22
+
23
23
  it "should be Solaris for SunOS" do
24
24
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
25
-
25
+
26
26
  Facter.fact(:operatingsystem).value.should == "Solaris"
27
27
  end
28
-
29
- it "should identify Oracle VM as OVS" do
30
28
 
29
+ it "should be ESXi for VMkernel" do
30
+ Facter.fact(:kernel).stubs(:value).returns("VMkernel")
31
+
32
+ Facter.fact(:operatingsystem).value.should == "ESXi"
33
+ end
34
+
35
+ it "should identify Oracle VM as OVS" do
31
36
  Facter.fact(:kernel).stubs(:value).returns("Linux")
32
37
  FileTest.stubs(:exists?).returns false
33
38
 
34
39
  FileTest.expects(:exists?).with("/etc/ovs-release").returns true
35
40
  FileTest.expects(:exists?).with("/etc/enterprise-release").returns true
36
-
41
+
37
42
  Facter.fact(:operatingsystem).value.should == "OVS"
38
43
  end
44
+
45
+ it "should identify VMWare ESX" do
46
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
47
+ FileTest.stubs(:exists?).returns false
48
+
49
+ FileTest.expects(:exists?).with("/etc/vmware-release").returns true
50
+
51
+ Facter.fact(:operatingsystem).value.should == "VMWareESX"
52
+ end
39
53
  end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ require 'facter'
6
+
7
+ describe "Operating System Release fact" do
8
+
9
+ before do
10
+ Facter.clear
11
+ end
12
+
13
+ after do
14
+ Facter.clear
15
+ end
16
+
17
+ test_cases = {
18
+ "CentOS" => "/etc/redhat-release",
19
+ "RedHat" => "/etc/redhat-release",
20
+ "Fedora" => "/etc/fedora-release",
21
+ "MeeGo" => "/etc/meego-release",
22
+ "OEL" => "/etc/enterprise-release",
23
+ "oel" => "/etc/enterprise-release",
24
+ "OVS" => "/etc/ovs-release",
25
+ "ovs" => "/etc/ovs-release",
26
+ }
27
+
28
+ test_cases.each do |system, file|
29
+ describe "with operatingsystem reported as #{system.inspect}" do
30
+ it "should read the #{file.inspect} file" do
31
+ Facter.fact(:operatingsystem).stubs(:value).returns(system)
32
+
33
+ File.expects(:open).with(file, "r").at_least(1)
34
+
35
+ Facter.fact(:operatingsystemrelease).value
36
+ end
37
+ end
38
+ end
39
+
40
+ it "for VMWareESX it should run the vmware -v command" do
41
+ Facter.fact(:kernel).stubs(:value).returns("VMkernel")
42
+ Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0")
43
+ Facter.fact(:operatingsystem).stubs(:value).returns("VMwareESX")
44
+
45
+ Facter::Util::Resolution.stubs(:exec).with('vmware -v').returns('foo')
46
+
47
+ Facter.fact(:operatingsystemrelease).value
48
+ end
49
+ end
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ require 'facter'
6
+
7
+ describe "SELinux facts" do
8
+
9
+
10
+ after do
11
+ Facter.clear
12
+ end
13
+
14
+ it "should return true if SELinux enabled" do
15
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
16
+
17
+ FileTest.stubs(:exists?).returns false
18
+ File.stubs(:read).with("/proc/self/attr/current").returns("notkernel")
19
+
20
+ FileTest.expects(:exists?).with("/selinux/enforce").returns true
21
+ FileTest.expects(:exists?).with("/proc/self/attr/current").returns true
22
+ File.expects(:read).with("/proc/self/attr/current").returns("kernel")
23
+
24
+ Facter.fact(:selinux).value.should == "true"
25
+ end
26
+
27
+ it "should return true if SELinux policy enabled" do
28
+ Facter.fact(:selinux).stubs(:value).returns("true")
29
+
30
+ FileTest.stubs(:exists?).returns false
31
+ File.stubs(:read).with("/selinux/enforce").returns("0")
32
+
33
+ FileTest.expects(:exists?).with("/selinux/enforce").returns true
34
+ File.expects(:read).with("/selinux/enforce").returns("1")
35
+
36
+ Facter.fact(:selinux_enforced).value.should == "true"
37
+ end
38
+
39
+ it "should return an SELinux policy version" do
40
+ Facter.fact(:selinux).stubs(:value).returns("true")
41
+
42
+ File.stubs(:read).with("/selinux/policyvers").returns("")
43
+
44
+ File.expects(:read).with("/selinux/policyvers").returns("1")
45
+
46
+ Facter.fact(:selinux_policyversion).value.should == "1"
47
+ end
48
+
49
+ it "should return the SELinux current mode" do
50
+ Facter.fact(:selinux).stubs(:value).returns("true")
51
+
52
+ sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus'
53
+ selinux_sestatus = File.read(sample_output_file)
54
+
55
+ Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
56
+
57
+ Facter.fact(:selinux_current_mode).value.should == "permissive"
58
+ end
59
+
60
+ it "should return the SELinux mode from the configuration file" do
61
+ Facter.fact(:selinux).stubs(:value).returns("true")
62
+
63
+ sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus'
64
+ selinux_sestatus = File.read(sample_output_file)
65
+
66
+ Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
67
+
68
+ Facter.fact(:selinux_config_mode).value.should == "permissive"
69
+ end
70
+
71
+ it "should return the SELinux configuration file policy" do
72
+ Facter.fact(:selinux).stubs(:value).returns("true")
73
+
74
+ sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus'
75
+ selinux_sestatus = File.read(sample_output_file)
76
+
77
+ Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
78
+
79
+ Facter.fact(:selinux_config_policy).value.should == "targeted"
80
+ end
81
+
82
+ it "should ensure legacy selinux_mode facts returns same value as selinux_config_policy fact" do
83
+ Facter.fact(:selinux).stubs(:value).returns("true")
84
+
85
+ Facter.fact(:selinux_config_policy).stubs(:value).returns("targeted")
86
+
87
+ Facter.fact(:selinux_mode).value.should == "targeted"
88
+ end
89
+ end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
4
 
5
5
  require 'facter'
6
6
  require 'facter/util/uptime'
@@ -9,7 +9,7 @@ describe "uptime facts:" do
9
9
  before { Facter.clear }
10
10
  after { Facter.clear }
11
11
 
12
- context "when uptime information is available" do
12
+ describe "when uptime information is available" do
13
13
  describe "uptime" do
14
14
  test_cases = [
15
15
  [60 * 60 * 24 * 3, '3 days'],
@@ -34,7 +34,7 @@ describe "uptime facts:" do
34
34
 
35
35
  end
36
36
 
37
- context "when uptime information is available" do
37
+ describe "when uptime information is available" do
38
38
  before do
39
39
  Facter::Util::Uptime.stubs(:get_uptime_seconds_unix).returns(60 * 60 * 24 + 23)
40
40
  Facter::Util::Uptime.stubs(:get_uptime_seconds_win).returns(60 * 60 * 24 + 23)
@@ -59,7 +59,7 @@ describe "uptime facts:" do
59
59
  end
60
60
  end
61
61
 
62
- context "when uptime information is not available" do
62
+ describe "when uptime information is not available" do
63
63
  before do
64
64
  Facter::Util::Uptime.stubs(:get_uptime_seconds_unix).returns(nil)
65
65
  Facter::Util::Uptime.stubs(:get_uptime_seconds_win).returns(nil)
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
4
 
5
5
  require 'facter/util/collection'
6
6
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
4
 
5
5
  require 'facter/util/confine'
6
6
  require 'facter/util/values'
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
4
 
5
5
  require 'facter/util/fact'
6
6
 
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
4
 
5
5
  require 'facter/util/ip'
6
6
 
7
7
  describe Facter::Util::IP do
8
- [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform|
8
+ [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd"].each do |platform|
9
9
  it "should be supported on #{platform}" do
10
10
  Facter::Util::IP.supported_platforms.should be_include(platform)
11
11
  end
@@ -20,11 +20,11 @@ describe Facter::Util::IP do
20
20
  Facter::Util::IP.get_interfaces().should == []
21
21
  end
22
22
 
23
- it "should return a list with a single interface on Linux with a single interface" do
23
+ it "should return a list with a single interface and the loopback interface on Linux with a single interface" do
24
24
  sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface'
25
25
  linux_ifconfig = File.new(sample_output_file).read()
26
26
  Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig)
27
- Facter::Util::IP.get_interfaces().should == ["eth0"]
27
+ Facter::Util::IP.get_interfaces().should == ["eth0", "lo"]
28
28
  end
29
29
 
30
30
  it "should return a list two interfaces on Darwin with two interfaces" do
@@ -46,7 +46,14 @@ describe Facter::Util::IP do
46
46
  hpux_netstat = File.new(sample_output_file).read()
47
47
  Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat)
48
48
  Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"]
49
- end
49
+ end
50
+
51
+ it "should return a list of six interfaces on a GNU/kFreeBSD with six interfaces" do
52
+ sample_output_file = File.dirname(__FILE__) + '/../data/debian_kfreebsd_ifconfig'
53
+ kfreebsd_ifconfig = File.new(sample_output_file).read()
54
+ Facter::Util::IP.stubs(:get_all_interface_output).returns(kfreebsd_ifconfig)
55
+ Facter::Util::IP.get_interfaces().should == ["em0", "em1", "bge0", "bge1", "lo0", "vlan0"]
56
+ end
50
57
 
51
58
  it "should return a value for a specific interface" do
52
59
  Facter::Util::IP.should respond_to(:get_interface_value)
@@ -95,7 +102,7 @@ describe Facter::Util::IP do
95
102
  Facter.stubs(:value).with(:kernel).returns("HP-UX")
96
103
 
97
104
  Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == "168.24.80.71"
98
- end
105
+ end
99
106
 
100
107
  it "should return macaddress information for HP-UX" do
101
108
  sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
@@ -105,7 +112,17 @@ describe Facter::Util::IP do
105
112
  Facter.stubs(:value).with(:kernel).returns("HP-UX")
106
113
 
107
114
  Facter::Util::IP.get_interface_value("lan0", "macaddress").should == "00:13:21:BD:9C:B7"
108
- end
115
+ end
116
+
117
+ it "should return macaddress with leading zeros stripped off for GNU/kFreeBSD" do
118
+ sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig"
119
+ kfreebsd_ifconfig = File.new(sample_output_file).read()
120
+
121
+ Facter::Util::IP.expects(:get_single_interface_output).with("em0").returns(kfreebsd_ifconfig)
122
+ Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD")
123
+
124
+ Facter::Util::IP.get_interface_value("em0", "macaddress").should == "0:11:a:59:67:90"
125
+ end
109
126
 
110
127
  it "should return netmask information for HP-UX" do
111
128
  sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
@@ -115,7 +132,7 @@ describe Facter::Util::IP do
115
132
  Facter.stubs(:value).with(:kernel).returns("HP-UX")
116
133
 
117
134
  Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0"
118
- end
135
+ end
119
136
 
120
137
  it "should return calculated network information for HP-UX" do
121
138
  sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
@@ -125,7 +142,7 @@ describe Facter::Util::IP do
125
142
  Facter.stubs(:value).with(:kernel).returns("HP-UX")
126
143
 
127
144
  Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0"
128
- end
145
+ end
129
146
 
130
147
  it "should return interface information for FreeBSD supported via an alias" do
131
148
  sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig"
@@ -175,7 +192,7 @@ describe Facter::Util::IP do
175
192
  Facter.stubs(:value).with(:kernel).returns("HP-UX")
176
193
 
177
194
  Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0"
178
- end
195
+ end
179
196
 
180
197
  it "should return a human readable netmask on Darwin" do
181
198
  sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface"
@@ -187,10 +204,21 @@ describe Facter::Util::IP do
187
204
 
188
205
  Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0"
189
206
  end
190
-
207
+
208
+ it "should return a human readable netmask on GNU/kFreeBSD" do
209
+ sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig"
210
+
211
+ kfreebsd_ifconfig = File.new(sample_output_file).read()
212
+
213
+ Facter::Util::IP.expects(:get_single_interface_output).with("em1").returns(kfreebsd_ifconfig)
214
+ Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD")
215
+
216
+ Facter::Util::IP.get_interface_value("em1", "netmask").should == "255.255.255.0"
217
+ end
218
+
191
219
  it "should not get bonding master on interface aliases" do
192
220
  Facter.stubs(:value).with(:kernel).returns("Linux")
193
-
221
+
194
222
  Facter::Util::IP.get_bonding_master("eth0:1").should be_nil
195
223
  end
196
224
 
@@ -199,4 +227,11 @@ describe Facter::Util::IP do
199
227
  Facter::Util::IP.convert_from_hex?(platform).should == true
200
228
  end
201
229
  end
230
+
231
+ it "should return an arp address on Linux" do
232
+ Facter.stubs(:value).with(:kernel).returns("Linux")
233
+
234
+ Facter::Util::IP.expects(:get_arp_value).with("eth0").returns("00:00:0c:9f:f0:04")
235
+ Facter::Util::IP.get_arp_value("eth0").should == "00:00:0c:9f:f0:04"
236
+ end
202
237
  end
@@ -1,9 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
4
 
5
5
  require 'facter/util/loader'
6
6
 
7
+
8
+ # loader subclass for making assertions about file/directory ordering
9
+ class TestLoader < Facter::Util::Loader
10
+ def loaded_files
11
+ @loaded_files ||= []
12
+ end
13
+
14
+ def load_file(file)
15
+ loaded_files << file
16
+ super
17
+ end
18
+ end
19
+
20
+
7
21
  describe Facter::Util::Loader do
8
22
  def with_env(values)
9
23
  old = {}
@@ -96,6 +110,24 @@ describe Facter::Util::Loader do
96
110
  @loader.load(:testing)
97
111
  end
98
112
 
113
+ it 'should load any ruby files in directories matching the fact name in the search path in sorted order regardless of the order returned by Dir.entries' do
114
+ @loader = TestLoader.new
115
+
116
+ @loader.stubs(:search_path).returns %w{/one/dir}
117
+ FileTest.stubs(:exist?).returns false
118
+ FileTest.stubs(:directory?).with("/one/dir/testing").returns true
119
+ @loader.stubs(:search_path).returns %w{/one/dir}
120
+
121
+ Dir.stubs(:entries).with("/one/dir/testing").returns %w{foo.rb bar.rb}
122
+ %w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each do |f|
123
+ File.stubs(:directory?).with(f).returns false
124
+ Kernel.stubs(:load).with(f)
125
+ end
126
+
127
+ @loader.load(:testing)
128
+ @loader.loaded_files.should == %w{/one/dir/testing/bar.rb /one/dir/testing/foo.rb}
129
+ end
130
+
99
131
  it "should load any ruby files in directories matching the fact name in the search path" do
100
132
  @loader.expects(:search_path).returns %w{/one/dir}
101
133
  FileTest.stubs(:exist?).returns false
@@ -166,6 +198,24 @@ describe Facter::Util::Loader do
166
198
  @loader.load_all
167
199
  end
168
200
 
201
+ it 'should load all files in sorted order for any given directory regardless of the order returned by Dir.entries' do
202
+ @loader = TestLoader.new
203
+
204
+ @loader.stubs(:search_path).returns %w{/one/dir}
205
+ Dir.stubs(:entries).with("/one/dir").returns %w{foo.rb bar.rb}
206
+
207
+ %w{/one/dir}.each { |f| File.stubs(:directory?).with(f).returns true }
208
+
209
+ %w{/one/dir/foo.rb /one/dir/bar.rb}.each do |f|
210
+ File.stubs(:directory?).with(f).returns false
211
+ Kernel.expects(:load).with(f)
212
+ end
213
+
214
+ @loader.load_all
215
+
216
+ @loader.loaded_files.should == %w{/one/dir/bar.rb /one/dir/foo.rb}
217
+ end
218
+
169
219
  it "should not load files in the util subdirectory" do
170
220
  @loader.expects(:search_path).returns %w{/one/dir}
171
221