facter 1.7.0.rc1 → 1.7.0.rc2

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.

data/Gemfile CHANGED
@@ -26,6 +26,7 @@ platform :mswin, :mingw do
26
26
  gem "win32-dir", "~> 0.3.7"
27
27
  gem "windows-api", "~> 0.4.1"
28
28
  gem "windows-pr", "~> 1.2.1"
29
+ gem "win32console", "~> 1.3.2"
29
30
  end
30
31
 
31
32
  if File.exists? "#{__FILE__}.local"
@@ -21,6 +21,8 @@
21
21
  # Used the ipaddress fact that is already part of
22
22
  # Facter as a template.
23
23
 
24
+ require 'facter/util/ip'
25
+
24
26
  def get_address_after_token(output, token, return_first=false)
25
27
  ip = nil
26
28
 
@@ -103,7 +103,12 @@ module Util
103
103
  #
104
104
  # @api private
105
105
  def parse!
106
- rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
106
+ if @zoneadm_output
107
+ rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
108
+ else
109
+ Facter.debug "Cannot parse zone facts, #{zoneadm_cmd} returned no output"
110
+ rows = []
111
+ end
107
112
 
108
113
  @zone_hash = rows.inject({}) do |memo, fields|
109
114
  zone = fields[1].intern
@@ -3,8 +3,23 @@ module Facter::Util::Virtual
3
3
  # virt_what is a delegating helper method intended to make it easier to stub
4
4
  # the system call without affecting other calls to
5
5
  # Facter::Util::Resolution.exec
6
+ #
7
+ # Per https://bugzilla.redhat.com/show_bug.cgi?id=719611 when run as a
8
+ # non-root user the virt-what command may emit an error message on stdout,
9
+ # and later versions of virt-what may emit this message on stderr. This
10
+ # method ensures stderr is redirected and that error messages are stripped
11
+ # from stdout.
6
12
  def self.virt_what(command = "virt-what")
7
- Facter::Util::Resolution.exec command
13
+ command = Facter::Util::Resolution.which(command)
14
+ return unless command
15
+
16
+ if Facter.value(:kernel) == 'windows'
17
+ redirected_cmd = "#{command} 2>NUL"
18
+ else
19
+ redirected_cmd = "#{command} 2>/dev/null"
20
+ end
21
+ output = Facter::Util::Resolution.exec redirected_cmd
22
+ output.gsub(/^virt-what: .*$/, '') if output
8
23
  end
9
24
 
10
25
  ##
@@ -47,6 +62,9 @@ module Facter::Util::Virtual
47
62
  def self.vserver?
48
63
  return false unless FileTest.exists?("/proc/self/status")
49
64
  txt = File.open("/proc/self/status", "rb").read
65
+ if txt.respond_to?(:encode!)
66
+ txt.encode!('UTF-8', 'UTF-8', :invalid => :replace)
67
+ end
50
68
  return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/
51
69
  return false
52
70
  end
@@ -1,6 +1,6 @@
1
1
  module Facter
2
2
  if not defined? FACTERVERSION then
3
- FACTERVERSION = '1.7.0-rc1'
3
+ FACTERVERSION = '1.7.0-rc2'
4
4
  end
5
5
 
6
6
  ##
@@ -206,20 +206,21 @@ Facter.add("virtual") do
206
206
  has_weight 500
207
207
 
208
208
  setcode do
209
- output = Facter::Util::Virtual.virt_what
210
- case output
211
- when 'linux_vserver'
212
- Facter::Util::Virtual.vserver_type
213
- when /xen-hvm/i
214
- 'xenhvm'
215
- when /xen-dom0/i
216
- 'xen0'
217
- when /xen-domU/i
218
- 'xenu'
219
- when /ibm_systemz/i
220
- 'zlinux'
221
- else
222
- output.to_s.split("\n").last
209
+ if output = Facter::Util::Virtual.virt_what
210
+ case output
211
+ when 'linux_vserver'
212
+ Facter::Util::Virtual.vserver_type
213
+ when /xen-hvm/i
214
+ 'xenhvm'
215
+ when /xen-dom0/i
216
+ 'xen0'
217
+ when /xen-domU/i
218
+ 'xenu'
219
+ when /ibm_systemz/i
220
+ 'zlinux'
221
+ else
222
+ output.to_s.split("\n").last
223
+ end
223
224
  end
