Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

handle case where Eucalyptus metadata API returns 404 #178

Closed
wants to merge 1 commit into from

4 participants

@bcarpenter

Eucalyptus 3.3.0 and earlier has http://169.254.169.254/ return a 404. This will make Ohai work with eucalyptus again like it did in Ohai 6.16.0 and earlier.

Note: This bug is fixed in a future (unreleased) version of eucalyptus, probably 3.3.1.

@bcarpenter bcarpenter handle case where Eucalyptus metadata API returns 404
Eucalyptus 3.3.0 and earlier has http://169.254.169.254/ return a 404.  This will make Ohai work with eucalyptus again like it did in Ohai 6.16.0 and earlier.

Note:  This bug is fixed in a future (unreleased) version of eucalyptus, probably 3.3.1.
4a100f8
@bcarpenter

Eucalyptus version 3.3.1 was just released on 8/26/2013. It should have this bug fixed, however all earlier versions still need this patch (or a similar fix).

@svanzoest

We are unable to upgrade our eucalyptus cloud at this moment. We are still on 3.1.2-0precise.174 and this breaks our eucalyptus staging environment deployment via chef server 11.0.8

@bcarpenter
@sersut sersut commented on the diff
lib/ohai/mixin/ec2_metadata.rb
@@ -77,6 +77,7 @@ def can_metadata_connect?(addr, port, timeout=2)
def best_api_version
response = http_client.get("/")
unless response.code == '200'
+ return 'latest' if response.code == '404' && response.body == '<?xml version="1.0"?><Response><Errors><Error><Code>404 Not Found</Code><Message>unknown</Message></Error></Errors><RequestID>unknown</RequestID></Response>'
@sersut Owner
sersut added a note

Is there a reason to check the response.body here @bcarpenter ?

I think the code here will be much cleaner if we can do something like:

if response.code == '404'
  return "latest"
elsif response.code != '200'
  raise "Unable to ..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sersut
Owner

Thanks for taking time to work on this @bcarpenter. Apologies for the delay in getting back to you. We were using a separate issue tracking system before and this fell through the cracks. We will be using GIthub Issues in the future to minimize these kind of issues.

Let us know if you need help with anything.

@svanzoest

FYI: We are now on Eucalyptus 3.4 that fixed this on the eucalyptus side, but having better error handling here would be appreciated. We ended up re-installing our setup on CentOS, although I would like to move it back to Ubuntu one of these days if Eucalyptus works well on there. For now, what we have works. I do think having a fix like this in ohai would be useful to ensure this issue does not show up again.

@sersut
Owner

Thanks for the update @svanzoest. :+1: for having this in ohai.

@sersut sersut added Needs Action and removed Attack List labels
@btm
Owner

@sersut :+1 on your code suggestion, with the addition of a debug message that explains we're choosing latest by default because we got a 404. We'd like to not hardcode that xml body if we can just rely on the HTTP response code instead.

@btm
Owner

So :+1: on merging with those changes.

@btm
Owner

I've added those changes and updated the test on #368.

@btm btm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 26, 2013
  1. @bcarpenter

    handle case where Eucalyptus metadata API returns 404

    bcarpenter authored
    Eucalyptus 3.3.0 and earlier has http://169.254.169.254/ return a 404.  This will make Ohai work with eucalyptus again like it did in Ohai 6.16.0 and earlier.
    
    Note:  This bug is fixed in a future (unreleased) version of eucalyptus, probably 3.3.1.
This page is out of date. Refresh to see the latest.
View
1  lib/ohai/mixin/ec2_metadata.rb
@@ -77,6 +77,7 @@ def can_metadata_connect?(addr, port, timeout=2)
def best_api_version
response = http_client.get("/")
unless response.code == '200'
+ return 'latest' if response.code == '404' && response.body == '<?xml version="1.0"?><Response><Errors><Error><Code>404 Not Found</Code><Message>unknown</Message></Error></Errors><RequestID>unknown</RequestID></Response>'
@sersut Owner
sersut added a note

Is there a reason to check the response.body here @bcarpenter ?

I think the code here will be much cleaner if we can do something like:

if response.code == '404'
  return "latest"
elsif response.code != '200'
  raise "Unable to ..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
raise "Unable to determine EC2 metadata version (returned #{response.code} response)"
end
# Note: Sorting the list of versions may have unintended consequences in
View
8 spec/unit/mixin/ec2_metadata_spec.rb
@@ -68,6 +68,14 @@
lambda { mixin.best_api_version}.should raise_error
end
end
+
+ context "when the response is from eucalyptus" do
+ let(:response) { double("Net::HTTP Response", :body => "<?xml version=\"1.0\"?><Response><Errors><Error><Code>404 Not Found</Code><Message>unknown</Message></Error></Errors><RequestID>unknown</RequestID></Response>", :code => "404") }
+
+ it "returns 'latest' as the version" do
+ mixin.best_api_version.should == 'latest'
+ end
+ end
end
context "#metadata_get" do
Something went wrong with that request. Please try again.