facter 1.6.18 → 1.7.0.rc1

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 (126) hide show
  1. data/Gemfile +23 -8
  2. data/bin/facter +4 -1
  3. data/ext/build_defaults.yaml +1 -1
  4. data/ext/debian/changelog.erb +4 -22
  5. data/ext/debian/control +2 -2
  6. data/ext/project_data.yaml +1 -1
  7. data/ext/redhat/facter.spec.erb +10 -9
  8. data/install.rb +27 -53
  9. data/lib/facter.rb +23 -5
  10. data/lib/facter/application.rb +21 -0
  11. data/lib/facter/blockdevices.rb +105 -0
  12. data/lib/facter/domain.rb +19 -7
  13. data/lib/facter/filesystems.rb +38 -0
  14. data/lib/facter/hardwaremodel.rb +3 -2
  15. data/lib/facter/ipaddress6.rb +1 -2
  16. data/lib/facter/kernelrelease.rb +10 -2
  17. data/lib/facter/ldom.rb +47 -0
  18. data/lib/facter/macaddress.rb +1 -1
  19. data/lib/facter/manufacturer.rb +7 -1
  20. data/lib/facter/memory.rb +58 -160
  21. data/lib/facter/operatingsystem.rb +17 -2
  22. data/lib/facter/operatingsystemmajrelease.rb +33 -0
  23. data/lib/facter/operatingsystemrelease.rb +88 -37
  24. data/lib/facter/osfamily.rb +6 -2
  25. data/lib/facter/processor.rb +2 -2
  26. data/lib/facter/ps.rb +5 -0
  27. data/lib/facter/ssh.rb +50 -12
  28. data/lib/facter/util/cfpropertylist.rb +6 -0
  29. data/lib/facter/util/cfpropertylist/LICENSE +19 -0
  30. data/lib/facter/util/cfpropertylist/README +44 -0
  31. data/lib/facter/util/cfpropertylist/Rakefile +44 -0
  32. data/lib/facter/util/cfpropertylist/THANKS +7 -0
  33. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +6 -0
  34. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +562 -0
  35. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +26 -0
  36. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +402 -0
  37. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +244 -0
  38. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +135 -0
  39. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +140 -0
  40. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +136 -0
  41. data/lib/facter/util/collection.rb +36 -14
  42. data/lib/facter/util/composite_loader.rb +12 -0
  43. data/lib/facter/util/config.rb +36 -0
  44. data/lib/facter/util/confine.rb +1 -6
  45. data/lib/facter/util/directory_loader.rb +83 -0
  46. data/lib/facter/util/fact.rb +49 -42
  47. data/lib/facter/util/file_read.rb +32 -0
  48. data/lib/facter/util/ip.rb +2 -9
  49. data/lib/facter/util/loader.rb +16 -2
  50. data/lib/facter/util/macosx.rb +15 -2
  51. data/lib/facter/util/memory.rb +154 -27
  52. data/lib/facter/util/nothing_loader.rb +15 -0
  53. data/lib/facter/util/parser.rb +141 -0
  54. data/lib/facter/util/processor.rb +27 -35
  55. data/lib/facter/util/resolution.rb +97 -26
  56. data/lib/facter/util/solaris_zones.rb +153 -0
  57. data/lib/facter/util/virtual.rb +32 -3
  58. data/lib/facter/version.rb +72 -2
  59. data/lib/facter/virtual.rb +56 -3
  60. data/lib/facter/zfs_version.rb +10 -0
  61. data/lib/facter/zonename.rb +6 -0
  62. data/lib/facter/zones.rb +17 -0
  63. data/lib/facter/zpool_version.rb +10 -0
  64. data/spec/fixtures/ifconfig/ifconfig_net_tools_1.60.txt +19 -0
  65. data/spec/fixtures/ifconfig/ifconfig_ubuntu_1204.txt +16 -0
  66. data/spec/fixtures/ldom/ldom_v1 +6 -0
  67. data/spec/fixtures/unit/filesystems/linux +28 -0
  68. data/spec/fixtures/unit/util/manufacturer/intel_linux_dmidecode +549 -0
  69. data/spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt +0 -0
  70. data/spec/fixtures/unit/zfs_version/freebsd_8.2 +14 -0
  71. data/spec/fixtures/unit/zfs_version/freebsd_9.0 +13 -0
  72. data/spec/fixtures/unit/zfs_version/linux-fuse_0.6.9 +14 -0
  73. data/spec/fixtures/unit/zfs_version/solaris_10 +10 -0
  74. data/spec/fixtures/unit/zfs_version/solaris_11 +12 -0
  75. data/spec/fixtures/unit/zpool_version/freebsd_8.2 +26 -0
  76. data/spec/fixtures/unit/zpool_version/freebsd_9.0 +38 -0
  77. data/spec/fixtures/unit/zpool_version/linux-fuse_0.6.9 +35 -0
  78. data/spec/fixtures/unit/zpool_version/solaris_10 +31 -0
  79. data/spec/fixtures/unit/zpool_version/solaris_11 +43 -0
  80. data/spec/integration/facter_spec.rb +12 -0
  81. data/spec/spec_helper.rb +9 -0
  82. data/spec/unit/architecture_spec.rb +1 -1
  83. data/spec/unit/blockdevices_spec.rb +109 -0
  84. data/spec/unit/domain_spec.rb +189 -81
  85. data/spec/unit/ec2_spec.rb +15 -8
  86. data/spec/unit/filesystems_spec.rb +50 -0
  87. data/spec/unit/hardwaremodel_spec.rb +8 -1
  88. data/spec/unit/id_spec.rb +6 -5
  89. data/spec/unit/ipaddress6_spec.rb +14 -2
  90. data/spec/unit/ipaddress_spec.rb +1 -1
  91. data/spec/unit/kernel_spec.rb +24 -0
  92. data/spec/unit/kernelmajversion_spec.rb +17 -0
  93. data/spec/unit/kernelrelease_spec.rb +53 -0
  94. data/spec/unit/kernelversion_spec.rb +32 -0
  95. data/spec/unit/ldom_spec.rb +74 -0
  96. data/spec/unit/macaddress_spec.rb +3 -1
  97. data/spec/unit/manufacturer_spec.rb +115 -0
  98. data/spec/unit/memory_spec.rb +442 -75
  99. data/spec/unit/operatingsystem_spec.rb +16 -2
  100. data/spec/unit/operatingsystemmajrelease_spec.rb +16 -0
  101. data/spec/unit/operatingsystemrelease_spec.rb +110 -1
  102. data/spec/unit/processor_spec.rb +22 -7
  103. data/spec/unit/ps_spec.rb +42 -0
  104. data/spec/unit/ssh_spec.rb +76 -0
  105. data/spec/unit/util/collection_spec.rb +94 -118
  106. data/spec/unit/util/config_spec.rb +36 -5
  107. data/spec/unit/util/confine_spec.rb +31 -43
  108. data/spec/unit/util/directory_loader_spec.rb +87 -0
  109. data/spec/unit/util/fact_spec.rb +37 -25
  110. data/spec/unit/util/file_read_spec.rb +29 -0
  111. data/spec/unit/util/ip_spec.rb +4 -2
  112. data/spec/unit/util/loader_spec.rb +102 -45
  113. data/spec/unit/util/macosx_spec.rb +40 -9
  114. data/spec/unit/util/manufacturer_spec.rb +12 -1
  115. data/spec/unit/util/parser_spec.rb +135 -0
  116. data/spec/unit/util/resolution_spec.rb +136 -4
  117. data/spec/unit/util/solaris_zones_spec.rb +127 -0
  118. data/spec/unit/util/virtual_spec.rb +54 -0
  119. data/spec/unit/version_spec.rb +42 -0
  120. data/spec/unit/virtual_spec.rb +102 -27
  121. data/spec/unit/zfs_version_spec.rb +76 -0
  122. data/spec/unit/zonename_spec.rb +14 -0
  123. data/spec/unit/zones_spec.rb +55 -0
  124. data/spec/unit/zpool_version_spec.rb +76 -0
  125. metadata +113 -11
  126. data/lib/facter/arp.rb +0 -28
