Codebase list facter / f6fb7b7
Merge 1.6.x into master branch of Facter. Daniel Pittman 12 years ago
17 changed file(s) with 256 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
0 1.6.9rc1
1 ===
2 b398bd8 (#14334) Fix dmidecode based facts on DragonFly BSD
3 6c46b2c (#14332) Correct stubbing on Ubuntu
4 753f3a4 Revert "(#12864) Windows: get primary DNS from registry"
5 ac51593 Wrap dmidecode/pciutils in ifarch block
6 fbaa8fe (#11511) Correct lsbrelease specfile filename
7 14eee2b (#12864) Windows: get primary DNS from registry
8 2842c96 Update rpm spec file
9 515fd65 (#11511) Split lsb facts into multiple files
10
011 1.6.8
112 ===
213 b86fe4c (#12831) Add rspec tests to have_which method in Resolution
00 %{!?ruby_sitelibdir: %define ruby_sitelibdir %(ruby -rrbconfig -e 'puts Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG["sitelibdir"]')}
1
2 %define has_ruby_abi 0%{?fedora} || 0%{?rhel} >= 5
3 %define has_ruby_noarch %has_ruby_abi
41
52 Summary: Ruby module for collecting simple facts about a host operating system
63 Name: facter
7 Version: 1.6.6
8 Release: 1%{?dist}
9 #Release: 0.1rc1%{?dist}
4 Version: 1.6.9
5 #Release: 1%{?dist}
6 Release: 0.1rc1%{?dist}
107 License: Apache 2.0
118 Group: System Environment/Base
129 URL: http://www.puppetlabs.com/puppet/related-projects/%{name}
13 #Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}rc1.tar.gz
14 Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz
15 #Source1: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}rc1.tar.gz.asc
10 Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}rc1.tar.gz
11 #Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz
12 Source1: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}rc1.tar.gz.asc
13 #Source1: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz.asc
1614
1715 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
18 %if %has_ruby_noarch
19 BuildArch: noarch
20 %endif
2116
22 Requires: ruby >= 1.8.1
17 Requires: ruby >= 1.8.5
2318 Requires: which
24 # Note: dmidecode is only available on x86 and x86_64 so this package may need to move into being
25 # arch specific if people are using ppc, arm, s390 etc
19 # dmidecode and pciutils are not available on all arches
20 %ifarch %ix86 x86_64 ia64
2621 Requires: dmidecode
2722 Requires: pciutils
28 %if %has_ruby_abi
23 %endif
2924 Requires: ruby(abi) = 1.8
30 %endif
31 BuildRequires: ruby >= 1.8.1
25 BuildRequires: ruby >= 1.8.5
3226
3327 %description
3428 Ruby module for collecting simple facts about a host Operating
3630 operating system. Additional facts can be added through simple Ruby scripts
3731
3832 %prep
39 %setup -q -n %{name}-%{version}
40 #%setup -q -n %{name}-%{version}rc1
33 #%setup -q -n %{name}-%{version}
34 %setup -q -n %{name}-%{version}rc1
4135
4236 %build
4337
5852
5953
6054 %changelog
55 * Thu May 10 2012 Matthaus Litteken <matthaus@puppetlabs.com> - 1.6.9-0.1rc1
56 - Update for 1.6.9rc1
57
58 * Mon Apr 30 2012 Moses Mendoza <moses@puppetlabs.com> - 1.6.8-1
59 - Update for 1.6.8, spec for arch-specific build, req ruby 1.8.5
60
6161 * Thu Feb 23 2012 Michael Stahnke <stahnma@puppetlabs.com> - 1.6.6-1
6262 - Update for 1.6.6
6363
+0
-39
lib/facter/lsb.rb less more
0 # Fact: lsb
1 #
2 # Purpose: Return Linux Standard Base information for the host.
3 #
4 # Resolution:
5 # Uses the lsb_release system command and parses the output with a series of
6 # regular expressions.
7 #
8 # Caveats:
9 # Only works on Linux (and the kfreebsd derivative) systems.
10 # Requires the lsb_release program, which may not be installed by default.
11 # Also is as only as accurate as that program outputs.
12
13 ## lsb.rb
14 ## Facts related to Linux Standard Base (LSB)
15
16 { "LSBRelease" => %r{^LSB Version:\t(.*)$},
17 "LSBDistId" => %r{^Distributor ID:\t(.*)$},
18 "LSBDistRelease" => %r{^Release:\t(.*)$},
19 "LSBDistDescription" => %r{^Description:\t(.*)$},
20 "LSBDistCodeName" => %r{^Codename:\t(.*)$}
21 }.each do |fact, pattern|
22 Facter.add(fact) do
23 confine :kernel => [ :linux, :"gnu/kfreebsd" ]
24 setcode do
25 unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5)
26 type = nil
27 lsbtime = Time.now
28 lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null')
29 end
30
31 if pattern.match(lsbdata)
32 $1
33 else
34 nil
35 end
36 end
37 end
38 end
0 # Fact: lsbdistcodename
1 #
2 # Purpose: Return Linux Standard Base information for the host.
3 #
4 # Resolution:
5 # Uses the lsb_release system command
6 #
7 # Caveats:
8 # Only works on Linux (and the kfreebsd derivative) systems.
9 # Requires the lsb_release program, which may not be installed by default.
10 # Also is as only as accurate as that program outputs.
11
12 Facter.add(:lsbdistcodename) do
13 confine :kernel => [ :linux, :"gnu/kfreebsd" ]
14 setcode do
15 Facter::Util::Resolution.exec('lsb_release -c -s')
16 end
17 end
0 # Fact: lsbdistdescription
1 #
2 # Purpose: Return Linux Standard Base information for the host.
3 #
4 # Resolution:
5 # Uses the lsb_release system command
6 #
7 # Caveats:
8 # Only works on Linux (and the kfreebsd derivative) systems.
9 # Requires the lsb_release program, which may not be installed by default.
10 # Also is as only as accurate as that program outputs.
11
12 Facter.add(:lsbdistdescription) do
13 confine :kernel => [ :linux, :"gnu/kfreebsd" ]
14 setcode do
15 if output = Facter::Util::Resolution.exec('lsb_release -d -s')
16 # the output may be quoted (at least it is on gentoo)
17 output.sub(/^"(.*)"$/,'\1')
18 end
19 end
20 end
0 # Fact: lsbdistid
1 #
2 # Purpose: Return Linux Standard Base information for the host.
3 #
4 # Resolution:
5 # Uses the lsb_release system command
6 #
7 # Caveats:
8 # Only works on Linux (and the kfreebsd derivative) systems.
9 # Requires the lsb_release program, which may not be installed by default.
10 # Also is as only as accurate as that program outputs.
11
12 Facter.add(:lsbdistid) do
13 confine :kernel => [ :linux, :"gnu/kfreebsd" ]
14 setcode do
15 Facter::Util::Resolution.exec('lsb_release -i -s')
16 end
17 end
0 # Fact: lsbdistrelease
1 #
2 # Purpose: Return Linux Standard Base information for the host.
3 #
4 # Resolution:
5 # Uses the lsb_release system command
6 #
7 # Caveats:
8 # Only works on Linux (and the kfreebsd derivative) systems.
9 # Requires the lsb_release program, which may not be installed by default.
10 # Also is as only as accurate as that program outputs.
11
12 Facter.add(:lsbdistrelease) do
13 confine :kernel => [ :linux, :"gnu/kfreebsd" ]
14 setcode do
15 Facter::Util::Resolution.exec('lsb_release -r -s')
16 end
17 end
0 # Fact: lsbrelease
1 #
2 # Purpose: Return Linux Standard Base information for the host.
3 #
4 # Resolution:
5 # Uses the lsb_release system command
6 #
7 # Caveats:
8 # Only works on Linux (and the kfreebsd derivative) systems.
9 # Requires the lsb_release program, which may not be installed by default.
10 # Also is as only as accurate as that program outputs.
11
12 Facter.add(:lsbrelease) do
13 confine :kernel => [ :linux, :"gnu/kfreebsd" ]
14 setcode do
15 Facter::Util::Resolution.exec('lsb_release -v -s')
16 end
17 end
99 #
1010 # Caveats:
1111 #
12 require 'facter/lsb'
1312
1413 Facter.add(:operatingsystem) do
1514 confine :kernel => :sunos
1212 return nil unless FileTest.exists?("/usr/local/sbin/dmidecode")
1313
1414 output=%x{/usr/local/sbin/dmidecode 2>/dev/null}
15 when 'NetBSD'
15 when 'NetBSD', 'DragonFly'
1616 return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode")
1717
1818 output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
3737 if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/
3838 result = $1.strip
3939 Facter.add(facterkey) do
40 confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :"gnu/kfreebsd" ]
40 confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :"gnu/kfreebsd", :dragonfly ]
4141 setcode do
4242 result
4343 end
2424 include Comparable
2525 include Enumerable
2626
27 FACTERVERSION = '1.6.8'
27 FACTERVERSION = '1.6.9'
2828 # = Facter
2929 # Functions as a hash of 'facts' you might care about about your
3030 # system, such as mac address, IP address, Video card, etc.
0 #!/usr/bin/env rspec
1
2 require 'spec_helper'
3
4 describe "lsbdistcodename fact" do
5
6 [ "Linux", "GNU/kFreeBSD"].each do |kernel|
7 describe "on #{kernel}" do
8 before :each do
9 Facter.fact(:kernel).stubs(:value).returns kernel
10 end
11
12 it "should return the codename through lsb_release -c -s" do
13 Facter::Util::Resolution.stubs(:exec).with('lsb_release -c -s').returns 'n/a'
14 Facter.fact(:lsbdistcodename).value.should == 'n/a'
15 end
16
17 it "should return nil if lsb_release is not installed" do
18 Facter::Util::Resolution.stubs(:exec).with('lsb_release -c -s').returns nil
19 Facter.fact(:lsbdistcodename).value.should be_nil
20 end
21 end
22 end
23
24 end
0 #!/usr/bin/env rspec
1
2 require 'spec_helper'
3
4 describe "lsbdistdescription fact" do
5
6 [ "Linux", "GNU/kFreeBSD"].each do |kernel|
7 describe "on #{kernel}" do
8 before :each do
9 Facter.fact(:kernel).stubs(:value).returns kernel
10 end
11
12 it "should return the description through lsb_release -d -s" do
13 Facter::Util::Resolution.stubs(:exec).with('lsb_release -d -s').returns '"Gentoo Base System release 2.1"'
14 Facter.fact(:lsbdistdescription).value.should == 'Gentoo Base System release 2.1'
15 end
16
17 it "should return nil if lsb_release is not installed" do
18 Facter::Util::Resolution.stubs(:exec).with('lsb_release -d -s').returns nil
19 Facter.fact(:lsbdistdescription).value.should be_nil
20 end
21 end
22 end
23
24 end
0 #!/usr/bin/env rspec
1
2 require 'spec_helper'
3
4 describe "lsbdistid fact" do
5
6 [ "Linux", "GNU/kFreeBSD"].each do |kernel|
7 describe "on #{kernel}" do
8 before :each do
9 Facter.fact(:kernel).stubs(:value).returns kernel
10 end
11
12 it "should return the id through lsb_release -i -s" do
13 Facter::Util::Resolution.stubs(:exec).with('lsb_release -i -s').returns 'Gentoo'
14 Facter.fact(:lsbdistid).value.should == 'Gentoo'
15 end
16
17 it "should return nil if lsb_release is not installed" do
18 Facter::Util::Resolution.stubs(:exec).with('lsb_release -i -s').returns nil
19 Facter.fact(:lsbdistid).value.should be_nil
20 end
21 end
22 end
23
24 end
0 #!/usr/bin/env rspec
1
2 require 'spec_helper'
3
4 describe "lsbdistrelease fact" do
5
6 [ "Linux", "GNU/kFreeBSD"].each do |kernel|
7 describe "on #{kernel}" do
8 before :each do
9 Facter.fact(:kernel).stubs(:value).returns kernel
10 end
11
12 it "should return the release through lsb_release -r -s" do
13 Facter::Util::Resolution.stubs(:exec).with('lsb_release -r -s').returns '2.1'
14 Facter.fact(:lsbdistrelease).value.should == '2.1'
15 end
16
17 it "should return nil if lsb_release is not installed" do
18 Facter::Util::Resolution.stubs(:exec).with('lsb_release -r -s').returns nil
19 Facter.fact(:lsbdistrelease).value.should be_nil
20 end
21 end
22 end
23
24 end
0 #!/usr/bin/env rspec
1
2 require 'spec_helper'
3
4 describe "lsbrelease fact" do
5
6 [ "Linux", "GNU/kFreeBSD"].each do |kernel|
7 describe "on #{kernel}" do
8 before :each do
9 Facter.fact(:kernel).stubs(:value).returns kernel
10 end
11
12 it "should return the release through lsb_release -v -s" do
13 Facter::Util::Resolution.stubs(:exec).with('lsb_release -v -s').returns 'n/a'
14 Facter.fact(:lsbrelease).value.should == 'n/a'
15 end
16
17 it "should return nil if lsb_release is not installed" do
18 Facter::Util::Resolution.stubs(:exec).with('lsb_release -v -s').returns nil
19 Facter.fact(:lsbrelease).value.should be_nil
20 end
21 end
22 end
23
24 end
3636 describe "on Linux" do
3737 before :each do
3838 Facter.fact(:kernel).stubs(:value).returns("Linux")
39
40 # Always stub lsbdistid by default, so tests work on Ubuntu
41 Facter.stubs(:value).with(:lsbdistid).returns(nil)
3942 end
4043
4144 {
6871 it "on Ubuntu should use the lsbdistid fact" do
6972 FileUtils.stubs(:exists?).with("/etc/debian_version").returns true
7073
71 Facter.fact(:lsbdistid).expects(:value).returns("Ubuntu")
74 Facter.stubs(:value).with(:lsbdistid).returns("Ubuntu")
7275 Facter.fact(:operatingsystem).value.should == "Ubuntu"
7376 end
7477