224
225
  end
225
226
  end
@@ -20,6 +20,13 @@ end
20
20
  RSpec.configure do |config|
21
21
  config.mock_with :mocha
22
22
 
23
+ if Facter::Util::Config.is_windows?
24
+ require 'win32console'
25
+ config.output_stream = $stdout
26
+ config.error_stream = $stderr
27
+ config.formatters.each { |f| f.instance_variable_set(:@output, $stdout) }
28
+ end
29
+
23
30
  config.before :each do
24
31
  # Ensure that we don't accidentally cache facts and environment
25
32
  # between test cases.
@@ -321,12 +321,11 @@ describe Facter::Util::Loader do
321
321
  end
322
322
 
323
323
  it "should load all facts from the environment" do
324
- Facter.expects(:add).with('one')
325
- Facter.expects(:add).with('two')
326
-
327
324
  Facter::Util::Resolution.with_env "facter_one" => "yayness", "facter_two" => "boo" do
328
325
  @loader.load_all
329
326
  end
327
+ Facter.value(:one).should == 'yayness'
328
+ Facter.value(:two).should == 'boo'
330
329
  end
331
330
 
332
331
  it "should only load all facts one time" do
@@ -18,7 +18,7 @@ describe "standardized MAC address" do
18
18
  end
19
19
  end
20
20
 
21
- describe "Darwin", :unless => Facter.value(:operatingsystem) == 'windows' do
21
+ describe "Darwin", :unless => Facter::Util::Config.is_windows? do
22
22
  test_cases = [
23
23
  # version, iface, real macaddress, fallback macaddress
24
24
  ["9.8.0", 'en0', "00:17:f2:06:e4:2e", "00:17:f2:06:e4:2e"],
@@ -42,8 +42,10 @@ describe Facter::Util::Macosx do
42
42
  end
43
43
 
44
44
  it 'should fail when trying to read invalid XML' do
45
- expect { Facter::Util::Macosx.intern_xml('<bad}|%-->xml<--->') }.to \
46
- raise_error(RuntimeError, /A plist file could not be properly read by Facter::Util::CFPropertyList/)
45
+ STDERR.stubs(:<<)
46
+ expect {
47
+ Facter::Util::Macosx.intern_xml('<bad}|%-->xml<--->')
48
+ }.to raise_error(RuntimeError, /A plist file could not be properly read by Facter::Util::CFPropertyList/)
47
49
  end
48
50
 
49
51
  describe "when collecting profiler data" do
@@ -5,7 +5,7 @@ require 'facter/util/uptime'
5
5
 
6
6
  describe Facter::Util::Uptime do
7
7
 
8
- describe ".get_uptime_seconds_unix", :unless => Facter.value(:operatingsystem) == 'windows' do
8
+ describe ".get_uptime_seconds_unix", :unless => Facter::Util::Config.is_windows? do
9
9
  describe "when /proc/uptime is available" do
10
10
  before do
11
11
  uptime_file = my_fixture("ubuntu_proc_uptime")
@@ -118,7 +118,7 @@ describe Facter::Util::Uptime do
118
118
  end
119
119
  end
120
120
 
121
- describe ".get_uptime_seconds_win", :if => Facter.value(:operatingsystem) == 'windows' do
121
+ describe ".get_uptime_seconds_win", :if => Facter::Util::Config.is_windows? do
122
122
  it "should return a postive value" do
123
123
  Facter::Util::Uptime.get_uptime_seconds_win.should > 0
124
124
  end
@@ -58,6 +58,14 @@ describe Facter::Util::Virtual do
58
58
  Facter::Util::Virtual.should_not be_zone
59
59
  end
60
60
 
61
+ it "(#14522) handles the unencoded binary data in /proc/self/status on Solaris" do
62
+ Facter.fact(:osfamily).stubs(:value).returns("Solaris")
63
+ File.stubs(:open).with('/proc/self/status', 'rb').returns(solaris_proc_self_status)
64
+ FileTest.stubs(:exists?).with('/proc/self/status').returns(true)
65
+
66
+ Facter::Util::Virtual.vserver?.should eq(false)
67
+ end
68
+
61
69
  it "should not detect vserver if no self status" do
62
70
  FileTest.stubs(:exists?).with("/proc/self/status").returns(false)
63
71
  Facter::Util::Virtual.should_not be_vserver
@@ -235,4 +243,38 @@ describe Facter::Util::Virtual do
235
243
 
236
244
  Facter::Util::Virtual.should_not be_virtualbox
237
245
  end
246
+
247
+ let :solaris_proc_self_status do
248
+ sample_data = my_fixture_read('solaris10_proc_self_status1')
249
+ mockfile = mock('File')
250
+ mockfile.stubs(:read).returns(sample_data)
251
+ mockfile
252
+ end
253
+
254
+ shared_examples_for "virt-what" do |kernel, path, null_device|
255
+ Facter.fact(:kernel).stubs(:value).returns(kernel)
256
+ Facter::Util::Resolution.expects(:which).with("virt-what").returns(path)
257
+ Facter::Util::Resolution.expects(:exec).with("#{path} 2>#{null_device}")
258
+ Facter::Util::Virtual.virt_what
259
+ end
260
+
261
+ context "on linux" do
262
+ it_should_behave_like "virt-what", "linux", "/usr/bin/virt-what", "/dev/null"
263
+
264
+ it "should strip out warnings on stdout from virt-what" do
265
+ virt_what_warning = "virt-what: this script must be run as root"
266
+ Facter.fact(:kernel).stubs(:value).returns('linux')
267
+ Facter::Util::Resolution.expects(:which).with('virt-what').returns "/usr/bin/virt-what"
268
+ Facter::Util::Resolution.expects(:exec).with('/usr/bin/virt-what 2>/dev/null').returns virt_what_warning
269
+ Facter::Util::Virtual.virt_what.should_not match /^virt-what: /
270
+ end
271
+ end
272
+
273
+ context "on unix" do
274
+ it_should_behave_like "virt-what", "unix", "/usr/bin/virt-what", "/dev/null"
275
+ end
276
+
277
+ context "on windows" do
278
+ it_should_behave_like "virt-what", "windows", 'c:\windows\system32\virt-what', "NUL"
279
+ end
238
280
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1394194789
4
+ hash: 3969496243
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
9
  - 0
10
10
  - rc
11
- - 1
12
- version: 1.7.0.rc1
11
+ - 2
12
+ version: 1.7.0.rc2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Puppet Labs
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2013-04-01 00:00:00 Z
20
+ date: 2013-04-08 00:00:00 Z
21
21
  dependencies: []
22
22
 
23
23
  description: You can prove anything with facts!
@@ -210,6 +210,7 @@ files:
210
210
  - spec/fixtures/unit/util/ec2/solaris8_arp_a_not_ec2.out
211
211
  - spec/fixtures/unit/util/ec2/windows-2008-arp-a-not-ec2.out
212
212
  - spec/fixtures/unit/util/ec2/linux-arp-ec2.out
213
+ - spec/fixtures/unit/util/virtual/solaris10_proc_self_status1
213
214
  - spec/fixtures/unit/util/loader/nosuchfact.rb
214
215
  - spec/fixtures/unit/util/processor/solaris-i86pc
215
216
  - spec/fixtures/unit/util/processor/x86-pentium2
@@ -458,6 +459,7 @@ test_files:
458
459
  - spec/fixtures/unit/util/ec2/solaris8_arp_a_not_ec2.out
459
460
  - spec/fixtures/unit/util/ec2/windows-2008-arp-a-not-ec2.out
460
461
  - spec/fixtures/unit/util/ec2/linux-arp-ec2.out
462
+ - spec/fixtures/unit/util/virtual/solaris10_proc_self_status1
461
463
  - spec/fixtures/unit/util/loader/nosuchfact.rb
462
464
  - spec/fixtures/unit/util/processor/solaris-i86pc
463
465
  - spec/fixtures/unit/util/processor/x86-pentium2