@@ -0,0 +1,14 @@
1
+ The following filesystem versions are supported:
2
+
3
+ VER DESCRIPTION
4
+ --- --------------------------------------------------------
5
+ 1 Initial ZFS filesystem version
6
+ 2 Enhanced directory entries
7
+ 3 Case insensitive and File system unique identifer (FUID)
8
+ 4 userquota, groupquota properties
9
+
10
+ For more information on a particular version, including supported releases, see:
11
+
12
+ http://www.opensolaris.org/os/community/zfs/version/zpl/N
13
+
14
+ Where 'N' is the version number.
@@ -0,0 +1,13 @@
1
+ The following filesystem versions are supported:
2
+
3
+ VER DESCRIPTION
4
+ --- --------------------------------------------------------
5
+ 1 Initial ZFS filesystem version
6
+ 2 Enhanced directory entries
7
+ 3 Case insensitive and File system unique identifier (FUID)
8
+ 4 userquota, groupquota properties
9
+ 5 System attributes
10
+
11
+ For more information on a particular version, including supported releases,
12
+ see the ZFS Administration Guide.
13
+
@@ -0,0 +1,14 @@
1
+ The following filesystem versions are supported:
2
+
3
+ VER DESCRIPTION
4
+ --- --------------------------------------------------------
5
+ 1 Initial ZFS filesystem version
6
+ 2 Enhanced directory entries
7
+ 3 Case insensitive and File system unique identifier (FUID)
8
+ 4 userquota, groupquota properties
9
+
10
+ For more information on a particular version, including supported releases, see:
11
+
12
+ http://www.opensolaris.org/os/community/zfs/version/zpl/N
13
+
14
+ Where 'N' is the version number.
@@ -0,0 +1,10 @@
1
+ The following filesystem versions are supported:
2
+
3
+ VER DESCRIPTION
4
+ --- --------------------------------------------------------
5
+ 1 Initial ZFS filesystem version
6
+ 2 Enhanced directory entries
7
+ 3 Case insensitive and SMB credentials support
8
+
9
+ For more information on a particular version, including supported releases,
10
+ see the ZFS Administration Guide.
@@ -0,0 +1,12 @@
1
+ The following filesystem versions are supported:
2
+
3
+ VER DESCRIPTION
4
+ --- --------------------------------------------------------
5
+ 1 Initial ZFS filesystem version
6
+ 2 Enhanced directory entries
7
+ 3 Case insensitive and SMB credentials support
8
+ 4 userquota, groupquota properties
9
+ 5 System attributes
10
+
11
+ For more information on a particular version, including supported releases,
12
+ see the ZFS Administration Guide.
@@ -0,0 +1,26 @@
1
+ This system is currently running ZFS pool version 15.
2
+
3
+ The following versions are supported:
4
+
5
+ VER DESCRIPTION
6
+ --- --------------------------------------------------------
7
+ 1 Initial ZFS version
8
+ 2 Ditto blocks (replicated metadata)
9
+ 3 Hot spares and double parity RAID-Z
10
+ 4 zpool history
11
+ 5 Compression using the gzip algorithm
12
+ 6 bootfs pool property
13
+ 7 Separate intent log devices
14
+ 8 Delegated administration
15
+ 9 refquota and refreservation properties
16
+ 10 Cache devices
17
+ 11 Improved scrub performance
18
+ 12 Snapshot properties
19
+ 13 snapused property
20
+ 14 passthrough-x aclinherit
21
+ 15 user/group space accounting
22
+ For more information on a particular version, including supported releases, see:
23
+
24
+ http://www.opensolaris.org/os/community/zfs/version/N
25
+
26
+ Where 'N' is the version number.
@@ -0,0 +1,38 @@
1
+ This system is currently running ZFS pool version 28.
2
+
3
+ The following versions are supported:
4
+
5
+ VER DESCRIPTION
6
+ --- --------------------------------------------------------
7
+ 1 Initial ZFS version
8
+ 2 Ditto blocks (replicated metadata)
9
+ 3 Hot spares and double parity RAID-Z
10
+ 4 zpool history
11
+ 5 Compression using the gzip algorithm
12
+ 6 bootfs pool property
13
+ 7 Separate intent log devices
14
+ 8 Delegated administration
15
+ 9 refquota and refreservation properties
16
+ 10 Cache devices
17
+ 11 Improved scrub performance
18
+ 12 Snapshot properties
19
+ 13 snapused property
20
+ 14 passthrough-x aclinherit
21
+ 15 user/group space accounting
22
+ 16 stmf property support
23
+ 17 Triple-parity RAID-Z
24
+ 18 Snapshot user holds
25
+ 19 Log device removal
26
+ 20 Compression using zle (zero-length encoding)
27
+ 21 Deduplication
28
+ 22 Received properties
29
+ 23 Slim ZIL
30
+ 24 System attributes
31
+ 25 Improved scrub stats
32
+ 26 Improved snapshot deletion performance
33
+ 27 Improved snapshot creation performance
34
+ 28 Multiple vdev replacements
35
+
36
+ For more information on a particular version, including supported releases,
37
+ see the ZFS Administration Guide.
38
+
@@ -0,0 +1,35 @@
1
+ This system is currently running ZFS pool version 23.
2
+
3
+ The following versions are supported:
4
+
5
+ VER DESCRIPTION
6
+ --- --------------------------------------------------------
7
+ 1 Initial ZFS version
8
+ 2 Ditto blocks (replicated metadata)
9
+ 3 Hot spares and double parity RAID-Z
10
+ 4 zpool history
11
+ 5 Compression using the gzip algorithm
12
+ 6 bootfs pool property
13
+ 7 Separate intent log devices
14
+ 8 Delegated administration
15
+ 9 refquota and refreservation properties
16
+ 10 Cache devices
17
+ 11 Improved scrub performance
18
+ 12 Snapshot properties
19
+ 13 snapused property
20
+ 14 passthrough-x aclinherit
21
+ 15 user/group space accounting
22
+ 16 stmf property support
23
+ 17 Triple-parity RAID-Z
24
+ 18 Snapshot user holds
25
+ 19 Log device removal
26
+ 20 Compression using zle (zero-length encoding)
27
+ 21 Deduplication
28
+ 22 Received properties
29
+ 23 Slim ZIL
30
+
31
+ For more information on a particular version, including supported releases, see:
32
+
33
+ http://www.opensolaris.org/os/community/zfs/version/N
34
+
35
+ Where 'N' is the version number.
@@ -0,0 +1,31 @@
1
+ This system is currently running ZFS pool version 22.
2
+
3
+ The following versions are supported:
4
+
5
+ VER DESCRIPTION
6
+ --- --------------------------------------------------------
7
+ 1 Initial ZFS version
8
+ 2 Ditto blocks (replicated metadata)
9
+ 3 Hot spares and double parity RAID-Z
10
+ 4 zpool history
11
+ 5 Compression using the gzip algorithm
12
+ 6 bootfs pool property
13
+ 7 Separate intent log devices
14
+ 8 Delegated administration
15
+ 9 refquota and refreservation properties
16
+ 10 Cache devices
17
+ 11 Improved scrub performance
18
+ 12 Snapshot properties
19
+ 13 snapused property
20
+ 14 passthrough-x aclinherit
21
+ 15 user/group space accounting
22
+ 16 stmf property support
23
+ 17 Triple-parity RAID-Z
24
+ 18 Snapshot user holds
25
+ 19 Log device removal
26
+ 20 Compression using zle (zero-length encoding)
27
+ 21 Reserved
28
+ 22 Received properties
29
+
30
+ For more information on a particular version, including supported releases,
31
+ see the ZFS Administration Guide.
@@ -0,0 +1,43 @@
1
+ zpool upgrade -v
2
+ This system is currently running ZFS pool version 33.
3
+
4
+ The following versions are supported:
5
+
6
+ VER DESCRIPTION
7
+ --- --------------------------------------------------------
8
+ 1 Initial ZFS version
9
+ 2 Ditto blocks (replicated metadata)
10
+ 3 Hot spares and double parity RAID-Z
11
+ 4 zpool history
12
+ 5 Compression using the gzip algorithm
13
+ 6 bootfs pool property
14
+ 7 Separate intent log devices
15
+ 8 Delegated administration
16
+ 9 refquota and refreservation properties
17
+ 10 Cache devices
18
+ 11 Improved scrub performance
19
+ 12 Snapshot properties
20
+ 13 snapused property
21
+ 14 passthrough-x aclinherit
22
+ 15 user/group space accounting
23
+ 16 stmf property support
24
+ 17 Triple-parity RAID-Z
25
+ 18 Snapshot user holds
26
+ 19 Log device removal
27
+ 20 Compression using zle (zero-length encoding)
28
+ 21 Deduplication
29
+ 22 Received properties
30
+ 23 Slim ZIL
31
+ 24 System attributes
32
+ 25 Improved scrub stats
33
+ 26 Improved snapshot deletion performance
34
+ 27 Improved snapshot creation performance
35
+ 28 Multiple vdev replacements
36
+ 29 RAID-Z/mirror hybrid allocator
37
+ 30 Encryption
38
+ 31 Improved 'zfs list' performance
39
+ 32 One MB blocksize
40
+ 33 Improved share support
41
+
42
+ For more information on a particular version, including supported releases,
43
+ see the ZFS Administration Guide.
@@ -24,4 +24,16 @@ describe Facter do
24
24
  Facter.reset
