Codebase list facter / upstream/1.6.6
Imported Upstream version 1.6.6 Stig Sandbeck Mathisen 12 years ago
10 changed file(s) with 113 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
0 1.6.6
1 ===
2 e046144 Updated CHANGELOG for 1.6.6rc2
3 c273d34 Make ec2 facts work on CentOS again (#12666)
4 c218d84 (#12362) Use Tempfile to generate temp files
5 f6bbe14 (#12170) Adds gem spec description Without this patch, the gem spec file is missing a description attribute, which caus
6 5c5c330 Changes apple rake task to reflect package name facter instead of puppet.
7 9b5cb26 Updating conf/redhat/facter.spec for 1.6.5 release.
8 7d3889d (#12079) Fix order-dependent test failure due to odd stubbing.
9 7f2a0e2 add a simple test for openstack ec2 facts
10 cb598aa Support EC2 facts on OpenStack
11
012 1.6.5
113 ===
214 71d3d3d (#12077) Add pciutils RPM dependency
3737 spec.executables = %w{facter}
3838 spec.version = Facter::FACTERVERSION
3939 spec.summary = 'Facter, a system inventory tool'
40 spec.description = 'You can prove anything with facts!'
4041 spec.author = 'Puppet Labs'
4142 spec.email = 'info@puppetlabs.com'
4243 spec.homepage = 'http://puppetlabs.com'
0 %{!?ruby_sitelibdir: %define ruby_sitelibdir %(ruby -rrbconfig -e 'puts Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG["sitelibdir"]'
0 %{!?ruby_sitelibdir: %define ruby_sitelibdir %(ruby -rrbconfig -e 'puts Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG["sitelibdir"]')}
11
22 %define has_ruby_abi 0%{?fedora} || 0%{?rhel} >= 5
33 %define has_ruby_noarch %has_ruby_abi
4 %global _ver 1.6.4
54
65 Summary: Ruby module for collecting simple facts about a host operating system
76 Name: facter
8 Version: 1.6.4
9 Release: 0.1rc1%{?dist}
7 Version: 1.6.6
8 Release: 1%{?dist}
9 #Release: 0.1rc1%{?dist}
1010 License: Apache 2.0
1111 Group: System Environment/Base
12 URL: http://www.puppetlabs.com/puppet/related-projects/%{name}/
13 Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}rc1.tar.gz
12 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
1415 #Source1: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}rc1.tar.gz.asc
1516
1617 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
2021
2122 Requires: ruby >= 1.8.1
2223 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
2326 Requires: dmidecode
2427 Requires: pciutils
2528 %if %has_ruby_abi
3336 operating system. Additional facts can be added through simple Ruby scripts
3437
3538 %prep
36 %setup -q -n %{name}-%{version}rc1
39 %setup -q -n %{name}-%{version}
40 #%setup -q -n %{name}-%{version}rc1
3741
3842 %build
3943
5458
5559
5660 %changelog
61 * Thu Feb 23 2012 Michael Stahnke <stahnma@puppetlabs.com> - 1.6.6-1
62 - Update for 1.6.6
63
64 * Wed Jan 25 2012 Matthaus Litteken <matthaus@puppetlabs.com> - 1.6.5-1
65 - Update to 1.6.5
66
5767 * Wed Nov 30 2011 Matthaus Litteken <matthaus@puppetlabs.com> - 1.6.4-0.1rc1
5868 - 1.6.4 rc1
5969
3636 require 'fileutils'
3737 require 'optparse'
3838 require 'ostruct'
39 require 'tempfile'
3940
4041 begin
4142 require 'rdoc/rdoc'
216217 opts.parse!
217218 end
218219
219 tmpdirs = [ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp", "."]
220
221220 version = [RbConfig::CONFIG["MAJOR"], RbConfig::CONFIG["MINOR"]].join(".")
222221 libdir = File.join(RbConfig::CONFIG["libdir"], "ruby", version)
223222
288287 FileUtils.makedirs(sitelibdir)
289288 end
290289
291 tmpdirs << bindir
292
293 InstallOptions.tmp_dirs = tmpdirs.compact
294290 InstallOptions.site_dir = sitelibdir
295291 InstallOptions.bin_dir = bindir
296292 InstallOptions.sbin_dir = sbindir
383379 # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under
384380 # windows, we add an '.rb' extension and let file associations do their stuff.
385381 def install_binfile(from, op_file, target)
386 tmp_dir = nil
387 InstallOptions.tmp_dirs.each do |t|
388 if File.directory?(t) and File.writable?(t)
389 tmp_dir = t
390 break
391 end
392 end
393
394 fail "Cannot find a temporary directory" unless tmp_dir
395 tmp_file = File.join(tmp_dir, '_tmp')
382 tmp_file = Tempfile.new('facter-binfile')
383
396384 ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
397385
398386 File.open(from) do |ip|
399 File.open(tmp_file, "w") do |op|
387 File.open(tmp_file.path, "w") do |op|
400388 ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
401389 op.puts "#!#{ruby}"
402390 contents = ip.readlines
421409 end
422410
423411 if not installed_wrapper
424 tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
412 tmp_file2 = Tempfile.new('facter-wrapper')
425413 cwv = <<-EOS
426414 @echo off
427415 setlocal
429417 set RUBY_BIN=%RUBY_BIN:\\=/%
430418 "%RUBY_BIN%ruby.exe" -x "%RUBY_BIN%facter" %*
431419 EOS
432 File.open(tmp_file2, "w") { |cw| cw.puts cwv }
433 FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
434
435 File.unlink(tmp_file2)
420 File.open(tmp_file2.path, "w") { |cw| cw.puts cwv }
421 FileUtils.install(tmp_file2.path, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
422
423 tmp_file2.unlink
436424 installed_wrapper = true
437425 end
438426 end
439 FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true)
440 File.unlink(tmp_file)
427 FileUtils.install(tmp_file.path, File.join(target, op_file), :mode => 0755, :verbose => true)
428 tmp_file.unlink
441429 end
442430
443431 check_prereqs
2323 end
2424 end
2525
26 if (Facter::Util::EC2.has_euca_mac? || Facter::Util::EC2.has_ec2_arp?) &&
27 Facter::Util::EC2.can_connect?
26 if (Facter::Util::EC2.has_euca_mac? || Facter::Util::EC2.has_openstack_mac? ||
27 Facter::Util::EC2.has_ec2_arp?) && Facter::Util::EC2.can_connect?
2828
2929 metadata
3030 userdata
2525 !!(Facter.value(:macaddress) =~ %r{^[dD]0:0[dD]:})
2626 end
2727
28 # Test if this host has a mac address used by OpenStack, which
29 # normally starts with 02:16:3E
30 def has_openstack_mac?
31 !!(Facter.value(:macaddress) =~ %r{^02:16:3[eE]})
32 end
33
2834 # Test if the host has an arp entry in its cache that matches the EC2 arp,
2935 # which is normally +fe:ff:ff:ff:ff:ff+.
3036 def has_ec2_arp?
3945 arp_table = Facter::Util::Resolution.exec(arp_command)
4046 if not arp_table.nil?
4147 arp_table.each_line do |line|
42 return true if line.include?(mac_address)
48 return true if line.downcase.include?(mac_address)
4349 end
4450 end
4551 return false
2424 include Comparable
2525 include Enumerable
2626
27 FACTERVERSION = '1.6.5'
27 FACTERVERSION = '1.6.6'
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 ? (10.240.93.1) at FE:FF:FF:FF:FF:FF [ether] on eth0
1010 describe "when running on ec2" do
1111 before :each do
1212 # This is an ec2 instance, not a eucalyptus instance
13 Facter::Util::EC2.expects(:has_euca_mac?).at_least_once.returns(false)
14 Facter::Util::EC2.expects(:has_ec2_arp?).at_least_once.returns(true)
13 Facter::Util::EC2.stubs(:has_euca_mac?).returns(false)
14 Facter::Util::EC2.stubs(:has_openstack_mac?).returns(false)
15 Facter::Util::EC2.stubs(:has_ec2_arp?).returns(true)
1516
1617 # Assume we can connect
17 Facter::Util::EC2.expects(:can_connect?).at_least_once.returns(true)
18 Facter::Util::EC2.stubs(:can_connect?).returns(true)
1819 end
1920
2021 it "should create flat meta-data facts" do
9394 describe "when running on eucalyptus" do
9495 before :each do
9596 # Return false for ec2, true for eucalyptus
96 Facter::Util::EC2.expects(:has_euca_mac?).at_least_once.returns(true)
97 Facter::Util::EC2.expects(:has_ec2_arp?).never
97 Facter::Util::EC2.stubs(:has_euca_mac?).returns(true)
98 Facter::Util::EC2.stubs(:has_openstack_mac?).returns(false)
99 Facter::Util::EC2.stubs(:has_ec2_arp?).returns(false)
98100
99101 # Assume we can connect
100 Facter::Util::EC2.expects(:can_connect?).at_least_once.returns(true)
102 Facter::Util::EC2.stubs(:can_connect?).returns(true)
103 end
104
105 it "should create ec2_user_data fact" do
106 # No meta-data
107 Object.any_instance.expects(:open).\
108 with("#{api_prefix}/2008-02-01/meta-data/").\
109 at_least_once.returns(StringIO.new(""))
110
111 Object.any_instance.expects(:open).\
112 with("#{api_prefix}/2008-02-01/user-data/").\
113 at_least_once.returns(StringIO.new("test"))
114
115 # Force a fact load
116 Facter.collection.loader.load(:ec2)
117
118 Facter.fact(:ec2_userdata).value.should == ["test"]
119 end
120 end
121
122 describe "when running on openstack" do
123 before :each do
124 # Return false for ec2, true for eucalyptus
125 Facter::Util::EC2.stubs(:has_openstack_mac?).returns(true)
126 Facter::Util::EC2.stubs(:has_euca_mac?).returns(false)
127 Facter::Util::EC2.stubs(:has_ec2_arp?).returns(false)
128
129 # Assume we can connect
130 Facter::Util::EC2.stubs(:can_connect?).returns(true)
101131 end
102132
103133 it "should create ec2_user_data fact" do
120150 describe "when api connect test fails" do
121151 it "should not populate ec2_userdata" do
122152 # Emulate ec2 for now as it matters little to this test
123 Facter::Util::EC2.expects(:has_euca_mac?).at_least_once.returns(true)
124 Facter::Util::EC2.expects(:has_ec2_arp?).never
153 Facter::Util::EC2.stubs(:has_euca_mac?).returns(true)
154 Facter::Util::EC2.stubs(:has_ec2_arp?).never
125155 Facter::Util::EC2.expects(:can_connect?).at_least_once.returns(false)
126156
127157 # The API should never be called at this point
1616
1717 it "should succeed if arp table contains fe:ff:ff:ff:ff:ff" do
1818 ec2arp = my_fixture_read("linux-arp-ec2.out")
19 Facter::Util::Resolution.expects(:exec).with("arp -an").\
20 at_least_once.returns(ec2arp)
21 Facter::Util::EC2.has_ec2_arp?.should == true
22 end
23
24 it "should succeed if arp table contains FE:FF:FF:FF:FF:FF" do
25 ec2arp = my_fixture_read("centos-arp-ec2.out")
1926 Facter::Util::Resolution.expects(:exec).with("arp -an").\
2027 at_least_once.returns(ec2arp)
2128 Facter::Util::EC2.has_ec2_arp?.should == true
6774 end
6875 end
6976
77 describe "is_openstack_mac? method" do
78 it "should return true when the mac is an openstack one" do
79 Facter.expects(:value).with(:macaddress).\
80 at_least_once.returns("02:16:3e:54:89:fd")
81
82 Facter::Util::EC2.has_openstack_mac?.should == true
83 end
84
85 it "should return false when the mac is not a openstack one" do
86 Facter.expects(:value).with(:macaddress).\
87 at_least_once.returns("0c:1d:a0:bc:aa:02")
88
89 Facter::Util::EC2.has_openstack_mac?.should == false
90 end
91 end
92
7093 describe "can_connect? method" do
7194 it "returns true if api responds" do
7295 # Return something upon connecting to the root