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

Improve Linux EC2 detection, fix false detection, and add Windows detection #793

Merged
merged 7 commits into from
Apr 8, 2016

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Apr 7, 2016

Remove the Xen MAC address detection method, which we previously deprecated
Detect Windows hosts based on Kernel owner information
Detect Linux hosts based on the Xen UUID starting with ec2

@@ -19,8 +20,9 @@

# How we detect EC2 from easiest to hardest & least reliable
# 1. Ohai ec2 hint exists. This always works
# 2. Xen hypervisor UUID starts with 'ec2'. This catches Linux HVM & paravirt instances
# 2. DMI data mentions amazon. This catches HVM instances in a VPC
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this line be removed?

Ohai::Log.debug("ec2 plugin: has_amazon_org? == true")
true
end
rescue NoMethodError
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm slightly uncomfortable catching the nonexistance of kernel[:os_info][:organization] with an exception. If it's set to not Amazon, then you'll also miss the logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was pretty aggressive there since the keys aren't going to exist on a lot of platforms. kernel[:os_info][:organization] only exists on Windows and I haven't checked, but I assume we don't have kernel on every platform. Do we have a better way to check for the existence of the complete path to that key and it's content?

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a DSL method attribute? that may be helpful

ohai/lib/ohai/dsl/plugin.rb

Lines 124 to 128 in 8f48805

def has_key?(name)
@data.has_key?(name)
end
alias :attribute? :has_key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so switch that to this?:

if kernel.attribute?('os_info') && kernel[:os_info].attribute?('organization') && kernel[:os_info][:organization] =~ /Amazon/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some offline discussion we're going to stick with this for now and add a helper to allow better checking nested Mashes with logging #794

Previously we only got false logging when we rescued
return true
end
else
Ohai::Log.debug("ec2 plugin: has_ec2_xen_uuid? == false")
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't show up if the file exists and does not contain ec2. If you just remove the else line and put this at the end of the method unconditionally, it will probably do what you want since the if statement terminates with a return.

@tas50
Copy link
Contributor Author

tas50 commented Apr 8, 2016

I'm normally not a fan of empty rescues, but I think it makes sense here to avoid duplicating the debug logging in each method.

end
rescue NoMethodError
Ohai::Log.debug("ec2 plugin: has_amazon_org? == false")
false
Copy link
Contributor

Choose a reason for hiding this comment

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

You could do the same if else reduction here and save yourself a repeat of this debug line, but this one isn't as important since it works.

@jkeiser
Copy link
Contributor

jkeiser commented Apr 8, 2016

👍

@tas50
Copy link
Contributor Author

tas50 commented Apr 8, 2016

@mcquin Any chance you can look over the updates to this?

@tyler-ball
Copy link
Contributor

👍

@mcquin
Copy link
Contributor

mcquin commented Apr 8, 2016

Looks great @tas50 👍

@tas50 tas50 merged commit 41fc205 into chef:master Apr 8, 2016
@thommay thommay added Type: Enhancement Adds new functionality. and removed Enhancement labels 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.

None yet

6 participants