From a75f0f9bc7ea1e03dc3a19fba8fae61165ab2b05 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Tue, 12 Apr 2011 11:15:06 -0700 Subject: (#7039) Pre-load all facts when requesting a single fact Since multiple facts can be defined in a single file and we have no way of knowing which "additional" facts are defined in which files, we pre-load all facts when we're looking for specific one. Paired-with: Max Martin --- lib/facter/application.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/facter/application.rb b/lib/facter/application.rb index 6b351b1..bd68149 100644 --- a/lib/facter/application.rb +++ b/lib/facter/application.rb @@ -9,19 +9,21 @@ module Facter # Accept fact names to return from the command line names = argv - # Create the facts hash that is printed to standard out - if names.empty? - facts = Facter.to_hash - else + # Create the facts hash that is printed to standard out. + # Pre-load all of the facts, since we can have multiple facts + # per file, and since we can't know ahead of time which file a + # fact will be in, we'll need to load every file. + facts = Facter.to_hash + unless names.empty? facts = {} - names.each { |name| + names.each do |name| begin facts[name] = Facter.value(name) rescue => error $stderr.puts "Could not retrieve #{name}: #{error}" exit 10 end - } + end end # Print the facts as YAML and exit -- cgit From f91c1205e4dc9a78066af8818fdb92f630aad0d9 Mon Sep 17 00:00:00 2001 From: Jeremy Katz Date: Mon, 18 Apr 2011 12:28:11 -0400 Subject: downcase arp output so that the ec2 arp is matched CentOS 5.4 arp gives the arp output as uppercase; downcase it so we're ensured a match --- lib/facter/arp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/arp.rb b/lib/facter/arp.rb index 0a7cf67..6269ae0 100644 --- a/lib/facter/arp.rb +++ b/lib/facter/arp.rb @@ -8,7 +8,7 @@ Facter.add(:arp) do arp = "" output.each_line do |s| if s =~ /^\S+\s\S+\s\S+\s(\S+)\s\S+\s\S+\s\S+$/ - arp = $1 + arp = $1.downcase break # stops on the first match end end -- cgit From 69f98dad7969801f8b573bb120a5e0a6ea528176 Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Thu, 21 Apr 2011 10:39:30 -0700 Subject: Add facter test for ticket 7039 --- .../ticket_7039_facter_multiple_facts_one_file.rb | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 accecptance/tests/ticket_7039_facter_multiple_facts_one_file.rb diff --git a/accecptance/tests/ticket_7039_facter_multiple_facts_one_file.rb b/accecptance/tests/ticket_7039_facter_multiple_facts_one_file.rb new file mode 100644 index 0000000..fb78628 --- /dev/null +++ b/accecptance/tests/ticket_7039_facter_multiple_facts_one_file.rb @@ -0,0 +1,31 @@ +test_name "#7039: Facter having issue handling multiple facts in a single file" + +fact_file= %q{ +Facter.add(:test_fact1) do + setcode do + "test fact 1" + end +end + +Facter.add(:test_fact2) do + setcode do + "test fact 2" + end +end +} + +agent1=agents.first +step "Agent: Create fact file with multiple facts" +create_remote_file(agent1, '/tmp/test_facts.rb', fact_file ) + +step "Agent: Verify test_fact1 from /tmp/test_facts.rb" +on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact1") do + fail_test "Fact 1 not returned by facter --puppet test_fact1" unless + stdout.include? 'test fact 1' +end + +step "Agent: Verify test_fact2 from /tmp/test_facts.rb" +on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact2") do + fail_test "Fact 1 not returned by facter --puppet test_fact2" unless + stdout.include? 'test fact 2' +end -- cgit From cc67a0148b97e315572cdb905476df1224a78dd5 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 4 May 2011 11:02:41 +1000 Subject: Removed inappropriately uncredited Ohai method from ec2 fact --- lib/facter/arp.rb | 4 ++-- lib/facter/ec2.rb | 54 ++++++++++++++++-------------------------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/lib/facter/arp.rb b/lib/facter/arp.rb index 6269ae0..383fb48 100644 --- a/lib/facter/arp.rb +++ b/lib/facter/arp.rb @@ -13,7 +13,7 @@ Facter.add(:arp) do end end end - EC2_ARP == arp ? arp : nil + "fe:ff:ff:ff:ff:ff" == arp ? arp : nil end end @@ -22,7 +22,7 @@ Facter::Util::IP.get_interfaces.each do |interface| confine :kernel => :linux setcode do arp = Facter::Util::IP.get_arp_value(interface) - EC2_ARP == arp ? arp : nil + "fe:ff:ff:ff:ff:ff" == arp ? arp : nil end end end diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb index 693e78e..c52f76b 100644 --- a/lib/facter/ec2.rb +++ b/lib/facter/ec2.rb @@ -4,45 +4,24 @@ # Additional work modelled on Ohai EC2 fact require 'open-uri' -require 'socket' - -EC2_ADDR = "169.254.169.254" -EC2_METADATA_URL = "http://#{EC2_ADDR}/2008-02-01/meta-data" -EC2_USERDATA_URL = "http://#{EC2_ADDR}/2008-02-01/user-data" -EC2_ARP = "fe:ff:ff:ff:ff:ff" -EC2_EUCA_MAC = %r{^[dD]0:0[dD]:} - -def can_metadata_connect?(addr, port, timeout=2) - t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) - saddr = Socket.pack_sockaddr_in(port, addr) - connected = false - - begin - t.connect_nonblock(saddr) - rescue Errno::EINPROGRESS - r,w,e = IO::select(nil,[t],nil,timeout) - if !w.nil? - connected = true - else - begin - t.connect_nonblock(saddr) - rescue Errno::EISCONN - t.close - connected = true - rescue SystemCallError - end - end - rescue SystemCallError - end - connected +require 'timeout' + +def can_connect?(wait_sec=2) + url = "http://169.254.169.254:80/" + Timeout::timeout(wait_sec) {open(url)} + return true + rescue Timeout::Error + return false + rescue + return false end def metadata(id = "") - open("#{EC2_METADATA_URL}/#{id||=''}").read. + open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read. split("\n").each do |o| key = "#{id}#{o.gsub(/\=.*$/, '/')}" if key[-1..-1] != '/' - value = open("#{EC2_METADATA_URL}/#{key}").read. + value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read. split("\n") value = value.size>1 ? value : value.first symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym @@ -54,23 +33,22 @@ def metadata(id = "") end def userdata() - # assumes the only expected error is the 404 if there's no user-data begin - value = OpenURI.open_uri("#{EC2_USERDATA_URL}/").read.split + value = OpenURI.open_uri("http://169.254.169.254/2008-02-01/user-data/").read.split Facter.add(:ec2_userdata) { setcode { value } } rescue OpenURI::HTTPError end end def has_euca_mac? - !!(Facter.value(:macaddress) =~ EC2_EUCA_MAC) + !!(Facter.value(:macaddress) =~ %r{^[dD]0:0[dD]:}) end def has_ec2_arp? - !!(Facter.value(:arp) == EC2_ARP) + !!(Facter.value(:arp) == "fe:ff:ff:ff:ff:ff") end -if (has_euca_mac? || has_ec2_arp?) && can_metadata_connect?(EC2_ADDR,80) +if (has_euca_mac? || has_ec2_arp?) && can_connect? metadata userdata else -- cgit From 4de8b20a3d3a6e8e3cc25f8900887bfb68e496af Mon Sep 17 00:00:00 2001 From: Nigel Kersten Date: Mon, 9 May 2011 17:28:32 -0700 Subject: Updated CHANGELOG for 1.5.9rc6 --- CHANGELOG | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 43382d3..ea3ccb8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +1.5.9rc6 +======== +cc67a01 Removed inappropriately uncredited Ohai method from ec2 fact +69f98da Add facter test for ticket 7039 +f91c120 downcase arp output so that the ec2 arp is matched +a75f0f9 (#7039) Pre-load all facts when requesting a single fact + 1.5.9rc5 ======== acf0bb2 Ensures that ARP facts are returned only on EC2 hosts -- cgit From 024f7c99543e58ec00bb8f755a1d89d01fd5174c Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Fri, 20 May 2011 11:10:56 -0700 Subject: Update CHANGELOG for 1.5.9 --- CHANGELOG | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ea3ccb8..cbb40bc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,43 +1,34 @@ -1.5.9rc6 -======== +1.5.9 +===== +4de8b20 Updated CHANGELOG for 1.5.9rc6 cc67a01 Removed inappropriately uncredited Ohai method from ec2 fact 69f98da Add facter test for ticket 7039 f91c120 downcase arp output so that the ec2 arp is matched a75f0f9 (#7039) Pre-load all facts when requesting a single fact - -1.5.9rc5 -======== +6b97242 Update CHANGELOG for 1.5.9rc5 acf0bb2 Ensures that ARP facts are returned only on EC2 hosts - -1.5.9rc4 -======== +76f544b Updated CHANGELOG for 1.5.9rc4 09b9f9b (#6795) Update tests to reflect changed exec - -1.5.9rc3 -======== +3db1cd0 Updated CHANGELOG for 1.5.9rc3 def3322 (#6795) xendomains: Ignore error output from xm list f39d487 (#6763) Use Facter::Util::Resolution.exec for arp 3eb9410 arp: Cleanup indendation - -1.5.9rc2 -======== +50b9b3f Updated CHANGELOG for 1.5.9rc2 2fb8316 Clean up indentation, and alignment in macaddress_spec.rb 3f0a340 (#6716) fix facter issues on OSX with ipv6 in macaddress.rb. +43f82ef Update CHANGELOG for 1.5.9rc1 d62e079 Fixed #2346 - A much cleverer EC2 fact 0411d2e Fixed #2346 - Part 1: Added arp fact for Linux 5b6f4fa Discussion on ec2 facts - #2346 e917e1a Fixed #3087 - Identify VMWare d0f0f63 (#6327) Memory facts should be available on Mac Darwin -2e48e18 Fixed #6695 - Updated id fact for Darwin et al - -1.5.9rc1 -======== 458a22d Incremented release to 1.5.9 4eb64fe Fixed #6719 Typo ffd80ac (#5011) Adds swap statistics for OSX 1207765 (#6719) Restricts virtualization types for zones 8d71db3 Fixed #6616 - Stubbing in VMware tests on Linux aa959df Remove Solaris from the list of confined systems. It won't get the original lsb facts, and it's nonsensical too. +2e48e18 Fixed #6695 - Updated id fact for Darwin et al d718af4 Fix #6679 - Added Scientific Linux to operatingsystem fact dea6f78 Further fix to #5485 - SELinux facts 6d6d8da (#2721) Merged patch from Brane GraAnar -- cgit