Codebase list facter / upstream/1.7.2
Imported Upstream version 1.7.2 Stig Sandbeck Mathisen 10 years ago
33 changed file(s) with 671 addition(s) and 462 deletion(s). Raw diff Collapse all Expand all
55
66 $LOAD_PATH << File.join(File.dirname(__FILE__), 'tasks')
77
8 require 'rake'
9
810 begin
11 load File.join(File.dirname(__FILE__), 'ext', 'packaging', 'packaging.rake')
912 require 'rubygems'
1013 require 'rspec'
1114 require 'rspec/core/rake_task'
1316 rescue LoadError
1417 end
1518
16 require 'rake'
17
1819 Dir['tasks/**/*.rake'].each { |t| load t }
19 Dir['ext/packaging/tasks/**/*'].sort.each { |t| load t }
2020
2121 build_defs_file = 'ext/build_defaults.yaml'
2222 if File.exist?(build_defs_file)
11 packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=master'
22 packaging_repo: 'packaging'
33 default_cow: 'base-squeeze-i386.cow'
4 cows: 'base-lucid-i386.cow base-lucid-amd64.cow base-oneiric-i386.cow base-oneiric-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-sid-i386.cow base-sid-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-unstable-i386.cow base-unstable-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow'
4 cows: 'base-lucid-i386.cow base-lucid-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-raring-i386.cow base-raring-amd64.cow base-sid-i386.cow base-sid-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-unstable-i386.cow base-unstable-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow'
55 pbuild_conf: '/etc/pbuilderrc'
66 packager: 'puppetlabs'
77 gpg_name: 'info@puppetlabs.com'
88 gpg_key: '4BD6EC30'
99 sign_tar: FALSE
1010 # a space separated list of mock configs
11 final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-fedora-16-i386 pl-fedora-16-x86_64 pl-fedora-17-i386 pl-fedora-17-x86_64 pl-fedora-18-i386 pl-fedora-18-x86_64'
11 final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-fedora-17-i386 pl-fedora-17-x86_64 pl-fedora-18-i386 pl-fedora-18-x86_64'
1212 yum_host: 'burji.puppetlabs.com'
1313 yum_repo_path: '/opt/repository/yum/'
1414 build_gem: TRUE
0 facter (1.7.0-1puppetlabs1) hardy lucid oneiric unstable sid wheezy lucid squeeze precise quantal; urgency=low
0 facter (1.7.2-1puppetlabs1) hardy lucid oneiric unstable sid wheezy lucid squeeze precise quantal; urgency=low
11
22 * Update to version
33
4 -- Puppet Labs Release <info@puppetlabs.com> Mon, 15 Apr 2013 11:13:19 -0700
4 -- Puppet Labs Release <info@puppetlabs.com> Wed, 10 Jul 2013 23:00:17 +0000
55
66 facter (1.7.0-0.1rc1puppetlabs1) hardy lucid oneiric unstable sid wheezy lucid squeeze precise; urgency=low
77
0 set name=pkg.fmri value=pkg://puppetlabs.com/application/facter@1.7.0,11.4.2-0
0 set name=pkg.fmri value=pkg://puppetlabs.com/application/facter@1.7.2,11.4.2-0
11 set name=pkg.summary value="Facter, a system inventory tool"
2 set name=pkg.human-version value="1.7.0"
2 set name=pkg.human-version value="1.7.2"
33 set name=pkg.description value="You can prove anything with facts!"
44 set name=info.classification value="org.opensolaris.category.2008:Applications/System Utilities"
55 set name=org.opensolaris.consolidation value="puppet"
1515 # remove libdir
1616
1717
18 /bin/rm -Rf "${3}/facter/util/loader.rb"
19
20 /bin/rm -Rf "${3}/facter/util/uptime.rb"
21
22 /bin/rm -Rf "${3}/facter/util/virtual.rb"
23
24 /bin/rm -Rf "${3}/facter/util/netmask.rb"
25
26 /bin/rm -Rf "${3}/facter/util/nothing_loader.rb"
27
28 /bin/rm -Rf "${3}/facter/util/macaddress.rb"
29
30 /bin/rm -Rf "${3}/facter/util/cfpropertylist/README"
31
32 /bin/rm -Rf "${3}/facter/util/cfpropertylist/THANKS"
33
34 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFTypes.rb"
35
36 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFPlistError.rb"
37
38 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb"
39
40 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFPropertyList.rb"
41
42 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbNokogiriParser.rb"
43
44 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbREXMLParser.rb"
45
46 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/cfpropertylist.rb"
47
48 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbLibXMLParser.rb"
49
50 /bin/rm -Rf "${3}/facter/util/cfpropertylist/LICENSE"
51
52 /bin/rm -Rf "${3}/facter/util/cfpropertylist/Rakefile"
53
54 /bin/rm -Rf "${3}/facter/util/xendomains.rb"
55
56 /bin/rm -Rf "${3}/facter/util/wmi.rb"
57
58 /bin/rm -Rf "${3}/facter/util/file_read.rb"
59
60 /bin/rm -Rf "${3}/facter/util/registry.rb"
61
62 /bin/rm -Rf "${3}/facter/util/values.rb"
63
64 /bin/rm -Rf "${3}/facter/util/parser.rb"
65
66 /bin/rm -Rf "${3}/facter/util/vlans.rb"
67
68 /bin/rm -Rf "${3}/facter/util/processor.rb"
69
70 /bin/rm -Rf "${3}/facter/util/plist.rb"
71
72 /bin/rm -Rf "${3}/facter/util/ec2.rb"
73
74 /bin/rm -Rf "${3}/facter/util/manufacturer.rb"
75
76 /bin/rm -Rf "${3}/facter/util/fact.rb"
77
78 /bin/rm -Rf "${3}/facter/util/resolution.rb"
79
80 /bin/rm -Rf "${3}/facter/util/collection.rb"
81
82 /bin/rm -Rf "${3}/facter/util/memory.rb"
83
84 /bin/rm -Rf "${3}/facter/util/ip.rb"
85
86 /bin/rm -Rf "${3}/facter/util/solaris_zones.rb"
87
88 /bin/rm -Rf "${3}/facter/util/cfpropertylist.rb"
89
90 /bin/rm -Rf "${3}/facter/util/config.rb"
91
92 /bin/rm -Rf "${3}/facter/util/monkey_patches.rb"
93
94 /bin/rm -Rf "${3}/facter/util/plist/parser.rb"
95
96 /bin/rm -Rf "${3}/facter/util/plist/generator.rb"
97
98 /bin/rm -Rf "${3}/facter/util/directory_loader.rb"
99
100 /bin/rm -Rf "${3}/facter/util/confine.rb"
101
102 /bin/rm -Rf "${3}/facter/util/composite_loader.rb"
103
104 /bin/rm -Rf "${3}/facter/util/macosx.rb"
105
106 /bin/rm -Rf "${3}/facter/lsbrelease.rb"
107
108 /bin/rm -Rf "${3}/facter/hardwareisa.rb"
109
110 /bin/rm -Rf "${3}/facter/zonename.rb"
111
112 /bin/rm -Rf "${3}/facter/lsbdistcodename.rb"
113
114 /bin/rm -Rf "${3}/facter/kernelmajversion.rb"
115
116 /bin/rm -Rf "${3}/facter/uptime_seconds.rb"
117
118 /bin/rm -Rf "${3}/facter/interfaces.rb"
119
120 /bin/rm -Rf "${3}/facter/augeasversion.rb"
121
122 /bin/rm -Rf "${3}/facter/ipaddress6.rb"
123
124 /bin/rm -Rf "${3}/facter/uptime.rb"
125
126 /bin/rm -Rf "${3}/facter/virtual.rb"
127
128 /bin/rm -Rf "${3}/facter/operatingsystem.rb"
129
130 /bin/rm -Rf "${3}/facter/physicalprocessorcount.rb"
131
132 /bin/rm -Rf "${3}/facter/ldom.rb"
133
134 /bin/rm -Rf "${3}/facter/blockdevices.rb"
135
136 /bin/rm -Rf "${3}/facter/netmask.rb"
137
138 /bin/rm -Rf "${3}/facter/version.rb"
139
140 /bin/rm -Rf "${3}/facter/uptime_days.rb"
141
142 /bin/rm -Rf "${3}/facter/uptime_hours.rb"
143
144 /bin/rm -Rf "${3}/facter/operatingsystemrelease.rb"
145
146 /bin/rm -Rf "${3}/facter/selinux.rb"
147
148 /bin/rm -Rf "${3}/facter/kernelversion.rb"
149
150 /bin/rm -Rf "${3}/facter/macaddress.rb"
151
152 /bin/rm -Rf "${3}/facter/xendomains.rb"
153
154 /bin/rm -Rf "${3}/facter/hostname.rb"
155
156 /bin/rm -Rf "${3}/facter/rubyversion.rb"
157
158 /bin/rm -Rf "${3}/facter/path.rb"
159
160 /bin/rm -Rf "${3}/facter/zones.rb"
161
162 /bin/rm -Rf "${3}/facter/operatingsystemmajrelease.rb"
163
164 /bin/rm -Rf "${3}/facter/vlans.rb"
165
166 /bin/rm -Rf "${3}/facter/application.rb"
167
168 /bin/rm -Rf "${3}/facter/processor.rb"
169
170 /bin/rm -Rf "${3}/facter/id.rb"
171
18172 /bin/rm -Rf "${3}/facter/fqdn.rb"
19173
174 /bin/rm -Rf "${3}/facter/ec2.rb"
175
176 /bin/rm -Rf "${3}/facter/architecture.rb"
177
178 /bin/rm -Rf "${3}/facter/ssh.rb"
179
180 /bin/rm -Rf "${3}/facter/ipaddress.rb"
181
182 /bin/rm -Rf "${3}/facter/uniqueid.rb"
183
184 /bin/rm -Rf "${3}/facter/manufacturer.rb"
185
186 /bin/rm -Rf "${3}/facter/kernel.rb"
187
188 /bin/rm -Rf "${3}/facter/kernelrelease.rb"
189
190 /bin/rm -Rf "${3}/facter/timezone.rb"
191
192 /bin/rm -Rf "${3}/facter/puppetversion.rb"
193
194 /bin/rm -Rf "${3}/facter/rubysitedir.rb"
195
196 /bin/rm -Rf "${3}/facter/facterversion.rb"
197
198 /bin/rm -Rf "${3}/facter/filesystems.rb"
199
20200 /bin/rm -Rf "${3}/facter/lsbdistid.rb"
21201
22 /bin/rm -Rf "${3}/facter/operatingsystemmajrelease.rb"
23
24 /bin/rm -Rf "${3}/facter/version.rb"
202 /bin/rm -Rf "${3}/facter/memory.rb"
203
204 /bin/rm -Rf "${3}/facter/lsbdistdescription.rb"
205
206 /bin/rm -Rf "${3}/facter/network.rb"
207
208 /bin/rm -Rf "${3}/facter/zpool_version.rb"
209
210 /bin/rm -Rf "${3}/facter/zfs_version.rb"
211
212 /bin/rm -Rf "${3}/facter/domain.rb"
213
214 /bin/rm -Rf "${3}/facter/lsbdistrelease.rb"
215
216 /bin/rm -Rf "${3}/facter/Cfkey.rb"
25217
26218 /bin/rm -Rf "${3}/facter/osfamily.rb"
27219
28 /bin/rm -Rf "${3}/facter/ipaddress6.rb"
29
30 /bin/rm -Rf "${3}/facter/puppetversion.rb"
31
32 /bin/rm -Rf "${3}/facter/rubysitedir.rb"
220 /bin/rm -Rf "${3}/facter/ps.rb"
221
222 /bin/rm -Rf "${3}/facter/hardwaremodel.rb"
223
224 /bin/rm -Rf "${3}/facter/macosx.rb"
225
226 /bin/rm -Rf "${3}/facter/lsbmajdistrelease.rb"
33227
34228 /bin/rm -Rf "${3}/facter/iphostnumber.rb"
35
36 /bin/rm -Rf "${3}/facter/util/solaris_zones.rb"
37
38 /bin/rm -Rf "${3}/facter/util/file_read.rb"
39
40 /bin/rm -Rf "${3}/facter/util/confine.rb"
41
42 /bin/rm -Rf "${3}/facter/util/cfpropertylist/THANKS"
43
44 /bin/rm -Rf "${3}/facter/util/cfpropertylist/Rakefile"
45
46 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFPlistError.rb"
47
48 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbLibXMLParser.rb"
49
50 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFPropertyList.rb"
51
52 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/cfpropertylist.rb"
53
54 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbNokogiriParser.rb"
55
56 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbREXMLParser.rb"
57
58 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb"
59
60 /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFTypes.rb"
61
62 /bin/rm -Rf "${3}/facter/util/cfpropertylist/LICENSE"
63
64 /bin/rm -Rf "${3}/facter/util/cfpropertylist/README"
65
66 /bin/rm -Rf "${3}/facter/util/ip.rb"
67
68 /bin/rm -Rf "${3}/facter/util/vlans.rb"
69
70 /bin/rm -Rf "${3}/facter/util/resolution.rb"
71
72 /bin/rm -Rf "${3}/facter/util/ec2.rb"
73
74 /bin/rm -Rf "${3}/facter/util/plist/generator.rb"
75
76 /bin/rm -Rf "${3}/facter/util/plist/parser.rb"
77
78 /bin/rm -Rf "${3}/facter/util/composite_loader.rb"
79
80 /bin/rm -Rf "${3}/facter/util/cfpropertylist.rb"
81
82 /bin/rm -Rf "${3}/facter/util/registry.rb"
83
84 /bin/rm -Rf "${3}/facter/util/memory.rb"
85
86 /bin/rm -Rf "${3}/facter/util/plist.rb"
87
88 /bin/rm -Rf "${3}/facter/util/manufacturer.rb"
89
90 /bin/rm -Rf "${3}/facter/util/fact.rb"
91
92 /bin/rm -Rf "${3}/facter/util/collection.rb"
93
94 /bin/rm -Rf "${3}/facter/util/netmask.rb"
95
96 /bin/rm -Rf "${3}/facter/util/config.rb"
97
98 /bin/rm -Rf "${3}/facter/util/xendomains.rb"
99
100 /bin/rm -Rf "${3}/facter/util/processor.rb"
101
102 /bin/rm -Rf "${3}/facter/util/macosx.rb"
103
104 /bin/rm -Rf "${3}/facter/util/wmi.rb"
105
106 /bin/rm -Rf "${3}/facter/util/parser.rb"
107
108 /bin/rm -Rf "${3}/facter/util/virtual.rb"
109
110 /bin/rm -Rf "${3}/facter/util/values.rb"
111
112 /bin/rm -Rf "${3}/facter/util/uptime.rb"
113
114 /bin/rm -Rf "${3}/facter/util/monkey_patches.rb"
115
116 /bin/rm -Rf "${3}/facter/util/nothing_loader.rb"
117
118 /bin/rm -Rf "${3}/facter/util/directory_loader.rb"
119
120 /bin/rm -Rf "${3}/facter/util/loader.rb"
121
122 /bin/rm -Rf "${3}/facter/util/macaddress.rb"
123
124 /bin/rm -Rf "${3}/facter/ps.rb"
125
126 /bin/rm -Rf "${3}/facter/vlans.rb"
127
128 /bin/rm -Rf "${3}/facter/lsbdistrelease.rb"
129
130 /bin/rm -Rf "${3}/facter/kernel.rb"
131
132 /bin/rm -Rf "${3}/facter/zonename.rb"
133
134 /bin/rm -Rf "${3}/facter/kernelversion.rb"
135
136 /bin/rm -Rf "${3}/facter/ec2.rb"
137
138 /bin/rm -Rf "${3}/facter/lsbdistdescription.rb"
139
140 /bin/rm -Rf "${3}/facter/augeasversion.rb"
141
142 /bin/rm -Rf "${3}/facter/ssh.rb"
143
144 /bin/rm -Rf "${3}/facter/memory.rb"
145
146 /bin/rm -Rf "${3}/facter/lsbrelease.rb"
147
148 /bin/rm -Rf "${3}/facter/manufacturer.rb"
149
150 /bin/rm -Rf "${3}/facter/kernelrelease.rb"
151
152 /bin/rm -Rf "${3}/facter/blockdevices.rb"
153
154 /bin/rm -Rf "${3}/facter/hardwaremodel.rb"
155
156 /bin/rm -Rf "${3}/facter/facterversion.rb"
157
158 /bin/rm -Rf "${3}/facter/zfs_version.rb"
159
160 /bin/rm -Rf "${3}/facter/lsbdistcodename.rb"
161
162 /bin/rm -Rf "${3}/facter/ldom.rb"
163
164 /bin/rm -Rf "${3}/facter/architecture.rb"
165
166 /bin/rm -Rf "${3}/facter/netmask.rb"
167
168 /bin/rm -Rf "${3}/facter/filesystems.rb"
169
170 /bin/rm -Rf "${3}/facter/id.rb"
171
172 /bin/rm -Rf "${3}/facter/xendomains.rb"
173
174 /bin/rm -Rf "${3}/facter/uptime_seconds.rb"
175
176 /bin/rm -Rf "${3}/facter/hardwareisa.rb"
177
178 /bin/rm -Rf "${3}/facter/interfaces.rb"
179
180 /bin/rm -Rf "${3}/facter/zones.rb"
181
182 /bin/rm -Rf "${3}/facter/processor.rb"
183
184 /bin/rm -Rf "${3}/facter/lsbmajdistrelease.rb"
185
186 /bin/rm -Rf "${3}/facter/macosx.rb"
187
188 /bin/rm -Rf "${3}/facter/zpool_version.rb"
189
190 /bin/rm -Rf "${3}/facter/Cfkey.rb"
191
192 /bin/rm -Rf "${3}/facter/network.rb"
193
194 /bin/rm -Rf "${3}/facter/uniqueid.rb"
195
196 /bin/rm -Rf "${3}/facter/virtual.rb"
197
198 /bin/rm -Rf "${3}/facter/hostname.rb"
199
200 /bin/rm -Rf "${3}/facter/kernelmajversion.rb"
201
202 /bin/rm -Rf "${3}/facter/domain.rb"
203
204 /bin/rm -Rf "${3}/facter/uptime.rb"
205
206 /bin/rm -Rf "${3}/facter/path.rb"
207
208 /bin/rm -Rf "${3}/facter/uptime_hours.rb"
209
210 /bin/rm -Rf "${3}/facter/application.rb"
211
212 /bin/rm -Rf "${3}/facter/operatingsystemrelease.rb"
213
214 /bin/rm -Rf "${3}/facter/rubyversion.rb"
215
216 /bin/rm -Rf "${3}/facter/uptime_days.rb"
217
218 /bin/rm -Rf "${3}/facter/ipaddress.rb"
219
220 /bin/rm -Rf "${3}/facter/timezone.rb"
221
222 /bin/rm -Rf "${3}/facter/physicalprocessorcount.rb"
223
224 /bin/rm -Rf "${3}/facter/macaddress.rb"
225
226 /bin/rm -Rf "${3}/facter/selinux.rb"
227
228 /bin/rm -Rf "${3}/facter/operatingsystem.rb"
229229
230230 /bin/rm -Rf "${3}/facter.rb"
231231
44 <key>CFBundleIdentifier</key>
55 <string></string>
66 <key>CFBundleShortVersionString</key>
7 <string>1.7.0</string>
7 <string>1.7.2</string>
88 <key>IFMajorVersion</key>
99 <integer></integer>
1010 <key>IFMinorVersion</key>
66 %endif
77
88 # VERSION is subbed out during rake srpm process
9 %global realversion 1.7.0
10 %global rpmversion 1.7.0
9 %global realversion 1.7.2
10 %global rpmversion 1.7.2
1111
1212 Summary: Ruby module for collecting simple facts about a host operating system
1313 Name: facter
6969
7070
7171 %changelog
72 * Mon Apr 15 2013 Puppet Labs Release <info@puppetlabs.com> - 1:1.7.0-1
73 - Build for 1.7.0
72 * Wed Jul 10 2013 Puppet Labs Release <info@puppetlabs.com> - 1:1.7.2-1
73 - Build for 1.7.2
7474
7575 * Mon Apr 01 2013 Matthaus Owens <matthaus@puppetlabs.com> - 1:1.7.0-0.1rc1
7676 - Add dependency on virt-what to facter for better virutalization detection
2222 # Get the domain from various sources; the order of these
2323 # steps is important
2424
25 # In some OS 'hostname -f' will change the hostname to '-f'
26 # We know that Solaris and HP-UX exhibit this behavior
27 # On good OS, 'hostname -f' will return the FQDN which is preferable
28 # Due to dangerous behavior of 'hostname -f' on old OS, we will explicitly opt-in
25 # In some OS 'hostname -f' will change the hostname to '-f'
26 # We know that Solaris and HP-UX exhibit this behavior
27 # On good OS, 'hostname -f' will return the FQDN which is preferable
28 # Due to dangerous behavior of 'hostname -f' on old OS, we will explicitly opt-in
2929 # 'hostname -f' --hkenney May 9, 2012
30 hostname_command = 'hostname'
30 basic_hostname = 'hostname 2> /dev/null'
31 full_hostname = 'hostname -f 2> /dev/null'
3132 can_do_hostname_f = Regexp.union /Linux/i, /FreeBSD/i, /Darwin/i
32 hostname_command = 'hostname -f' if Facter.value(:kernel) =~ can_do_hostname_f
3333
34
34 hostname_command = if Facter.value(:kernel) =~ can_do_hostname_f
35 full_hostname
36 else
37 basic_hostname
38 end
39
3540 if name = Facter::Util::Resolution.exec(hostname_command) \
3641 and name =~ /.*?\.(.+$)/
3742
3843 return_value = $1
39 elsif domain = Facter::Util::Resolution.exec('dnsdomainname') \
44 elsif domain = Facter::Util::Resolution.exec('dnsdomainname 2> /dev/null') \
4045 and domain =~ /.+/
4146
4247 return_value = domain
2727 confine :kernel => :linux
2828 setcode do
2929 ip = nil
30 if output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"])
30 output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"])
31 if output
3132 regexp = /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
32 if match = regexp.match(output)
33 match[1] unless /^127/.match(match[1])
33 output.split("\n").each do |line|
34 match = regexp.match(line)
35 if match
36 break match[1] unless /^127/.match(match[1])
37 end
3438 end
3539 end
3640 end
116116 # get each physical processor
117117 Facter::Util::WMI.execquery("select * from Win32_Processor").each do |proc|
118118 # not supported before 2008
119 begin
119 if proc.respond_to?(:NumberOfLogicalProcessors)
120120 processor_num = proc.NumberOfLogicalProcessors
121 rescue RuntimeError => e
121 else
122122 processor_num = 1
123123 end
124124
2626 Facter.debug "Could not read #{path}: #{detail.message}"
2727 nil
2828 end
29
30 def self.read_binary(path)
31 File.open(path, "rb") { |contents| contents.read }
32 end
2933 end
3034 end
3135 end
77 :ipaddress => /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
88 :ipaddress6 => /inet6 (?:addr: )?((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/,
99 :macaddress => /(?:ether|HWaddr)\s+((\w{1,2}:){5,}\w{1,2})/,
10 :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
10 :netmask => /(?:Mask:|netmask )([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
1111 :mtu => /MTU:(\d+)/
1212 },
1313 :bsd => {
77 when 'Linux'
88 ops = {
99 :ifconfig_opts => ['2>/dev/null'],
10 :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
10 :regex => %r{#{Facter.ipaddress}.*?(?:Mask:|netmask)\s*(#{ipregex})}x,
1111 :munge => nil,
1212 }
1313 when 'SunOS'
168168
169169 begin
170170 out = %x{#{code}}.chomp
171 Facter.warnonce 'Using Facter::Util::Resolution.exec with a shell built-in is deprecated. Most built-ins can be replaced with native ruby commands. If you really have to run a built-in, pass "cmd /c your_builtin" as a command' unless expanded_code
171 Facter.warnonce "Using Facter::Util::Resolution.exec with a shell built-in is deprecated. Most built-ins can be replaced with native ruby commands. If you really have to run a built-in, pass \"cmd /c your_builtin\" as a command (command responsible for this message was \"#{code}\")" unless expanded_code
172172 rescue Errno::ENOENT => detail
173173 # command not found on Windows
174174 return nil
0 require 'facter/util/file_read'
1
02 module Facter::Util::Virtual
13 ##
24 # virt_what is a delegating helper method intended to make it easier to stub
6264 return false unless FileTest.exists?("/proc/self/status")
6365 txt = File.open("/proc/self/status", "rb").read
6466 if txt.respond_to?(:encode!)
65 txt.encode!('UTF-8', 'UTF-8', :invalid => :replace)
67 txt.encode!('UTF-16', 'UTF-8', :invalid => :replace)
68 txt.encode!('UTF-8', 'UTF-16')
6669 end
6770 return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/
6871 return false
141144 # @return [String] or nil if the path does not exist
142145 def self.read_sysfs_dmi_entries(path="/sys/firmware/dmi/entries/1-0/raw")
143146 if File.exists?(path)
144 File.read(path)
147 Facter::Util::FileRead.read_binary(path)
145148 end
146149 end
147150 end
00 module Facter
11 if not defined? FACTERVERSION then
2 FACTERVERSION = '1.7.0'
2 FACTERVERSION = '1.7.2'
33 end
44
55 ##
4343 end
4444 end
4545
46 Facter.add("virtual") do
47 confine :kernel => ["FreeBSD", "GNU/kFreeBSD"]
48
49 setcode do
50 "jail" if Facter::Util::Virtual.jail?
51 end
52 end
53
54 Facter.add("virtual") do
55 confine :kernel => 'SunOS'
56
57 setcode do
58 next "zone" if Facter::Util::Virtual.zone?
59
60 resolver = Facter::Util::Resolution.new('prtdiag')
61 resolver.timeout = 6
62 resolver.setcode('prtdiag')
63 output = resolver.value
64 if output
65 lines = output.split("\n")
66 next "parallels" if lines.any? {|l| l =~ /Parallels/ }
67 next "vmware" if lines.any? {|l| l =~ /VM[wW]are/ }
68 next "virtualbox" if lines.any? {|l| l =~ /VirtualBox/ }
69 next "xenhvm" if lines.any? {|l| l =~ /HVM domU/ }
70 end
71 end
72 end
73
74 Facter.add("virtual") do
75 confine :kernel => 'HP-UX'
76
77 setcode do
78 "hpvm" if Facter::Util::Virtual.hpvm?
79 end
80 end
81
82 Facter.add("virtual") do
83 confine :architecture => 's390x'
84
85 setcode do
86 "zlinux" if Facter::Util::Virtual.zlinux?
87 end
88 end
89
90 Facter.add("virtual") do
91 confine :kernel => 'OpenBSD'
92
93 setcode do
94 output = Facter::Util::Resolution.exec('sysctl -n hw.product 2>/dev/null')
95 if output
96 lines = output.split("\n")
97 next "parallels" if lines.any? {|l| l =~ /Parallels/ }
98 next "vmware" if lines.any? {|l| l =~ /VMware/ }
99 next "virtualbox" if lines.any? {|l| l =~ /VirtualBox/ }
100 next "xenhvm" if lines.any? {|l| l =~ /HVM domU/ }
101 end
102 end
103 end
46104
47105 Facter.add("virtual") do
48106 confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX GNU/kFreeBSD}
49107
50 result = "physical"
51
52 setcode do
53
54 if Facter.value(:kernel) == "SunOS" and Facter::Util::Virtual.zone?
55 result = "zone"
56 end
57
58 if Facter.value(:kernel)=="HP-UX"
59 result = "hpvm" if Facter::Util::Virtual.hpvm?
60 end
61
62 if Facter.value(:architecture)=="s390x"
63 result = "zlinux" if Facter::Util::Virtual.zlinux?
64 end
65
66 if Facter::Util::Virtual.openvz?
67 result = Facter::Util::Virtual.openvz_type()
68 end
69
70 if Facter::Util::Virtual.vserver?
71 result = Facter::Util::Virtual.vserver_type()
72 end
108 setcode do
109 next Facter::Util::Virtual.openvz_type if Facter::Util::Virtual.openvz?
110 next Facter::Util::Virtual.vserver_type if Facter::Util::Virtual.vserver?
73111
74112 if Facter::Util::Virtual.xen?
75 if FileTest.exists?("/dev/xen/evtchn")
76 result = "xen0"
77 elsif FileTest.exists?("/proc/xen")
78 result = "xenu"
79 end
80 end
81
82 if Facter::Util::Virtual.virtualbox?
83 result = "virtualbox"
84 end
85
86 if Facter::Util::Virtual.kvm?
87 result = Facter::Util::Virtual.kvm_type()
88 end
89
90 if ["FreeBSD", "GNU/kFreeBSD"].include? Facter.value(:kernel)
91 result = "jail" if Facter::Util::Virtual.jail?
92 end
93
94 if Facter::Util::Virtual.rhev?
95 result = "rhev"
96 end
97
98 if Facter::Util::Virtual.ovirt?
99 result = "ovirt"
100 end
101
102 if result == "physical"
103 output = Facter::Util::Virtual.lspci
104 if not output.nil?
105 output.each_line do |p|
106 # --- look for the vmware video card to determine if it is virtual => vmware.
107 # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter
108 result = "vmware" if p =~ /VM[wW]are/
109 # --- look for virtualbox video card to determine if it is virtual => virtualbox.
110 # --- 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter
111 result = "virtualbox" if p =~ /VirtualBox/
112 # --- look for pci vendor id used by Parallels video card
113 # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005
114 result = "parallels" if p =~ /1ab8:|[Pp]arallels/
115 # --- look for pci vendor id used by Xen HVM device
116 # --- 00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01)
117 result = "xenhvm" if p =~ /XenSource/
118 # --- look for Hyper-V video card
119 # --- 00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA
120 result = "hyperv" if p =~ /Microsoft Corporation Hyper-V/
121 # --- look for gmetrics for GCE
122 # --- 00:05.0 Class 8007: Google, Inc. Device 6442
123 result = "gce" if p =~ /Class 8007: Google, Inc/
124 end
125 else
126 output = Facter::Util::Resolution.exec('dmidecode')
127 if not output.nil?
128 output.each_line do |pd|
129 result = "parallels" if pd =~ /Parallels/
130 result = "vmware" if pd =~ /VMware/
131 result = "virtualbox" if pd =~ /VirtualBox/
132 result = "xenhvm" if pd =~ /HVM domU/
133 result = "hyperv" if pd =~ /Product Name: Virtual Machine/
134 result = "rhev" if pd =~ /Product Name: RHEV Hypervisor/
135 result = "ovirt" if pd =~ /Product Name: oVirt Node/
136 end
137 elsif Facter.value(:kernel) == 'SunOS'
138 res = Facter::Util::Resolution.new('prtdiag')
139 res.timeout = 6
140 res.setcode('prtdiag')
141 output = res.value
142 if not output.nil?
143 output.each_line do |pd|
144 result = "parallels" if pd =~ /Parallels/
145 result = "vmware" if pd =~ /VMware/
146 result = "virtualbox" if pd =~ /VirtualBox/
147 result = "xenhvm" if pd =~ /HVM domU/
148 end
149 end
150 elsif Facter.value(:kernel) == 'OpenBSD'
151 output = Facter::Util::Resolution.exec('sysctl -n hw.product 2>/dev/null')
152 if not output.nil?
153 output.each_line do |pd|
154 result = "parallels" if pd =~ /Parallels/
155 result = "vmware" if pd =~ /VMware/
156 result = "virtualbox" if pd =~ /VirtualBox/
157 result = "xenhvm" if pd =~ /HVM domU/
158 end
159 end
160 end
161 end
162
163 if output = Facter::Util::Resolution.exec("vmware -v")
164 result = output.sub(/(\S+)\s+(\S+).*/) { | text | "#{$1}_#{$2}"}.downcase
165 end
166 end
167
168 result
113 next "xen0" if FileTest.exists?("/dev/xen/evtchn")
114 next "xenu" if FileTest.exists?("/proc/xen")
115 end
116
117 next "virtualbox" if Facter::Util::Virtual.virtualbox?
118 next Facter::Util::Virtual.kvm_type if Facter::Util::Virtual.kvm?
119 next "rhev" if Facter::Util::Virtual.rhev?
120 next "ovirt" if Facter::Util::Virtual.ovirt?
121
122 # Parse lspci
123 output = Facter::Util::Virtual.lspci
124 if output
125 lines = output.split("\n")
126 next "vmware" if lines.any? {|l| l =~ /VM[wW]are/ }
127 next "virtualbox" if lines.any? {|l| l =~ /VirtualBox/ }
128 next "parallels" if lines.any? {|l| l =~ /1ab8:|[Pp]arallels/ }
129 next "xenhvm" if lines.any? {|l| l =~ /XenSource/ }
130 next "hyperv" if lines.any? {|l| l =~ /Microsoft Corporation Hyper-V/ }
131 next "gce" if lines.any? {|l| l =~ /Class 8007: Google, Inc/ }
132 end
133
134 # Parse dmidecode
135 output = Facter::Util::Resolution.exec('dmidecode')
136 if output
137 lines = output.split("\n")
138 next "parallels" if lines.any? {|l| l =~ /Parallels/ }
139 next "vmware" if lines.any? {|l| l =~ /VMware/ }
140 next "virtualbox" if lines.any? {|l| l =~ /VirtualBox/ }
141 next "xenhvm" if lines.any? {|l| l =~ /HVM domU/ }
142 next "hyperv" if lines.any? {|l| l =~ /Product Name: Virtual Machine/ }
143 next "rhev" if lines.any? {|l| l =~ /Product Name: RHEV Hypervisor/ }
144 next "ovirt" if lines.any? {|l| l =~ /Product Name: oVirt Node/ }
145 end
146
147 # Sample output of vmware -v `VMware Server 1.0.5 build-80187`
148 output = Facter::Util::Resolution.exec("vmware -v")
149 if output
150 mdata = output.match /(\S+)\s+(\S+)/
151 next "#{mdata[1]}_#{mdata[2]}".downcase if mdata
152 end
153
154 # Default to 'physical'
155 next 'physical'
169156 end
170157 end
171158
0 em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
1 inet 131.252.209.153 netmask 255.255.255.0 broadcast 192.168.76.255
2 inet6 2610:10:20:209:212:3fff:febe:2201 prefixlen 128 scopeid 0x0<global>
3 inet6 fe80::221:ccff:fe4b:297d prefixlen 64 scopeid 0x20<link>
4 ether 00:21:cc:4b:29:7d txqueuelen 1000 (Ethernet)
5 RX packets 27222144 bytes 31247414760 (29.1 GiB)
6 RX errors 0 dropped 0 overruns 0 frame 0
7 TX packets 10259038 bytes 7784519352 (7.2 GiB)
8 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
9 device interrupt 20 memory 0xd2600000-d2620000
10
11 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 16436
12 inet 127.0.0.1 netmask 255.0.0.0
13 inet6 ::1 prefixlen 128 scopeid 0x10<host>
14 loop txqueuelen 0 (Local Loopback)
15 RX packets 257371 bytes 37104110 (35.3 MiB)
16 RX errors 0 dropped 0 overruns 0 frame 0
17 TX packets 257371 bytes 37104110 (35.3 MiB)
18 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
0 em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
1 inet 131.252.209.153 netmask 255.255.255.0 broadcast 192.168.76.255
2 inet6 2610:10:20:209:212:3fff:febe:2201 prefixlen 128 scopeid 0x0<global>
3 inet6 fe80::221:ccff:fe4b:297d prefixlen 64 scopeid 0x20<link>
4 ether 00:21:cc:4b:29:7d txqueuelen 1000 (Ethernet)
5 RX packets 27222144 bytes 31247414760 (29.1 GiB)
6 RX errors 0 dropped 0 overruns 0 frame 0
7 TX packets 10259038 bytes 7784519352 (7.2 GiB)
8 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
9 device interrupt 20 memory 0xd2600000-d2620000
0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 16436
1 inet 127.0.0.1 netmask 255.0.0.0
2 inet6 ::1 prefixlen 128 scopeid 0x10<host>
3 loop txqueuelen 0 (Local Loopback)
4 RX packets 257371 bytes 37104110 (35.3 MiB)
5 RX errors 0 dropped 0 overruns 0 frame 0
6 TX packets 257371 bytes 37104110 (35.3 MiB)
7 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
0 lo Link encap:Local Loopback
1 inet addr:127.0.0.1 Mask:255.0.0.0
2 inet6 addr: ::1/128 Scope:Host
3 UP LOOPBACK RUNNING MTU:16436 Metric:1
4 RX packets:9031461 errors:0 dropped:0 overruns:0 frame:0
5 TX packets:9031461 errors:0 dropped:0 overruns:0 carrier:0
6 collisions:0 txqueuelen:0
7 RX bytes:3205490447 (2.9 GiB) TX bytes:3205490447 (2.9 GiB)
8
9 venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
10 inet addr:127.0.0.1 P-t-P:127.0.0.1 Bcast:0.0.0.0 Mask:255.255.255.255
11 UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
12 RX packets:38161277 errors:0 dropped:0 overruns:0 frame:0
13 TX packets:24601924 errors:0 dropped:0 overruns:0 carrier:0
14 collisions:0 txqueuelen:0
15 RX bytes:3847964603 (3.5 GiB) TX bytes:5770630041 (5.3 GiB)
16
17 venet0:1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
18 inet addr:10.0.222.20 P-t-P:10.0.222.20 Bcast:10.0.222.20 Mask:255.255.255.255
19 UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
0 em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
1 inet 131.252.209.153 netmask 255.255.255.0 broadcast 192.168.76.255
2 inet6 2610:10:20:209:212:3fff:febe:2201 prefixlen 128 scopeid 0x0<global>
3 inet6 fe80::221:ccff:fe4b:297d prefixlen 64 scopeid 0x20<link>
4 ether 00:21:cc:4b:29:7d txqueuelen 1000 (Ethernet)
5 RX packets 27222144 bytes 31247414760 (29.1 GiB)
6 RX errors 0 dropped 0 overruns 0 frame 0
7 TX packets 10259038 bytes 7784519352 (7.2 GiB)
8 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
9 device interrupt 20 memory 0xd2600000-d2620000
10
11 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 16436
12 inet 127.0.0.1 netmask 255.0.0.0
13 inet6 ::1 prefixlen 128 scopeid 0x10<host>
14 loop txqueuelen 0 (Local Loopback)
15 RX packets 257371 bytes 37104110 (35.3 MiB)
16 RX errors 0 dropped 0 overruns 0 frame 0
17 TX packets 257371 bytes 37104110 (35.3 MiB)
18 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
0 eth0 Link encap:Ethernet HWaddr 42:01:0a:57:50:6e
1 inet addr:10.87.80.110 Bcast:10.87.80.110 Mask:255.255.255.255
2 UP BROADCAST RUNNING MULTICAST MTU:1460 Metric:1
3 RX packets:1609444 errors:0 dropped:0 overruns:0 frame:0
4 TX packets:1479569 errors:0 dropped:0 overruns:0 carrier:0
5 collisions:0 txqueuelen:1000
6 RX bytes:673812693 (673.8 MB) TX bytes:221186872 (221.1 MB)
7
8 lo Link encap:Local Loopback
9 inet addr:127.0.0.1 Mask:255.0.0.0
10 UP LOOPBACK RUNNING MTU:16436 Metric:1
11 RX packets:5435415 errors:0 dropped:0 overruns:0 frame:0
12 TX packets:5435415 errors:0 dropped:0 overruns:0 carrier:0
13 collisions:0 txqueuelen:0
14 RX bytes:734540224 (734.5 MB) TX bytes:734540224 (734.5 MB)
15
0 RSpec.configure do |config|
1 config.alias_it_should_behave_like_to :example_behavior_for, "parses"
2 end
00 #! /usr/bin/env ruby
11
22 require 'spec_helper'
3 require 'stringio'
34
45 describe "Domain name facts" do
56
6 { :linux => {:kernel => "Linux", :hostname_command => "hostname -f"},
7 :solaris => {:kernel => "SunOS", :hostname_command => "hostname"},
8 :darwin => {:kernel => "Darwin", :hostname_command => "hostname -f"},
9 :freebsd => {:kernel => "FreeBSD", :hostname_command => "hostname -f"},
10 :hpux => {:kernel => "HP-UX", :hostname_command => "hostname"},
11 }.each do |key, nested_hash|
12
13 describe "on #{key}" do
7 def resolv_conf_contains(*lines)
8 file_handle = StringIO.new(lines.join("\n"))
9 FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
10 File.stubs(:open).with("/etc/resolv.conf").yields(file_handle)
11 end
12
13 [
14 { :kernel => "Linux", :hostname_command => "hostname -f 2> /dev/null" },
15 { :kernel => "SunOS", :hostname_command => "hostname 2> /dev/null" },
16 { :kernel => "Darwin", :hostname_command => "hostname -f 2> /dev/null" },
17 { :kernel => "FreeBSD", :hostname_command => "hostname -f 2> /dev/null" },
18 { :kernel => "HP-UX", :hostname_command => "hostname 2> /dev/null" },
19 ].each do |scenario|
20
21 describe "on #{scenario[:kernel]}" do
22 let(:hostname_command) { scenario[:hostname_command] }
23 let(:dnsdomain_command) { "dnsdomainname 2> /dev/null" }
24
25 def the_hostname_is(value)
26 Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns(value)
27 end
28
29 def the_dnsdomainname_is(value)
30 Facter::Util::Resolution.stubs(:exec).with(dnsdomain_command).returns(value)
31 end
32
1433 before do
15 Facter.fact(:kernel).stubs(:value).returns(nested_hash[:kernel])
16 FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
17 end
18
19 let :hostname_command do
20 nested_hash[:hostname_command]
21 end
22
34 Facter.fact(:kernel).stubs(:value).returns(scenario[:kernel])
35 end
36
2337 it "should use the hostname binary" do
24 Facter::Util::Resolution.expects(:exec).with(hostname_command).returns "test.example.com"
38 the_hostname_is("test.example.com")
39
2540 Facter.fact(:domain).value.should == "example.com"
2641 end
27
42
2843 it "should fall back to the dnsdomainname binary" do
29 Facter::Util::Resolution.expects(:exec).with(hostname_command).returns("myhost")
30 Facter::Util::Resolution.expects(:exec).with("dnsdomainname").returns("example.com")
44 the_hostname_is("myhost")
45 the_dnsdomainname_is("example.com")
46
3147 Facter.fact(:domain).value.should == "example.com"
3248 end
33
34
49
3550 it "should fall back to /etc/resolv.conf" do
36 Facter::Util::Resolution.expects(:exec).with(hostname_command).at_least_once.returns("myhost")
37 Facter::Util::Resolution.expects(:exec).with("dnsdomainname").at_least_once.returns("")
38 File.expects(:open).with('/etc/resolv.conf').at_least_once
39 Facter.fact(:domain).value
40 end
41
42 it "should attempt to resolve facts in a specific order" do
43 seq = sequence('domain')
44 Facter::Util::Resolution.stubs(:exec).with(hostname_command).in_sequence(seq).at_least_once
45 Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").in_sequence(seq).at_least_once
46 File.expects(:open).with('/etc/resolv.conf').in_sequence(seq).at_least_once
47 Facter.fact(:domain).value
48 end
49
50 describe "Top level domain" do
51 the_hostname_is("myhost")
52 the_dnsdomainname_is("")
53
54 resolv_conf_contains("domain testing.com")
55
56 Facter.fact(:domain).value.should == "testing.com"
57 end
58
59 describe "Top level domain" do
5160 it "should find the domain name" do
52 Facter::Util::Resolution.expects(:exec).with(hostname_command).returns "ns01.tld"
53 Facter::Util::Resolution.expects(:exec).with("dnsdomainname").never
54 File.expects(:exists?).with('/etc/resolv.conf').never
55 Facter.fact(:domain).value.should == "tld"
56 end
57 end
58
61 the_hostname_is("ns01.tld")
62
63 Facter.fact(:domain).value.should == "tld"
64 end
65 end
66
5967 describe "when using /etc/resolv.conf" do
6068 before do
61 Facter::Util::Resolution.stubs(:exec).with(hostname_command)
62 Facter::Util::Resolution.stubs(:exec).with("dnsdomainname")
63 @mock_file = mock()
64 File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
65 end
66
69 the_hostname_is("")
70 the_dnsdomainname_is("")
71 end
72
6773 it "should use the domain field over the search field" do
68 lines = [
69 "nameserver 4.2.2.1",
70 "search example.org",
71 "domain example.com",
72 ]
73 @mock_file.expects(:each).multiple_yields(*lines)
74 resolv_conf_contains(
75 "nameserver 4.2.2.1",
76 "search example.org",
77 "domain example.com"
78 )
79
7480 Facter.fact(:domain).value.should == 'example.com'
7581 end
7682
7783 it "should fall back to the search field" do
78 lines = [
79 "nameserver 4.2.2.1",
80 "search example.org",
81 ]
82 @mock_file.expects(:each).multiple_yields(*lines)
84 resolv_conf_contains(
85 "nameserver 4.2.2.1",
86 "search example.org"
87 )
88
8389 Facter.fact(:domain).value.should == 'example.org'
8490 end
85
91
8692 it "should use the first domain in the search field" do
87 lines = [
88 "search example.org example.net",
89 ]
90 @mock_file.expects(:each).multiple_yields(*lines)
93 resolv_conf_contains("search example.org example.net")
94
9195 Facter.fact(:domain).value.should == 'example.org'
9296 end
93
97
9498 # Test permutations of domain and search, where 'domain' can be a value of
9599 # the search keyword and the domain keyword
96100 # and also where 'search' can be a value of the search keyword and the
106110 # Why someone would have their machines named 'www.domain' or 'www.search', I
107111 # don't know, but we'll at least handle it properly
108112 [
109 ["domain domain", "domain"],
110 ["domain search", "search"],
111 ["search domain", "domain"],
112 ["search search", "search"],
113 ["search domain notdomain", "domain"],
114 [["#search notdomain","search search"], "search"],
115 [["# search notdomain","search search"], "search"],
116 [["#domain notdomain","domain domain"], "domain"],
117 [["# domain notdomain","domain domain"], "domain"],
113 [["domain domain"], "domain"],
114 [["domain search"], "search"],
115 [["search domain"], "domain"],
116 [["search search"], "search"],
117 [["search domain notdomain"], "domain"],
118 [["#search notdomain", "search search"], "search"],
119 [["# search notdomain", "search search"], "search"],
120 [["#domain notdomain", "domain domain"], "domain"],
121 [["# domain notdomain", "domain domain"], "domain"],
118122 ].each do |tuple|
119 field = tuple[0]
123 conf = tuple[0]
120124 expect = tuple[1]
121 it "should return #{expect} from \"#{field}\"" do
122 lines = [
123 field
124 ].flatten
125 @mock_file.expects(:each).multiple_yields(*lines)
125 it "should return #{expect} from \"#{conf}\"" do
126 resolv_conf_contains(*conf)
127
126128 Facter.fact(:domain).value.should == expect
127129 end
128130 end
129131 end
130132 end
131 end
133 end
132134
133135 describe "on Windows" do
134136 before(:each) do
172174 end
173175 end
174176
175 describe "with trailing dots" do
176 describe "on Windows" do
177 describe "with trailing dots" do
178 describe "on Windows" do
177179 before do
178180 Facter.fact(:kernel).stubs(:value).returns("windows")
179181 require 'facter/util/registry'
180182 require 'facter/util/wmi'
181183 end
182
184
183185 [{:registry => 'testdomain.', :wmi => '', :expect => 'testdomain'},
184186 {:registry => '', :wmi => 'testdomain.', :expect => 'testdomain'},
185187 ].each do |scenario|
186188
187 describe "scenarios" do
189 describe "scenarios" do
188190 before(:each) do
189191 Facter::Util::Registry.stubs(:hklm_read).returns(scenario[:registry])
190192 nic = stubs 'nic'
191193 nic.stubs(:DNSDomain).returns(scenario[:wmi])
192194 Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic])
193195 end
194
196
195197 it "should return #{scenario[:expect]}" do
196198 Facter.fact(:domain).value.should == scenario[:expect]
197199 end
198
200
199201 it "should remove trailing dots" do
200202 Facter.fact(:domain).value.should_not =~ /\.$/
201203 end
202 end
203 end
204 end
205 end
204206 end
205207
206208 describe "on everything else" do
209211 FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
210212 end
211213
212 [{:hostname => 'host.testdomain.', :dnsdomainname => '', :resolve_domain => '', :resolve_search => '', :expect => 'testdomain'},
213 {:hostname => '', :dnsdomainname => 'testdomain.', :resolve_domain => '', :resolve_search => '', :expect => 'testdomain'},
214 {:hostname => '', :dnsdomainname => '', :resolve_domain => 'testdomain.', :resolve_search => '', :expect => 'testdomain'},
215 {:hostname => '', :dnsdomainname => '', :resolve_domain => '', :resolve_search => 'testdomain.', :expect => 'testdomain'},
216 {:hostname => '', :dnsdomainname => '', :resolve_domain => '', :resolve_search => '', :expect => nil}
214 [
215 {
216 :scenario => 'when there is only a hostname',
217 :hostname => 'host.testdomain.',
218 :dnsdomainname => '',
219 :resolve_domain => '',
220 :resolve_search => '',
221 :expect => 'testdomain'
222 },
223 {
224 :scenario => 'when there is only a domain name',
225 :hostname => '',
226 :dnsdomainname => 'testdomain.',
227 :resolve_domain => '',
228 :resolve_search => '',
229 :expect => 'testdomain'
230 },
231 {
232 :scenario => 'when there is only a resolve domain',
233 :hostname => '',
234 :dnsdomainname => '',
235 :resolve_domain => 'testdomain.',
236 :resolve_search => '',
237 :expect => 'testdomain'
238 },
239 {
240 :scenario => 'when there is only a resolve search',
241 :hostname => '',
242 :dnsdomainname => '',
243 :resolve_domain => '',
244 :resolve_search => 'testdomain.',
245 :expect => 'testdomain'
246 },
247 {
248 :scenario => 'when there is no information available',
249 :hostname => '',
250 :dnsdomainname => '',
251 :resolve_domain => '',
252 :resolve_search => '',
253 :expect => nil
254 }
217255 ].each do |scenario|
218256
219 describe "scenarios" do
220 before(:each) do
221 Facter::Util::Resolution.stubs(:exec).with("hostname -f").returns(scenario[:hostname])
222 Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").returns(scenario[:dnsdomainname])
223 @mock_file = mock()
224 File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
225 lines = [
226 "search #{scenario[:resolve_search]}",
227 "domain #{scenario[:resolve_domain]}",
228 ]
229 @mock_file.stubs(:each).multiple_yields(*lines)
257 describe scenario[:scenario] do
258 before(:each) do
259 Facter::Util::Resolution.stubs(:exec).with("hostname -f 2> /dev/null").returns(scenario[:hostname])
260 Facter::Util::Resolution.stubs(:exec).with("dnsdomainname 2> /dev/null").returns(scenario[:dnsdomainname])
261 resolv_conf_contains(
262 "search #{scenario[:resolve_search]}",
263 "domain #{scenario[:resolve_domain]}"
264 )
230265 end
231266
232267 it "should remove trailing dots" do
237272 Facter.fact(:domain).value.should == scenario[:expect]
238273 end
239274 end
240 end
275 end
241276 end
242277 end
243278 end
00 #! /usr/bin/env ruby
11
22 require 'spec_helper'
3 require 'shared_formats/parses'
34 require 'facter/util/ip'
5
6 shared_examples_for "netmask_* from ifconfig output" do |platform, interface, address, fixture|
7 it "correctly on #{platform} interface #{interface}" do
8 Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
9 Facter::Util::IP.stubs(:get_output_for_interface_and_label).
10 returns(my_fixture_read("#{fixture}.#{interface}"))
11 Facter.collection.internal_loader.load(:interfaces)
12
13 fact = Facter.fact("netmask_#{interface}".intern)
14 fact.value.should eq(address)
15 end
16 end
417
518 describe "Per Interface IP facts" do
619 it "should replace the ':' in an interface list with '_'" do
1831 Facter.fact(:interfaces).value.should == %{Local_Area_Connection,Loopback__Pseudo_Interface____1_}
1932 end
2033 end
34
35 describe "Netmask handling on Linux" do
36 before :each do
37 Facter.fact(:kernel).stubs(:value).returns("Linux")
38 end
39
40 example_behavior_for "netmask_* from ifconfig output",
41 "Archlinux (net-tools 1.60)", "em1",
42 "255.255.255.0", "ifconfig_net_tools_1.60.txt"
43 example_behavior_for "netmask_* from ifconfig output",
44 "Archlinux (net-tools 1.60)", "lo",
45 "255.0.0.0", "ifconfig_net_tools_1.60.txt"
46 end
2727 "Ubuntu 12.04", "10.87.80.110", "ifconfig_ubuntu_1204.txt"
2828 example_behavior_for "ifconfig output",
2929 "Fedora 17", "131.252.209.153", "ifconfig_net_tools_1.60.txt"
30 example_behavior_for "ifconfig output",
31 "Linux with multiple loopback addresses",
32 "10.0.222.20",
33 "ifconfig_multiple_127_addresses.txt"
3034 end
3135 end
0 #! /usr/bin/env ruby
1
2 require 'spec_helper'
3 require 'shared_formats/parses'
4 require 'facter/util/ip'
5
6 shared_examples_for "netmask from ifconfig output" do |platform, address, fixture|
7 it "correctly on #{platform}" do
8 Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
9 Facter.collection.internal_loader.load(:netmask)
10
11 Facter.fact(:netmask).value.should eq(address)
12 end
13 end
14
15 describe "netmask fact" do
16 before :each do
17 Facter.fact(:kernel).stubs(:value).returns("Linux")
18 end
19
20 context "on Linux" do
21 example_behavior_for "netmask from ifconfig output",
22 "Archlinux (net-tools 1.60)", "255.255.255.0",
23 "ifconfig_net_tools_1.60.txt"
24 example_behavior_for "netmask from ifconfig output",
25 "Ubuntu 12.04", "255.255.255.255",
26 "ifconfig_ubuntu_1204.txt"
27 end
28 end
2828 describe "2003" do
2929 before :each do
3030 proc = stubs 'proc'
31 proc.stubs(:NumberOfLogicalProcessors).raises(RuntimeError)
3231 proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
3332
3433 load(Array.new(2, proc))
3534 end
3635
3736 it "should count 2 processors" do
37 proc.expects(:NumberOfLogicalProcessors).never
38
3839 Facter.fact(:processorcount).value.should == "2"
3940 end
4041
684684 it "should try to run the command and return output of a shell-builtin" do
685685 Facter::Util::Resolution.expects(:expand_command).with(%q{echo foo}).returns nil
686686 Facter::Util::Resolution.expects(:`).with(%q{echo foo}).returns 'foo'
687 Facter.expects(:warnonce).with('Using Facter::Util::Resolution.exec with a shell built-in is deprecated. Most built-ins can be replaced with native ruby commands. If you really have to run a built-in, pass "cmd /c your_builtin" as a command')
687 Facter.expects(:warnonce).with 'Using Facter::Util::Resolution.exec with a shell built-in is deprecated. Most built-ins can be replaced with native ruby commands. If you really have to run a built-in, pass "cmd /c your_builtin" as a command (command responsible for this message was "echo foo")'
688688 Facter::Util::Resolution.exec(%q{echo foo}).should == 'foo'
689689 end
690690 it "should try to run the command and return nil if not shell-builtin" do
146146 end
147147 end
148148
149 it "reads dmi entries as ascii data" do
150 entries_file = my_fixture('invalid_unicode_dmi_entries')
151 expected_contents = 'Virtual'
152
153 entries = Facter::Util::Virtual.read_sysfs_dmi_entries(entries_file)
154
155 entries.should =~ /#{expected_contents}/
156 end
157
149158 it "should identify vserver_host when /proc/virtual exists" do
150159 Facter::Util::Virtual.expects(:vserver?).returns(true)
151160 FileTest.stubs(:exists?).with("/proc/virtual").returns(true)
204204 end
205205 end
206206 end
207
208 it "(#20236) is vmware when dmidecode contains vmware and lspci returns insufficient information" do
209 Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("garbage\ninformation\n")
210 Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device 1 Information\nType: Video\nStatus: Disabled\nDescription: VMware SVGA II")
211 Facter.fact(:virtual).value.should eq("vmware")
212 end
207213 end
208214
209215 describe "on Solaris" do
271277 require 'facter/util/wmi'
272278 before do
273279 Facter.fact(:kernel).stubs(:value).returns("windows")
280 Facter.fact(:architecture).stubs(:value).returns("x64")
274281 end
275282
276283 it "should be kvm with KVM model name from Win32_ComputerSystem" do