25
25
  Facter.collection.should_not equal(old)
26
26
  end
27
+
28
+ it "should raise an error if a recursion is detected" do
29
+ Facter.clear
30
+ Facter.add(:foo) do
31
+ confine :bar => 'some_value'
32
+ end
33
+ Facter.add(:bar) do
34
+ confine :foo => 'some_value'
35
+ end
36
+ lambda { Facter.value(:foo) }.should raise_error(RuntimeError, /Caught recursion on foo/)
37
+ end
38
+
27
39
  end
@@ -39,3 +39,12 @@ RSpec.configure do |config|
39
39
  to_remove.each {|key| ENV.delete key }
40
40
  end
41
41
  end
42
+
43
+ module FacterSpec
44
+ module ConfigHelper
45
+ def given_a_configuration_of(config)
46
+ Facter::Util::Config.stubs(:is_windows?).returns(config[:is_windows])
47
+ Facter::Util::Config.stubs(:external_facts_dir).returns(config[:external_facts_dir] || "data_dir")
48
+ end
49
+ end
50
+ end
@@ -32,7 +32,7 @@ describe "Architecture fact" do
32
32
  "i686" => "i386",
33
33
  "pentium" => "i386",
34
34
  }
35
-
35
+
36
36
  os_archs.each do |pair, result|
