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

Add detection for Arista EOS #158

Merged
merged 3 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/train/extras/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'train/extras/os_detect_unix'
require 'train/extras/os_detect_windows'
require 'train/extras/os_detect_esx'
require 'train/extras/os_detect_arista_eos'

module Train::Extras
class OSCommon
Expand All @@ -21,6 +22,7 @@ class OSCommon
include Train::Extras::DetectUnix
include Train::Extras::DetectWindows
include Train::Extras::DetectEsx
include Train::Extras::DetectAristaEos

attr_accessor :backend
def initialize(backend, platform = nil)
Expand Down Expand Up @@ -122,6 +124,7 @@ def detect_family_type # rubocop:disable Metrics/CyclomaticComplexity, Metrics/P
# unix based systems combine the above
return true if pf == 'unix' and detect_darwin
return true if pf == 'unix' and detect_esx
return true if pf == 'unix' and detect_arista_eos
return true if pf == 'unix' and detect_via_uname

# if we arrive here, we most likey have a regular linux
Expand Down
30 changes: 30 additions & 0 deletions lib/train/extras/os_detect_arista_eos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# encoding: utf-8
# author: Jere Julian
#
# Arista EOS has 2 modes. Most compliance tests will use the network CLI
# but when working with vagrant, its common to encounter the raw bash shell.
require 'json'

module Train::Extras
module DetectAristaEos
def detect_arista_eos
if unix_file?('/usr/bin/FastCli')
output = @backend.run_command('FastCli -p 15 -c "show version | json"').stdout
@platform[:name] = 'arista_eos_bash'
family = 'fedora'
else
output = @backend.run_command('show version | json').stdout
end

unless output.empty?
eos_ver = JSON.parse(output)
@platform[:name] = @platform[:name] || 'arista_eos'
family ||= 'arista_eos'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we not using fedora in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you are in the bash shell, then you can do all the fedora things. However, when you login the way you would to a typical running switch, you are in a custom EOS CLI. You can still prefix linux commands with 'bash' from this mode but common commands are things like 'show running-config', 'show interfaces status', etc. Thus, things that expect to be in a regular linux shell will need special handling.

I'm definitely willing to go another route, if appropriate.

You can test yourself by registering at http://Arista.com/, then going to Software Downloads --> vEOS and downloading the files for your preferred hypervisor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should use arista_eos as the family for both instead of fedora?

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 assumed that more resources would adapt their behavior based on :family but since that's not the case, I'm fine with setting both to arista_eos if you think that's best.

Copy link
Contributor

@chris-rock chris-rock Nov 2, 2016

Choose a reason for hiding this comment

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

If we want to count EOS as linux, we should also add it to https://github.com/chef/train/blob/master/lib/train/extras/os_common.rb#L68 because most resources go with inspec.os.linux?

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 thinking about this a bit. If we always mark EOS as family: arista_eos and include that as "linux", then resources will fail instead of skipping when we're in the usual CLI mode unless from the os detection I can specify to default to prefixing all linux commands with bash to drop to a linux shell (Ex: bash uname -a or bash sudo cat /etc/passwd).

Alternatively, I could just patch up the resources as we make use of them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or we make bash default and use the EOS CLI only withinEOS specific InSpec resources. Is bash available on all devices?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could achieve that by implementing a specific command wrapper for eos https://github.com/chef/train/blob/master/lib/train/extras/command_wrapper.rb#L164-L175

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 think that will work. I'm not sure I'll get the wrapper in by Friday but I don't think that needs to hold up the initial platform support. So, to recap, I'll set the family to arista_eos for both cases and we can improve handling the differences with a command wrapper.

@platform[:family] = family
@platform[:release] = eos_ver['version']
@platform[:arch] = eos_ver['architecture']
true
end
end
end
end