Codebase list facter / 5a730af
(#12116) Don't break on the first interface Previously, if there were multiple interfaces with IPEnabled on Windows, we would always use the DNSDomain value from the first interface, even if it was nil or empty. This commit changes the domain fact to look for the first non-nil and non-empty DNSDomain value. Josh Cooper 10 years ago
2 changed file(s) with 31 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
7878 if domain == ""
7979 require 'facter/util/wmi'
8080 Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
81 domain = nic.DNSDomain
82 break
81 if nic.DNSDomain && nic.DNSDomain.length > 0
82 domain = nic.DNSDomain
83 break
84 end
8385 }
8486 end
8587
159159 Facter::Util::Registry.stubs(:hklm_read).returns('')
160160 end
161161
162 it "should use the DNSDomain for the first nic where ip is enabled" do
163 nic = stubs 'nic'
164 nic.stubs(:DNSDomain).returns("foo.com")
165
166 nic2 = stubs 'nic'
167 nic2.stubs(:DNSDomain).returns("bar.com")
162 def expects_dnsdomains(domains)
163 nics = []
164
165 domains.each do |domain|
166 nic = stubs 'nic'
167 nic.stubs(:DNSDomain).returns(domain)
168 nics << nic
169 end
168170
169171 require 'facter/util/wmi'
170 Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic, nic2])
172 Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns(nics)
173 end
174
175 it "uses the first DNSDomain" do
176 expects_dnsdomains(['foo.com', 'bar.com'])
171177
172178 Facter.fact(:domain).value.should == 'foo.com'
179 end
180
181 it "uses the first non-nil DNSDomain" do
182 expects_dnsdomains([nil, 'bar.com'])
183
184 Facter.fact(:domain).value.should == 'bar.com'
185 end
186
187 it "uses the first non-empty DNSDomain" do
188 expects_dnsdomains(['', 'bar.com'])
189
190 Facter.fact(:domain).value.should == 'bar.com'
173191 end
174192
175193 context "without any network adapters with a specified DNSDomain" do
176194 let(:hostname_command) { 'hostname > NUL' }
177195
178196 it "should return nil" do
179 nic = stubs 'nic'
180 nic.stubs(:DNSDomain).returns(nil)
197 expects_dnsdomains([nil])
198
181199 Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns('sometest')
182200 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])
186201
187202 Facter.fact(:domain).value.should be_nil
188203 end