37
37
  it "should be #{result} if os is #{pair[0]} and hardwaremodel is #{pair[1]}" do
38
38
  Facter.fact(:operatingsystem).stubs(:value).returns(pair[0])
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+ require 'facter'
5
+ require 'facter/util/nothing_loader'
6
+
7
+ describe "Block device facts" do
8
+
9
+ describe "on non-Linux OS" do
10
+
11
+ it "should not exist when kernel isn't Linux" do
12
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
13
+ Facter.fact(:blockdevices).should == nil
14
+ end
15
+
16
+ end
17
+
18
+ describe "on Linux" do
19
+
20
+ describe "with /sys/block/" do
21
+
22
+ describe "with valid entries" do
23
+ before :each do
24
+ Facter::Util::Config.ext_fact_loader = Facter::Util::NothingLoader.new
25
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
26
+ File.stubs(:exist?).with('/sys/block/').returns(true)
27
+
28
+ Dir.stubs(:entries).with("/sys/block/").returns([".", "..", "hda", "sda", "sdb"])
29
+
30
+ File.stubs(:exist?).with("/sys/block/./device").returns(false)
31
+ File.stubs(:exist?).with("/sys/block/../device").returns(false)
32
+
33
+ stubdevices = [
34
+ #device, size, vendor, model
35
+ ["hda"],
36
+ ["sda", "976773168", "ATA", "WDC WD5000AAKS-0"],
37
+ ["sdb", "8787591168", "DELL", "PERC H700"]
38
+ ]
39
+
40
+ stubdevices.each do |device, size, vendor, model|
41
+ stubdir = "/sys/block/#{device}"
42
+ File.stubs(:exist?).with(stubdir + "/device").returns(true)
43
+ File.stubs(:exist?).with(stubdir + "/size").returns(size ? true : false)
44
+ File.stubs(:exist?).with(stubdir + "/device/model").returns(model ? true : false)
45
+ File.stubs(:exist?).with(stubdir + "/device/vendor").returns(vendor ? true : false)
46
+ IO.stubs(:read).with(stubdir + "/size").returns(size) if size
47
+ IO.stubs(:read).with(stubdir + "/device/vendor").returns(vendor) if vendor
48
+ IO.stubs(:read).with(stubdir + "/device/model").returns(model) if model
49
+ end
50
+ end
51
+
52
+ it "should report three block devices, hda, sda, and sdb, with accurate information from sda and sdb, and without invalid . or .. entries" do
53
+ Facter.fact(:blockdevices).value.should == "hda,sda,sdb"
54
+
55
+ # handle facts that should not exist
56
+ %w{ . .. hda }.each do |device|
57
+ Facter.fact("blockdevice_#{device}_size".to_sym).should == nil
58
+ Facter.fact("blockdevice_#{device}_vendor".to_sym).should == nil
59
+ Facter.fact("blockdevice_#{device}_model".to_sym).should == nil
60
+ end
61
+
62
+ # handle facts that should exist
63
+ %w{ sda sdb }.each do |device|
64
+ Facter.fact("blockdevice_#{device}_size".to_sym).should_not == nil
65
+ Facter.fact("blockdevice_#{device}_vendor".to_sym).should_not == nil
66
+ Facter.fact("blockdevice_#{device}_model".to_sym).should_not == nil
67
+ end
68
+
69
+ Facter.fact(:blockdevice_sda_model).value.should == "WDC WD5000AAKS-0"
70
+ Facter.fact(:blockdevice_sda_vendor).value.should == "ATA"
71
+ Facter.fact(:blockdevice_sda_size).value.should == 500107862016
72
+
73
+ Facter.fact(:blockdevice_sdb_model).value.should == "PERC H700"
74
+ Facter.fact(:blockdevice_sdb_vendor).value.should == "DELL"
75
+ Facter.fact(:blockdevice_sdb_size).value.should == 4499246678016
76
+
77
+ end
78
+
79
+ end
80
+ describe "with invalid entries in /sys/block" do
81
+ before :each do
82
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
83
+ File.stubs(:exist?).with('/sys/block/').returns(true)
84
+
85
+ Dir.stubs(:entries).with("/sys/block/").returns([".", "..", "xda", "ydb"])
86
+
87
+ File.stubs(:exist?).with("/sys/block/./device").returns(false)
88
+ File.stubs(:exist?).with("/sys/block/../device").returns(false)
89
+ File.stubs(:exist?).with("/sys/block/xda/device").returns(false)
90
+ File.stubs(:exist?).with("/sys/block/ydb/device").returns(false)
91
+ end
92
+
93
+ it "should not exist with invalid entries in /sys/block" do
94
+ Facter.fact(:blockdevices).should == nil
95
+ end
96
+ end
97
+ end
98
+ describe "without /sys/block/" do
99
+
100
+ it "should not exist without /sys/block/ on Linux" do
101
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
102
+ File.stubs(:exist?).with('/sys/block/').returns(false)
103
+ Facter.fact(:blockdevices).should == nil
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+ end
@@ -4,121 +4,160 @@ require 'spec_helper'
4
4
 
