lib/beaker/host/cisco.rb in beaker-4.38.1 vs lib/beaker/host/cisco.rb in beaker-4.39.0

- old
+ new

@@ -32,11 +32,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] =~ /cisco_nexus/ + if self[:platform].include?('cisco_nexus') execute( "mv #{scp_file_actual} #{scp_file_target}" ) end nil end @@ -45,14 +45,14 @@ # @param [String] path File path to SCP to # # @return [String] path, changed if needed due to host # constraints def scp_path(path) - if self[:platform] =~ /cisco_nexus/ + if self[:platform].include?('cisco_nexus') @home_dir ||= execute( 'pwd' ) answer = "#{@home_dir}/#{File.basename( path )}" - answer << '/' if path =~ /\/$/ + answer << '/' if /\/$/.match?(path) return answer end path end @@ -79,13 +79,13 @@ # @param [String] command Command to be executed # @param [String] user_pc List of user-specified commands to prepend # @param [Hash] opts optional parameters # # @return [String] Command string as needed for this host - def prepend_commands(command = '', user_pc = '', opts = {}) + def prepend_commands(command = '', user_pc = '', _opts = {}) return user_pc unless command.index('vsh').nil? - if self[:platform] =~ /cisco_nexus/ + 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' @@ -103,14 +103,14 @@ # @param [String] command Command to be executed # @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 = {}) + def append_commands(command = '', _user_ac = '', _opts = {}) command.gsub('"') {'\\"'} # vsh commands, ntpdate or when user is root commands do not require an appended `"` - return '"' unless command =~ /ntpdate|\/isan\/bin\/vsh/ || self[:user] == 'root' + return '"' unless /ntpdate|\/isan\/bin\/vsh/.match?(command) || self[:user] == 'root' end # Construct the environment string for this command # # @param [Hash{String=>String}] env An optional Hash containing @@ -126,35 +126,35 @@ prestring = '' return prestring if env.empty? env_array = self.environment_variable_string_pair_array( env ) environment_string = env_array.join(' ') - if self[:platform] =~ /cisco_nexus/ + if self[:platform].include?('cisco_nexus') prestring << " export" else prestring << " env" end environment_string = "#{prestring} #{environment_string}" - environment_string << ';' if prestring =~ /export/ + environment_string << ';' if prestring.include?('export') environment_string end # Validates that the host was setup correctly # # @return nil # @raise [ArgumentError] If the host is setup incorrectly, # this will be raised with the appropriate message def validate_setup msg = nil - if self[:platform] =~ /cisco_nexus/ + 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 end - if self[:platform] =~ /cisco_ios_xr/ + if self[:platform].include?('cisco_ios_xr') if !self[:user] msg = 'Cisco hosts must be provided with a :user value' end end