lib/beaker/host/cisco.rb in beaker-4.42.0 vs lib/beaker/host/cisco.rb in beaker-5.0.0
- old
+ new
@@ -1,23 +1,22 @@
-[ 'host', 'command_factory' ].each do |lib|
+%w[host command_factory].each do |lib|
require "beaker/#{lib}"
end
module Cisco
class Host < Unix::Host
-
# as the cisco hosts tend to have custom
# ssh configuration, the presets
# do not apply where verification of the
# host keys is disabled
def platform_defaults
h = Beaker::Options::OptionsHash.new
h.merge({
- 'ssh' => {
- :verify_host_key => false,
- },
- })
+ 'ssh' => {
+ :verify_host_key => false,
+ },
+ })
end
# Tells you whether a host platform supports beaker's
# {Beaker::HostPrebuiltSteps#set_env} method
#
@@ -32,13 +31,11 @@
# @param [String] scp_file_actual File path to actual SCP'd file on host
# @param [String] scp_file_target File path to target SCP location on host
#
# @return nil
def scp_post_operations(scp_file_actual, scp_file_target)
- if self[:platform].include?('cisco_nexus')
- execute( "mv #{scp_file_actual} #{scp_file_target}" )
- end
+ execute("mv #{scp_file_actual} #{scp_file_target}") if self[:platform].include?('cisco_nexus')
nil
end
# Handles any changes needed in a path for SCP
#
@@ -46,12 +43,12 @@
#
# @return [String] path, changed if needed due to host
# constraints
def scp_path(path)
if self[:platform].include?('cisco_nexus')
- @home_dir ||= execute( 'pwd' )
- answer = "#{@home_dir}/#{File.basename( path )}"
+ @home_dir ||= execute('pwd')
+ answer = "#{@home_dir}/#{File.basename(path)}"
answer << '/' if /\/$/.match?(path)
return answer
end
path
end
@@ -81,22 +78,19 @@
# @param [Hash] opts optional parameters
#
# @return [String] Command string as needed for this host
def prepend_commands(command = '', user_pc = '', _opts = {})
return user_pc unless command.index('vsh').nil?
+
if self[:platform].include?('cisco_nexus')
return user_pc unless command.index('ntpdate').nil?
end
prepend_cmds = 'source /etc/profile;'
prepend_cmds << " sudo -E sh -c \"" if self[:user] != 'root'
- if self[:vrf]
- prepend_cmds << "ip netns exec #{self[:vrf]} "
- end
- if user_pc && !user_pc.empty?
- prepend_cmds << "#{user_pc} "
- end
+ prepend_cmds << "ip netns exec #{self[:vrf]} " if self[:vrf]
+ prepend_cmds << "#{user_pc} " if user_pc && !user_pc.empty?
prepend_cmds.strip
end
# Gets the specific append commands as needed for this host
#
@@ -104,11 +98,11 @@
# @param [String] user_ac List of user-specified commands to append
# @param [Hash] opts optional parameters
#
# @return [String] Command string as needed for this host
def append_commands(command = '', _user_ac = '', _opts = {})
- command.gsub('"') {'\\"'}
+ command.gsub('"') { '\\"' }
# vsh commands, ntpdate or when user is root commands do not require an appended `"`
return '"' unless /ntpdate|\/isan\/bin\/vsh/.match?(command) || self[:user] == 'root'
end
# Construct the environment string for this command
@@ -123,18 +117,19 @@
# will ensure the environment is correctly set for the
# given host.
def environment_string env
prestring = ''
return prestring if env.empty?
- env_array = self.environment_variable_string_pair_array( env )
+
+ env_array = self.environment_variable_string_pair_array(env)
environment_string = env_array.join(' ')
- if self[:platform].include?('cisco_nexus')
- prestring << " export"
- else
- prestring << " env"
- end
+ prestring << if self[:platform].include?('cisco_nexus')
+ " export"
+ else
+ " env"
+ end
environment_string = "#{prestring} #{environment_string}"
environment_string << ';' if prestring.include?('export')
environment_string
end
@@ -144,28 +139,21 @@
# @raise [ArgumentError] If the host is setup incorrectly,
# this will be raised with the appropriate message
def validate_setup
msg = nil
if self[:platform].include?('cisco_nexus')
- if !self[:vrf]
- msg = 'Cisco Nexus hosts must be provided with a :vrf value.'
- end
- if !self[:user]
- msg = 'Cisco hosts must be provided with a :user value'
- end
+ msg = 'Cisco Nexus hosts must be provided with a :vrf value.' if !self[:vrf]
+ msg = 'Cisco hosts must be provided with a :user value' if !self[:user]
end
if self[:platform].include?('cisco_ios_xr')
- if !self[:user]
- msg = 'Cisco hosts must be provided with a :user value'
- end
+ msg = 'Cisco hosts must be provided with a :user value' if !self[:user]
end
- if msg
- msg << <<-EOF
+ return unless msg
+
+ msg << <<-EOF
Check https://github.com/puppetlabs/beaker/blob/master/docs/hosts/cisco.md for more info.'
- EOF
- raise ArgumentError, msg
- end
+ EOF
+ raise ArgumentError, msg
end
-
end
end