5
5
  describe "Domain name facts" do
6
6
 
7
- describe "on linux" do
8
- before do
9
- Facter.fact(:kernel).stubs(:value).returns("Linux")
10
- FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
11
- end
12
-
13
- it "should use the hostname binary" do
14
- Facter::Util::Resolution.expects(:exec).with("hostname").returns "test.example.com"
15
- Facter.fact(:domain).value.should == "example.com"
16
- end
17
-
18
- it "should fall back to the dnsdomainname binary" do
19
- Facter::Util::Resolution.expects(:exec).with("hostname").returns("myhost")
20
- Facter::Util::Resolution.expects(:exec).with("dnsdomainname").returns("example.com")
21
- Facter.fact(:domain).value.should == "example.com"
22
- end
23
-
24
-
25
- it "should fall back to /etc/resolv.conf" do
26
- Facter::Util::Resolution.expects(:exec).with("hostname").at_least_once.returns("myhost")
27
- Facter::Util::Resolution.expects(:exec).with("dnsdomainname").at_least_once.returns("")
28
- File.expects(:open).with('/etc/resolv.conf').at_least_once
29
- Facter.fact(:domain).value
30
- end
31
-
32
- it "should attempt to resolve facts in a specific order" do
33
- seq = sequence('domain')
34
- Facter::Util::Resolution.stubs(:exec).with("hostname").in_sequence(seq).at_least_once
35
- Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").in_sequence(seq).at_least_once
36
- File.expects(:open).with('/etc/resolv.conf').in_sequence(seq).at_least_once
37
- Facter.fact(:domain).value
38
- end
39
-
40
- describe "when using /etc/resolv.conf" do
7
+ { :linux => {:kernel => "Linux", :hostname_command => "hostname -f"},
8
+ :solaris => {:kernel => "SunOS", :hostname_command => "hostname"},
9
+ :darwin => {:kernel => "Darwin", :hostname_command => "hostname -f"},
10
+ :freebsd => {:kernel => "FreeBSD", :hostname_command => "hostname -f"},
11
+ :hpux => {:kernel => "HP-UX", :hostname_command => "hostname"},
12
+ }.each do |key, nested_hash|
13
+
14
+ describe "on #{key}" do
41
15
  before do
42
- Facter::Util::Resolution.stubs(:exec).with("hostname")
43
- Facter::Util::Resolution.stubs(:exec).with("dnsdomainname")
44
- @mock_file = mock()
45
- File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
16
+ Facter.fact(:kernel).stubs(:value).returns(nested_hash[:kernel])
17
+ FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
46
18
  end
47
-
48
- it "should use the domain field over the search field" do
49
- lines = [
50
- "nameserver 4.2.2.1",
51
- "search example.org",
52
- "domain example.com",
53
- ]
54
- @mock_file.expects(:each).multiple_yields(*lines)
55
- Facter.fact(:domain).value.should == 'example.com'
19
+
20
+ let :hostname_command do
21
+ nested_hash[:hostname_command]
22
+ end
23
+
24
+ it "should use the hostname binary" do
25
+ Facter::Util::Resolution.expects(:exec).with(hostname_command).returns "test.example.com"
26
+ Facter.fact(:domain).value.should == "example.com"
56
27
  end
57
-
58
- it "should fall back to the search field" do
59
- lines = [
60
- "nameserver 4.2.2.1",
61
- "search example.org",
62
- ]
63
- @mock_file.expects(:each).multiple_yields(*lines)
64
- Facter.fact(:domain).value.should == 'example.org'
28
+
29
+ it "should fall back to the dnsdomainname binary" do
30
+ Facter::Util::Resolution.expects(:exec).with(hostname_command).returns("myhost")
31
+ Facter::Util::Resolution.expects(:exec).with("dnsdomainname").returns("example.com")
32
+ Facter.fact(:domain).value.should == "example.com"
65
33
  end
66
-
67
- it "should use the first domain in the search field" do
68
- lines = [
69
- "search example.org example.net",
70
- ]
71
- @mock_file.expects(:each).multiple_yields(*lines)
72
- Facter.fact(:domain).value.should == 'example.org'
34
+
35
+
36
+ it "should fall back to /etc/resolv.conf" do
37
+ Facter::Util::Resolution.expects(:exec).with(hostname_command).at_least_once.returns("myhost")
38
+ Facter::Util::Resolution.expects(:exec).with("dnsdomainname").at_least_once.returns("")
39
+ File.expects(:open).with('/etc/resolv.conf').at_least_once
40
+ Facter.fact(:domain).value
41
+ end
42
+
43
+ it "should attempt to resolve facts in a specific order" do
44
+ seq = sequence('domain')
45
+ Facter::Util::Resolution.stubs(:exec).with(hostname_command).in_sequence(seq).at_least_once
46
+ Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").in_sequence(seq).at_least_once
47
+ File.expects(:open).with('/etc/resolv.conf').in_sequence(seq).at_least_once
48
+ Facter.fact(:domain).value
73
49
  end
50
+
51
+ describe "Top level domain" do
52
+ it "should find the domain name" do
53
+ Facter::Util::Resolution.expects(:exec).with(hostname_command).returns "ns01.tld"
54
+ Facter::Util::Resolution.expects(:exec).with("dnsdomainname").never
55
+ File.expects(:exists?).with('/etc/resolv.conf').never
56
+ Facter.fact(:domain).value.should == "tld"
57
+ end
58
+ end
59
+
60
+ describe "when using /etc/resolv.conf" do
61
+ before do
62
+ Facter::Util::Resolution.stubs(:exec).with(hostname_command)
63
+ Facter::Util::Resolution.stubs(:exec).with("dnsdomainname")
64
+ @mock_file = mock()
65
+ File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
66
+ end
67
+
68
+ it "should use the domain field over the search field" do
69
+ lines = [
70
+ "nameserver 4.2.2.1",
71
+ "search example.org",
72
+ "domain example.com",
73
+ ]
74
+ @mock_file.expects(:each).multiple_yields(*lines)
75
+ Facter.fact(:domain).value.should == 'example.com'
76
+ end
74
77
 
75
- # Test permutations of domain and search
76
- [
77
- ["domain domain", "domain"],
78
- ["domain search", "search"],
79
- ["search domain", "domain"],
80
- ["search search", "search"],
81
- ["search domain notdomain", "domain"],
82
- [["#search notdomain","search search"], "search"],
83
- [["# search notdomain","search search"], "search"],
84
- [["#domain notdomain","domain domain"], "domain"],
85
- [["# domain notdomain","domain domain"], "domain"],
86
- ].each do |tuple|
87
- field = tuple[0]
88
- expect = tuple[1]
89
- it "should return #{expect} from \"#{field}\"" do
78
+ it "should fall back to the search field" do
90
79
  lines = [
91
- field
92
- ].flatten
80
+ "nameserver 4.2.2.1",
81
+ "search example.org",
82
+ ]
93
83
  @mock_file.expects(:each).multiple_yields(*lines)
94
- Facter.fact(:domain).value.should == expect
84
+ Facter.fact(:domain).value.should == 'example.org'
85
+ end
86
+
87
+ it "should use the first domain in the search field" do
88
+ lines = [
89
+ "search example.org example.net",
90
+ ]
91
+ @mock_file.expects(:each).multiple_yields(*lines)
92
+ Facter.fact(:domain).value.should == 'example.org'
93
+ end
94
+
95
+ # Test permutations of domain and search, where 'domain' can be a value of
96
+ # the search keyword and the domain keyword
97
+ # and also where 'search' can be a value of the search keyword and the
98
+ # domain keyword
99
+ # For example, /etc/resolv.conf may look like:
100
+ # domain domain
101
+ # or
102
+ # search search
103
+ # or
104
+ # domain search
105
+ #
106
+ #
107
+ # Why someone would have their machines named 'www.domain' or 'www.search', I
108
+ # don't know, but we'll at least handle it properly
109
+ [
110
+ ["domain domain", "domain"],
111
+ ["domain search", "search"],
112
+ ["search domain", "domain"],
113
+ ["search search", "search"],
114
+ ["search domain notdomain", "domain"],
115
+ [["#search notdomain","search search"], "search"],
116
+ [["# search notdomain","search search"], "search"],
117
+ [["#domain notdomain","domain domain"], "domain"],
118
+ [["# domain notdomain","domain domain"], "domain"],
119
+ ].each do |tuple|
120
+ field = tuple[0]
121
+ expect = tuple[1]
122
+ it "should return #{expect} from \"#{field}\"" do
123
+ lines = [
124
+ field
125
+ ].flatten
126
+ @mock_file.expects(:each).multiple_yields(*lines)
127
+ Facter.fact(:domain).value.should == expect
128
+ end
95
129
  end
