Imported Upstream version 1.6.6
Stig Sandbeck Mathisen
12 years ago
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 | ||
0 | 12 | 1.6.5 |
1 | 13 | === |
2 | 14 | 71d3d3d (#12077) Add pciutils RPM dependency |
37 | 37 | spec.executables = %w{facter} |
38 | 38 | spec.version = Facter::FACTERVERSION |
39 | 39 | spec.summary = 'Facter, a system inventory tool' |
40 | spec.description = 'You can prove anything with facts!' | |
40 | 41 | spec.author = 'Puppet Labs' |
41 | 42 | spec.email = 'info@puppetlabs.com' |
42 | 43 | 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"]')} | |
1 | 1 | |
2 | 2 | %define has_ruby_abi 0%{?fedora} || 0%{?rhel} >= 5 |
3 | 3 | %define has_ruby_noarch %has_ruby_abi |
4 | %global _ver 1.6.4 | |
5 | 4 | |
6 | 5 | Summary: Ruby module for collecting simple facts about a host operating system |
7 | 6 | 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} | |
10 | 10 | License: Apache 2.0 |
11 | 11 | 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 | |
14 | 15 | #Source1: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}rc1.tar.gz.asc |
15 | 16 | |
16 | 17 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) |
20 | 21 | |
21 | 22 | Requires: ruby >= 1.8.1 |
22 | 23 | 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 | |
23 | 26 | Requires: dmidecode |
24 | 27 | Requires: pciutils |
25 | 28 | %if %has_ruby_abi |
33 | 36 | operating system. Additional facts can be added through simple Ruby scripts |
34 | 37 | |
35 | 38 | %prep |
36 | %setup -q -n %{name}-%{version}rc1 | |
39 | %setup -q -n %{name}-%{version} | |
40 | #%setup -q -n %{name}-%{version}rc1 | |
37 | 41 | |
38 | 42 | %build |
39 | 43 | |
54 | 58 | |
55 | 59 | |
56 | 60 | %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 | ||
57 | 67 | * Wed Nov 30 2011 Matthaus Litteken <matthaus@puppetlabs.com> - 1.6.4-0.1rc1 |
58 | 68 | - 1.6.4 rc1 |
59 | 69 |
36 | 36 | require 'fileutils' |
37 | 37 | require 'optparse' |
38 | 38 | require 'ostruct' |
39 | require 'tempfile' | |
39 | 40 | |
40 | 41 | begin |
41 | 42 | require 'rdoc/rdoc' |
216 | 217 | opts.parse! |
217 | 218 | end |
218 | 219 | |
219 | tmpdirs = [ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp", "."] | |
220 | ||
221 | 220 | version = [RbConfig::CONFIG["MAJOR"], RbConfig::CONFIG["MINOR"]].join(".") |
222 | 221 | libdir = File.join(RbConfig::CONFIG["libdir"], "ruby", version) |
223 | 222 | |
288 | 287 | FileUtils.makedirs(sitelibdir) |
289 | 288 | end |
290 | 289 | |
291 | tmpdirs << bindir | |
292 | ||
293 | InstallOptions.tmp_dirs = tmpdirs.compact | |
294 | 290 | InstallOptions.site_dir = sitelibdir |
295 | 291 | InstallOptions.bin_dir = bindir |
296 | 292 | InstallOptions.sbin_dir = sbindir |
383 | 379 | # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under |
384 | 380 | # windows, we add an '.rb' extension and let file associations do their stuff. |
385 | 381 | 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 | ||
396 | 384 | ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) |
397 | 385 | |
398 | 386 | File.open(from) do |ip| |
399 | File.open(tmp_file, "w") do |op| | |
387 | File.open(tmp_file.path, "w") do |op| | |
400 | 388 | ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) |
401 | 389 | op.puts "#!#{ruby}" |
402 | 390 | contents = ip.readlines |
421 | 409 | end |
422 | 410 | |
423 | 411 | if not installed_wrapper |
424 | tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') | |
412 | tmp_file2 = Tempfile.new('facter-wrapper') | |
425 | 413 | cwv = <<-EOS |
426 | 414 | @echo off |
427 | 415 | setlocal |
429 | 417 | set RUBY_BIN=%RUBY_BIN:\\=/% |
430 | 418 | "%RUBY_BIN%ruby.exe" -x "%RUBY_BIN%facter" %* |
431 | 419 | 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 | |
436 | 424 | installed_wrapper = true |
437 | 425 | end |
438 | 426 | 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 | |
441 | 429 | end |
442 | 430 | |
443 | 431 | check_prereqs |
23 | 23 | end |
24 | 24 | end |
25 | 25 | |
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? | |
28 | 28 | |
29 | 29 | metadata |
30 | 30 | userdata |
25 | 25 | !!(Facter.value(:macaddress) =~ %r{^[dD]0:0[dD]:}) |
26 | 26 | end |
27 | 27 | |
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 | ||
28 | 34 | # Test if the host has an arp entry in its cache that matches the EC2 arp, |
29 | 35 | # which is normally +fe:ff:ff:ff:ff:ff+. |
30 | 36 | def has_ec2_arp? |
39 | 45 | arp_table = Facter::Util::Resolution.exec(arp_command) |
40 | 46 | if not arp_table.nil? |
41 | 47 | arp_table.each_line do |line| |
42 | return true if line.include?(mac_address) | |
48 | return true if line.downcase.include?(mac_address) | |
43 | 49 | end |
44 | 50 | end |
45 | 51 | return false |
24 | 24 | include Comparable |
25 | 25 | include Enumerable |
26 | 26 | |
27 | FACTERVERSION = '1.6.5' | |
27 | FACTERVERSION = '1.6.6' | |
28 | 28 | # = Facter |
29 | 29 | # Functions as a hash of 'facts' you might care about about your |
30 | 30 | # 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⏎ |
10 | 10 | describe "when running on ec2" do |
11 | 11 | before :each do |
12 | 12 | # 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) | |
15 | 16 | |
16 | 17 | # 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) | |
18 | 19 | end |
19 | 20 | |
20 | 21 | it "should create flat meta-data facts" do |
93 | 94 | describe "when running on eucalyptus" do |
94 | 95 | before :each do |
95 | 96 | # 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) | |
98 | 100 | |
99 | 101 | # 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) | |
101 | 131 | end |
102 | 132 | |
103 | 133 | it "should create ec2_user_data fact" do |
120 | 150 | describe "when api connect test fails" do |
121 | 151 | it "should not populate ec2_userdata" do |
122 | 152 | # 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 | |
125 | 155 | Facter::Util::EC2.expects(:can_connect?).at_least_once.returns(false) |
126 | 156 | |
127 | 157 | # The API should never be called at this point |
16 | 16 | |
17 | 17 | it "should succeed if arp table contains fe:ff:ff:ff:ff:ff" do |
18 | 18 | 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") | |
19 | 26 | Facter::Util::Resolution.expects(:exec).with("arp -an").\ |
20 | 27 | at_least_once.returns(ec2arp) |
21 | 28 | Facter::Util::EC2.has_ec2_arp?.should == true |
67 | 74 | end |
68 | 75 | end |
69 | 76 | |
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 | ||
70 | 93 | describe "can_connect? method" do |
71 | 94 | it "returns true if api responds" do |
72 | 95 | # Return something upon connecting to the root |