facter 1.6.17 → 1.6.18.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.

data/Gemfile CHANGED
@@ -1,14 +1,20 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
- gemspec
3
+ group :development do
4
+ gem 'watchr'
5
+ end
4
6
 
5
- group(:development, :test) do
6
- gem "rspec", "~> 2.10.0", :require => false
7
- gem "mocha", "~> 0.10.5", :require => false
7
+ group :development, :test do
8
+ gem 'rake'
9
+ gem 'facter', ">= 1.0.0", :path => File.expand_path("..", __FILE__), :require => false
10
+ gem 'rspec', "~> 2.11.0", :require => false
11
+ gem 'mocha', "~> 0.10.5", :require => false
12
+ gem 'json', "~> 1.7", :require => false
13
+ gem 'puppetlabs_spec_helper', :require => false
8
14
  end
9
15
 
10
16
  if File.exists? "#{__FILE__}.local"
11
17
  eval(File.read("#{__FILE__}.local"), binding)
12
18
  end
13
19
 
14
- # vim:filetype=ruby
20
+ # vim:ft=ruby
data/README.md CHANGED
@@ -11,12 +11,14 @@ See `bin/facter` for an example of the interface.
11
11
  Running Facter
12
12
  --------------
13
13
 
14
- Run the `facter` binary on the command for a full list of facts supported on your host.
14
+ Run the `facter` binary on the command for a full list of facts supported on
15
+ your host.
15
16
 
16
17
  Adding your own facts
17
18
  ---------------------
18
19
 