96
130
  end
97
131
  end
98
- end
132
+ end
99
133
 
100
134
  describe "on Windows" do
101
135
  before(:each) do
102
136
  Facter.fact(:kernel).stubs(:value).returns("windows")
103
137
  require 'facter/util/registry'
104
138
  end
139
+
105
140
  describe "with primary dns suffix" do
106
141
  before(:each) do
107
142
  Facter::Util::Registry.stubs(:hklm_read).returns('baz.com')
108
143
  end
144
+
109
145
  it "should get the primary dns suffix" do
110
146
  Facter.fact(:domain).value.should == 'baz.com'
111
147
  end
148
+
112
149
  it "should not execute the wmi query" do
113
150
  require 'facter/util/wmi'
114
151
  Facter::Util::WMI.expects(:execquery).never
115
152
  Facter.fact(:domain).value
116
153
  end
117
154
  end
155
+
118
156
  describe "without primary dns suffix" do
119
157
  before(:each) do
120
158
  Facter::Util::Registry.stubs(:hklm_read).returns('')
121
159
  end
160
+
122
161
  it "should use the DNSDomain for the first nic where ip is enabled" do
123
162
  nic = stubs 'nic'
124
163
  nic.stubs(:DNSDomain).returns("foo.com")
@@ -133,4 +172,73 @@ describe "Domain name facts" do
133
172
  end
134
173
  end
135
174
  end
175
+
176
+ describe "with trailing dots" do
177
+ describe "on Windows" do
178
+ before do
179
+ Facter.fact(:kernel).stubs(:value).returns("windows")
180
+ require 'facter/util/registry'
181
+ require 'facter/util/wmi'
182
+ end
183
+
184
+ [{:registry => 'testdomain.', :wmi => '', :expect => 'testdomain'},
185
+ {:registry => '', :wmi => 'testdomain.', :expect => 'testdomain'},
186
+ ].each do |scenario|
187
+
188
+ describe "scenarios" do
189
+ before(:each) do
190
+ Facter::Util::Registry.stubs(:hklm_read).returns(scenario[:registry])
191
+ nic = stubs 'nic'
192
+ nic.stubs(:DNSDomain).returns(scenario[:wmi])
193
+ Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic])
194
+ end
195
+
196
+ it "should return #{scenario[:expect]}" do
197
+ Facter.fact(:domain).value.should == scenario[:expect]
198
+ end
199
+
200
+ it "should remove trailing dots" do
201
+ Facter.fact(:domain).value.should_not =~ /\.$/
202
+ end
203
+ end
204
+ end
205
+ end
206
+
207
+ describe "on everything else" do
208
+ before do
209
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
210
+ FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
211
+ end
212
+
213
+ [{:hostname => 'host.testdomain.', :dnsdomainname => '', :resolve_domain => '', :resolve_search => '', :expect => 'testdomain'},
214
+ {:hostname => '', :dnsdomainname => 'testdomain.', :resolve_domain => '', :resolve_search => '', :expect => 'testdomain'},
215
+ {:hostname => '', :dnsdomainname => '', :resolve_domain => 'testdomain.', :resolve_search => '', :expect => 'testdomain'},
216
+ {:hostname => '', :dnsdomainname => '', :resolve_domain => '', :resolve_search => 'testdomain.', :expect => 'testdomain'},
217
+ {:hostname => '', :dnsdomainname => '', :resolve_domain => '', :resolve_search => '', :expect => nil}
218
+ ].each do |scenario|
219
+
220
+ describe "scenarios" do
221
+ before(:each) do
222
+ Facter::Util::Resolution.stubs(:exec).with("hostname -f").returns(scenario[:hostname])
223
+ Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").returns(scenario[:dnsdomainname])
224
+ @mock_file = mock()
225
+ File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
226
+ lines = [
227
+ "search #{scenario[:resolve_search]}",
228
+ "domain #{scenario[:resolve_domain]}",
229
+ ]
230
+ @mock_file.stubs(:each).multiple_yields(*lines)
231
+ end
232
+
233
+ it "should remove trailing dots" do
234
+ Facter.fact(:domain).value.should_not =~ /\.$/
235
+ end
236
+
237
+ it "should return #{scenario[:expect]}" do
238
+ Facter.fact(:domain).value.should == scenario[:expect]
239
+ end
240
+ end
241
+ end
242
+ end
243
+ end
136
244
  end