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 openvms detection #159

Merged
merged 8 commits into from
Nov 11, 2016
10 changes: 8 additions & 2 deletions lib/train/extras/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'train/extras/os_detect_windows'
require 'train/extras/os_detect_esx'
require 'train/extras/os_detect_arista_eos'
require 'train/extras/os_detect_openvms'

module Train::Extras
class OSCommon
Expand All @@ -23,6 +24,7 @@ class OSCommon
include Train::Extras::DetectWindows
include Train::Extras::DetectEsx
include Train::Extras::DetectAristaEos
include Train::Extras::DetectOpenVMS

attr_accessor :backend
def initialize(backend, platform = nil)
Expand Down Expand Up @@ -96,6 +98,8 @@ def detect_family
# TODO: extend base implementation for detecting the family type
# to Windows and others
case uname_s
when /unrecognized command verb/
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if we can expect that every system that has not uname_s is openvms

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 just don't set any family then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

problem is that if we omit this part, it matches

when /./
@platform[:family] = 'unix'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its a pain because the uname_s command doesnt returns an error that can be detected by the command object (old os) but a message that says : %DCL-W-IVVERB, unrecognized command verb - check validity and spelling

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should create a method for detecting non-uname operating systems. Is there a reliable command that only works on openvms to detect the family?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, lets use this for now until we find any other non-uname operating system

@platform[:family] = 'openvms'
when /linux/i
@platform[:family] = 'linux'
when /./
Expand All @@ -105,8 +109,8 @@ def detect_family
@platform[:family] = nil
end

# try to detect the platform
return nil unless @platform[:family].nil?
# try to detect the platform if the platform is set to nil, otherwise this code will never work
return nil if @platform[:family].nil?
detect_family_type
end

Expand All @@ -116,6 +120,7 @@ def detect_family_type # rubocop:disable Metrics/CyclomaticComplexity, Metrics/P
return detect_windows if pf == 'windows'
return detect_darwin if pf == 'darwin'
return detect_esx if pf == 'esx'
return detect_openvms if pf =="openvms"

if %w{freebsd netbsd openbsd aix solaris2 hpux}.include?(pf)
return detect_via_uname
Expand All @@ -124,6 +129,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
#This is assuming that pf is set to unix, this should be if pf == 'linux'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can argue that arista should be in detect_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.

@backend.run_command('show system/noprocess') will always return OpenVMS Vxx e.g. "OpenVMS V8.2 on node VS3B2 3-NOV-2016 21:41:10.97 Uptime 171 04:49:02

"

return true if pf == 'unix' and detect_arista_eos
return true if pf == 'unix' and detect_via_uname

Expand Down
30 changes: 30 additions & 0 deletions lib/train/extras/os_detect_openvms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# encoding: utf-8
# author: Brian Doody (HPE)
# This is heavily based on:
#
# OHAI https://github.com/chef/ohai
# by Adam Jacob, Chef Software Inc
#
require 'train/extras/uname'

module Train::Extras
module DetectOpenVMS
include Train::Extras::Uname

def detect_openvms
cmd = @backend.run_command('show system/noprocess')

return false if cmd.exit_status != 0
return false if cmd.stdout.empty?

@platform[:name] = cmd.stdout.downcase.split(" ")[0]
cmd = @backend.run_command('write sys$output f$getsyi("VERSION")')
@platform[:release] = cmd.stdout.downcase.split("\n")[1][1..-1]
cmd = @backend.run_command('write sys$output f$getsyi("ARCH_NAME")')
@platform[:arch] = cmd.stdout.downcase.split("\n")[1]

true

end
end
end
2 changes: 1 addition & 1 deletion lib/train/transports/ssh_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def to_s

class OS < OSCommon
def initialize(backend)
super(backend, { family: 'unix' })
super(backend)
Copy link
Contributor

Choose a reason for hiding this comment

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

I just thinking if it is not easier to count openvms as a unix-like system as well? Not sure about that. This would allow us to just use

return true if pf =='unix' && detect_openvms 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the original code and the problem there is that

end
end
end
Expand Down