19
- See the [Adding Facts](http://docs.puppetlabs.com/guides/custom_facts.html) page for details of how to add your own custom facts to Facter.
20
+ See the [Adding Facts](http://docs.puppetlabs.com/guides/custom_facts.html)
21
+ page for details of how to add your own custom facts to Facter.
20
22
 
21
23
  Further Information
22
24
  -------------------
@@ -2,15 +2,14 @@
2
2
  packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=master'
3
3
  packaging_repo: 'packaging'
4
4
  default_cow: 'base-squeeze-i386.cow'
5
- cows: 'base-lucid-i386.cow base-natty-i386.cow base-oneiric-i386.cow base-precise-i386.cow base-quantal-i386.cow base-sid-i386.cow base-squeeze-i386.cow base-stable-i386.cow base-testing-i386.cow base-unstable-i386.cow base-wheezy-i386.cow'
5
+ cows: 'base-lucid-i386.cow base-oneiric-i386.cow base-precise-i386.cow base-quantal-i386.cow base-sid-i386.cow base-squeeze-i386.cow base-stable-i386.cow base-testing-i386.cow base-unstable-i386.cow base-wheezy-i386.cow'
6
6
  pbuild_conf: '/etc/pbuilderrc'
7
7
  packager: 'puppetlabs'
8
8
  gpg_name: 'info@puppetlabs.com'
9
9
  gpg_key: '4BD6EC30'
10
10
  sign_tar: FALSE
11
11
  # a space separated list of mock configs
12
- final_mocks: 'pl-5-i386 pl-5-x86_64 pl-6-i386 pl-6-x86_64 fedora-16-i386 fedora-16-x86_64 fedora-17-i386 fedora-17-x86_64'
13
- rc_mocks: 'pl-5-i386-dev pl-5-x86_64-dev pl-6-i386-dev pl-6-x86_64-dev fedora-16-i386-dev fedora-16-x86_64-dev fedora-17-i386-dev fedora-17-x86_64-dev'
12
+ 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'
14
13
  yum_host: 'burji.puppetlabs.com'
15
14
  yum_repo_path: '/opt/repository/yum/'
16
15
  build_gem: TRUE
@@ -67,6 +67,11 @@ module Facter
67
67
 
68
68
  private
69
69
 
70
+ # Parses the given argument array destructively to return an options hash
71
+ # (and possibly perform side effects such as changing settings).
72
+ #
73
+ # @param [Array<String>] argv command line arguments
74
+ # @return [Hash] options hash
70
75
  def self.parse(argv)
71
76
  options = {}
72
77
  OptionParser.new do |opts|
@@ -95,7 +100,7 @@ module Facter
95
100
  exit(1)
96
101
  end
97
102
  end
98
- end.parse!
103
+ end.parse!(argv)
99
104
 
100
105
  options
101
106
  rescue OptionParser::InvalidOption => e
@@ -28,7 +28,7 @@ Facter.add(:ipaddress) do
28
28
  confine :kernel => :linux
29
29
  setcode do
30
30
  ip = nil
31
- if output = Facter::Util::IP.get_ifconfig
31
+ if output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"])
32
32
  regexp = /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
33
33
  if match = regexp.match(output)
34
34
  match[1] unless /^127/.match(match[1])
@@ -41,7 +41,7 @@ Facter.add(:ipaddress) do
41
41
  confine :kernel => %w{FreeBSD OpenBSD Darwin DragonFly}
42
42
  setcode do
43
43
  ip = nil
44
- output = %x{/sbin/ifconfig}
44
+ output = Facter::Util::IP.exec_ifconfig
45
45
 
46
46
  output.split(/^\S/).each { |str|
47
47
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
@@ -61,7 +61,7 @@ Facter.add(:ipaddress) do
61
61
  confine :kernel => %w{NetBSD SunOS}
62
62
  setcode do
63
63
  ip = nil
64
- output = %x{/sbin/ifconfig -a}
64
+ output = Facter::Util::IP.exec_ifconfig(["-a"])
65
65
 
66
66
  output.split(/^\S/).each { |str|
67
67
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
@@ -81,7 +81,7 @@ Facter.add(:ipaddress) do
81
81
  confine :kernel => %w{AIX}
82
82
  setcode do
83
83
  ip = nil
84
- output = %x{/usr/sbin/ifconfig -a}
84
+ output = Facter::Util::IP.exec_ifconfig(["-a"])
85
85
 
86
86
  output.split(/^\S/).each { |str|
87
87
  if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
@@ -38,7 +38,7 @@ end
38
38
  Facter.add(:ipaddress6) do
39
39
  confine :kernel => :linux
40
40
  setcode do
41
- output = Facter::Util::Resolution.exec('/sbin/ifconfig 2>/dev/null')
41
+ output = Facter::Util::IP.exec_ifconfig(["2>/dev/null"])
42
42
 
43
43
  get_address_after_token(output, 'inet6 addr:')
44
44
  end
@@ -47,7 +47,7 @@ end
47
47
  Facter.add(:ipaddress6) do
48
48
  confine :kernel => %w{SunOS}
49
49
  setcode do
50
- output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a')
50
+ output = Facter::Util::IP.exec_ifconfig(["-a"])
51
51
 
52
52
  get_address_after_token(output, 'inet6')
53
53
  end
@@ -56,7 +56,7 @@ end
56
56
  Facter.add(:ipaddress6) do
57
57
  confine :kernel => %w{Darwin FreeBSD OpenBSD}
58
58
  setcode do
59
- output = Facter::Util::Resolution.exec('/sbin/ifconfig -a')
59
+ output = Facter::Util::IP.exec_ifconfig(["-a"])
60
60
 
61
61
  get_address_after_token(output, 'inet6', true)
62
62
  end
@@ -19,7 +19,7 @@ Facter.add(:iphostnumber) do
19
19
  confine :kernel => :darwin, :kernelrelease => "R6"
20
20
  setcode do
21
21
  ether = nil
22
- output = %x{/sbin/ifconfig}
22
+ output = Facter::Util::IP.exec_ifconfig
23
23
 
24
24
  output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
25
25
  ether = $1
@@ -8,6 +8,7 @@
8
8
  #
9
9
 
10
10
  require 'facter/util/macaddress'
11
+ require 'facter/util/ip'
11
12
 
12
13
  Facter.add(:macaddress) do
13
14
  confine :kernel => 'Linux'
@@ -26,7 +27,8 @@ Facter.add(:macaddress) do
26
27
  confine :kernel => 'Linux'
27
28
  setcode do
28
29
  ether = []
29
- output = Facter::Util::Resolution.exec("/sbin/ifconfig -a 2>/dev/null")
30
+ output = Facter::Util::IP.exec_ifconfig(["-a","2>/dev/null"])
31
+
30
32
  output.each_line do |s|
31
33
  ether.push($1) if s =~ /(?:ether|HWaddr) ((\w{1,2}:){5,}\w{1,2})/
32
34
  end
@@ -38,7 +40,7 @@ Facter.add(:macaddress) do
38
40
  confine :kernel => %w{SunOS GNU/kFreeBSD}
39
41
  setcode do
40
42
  ether = []
41
- output = Facter::Util::Resolution.exec("/sbin/ifconfig -a")
43
+ output = Facter::Util::IP.exec_ifconfig(["-a"])
42
44
  output.each_line do |s|
43
45
  ether.push($1) if s =~ /(?:ether|HWaddr) ((\w{1,2}:){5,}\w{1,2})/
44
46
  end
@@ -62,7 +64,7 @@ Facter.add(:macaddress) do
62
64
  confine :operatingsystem => %w{FreeBSD OpenBSD DragonFly}
63
65
  setcode do
64
66
  ether = []
65
- output = Facter::Util::Resolution.exec("/sbin/ifconfig")
67
+ output = Facter::Util::IP.exec_ifconfig
66
68
  output.each_line do |s|
67
69
  if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
68
70
  ether.push($1)
@@ -82,7 +84,7 @@ Facter.add(:macaddress) do
82
84
  setcode do
83
85
  ether = []
84
86
  ip = nil
85
- output = %x{/usr/sbin/ifconfig -a}
87
+ output = Facter::Util::IP.exec_ifconfig(["-a"])
86
88
  output.each_line do |str|
87
89
  if str =~ /([a-z]+\d+): flags=/
88
90
  devname = $1
@@ -77,9 +77,9 @@ module Facter::Util::IP
77
77
  def self.get_all_interface_output
78
78
  case Facter.value(:kernel)
79
79
  when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
80
- output = %x{/sbin/ifconfig -a 2>/dev/null}
80
+ output = Facter::Util::IP.exec_ifconfig(["-a","2>/dev/null"])
81
81
  when 'SunOS'
82
- output = %x{/usr/sbin/ifconfig -a}
82
+ output = Facter::Util::IP.exec_ifconfig(["-a"])
83
83
  when 'HP-UX'
84
84
  # (#17487)[https://projects.puppetlabs.com/issues/17487]
85
85
  # Handle NIC bonding where asterisks and virtual NICs are printed.
@@ -96,14 +96,22 @@ module Facter::Util::IP
96
96
  output
97
97
  end
98
98
 
99
+
99
100
  ##
100
- # get_ifconfig simply delegates to the ifconfig command.
101
+ # exec_ifconfig uses the ifconfig command
101
102
  #
102
- # @return [String] the output of `/sbin/ifconfig 2>/dev/null` or nil
103
+ # @return [String] the output of `ifconfig #{arguments} 2>/dev/null` or nil
104
+ def self.exec_ifconfig(additional_arguments=[])
105
+ Facter::Util::Resolution.exec("#{self.get_ifconfig} #{additional_arguments.join(' ')}")
106
+ end
107
+ ##
108
+ # get_ifconfig looks up the ifconfig binary
109
+ #
110
+ # @return [String] path to the ifconfig binary
103
111
  def self.get_ifconfig
104
- Facter::Util::Resolution.exec("/sbin/ifconfig 2>/dev/null")
112
+ common_paths=["/bin/ifconfig","/sbin/ifconfig","/usr/sbin/ifconfig"]
113
+ common_paths.select{|path| File.executable?(path)}.first
105
114
  end
106
-
107
115
  ##
108
116
  # hpux_netstat_in is a delegate method that allows us to stub netstat -in
109
117
  # without stubbing exec.
@@ -125,7 +133,7 @@ module Facter::Util::IP
125
133
  end
126
134
 
127
135
  def self.ifconfig_interface(interface)
128
- %x{/sbin/ifconfig #{interface} 2>/dev/null}
136
+ output = Facter::Util::IP.exec_ifconfig([interface,"2>/dev/null"])
129
137
  end
130
138
 
131
139
  def self.get_single_interface_output(interface)
@@ -142,7 +150,7 @@ module Facter::Util::IP
142
150
  output = ifconfig_output
143
151
  end
144
152
  when 'SunOS'
145
- output = %x{/usr/sbin/ifconfig #{interface}}
153
+ output = Facter::Util::IP.exec_ifconfig([interface])
146
154
  when 'HP-UX'
147
155
  mac = ""
148
156
  ifc = hpux_ifconfig_interface(interface)
@@ -154,7 +162,7 @@ module Facter::Util::IP
154
162
  end
155
163
 
156
164
  def self.hpux_ifconfig_interface(interface)
157
- Facter::Util::Resolution.exec("/usr/sbin/ifconfig #{interface}")
165
+ Facter::Util::IP.exec_ifconfig([interface])
158
166
  end
159
167
 
160
168
  def self.hpux_lanscan
@@ -7,25 +7,25 @@ module Facter::NetMask
7
7
  case Facter.value(:kernel)
8
8
  when 'Linux'
9
9
  ops = {
10
- :ifconfig => '/sbin/ifconfig 2>/dev/null',
10
+ :ifconfig_opts => ['2>/dev/null'],
11
11
  :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
12
12
  :munge => nil,
13
13
  }
14
14
  when 'SunOS'
15
15
  ops = {
16
- :ifconfig => '/usr/sbin/ifconfig -a',
16
+ :ifconfig_opts => ['-a'],
17
17
  :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s (\w{8})}x,
18
18
  :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
19
19
  }
20
20
  when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
21
21
  ops = {
22
- :ifconfig => '/sbin/ifconfig -a',
22
+ :ifconfig_opts => ['-a'],
23
23
  :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s 0x(\w{8})}x,
24
24
  :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
25
25
  }
26
26
  end
27
27
 
28
- %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line|
28
+ Facter::Util::IP.exec_ifconfig(ops[:ifconfig_opts]).split(/\n/).collect do |line|
29
29
  matches = line.match(ops[:regex])
30
30
  if !matches.nil?
31
31
  if ops[:munge].nil?
@@ -46,7 +46,7 @@ module Facter::Util::Virtual
46
46
 
47
47
  def self.vserver?
48
48
  return false unless FileTest.exists?("/proc/self/status")
49
- txt = File.read("/proc/self/status")
49
+ txt = File.open("/proc/self/status", "rb").read
50
50
  return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/
51
51
  return false
52
52
  end
@@ -1,6 +1,6 @@
1
1
  module Facter
2
2
  if not defined? FACTERVERSION then
3
- FACTERVERSION = '1.6.17'
3
+ FACTERVERSION = '1.6.18-rc1'
4
4
  end
5
5
 
6
6
  def self.version
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'facter/application'
3
+
4
+ describe Facter::Application do
5
+ describe '.parse' do
6
+ it 'returns an empty hash when given no options' do
7
+ Facter::Application.parse([]).should == {}
8
+ Facter::Application.parse(['architecture', 'kernel']).should == {}
9
+ end
10
+
11
+ [:yaml, :json, :trace].each do |option_key|
12
+ it "sets options[:#{option_key}] when given --#{option_key}" do
13
+ options = Facter::Application.parse(["--#{option_key}"])
14
+ options[option_key].should be_true
15
+ end
16
+ end
17
+
18
+ [['-y', :yaml], ['-j', :json]].each do |option, key|
19
+ it "sets options[:#{key}] when given #{option}" do
20
+ options = Facter::Application.parse([option])
21
+ options[key].should be_true
22
+ end
23
+ end
24
+
25
+ ['-d', '--debug'].each do |option|
26
+ it "enables debugging when given #{option}" do
27
+ Facter.debugging(false)
28
+ Facter::Application.parse([option])
29
+ Facter.should be_debugging
30
+ Facter.debugging(false)
31
+ end
32
+ end
33
+
34
+ ['-t', '--timing'].each do |option|
35
+ it "enables timing when given #{option}" do
36
+ Facter.timing(false)
37
+ Facter::Application.parse([option])
38
+ Facter.should be_timing
39
+ Facter.timing(false)
40
+ end
41
+ end
42
+
43
+ ['-p', '--puppet'].each do |option|
44
+ it "calls load_puppet when given #{option}" do
45
+ Facter::Application.expects(:load_puppet)
46
+ Facter::Application.parse([option])
47
+ end
48
+ end
49
+
50
+ it 'mutates argv so that non-option arguments are left' do
51
+ argv = ['-y', '--trace', 'uptime', 'virtual']
52
+ Facter::Application.parse(argv)
53
+ argv.should == ['uptime', 'virtual']
54
+ end
55
+ end
56
+ end
@@ -1,6 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
+ require 'facter/util/ip'
4
5
 
5
6
  def ifconfig_fixture(filename)
6
7
  File.read(fixtures('ifconfig', filename))
@@ -17,7 +18,8 @@ describe "IPv6 address fact" do
17
18
 
18
19
  it "should return ipaddress6 information for Darwin" do
19
20
  Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('Darwin')
20
- Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a').
21
+ Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
22
+ Facter::Util::IP.stubs(:exec_ifconfig).with(["-a"]).
21
23
  returns(ifconfig_fixture('darwin_ifconfig_all_with_multiple_interfaces'))
22
24
 
23
25
  Facter.value(:ipaddress6).should == "2610:10:20:209:223:32ff:fed5:ee34"
@@ -25,7 +27,8 @@ describe "IPv6 address fact" do
25
27
 
26
28
  it "should return ipaddress6 information for Linux" do
27
29
  Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('Linux')
28
- Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig 2>/dev/null').
30
+ Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
31
+ Facter::Util::IP.stubs(:exec_ifconfig).with(["2>/dev/null"]).
29
32
  returns(ifconfig_fixture('linux_ifconfig_all_with_multiple_interfaces'))
30
33
 
31
34
  Facter.value(:ipaddress6).should == "2610:10:20:209:212:3fff:febe:2201"
@@ -33,7 +36,8 @@ describe "IPv6 address fact" do
33
36
 
34
37
  it "should return ipaddress6 information for Solaris" do
35
38
  Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('SunOS')
36
- Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/ifconfig -a').
39
+ Facter::Util::IP.stubs(:get_ifconfig).returns("/usr/sbin/ifconfig")
40
+ Facter::Util::IP.stubs(:exec_ifconfig).with(["-a"]).
37
41
  returns(ifconfig_fixture('sunos_ifconfig_all_with_multiple_interfaces'))
38
42
 
39
43
  Facter.value(:ipaddress6).should == "2610:10:20:209:203:baff:fe27:a7c"
@@ -5,7 +5,7 @@ require 'facter/util/ip'
5
5
 
6
6
  shared_examples_for "ifconfig output" do |platform, address, fixture|
7
7
  it "correctly on #{platform}" do
8
- Facter::Util::IP.stubs(:get_ifconfig).returns(my_fixture_read(fixture))
8
+ Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
9
9
  subject.value.should == address
10
10
  end
11
11
  end
@@ -1,6 +1,8 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
+ require 'facter/util/ip'
5
+
4
6
 
5
7
  def ifconfig_fixture(filename)
6
8
  File.read(fixtures('ifconfig', filename))
@@ -19,17 +21,18 @@ describe "macaddress fact" do
19
21
  before :each do
20
22
  Facter.fact(:kernel).stubs(:value).returns("Linux")
21
23
  Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
24
+ Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
22
25
  end
23
26
 
24
27
  it "should return the macaddress of the first interface" do
25
- Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a 2>/dev/null').
28
+ Facter::Util::IP.stubs(:exec_ifconfig).with(["-a","2>/dev/null"]).
26
29
  returns(ifconfig_fixture('linux_ifconfig_all_with_multiple_interfaces'))
27
30
 
28
31
  Facter.value(:macaddress).should == "00:12:3f:be:22:01"
29
32
  end
30
33
 
31
34
  it "should return nil when no macaddress can be found" do
32
- Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a 2>/dev/null').
35
+ Facter::Util::IP.stubs(:exec_ifconfig).with(["-a","2>/dev/null"]).
33
36
  returns(ifconfig_fixture('linux_ifconfig_no_mac'))
34
37
 
35
38
  proc { Facter.value(:macaddress) }.should_not raise_error
@@ -38,7 +41,7 @@ describe "macaddress fact" do
38
41
 
39
42
  # some interfaces dont have a real mac addresses (like venet inside a container)
40
43
  it "should return nil when no interface has a real macaddress" do
41
- Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a 2>/dev/null').
44
+ Facter::Util::IP.stubs(:exec_ifconfig).with(["-a","2>/dev/null"]).
42
45
  returns(ifconfig_fixture('linux_ifconfig_venet'))
43
46
 
44
47
  proc { Facter.value(:macaddress) }.should_not raise_error
@@ -49,7 +52,8 @@ describe "macaddress fact" do
49
52
  describe "when run on BSD" do
50
53
  it "should return macaddress information" do
51
54
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
52
- Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig').
55
+ Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
56
+ Facter::Util::IP.stubs(:exec_ifconfig).
53
57
  returns(ifconfig_fixture('bsd_ifconfig_all_with_multiple_interfaces'))
54
58
 
55
59
  Facter.value(:macaddress).should == "00:0b:db:93:09:67"