diff options
author | Mike Javorski <mike.javorski@gmail.com> | 2013-04-12 16:24:39 -0700 |
---|---|---|
committer | Mike Javorski <mike.javorski@gmail.com> | 2013-04-12 16:30:45 -0700 |
commit | e636075ceaca5c20f706ec33f921172ba04609b1 (patch) | |
tree | cd8aabb0d2a5b97676e1a313ee3f833cfc424cf7 | |
parent | 9dc1965c1e4f6b6054dfc8102fff442c7917e291 (diff) | |
download | ohai-e636075ceaca5c20f706ec33f921172ba04609b1.tar.gz |
OHAI-434: Order metadata versions with basic String/Array#sort
-rw-r--r-- | lib/ohai/mixin/ec2_metadata.rb | 3 | ||||
-rw-r--r-- | spec/unit/mixin/ec2_metadata_spec.rb | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/lib/ohai/mixin/ec2_metadata.rb b/lib/ohai/mixin/ec2_metadata.rb index 0b750aae..0c66cf31 100644 --- a/lib/ohai/mixin/ec2_metadata.rb +++ b/lib/ohai/mixin/ec2_metadata.rb @@ -79,7 +79,10 @@ module Ohai unless response.code == '200' raise "Unable to determine EC2 metadata version (returned #{response.code} response)" end + # Note: Sorting the list of versions may have unintended consequences in + # non-EC2 environments. It appears to be safe in EC2 as of 2013-04-12. versions = response.body.split("\n") + versions = response.body.split("\n").sort until (versions.empty? || EC2_SUPPORTED_VERSIONS.include?(versions.last)) do pv = versions.pop Ohai::Log.debug("EC2 shows unsupported metadata version: #{pv}") unless pv == 'latest' diff --git a/spec/unit/mixin/ec2_metadata_spec.rb b/spec/unit/mixin/ec2_metadata_spec.rb index 9862b148..d327fabd 100644 --- a/spec/unit/mixin/ec2_metadata_spec.rb +++ b/spec/unit/mixin/ec2_metadata_spec.rb @@ -39,8 +39,8 @@ describe Ohai::Mixin::Ec2Metadata do context "with an unsorted list of metadata versions" do let(:response) { mock("Net::HTTP Response", :body => "1.0\n2009-04-04\n2007-03-01\n2011-05-01\n2008-09-01\nUnsupported", :code => "200") } - it "returns the most recent version" do + it "returns the most recent version (using string sort)" do mixin.best_api_version.should == "2011-05-01" end end |