summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2016-03-06 22:30:00 -0800
committerTim Smith <tsmith84@gmail.com>2016-03-07 10:07:40 -0800
commit60dd6c841471965f263536e0b42807039eededbf (patch)
tree89f5fa36a69c3e95acd8f618421ddd7272f7e582
parent75ab6df9a1d3415fa8dfbaaa45589be535bc02d7 (diff)
downloadohai-60dd6c841471965f263536e0b42807039eededbf.tar.gz
Handle mis-identifying ec2 better
Always try the quick to timeout socket "can_connect_metadata?" method if we think we're on EC2. We're often wrong If we find the ec2_metadata_bin file also make sure we don't have a Rackspace monitoring binary since Rackspace ships the EC2 binary
-rw-r--r--lib/ohai/plugins/ec2.rb12
-rw-r--r--spec/unit/plugins/ec2_spec.rb12
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb
index 769ea9c2..1f383035 100644
--- a/lib/ohai/plugins/ec2.rb
+++ b/lib/ohai/plugins/ec2.rb
@@ -74,12 +74,18 @@ EOM
end
end
+ # rackspace systems look like ec2 so instead of timing out dig a bit deeper
+ def looks_like_rackspace?
+ return true if File.exist?("/usr/bin/rackspace-monitoring-agent")
+ end
+
def looks_like_ec2?
return true if hint?("ec2")
- # if has ec2 mac try non-blocking connect so we don't "block" if
- # the Xen environment is *not* EC2
- return true if (has_ec2metadata_bin? || has_ec2_dmi?) || (has_xen_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80))
+ # Even if it looks like EC2 try to connect first
+ if has_ec2_dmi? || has_xen_mac? || (has_ec2metadata_bin? && !looks_like_rackspace?)
+ return true if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
+ end
end
collect_data do
diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb
index 18a08ee9..bddd887b 100644
--- a/spec/unit/plugins/ec2_spec.rb
+++ b/spec/unit/plugins/ec2_spec.rb
@@ -28,6 +28,7 @@ describe Ohai::System, "plugin ec2" do
allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/ec2.json").and_return(false)
allow(File).to receive(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
allow(File).to receive(:exist?).with("/usr/bin/ec2metadata").and_return(false)
+ allow(File).to receive(:exist?).with("/usr/bin/rackspace-monitoring-agent").and_return(false)
end
shared_examples_for "!ec2" do
@@ -310,7 +311,16 @@ describe Ohai::System, "plugin ec2" do
end
end
- describe "without hint file, mac address, dmi data, or ec2metadata binary" do
+ describe "with ec2metadata, but with rackspace-monitoring-agent" do
+ it_should_behave_like "!ec2"
+
+ before(:each) do
+ allow(File).to receive(:exist?).with("/usr/bin/ec2metadata").and_return(true)
+ allow(File).to receive(:exist?).with("/usr/bin/rackspace-monitoring-agent").and_return(true)
+ end
+ end
+
+ describe "without any hints that it is an ec2 system" do
it_should_behave_like "!ec2"
before(:each) do