Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect paravirt amazon instances without hint files #722

Merged
merged 4 commits into from
Feb 9, 2016

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Feb 3, 2016

Official AMIs ship with the ec2metadata binary which we can look for. With this change we should be detecting the majority of scenarios without a hint file.

has_ec2_mac has been renamed has_xen_mac since we're actually looking for a xen mac. Due to that the attempt to connect to the metadata only needs to happen when we only find the mac address since that can be either AWS or Xen. If we find dmi data, a hint, or the metadata binary we can safely assume the metadata endpoint will respond.

I also consolidated the "no hints or signs of AWS" scenario into a single spec since it seems to make more sense that way.

we should have enough other methods now, hints have been around for a while.
this detects xen, not ec2.

also cleans up some confusing whitespacing in the test.
@tas50
Copy link
Contributor Author

tas50 commented Feb 3, 2016

@chef/client-core ready for review

@thommay
Copy link
Contributor

thommay commented Feb 4, 2016

merge in #723 and then I'm 👍

Official AMIs ship with the ec2metadata binary which we can look for. With this change we should be detecting the majority of scenarios without a hint file.

has_ec2_mac has been renamed has_xen_mac since we're actually looking for a xen mac.  Due to that the attempt to connect to the metadata only needs to happen when we only find the mac address since that can be either AWS or Xen.  If we find dmi data, a hint, or the metadata binary we can safely assume the metadata endpoint will respond.

 I also consolidated the "no hints or signs of AWS" scenario into a single spec since it seems to make more sense that way.
@tas50
Copy link
Contributor Author

tas50 commented Feb 5, 2016

Merged in and tweaked the changes that @btm made to warn on the MAC detection logic

@btm
Copy link
Contributor

btm commented Feb 5, 2016

👍 after appveyor is green

appveyor failure looks like a legit test failure:

 1) Ohai::System plugin ec2 without dmi or ec2metadata binary, with xen mac, and metadata address connected warns that the arp table method is deprecated
     Failure/Error: expect(Ohai::Log).to receive(:warn).with(/will be removed/)

       (Ohai::Log (class)).warn(/will be removed/)
           expected: 1 time with arguments: (/will be removed/)
           received: 0 times
     # ./spec/unit/plugins/ec2_spec.rb:267:in `block (3 levels) in <top (required)>'

Finished in 14.59 seconds (files took 1.67 seconds to load)
1467 examples, 1 failure, 1 pending

looks like travis passed but shows failed due to some kind of caching issue....

@tas50
Copy link
Contributor Author

tas50 commented Feb 5, 2016

@btm any idea on the expects for the warn not triggering. It's clearly showing up in the output when you run the specs, but not triggering. I shuffled things around a bit, but no luck.

@btm
Copy link
Contributor

btm commented Feb 5, 2016

@tas50 can you make sure this branch is still pushed?

@btm
Copy link
Contributor

btm commented Feb 5, 2016

@tas50 n/m, I see your repositories are named silly on github.

@tas50
Copy link
Contributor Author

tas50 commented Feb 8, 2016

@btm any magical ideas about that travis failure?

@plugin[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
it "warns that the arp table method is deprecated" do
expect(Ohai::Log).to receive(:warn).with(/will be removed/)
@plugin.has_ec2_mac?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean has_xen_mac? or looks_like_ec2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was it. Thanks @mcquin

# the Xen environment is *not* EC2
hint?('ec2') || ( has_ec2_dmi? || has_ec2_mac?) && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80)
return true if (has_ec2metadata_bin? || has_ec2_dmi?) || (has_xen_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original logic and the new logic here look different to me (but I'm having trouble parsing it). It looks like the original logic would check can_metadata_connect? unless a hint was provided. The new logic only checks can_metadata_connect? if has_xen_mac? is true and both has_ec2metadata_bin? and has_ec2_dmi? are false. The variation I'm seeing here is that the new logic doesn't check can_metadata_connect? when has_ec2_dmi? is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original (pre-8.10) behavior was hint or xen mac + try to connect. I incorrectly changed it in 8.10 so that it would try to connect if it found the DMI data. The connection attempt was only in place because the MAC detection triggers on any Xen based system and is very unreliable. If we find the binary or the DMI data we know 100% that we're on Amazon so there's no need to try to open the socket before we later try to open the socket again.

tas50 added a commit that referenced this pull request Feb 9, 2016
Detect paravirt amazon instances without hint files
@tas50 tas50 merged commit 78082ae into chef:master Feb 9, 2016
@thommay thommay added the Type: Enhancement Adds new functionality. label Jan 24, 2017
@chef chef locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Enhancement Adds new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants