Blob Blame History Raw
From b842c77bf6957c318d1a74c70f584f56751ff43c Mon Sep 17 00:00:00 2001
From: Jeremy Katz <katzj@hubspot.com>
Date: Wed, 15 Feb 2012 09:22:49 -0500
Subject: [PATCH/facter] Make ec2 facts work on CentOS again

Refactoring the ec2 facts lost the support for CentOS where the
hardware address in arp -an is uppercased.  Fix and add a unit
test now that there are those
---
 lib/facter/util/ec2.rb                         |    2 +-
 spec/fixtures/unit/util/ec2/centos-arp-ec2.out |    1 +
 spec/unit/util/ec2_spec.rb                     |    7 +++++++
 3 files changed, 9 insertions(+), 1 deletions(-)
 create mode 100644 spec/fixtures/unit/util/ec2/centos-arp-ec2.out

diff --git a/lib/facter/util/ec2.rb b/lib/facter/util/ec2.rb
index bcfda60..d42254a 100644
--- a/lib/facter/util/ec2.rb
+++ b/lib/facter/util/ec2.rb
@@ -46,7 +46,7 @@ module Facter::Util::EC2
       arp_table = Facter::Util::Resolution.exec(arp_command)
       if not arp_table.nil?
         arp_table.each_line do |line|
-          return true if line.include?(mac_address)
+          return true if line.downcase.include?(mac_address)
         end
       end
       return false
diff --git a/spec/fixtures/unit/util/ec2/centos-arp-ec2.out b/spec/fixtures/unit/util/ec2/centos-arp-ec2.out
new file mode 100644
index 0000000..24d2ec0
--- /dev/null
+++ b/spec/fixtures/unit/util/ec2/centos-arp-ec2.out
@@ -0,0 +1 @@
+? (10.240.93.1) at FE:FF:FF:FF:FF:FF [ether] on eth0
\ No newline at end of file
diff --git a/spec/unit/util/ec2_spec.rb b/spec/unit/util/ec2_spec.rb
index 62fdcb7..f1fbe3c 100755
--- a/spec/unit/util/ec2_spec.rb
+++ b/spec/unit/util/ec2_spec.rb
@@ -22,6 +22,13 @@ describe Facter::Util::EC2 do
         Facter::Util::EC2.has_ec2_arp?.should == true
       end
 
+      it "should succeed if arp table contains FE:FF:FF:FF:FF:FF" do
+        ec2arp = my_fixture_read("centos-arp-ec2.out")
+        Facter::Util::Resolution.expects(:exec).with("arp -an").\
+          at_least_once.returns(ec2arp)
+        Facter::Util::EC2.has_ec2_arp?.should == true
+      end
+
       it "should fail if arp table does not contain fe:ff:ff:ff:ff:ff" do
         ec2arp = my_fixture_read("linux-arp-not-ec2.out")
         Facter::Util::Resolution.expects(:exec).with("arp -an").
-- 
1.7.6