Codebase list facter / b9abdd1
(#12116) Windows domain/fqdn error when no domain This fixes an annoying issue that causes facter to throw errors when domain is not properly configured or doesn't exist. With this fix, it will properly return an empty domain and empty fqdn without errorring. When moving up the chain to the less specific domain fact, added a windows_hostname command and a check so that it also does not fail with path not found errors. Paired-with: Josh Cooper<josh@puppetlabs.com> Rob Reynolds 10 years ago
2 changed file(s) with 23 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
2828 # Due to dangerous behavior of 'hostname -f' on old OS, we will explicitly opt-in
2929 # 'hostname -f' --hkenney May 9, 2012
3030 basic_hostname = 'hostname 2> /dev/null'
31 windows_hostname = 'hostname > NUL'
3132 full_hostname = 'hostname -f 2> /dev/null'
3233 can_do_hostname_f = Regexp.union /Linux/i, /FreeBSD/i, /Darwin/i
3334
3435 hostname_command = if Facter.value(:kernel) =~ can_do_hostname_f
3536 full_hostname
37 elsif Facter.value(:kernel) == "windows"
38 windows_hostname
3639 else
3740 basic_hostname
3841 end
4144 and name =~ /.*?\.(.+$)/
4245
4346 return_value = $1
44 elsif domain = Facter::Util::Resolution.exec('dnsdomainname 2> /dev/null') \
47 elsif Facter.value(:kernel) != "windows" and domain = Facter::Util::Resolution.exec('dnsdomainname 2> /dev/null') \
4548 and domain =~ /.+/
4649
4750 return_value = domain
7982 break
8083 }
8184 end
85
86 domain ||= ''
87
8288 domain.gsub(/\.$/, '')
8389 end
8490 end
171171
172172 Facter.fact(:domain).value.should == 'foo.com'
173173 end
174
175 context "without any network adapters with a specified DNSDomain" do
176 let(:hostname_command) { 'hostname > NUL' }
177
178 it "should return nil" do
179 nic = stubs 'nic'
180 nic.stubs(:DNSDomain).returns(nil)
181 Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns('sometest')
182 FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false)
183
184 require 'facter/util/wmi'
185 Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic])
186
187 Facter.fact(:domain).value.should be_nil
188 end
189 end
174190 end
175191 end
176192