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

rubocop: Fix more Style cops #1792

Merged
merged 8 commits into from
Mar 24, 2023
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
4 changes: 2 additions & 2 deletions acceptance/tests/base/host/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
logger.debug("can recursively copy a module over, ignoring some files/dirs")
# make sure that we are clean on the test host
host.rm_rf("module")
host.do_scp_to(module_fixture, ".", { :ignore => ['tests', 'Gemfile'] })
host.do_scp_to(module_fixture, ".", { :ignore => %w[tests Gemfile] })
Dir.mktmpdir do |tmp_dir|
# grab copy from host
host.do_scp_from("module", tmp_dir, {})
Expand Down Expand Up @@ -262,7 +262,7 @@
logger.debug("can recursively copy a module over, ignoring some sub-files/sub-dirs that also appear in the absolute path")
# make sure that we are clean on the test host
host.rm_rf("module")
host.do_scp_to(module_fixture, ".", { :ignore => ['module', 'Gemfile'] })
host.do_scp_to(module_fixture, ".", { :ignore => %w[module Gemfile] })
Dir.mktmpdir do |tmp_dir|
# grab copy from host
host.do_scp_from("module", tmp_dir, {})
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/base/test_suite/export.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_name 'ensure tests can export arbitrary data' do
step 'export nested hash' do
export({ 'middle earth' => {
'Hobbits' => ['Bilbo', 'Frodo'],
'Hobbits' => %w[Bilbo Frodo],
'Elves' => 'Arwen',
:total => { 'numbers' => 42 },
} })
Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def print_reproduction_info(log_level = :debug)
#
# @return nil
def print_env_vars_affecting_beaker(log_level)
non_beaker_env_vars = ['BUNDLE_PATH', 'BUNDLE_BIN', 'GEM_HOME', 'GEM_PATH', 'RUBYLIB', 'PATH']
non_beaker_env_vars = %w[BUNDLE_PATH BUNDLE_BIN GEM_HOME GEM_PATH RUBYLIB PATH]
env_var_map = non_beaker_env_vars.each_with_object({}) do |possibly_set_vars, memo|
set_var = Array(possibly_set_vars).detect { |possible_var| ENV.fetch(possible_var, nil) }
memo[set_var] = ENV.fetch(set_var, nil) if set_var
Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
['install_utils', 'roles', 'outcomes', 'assertions', 'patterns', 'structure', 'helpers', 'wrappers', 'test_tagging'].each do |lib|
%w[install_utils roles outcomes assertions patterns structure helpers wrappers test_tagging].each do |lib|
require "beaker/dsl/#{lib}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/dsl/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
['host', 'test', 'web', 'hocon'].each do |lib|
%w[host test web hocon].each do |lib|
require "beaker/dsl/helpers/#{lib}_helpers"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/dsl/helpers/web_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def link_exists?(link, limit = 10)
http.use_ssl = (url.scheme == 'https')
http.verify_mode = (OpenSSL::SSL::VERIFY_NONE)
response = http.start { |http| http.head(url.request_uri) }
if (['301', '302'].include? response.code) && limit > 0
if (%w[301 302].include? response.code) && limit > 0
logger.debug("#{__method__} following #{response.code} to #{response['location']}")
link_exists?(response['location'], limit - 1)
else
Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/dsl/roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def default
# end
#
def not_controller(host)
controllers = ['dashboard', 'database', 'master', 'console']
controllers = %w[dashboard database master console]
matched_roles = host['roles'].select { |v| controllers.include?(v) }
matched_roles.length == 0
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def agent_only(host)
#
# @return [Boolean] whether or not a host is AIO-capable
def aio_version?(host)
[:pe_ver, :version].each do |key|
%i[pe_ver version].each do |key|
version = host[key]
return !version_is_less(version, '4.0') if version && !version.empty?
end
Expand Down
22 changes: 11 additions & 11 deletions lib/beaker/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'beaker/dsl/helpers'
require 'beaker/dsl/patterns'

['command', 'ssh_connection', 'local_connection'].each do |lib|
%w[command ssh_connection local_connection].each do |lib|
require "beaker/#{lib}"
end

Expand Down Expand Up @@ -418,7 +418,7 @@ def do_scp_to source, target_path, options
dir_source = Dir.glob("#{source}/**/*").reject do |f|
ignore_re&.match?(f.gsub(/\A#{Regexp.escape(source)}/, '')) # only match against subdirs, not full path
end
@logger.trace "After rejecting ignored files/dirs, going to scp [#{dir_source.join(", ")}]"
@logger.trace "After rejecting ignored files/dirs, going to scp [#{dir_source.join(', ')}]"

# create necessary directory structure on host
# run this quietly (no STDOUT)
Expand Down Expand Up @@ -549,15 +549,15 @@ def do_rsync_to from_path, to_path, opts = {}
end
end

[
'unix',
'aix',
'mac',
'freebsd',
'windows',
'pswindows',
'eos',
'cisco',
%w[
unix
aix
mac
freebsd
windows
pswindows
eos
cisco
].each do |lib|
require "beaker/host/#{lib}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/aix.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
['host', 'command_factory'].each do |lib|
%w[host command_factory].each do |lib|
require "beaker/#{lib}"
end

module Aix
class Host < Unix::Host
['user', 'group', 'file', 'exec'].each do |lib|
%w[user group file exec].each do |lib|
require "beaker/host/aix/#{lib}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/host/cisco.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
['host', 'command_factory'].each do |lib|
%w[host command_factory].each do |lib|
require "beaker/#{lib}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/host/eos.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
['host', 'command_factory'].each do |lib|
%w[host command_factory].each do |lib|
require "beaker/#{lib}"
end

Expand Down
8 changes: 4 additions & 4 deletions lib/beaker/host/freebsd.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
['host', 'command_factory'].each do |lib|
%w[host command_factory].each do |lib|
require "beaker/#{lib}"
end

module FreeBSD
class Host < Unix::Host
[
'exec',
'pkg',
%w[
exec
pkg
].each do |lib|
require "beaker/host/freebsd/#{lib}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/mac.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
['host', 'command_factory', 'command', 'options'].each do |lib|
%w[host command_factory command options].each do |lib|
require "beaker/#{lib}"
end

module Mac
class Host < Unix::Host
['exec', 'user', 'group', 'pkg'].each do |lib|
%w[exec user group pkg].each do |lib|
require "beaker/host/mac/#{lib}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/host/pswindows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module PSWindows
class Host < Windows::Host
['user', 'group', 'exec', 'pkg', 'file'].each do |lib|
%w[user group exec pkg file].each do |lib|
require "beaker/host/pswindows/#{lib}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/host/pswindows/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_ip
# @return [Boolean] true of ping successful, overwise false
def ping target, attempts = 5
try = 0
while try < attempts do
while try < attempts
result = exec(Beaker::Command.new("ping -n 1 #{target}"), :accept_all_exit_codes => true)
return true if result.exit_code == 0

Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/unix.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
['host', 'command_factory', 'command', 'options'].each do |lib|
%w[host command_factory command options].each do |lib|
require "beaker/#{lib}"
end

module Unix
class Host < Beaker::Host
['user', 'group', 'exec', 'pkg', 'file'].each do |lib|
%w[user group exec pkg file].each do |lib|
require "beaker/host/unix/#{lib}"
end

Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/unix/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def mv orig, dest, rm = true
# @return [Boolean] true of ping successful, overwise false
def ping target, attempts = 5
try = 0
while try < attempts do
while try < attempts
result = exec(Beaker::Command.new("ping -c 1 #{target}"), :accept_all_exit_codes => true)
return true if result.exit_code == 0

Expand Down Expand Up @@ -397,7 +397,7 @@ def ssh_set_user_environment(env)
add_env_var('PATH', '$PATH')
if self['platform'].variant == 'openbsd'
arch = self['platform'].arch
arch = 'amd64' if ['x64', 'x86_64'].include?(arch)
arch = 'amd64' if %w[x64 x86_64].include?(arch)
add_env_var('PKG_PATH', "http://ftp.openbsd.org/pub/OpenBSD/#{self['platform'].version}/packages/#{arch}/")
elsif self['platform'].include?('solaris-10')
add_env_var('PATH', '/opt/csw/bin')
Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/unix/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def repo_filename(package_name, build_version)

case variant
when /fedora|el|redhat|centos|cisco_nexus|cisco_ios_xr|opensuse|sles/
variant = 'el' if ['centos', 'redhat'].include?(variant)
variant = 'el' if %w[centos redhat].include?(variant)

variant = 'redhatfips' if self['packaging_platform']&.include?('redhatfips')

Expand All @@ -126,7 +126,7 @@ def repo_filename(package_name, build_version)
variant = 'cisco-wrlinux'
version = '7'
end
fedora_prefix = ((variant == 'fedora') ? 'f' : '')
fedora_prefix = (variant == 'fedora' ? 'f' : '')

pattern = "%s-%s%s-%s.repo"

Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/windows.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
['host', 'command_factory', 'command', 'options'].each do |lib|
%w[host command_factory command options].each do |lib|
require "beaker/#{lib}"
end

module Windows
# A windows host with cygwin tools installed
class Host < Unix::Host
['user', 'group', 'exec', 'pkg', 'file'].each do |lib|
%w[user group exec pkg file].each do |lib|
require "beaker/host/windows/#{lib}"
end

Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/host/windows/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_ip
# @return [Boolean] true of ping successful, overwise false
def ping target, attempts = 5
try = 0
while try < attempts do
while try < attempts
result = exec(Beaker::Command.new("ping -n 1 #{target}"), :accept_all_exit_codes => true)
return true if result.exit_code == 0

Expand Down Expand Up @@ -97,7 +97,7 @@ def ssh_permit_user_environment
# @return [String] Command string as needed for this host
def prepend_commands(_command = '', user_pc = nil, opts = {})
cygwin_prefix = (self.is_cygwin? and opts[:cmd_exe]) ? 'cmd.exe /c' : ''
spacing = (user_pc && !cygwin_prefix.empty?) ? ' ' : ''
spacing = user_pc && !cygwin_prefix.empty? ? ' ' : ''
"#{cygwin_prefix}#{spacing}#{user_pc}"
end

Expand Down
22 changes: 11 additions & 11 deletions lib/beaker/host_prebuilt_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
['command', "dsl"].each do |lib|
%w[command dsl].each do |lib|
require "beaker/#{lib}"
end

Expand All @@ -10,21 +10,21 @@ module HostPrebuiltSteps
NTPSERVER = 'pool.ntp.org'
SLEEPWAIT = 5
TRIES = 5
RHEL8_PACKAGES = ['curl', 'chrony']
RHEL8_PACKAGES = %w[curl chrony]
RHEL9_PACKAGES = ['chrony']
FEDORA_PACKAGES = ['curl', 'chrony']
UNIX_PACKAGES = ['curl', 'ntpdate']
FEDORA_PACKAGES = %w[curl chrony]
UNIX_PACKAGES = %w[curl ntpdate]
FREEBSD_PACKAGES = ['curl', 'perl5|perl']
OPENBSD_PACKAGES = ['curl']
ARCHLINUX_PACKAGES = ['curl', 'ntp', 'net-tools', 'openssh']
ARCHLINUX_PACKAGES = %w[curl ntp net-tools openssh]
WINDOWS_PACKAGES = ['curl']
PSWINDOWS_PACKAGES = []
SLES10_PACKAGES = ['curl']
SLES_PACKAGES = ['curl', 'ntp']
DEBIAN_PACKAGES = ['curl', 'ntpdate', 'lsb-release', 'apt-transport-https']
CUMULUS_PACKAGES = ['curl', 'ntpdate']
SOLARIS10_PACKAGES = ['CSWcurl', 'CSWntp', 'wget']
SOLARIS11_PACKAGES = ['curl', 'ntp']
SLES_PACKAGES = %w[curl ntp]
DEBIAN_PACKAGES = %w[curl ntpdate lsb-release apt-transport-https]
CUMULUS_PACKAGES = %w[curl ntpdate]
SOLARIS10_PACKAGES = %w[CSWcurl CSWntp wget]
SOLARIS11_PACKAGES = %w[curl ntp]
ETC_HOSTS_PATH = "/etc/hosts"
ETC_HOSTS_PATH_SOLARIS = "/etc/inet/hosts"
ROOT_KEYS_SCRIPT = "https://raw.githubusercontent.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
Expand Down Expand Up @@ -61,7 +61,7 @@ def timesync host, opts
end
success = false
try = 0
until try >= TRIES do
until try >= TRIES
try += 1
if host.exec(Command.new(ntp_command), :accept_all_exit_codes => true).exit_code == 0
success = true
Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/hypervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def cleanup
nil
end

DEFAULT_CONNECTION_PREFERENCE = [:ip, :vmhostname, :hostname]
DEFAULT_CONNECTION_PREFERENCE = %i[ip vmhostname hostname]
# SSH connection method preference. Can be overwritten by hypervisor to change the order
def connection_preference(_host)
DEFAULT_CONNECTION_PREFERENCE
Expand Down
4 changes: 2 additions & 2 deletions lib/beaker/options/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Parser
GITREPO = 'git://github.com/puppetlabs'
# These options can have the form of arg1,arg2 or [arg] or just arg,
# should default to []
LONG_OPTS = [:helper, :load_path, :tests, :pre_suite, :post_suite, :install, :pre_cleanup, :modules]
LONG_OPTS = %i[helper load_path tests pre_suite post_suite install pre_cleanup modules]
# These options expand out into an array of .rb files
RB_FILE_OPTS = [:tests, :pre_suite, :post_suite, :pre_cleanup]
RB_FILE_OPTS = %i[tests pre_suite post_suite pre_cleanup]

PARSE_ERROR = Psych::SyntaxError

Expand Down
30 changes: 15 additions & 15 deletions lib/beaker/options/presets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ class Presets
# https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
ENVIRONMENT_SPEC = {
:home => 'HOME',
:project => ['BEAKER_PROJECT', 'BEAKER_project', 'JOB_NAME'],
:department => ['BEAKER_DEPARTMENT', 'BEAKER_department'],
:jenkins_build_url => ['BEAKER_BUILD_URL', 'BUILD_URL'],
:project => %w[BEAKER_PROJECT BEAKER_project JOB_NAME],
:department => %w[BEAKER_DEPARTMENT BEAKER_department],
:jenkins_build_url => %w[BEAKER_BUILD_URL BUILD_URL],
:created_by => ['BEAKER_CREATED_BY'],
:consoleport => ['BEAKER_CONSOLEPORT', 'consoleport'],
:is_pe => ['BEAKER_IS_PE', 'IS_PE'],
:pe_dir => ['BEAKER_PE_DIR', 'pe_dist_dir'],
:consoleport => %w[BEAKER_CONSOLEPORT consoleport],
:is_pe => %w[BEAKER_IS_PE IS_PE],
:pe_dir => %w[BEAKER_PE_DIR pe_dist_dir],
:puppet_agent_version => ['BEAKER_PUPPET_AGENT_VERSION'],
:puppet_agent_sha => ['BEAKER_PUPPET_AGENT_SHA'],
:puppet_collection => ['BEAKER_PUPPET_COLLECTION'],
:pe_version_file => ['BEAKER_PE_VERSION_FILE', 'pe_version_file'],
:pe_ver => ['BEAKER_PE_VER', 'pe_ver'],
:forge_host => ['BEAKER_FORGE_HOST', 'forge_host'],
:pe_version_file => %w[BEAKER_PE_VERSION_FILE pe_version_file],
:pe_ver => %w[BEAKER_PE_VER pe_ver],
:forge_host => %w[BEAKER_FORGE_HOST forge_host],
:package_proxy => ['BEAKER_PACKAGE_PROXY'],
:release_apt_repo_url => ['BEAKER_RELEASE_APT_REPO', 'RELEASE_APT_REPO'],
:release_yum_repo_url => ['BEAKER_RELEASE_YUM_REPO', 'RELEASE_YUM_REPO'],
:dev_builds_url => ['BEAKER_DEV_BUILDS_URL', 'DEV_BUILDS_URL'],
:vbguest_plugin => ['BEAKER_VB_GUEST_PLUGIN', 'BEAKER_vb_guest_plugin'],
:test_tag_and => ['BEAKER_TAG', 'BEAKER_TEST_TAG_AND'],
:release_apt_repo_url => %w[BEAKER_RELEASE_APT_REPO RELEASE_APT_REPO],
:release_yum_repo_url => %w[BEAKER_RELEASE_YUM_REPO RELEASE_YUM_REPO],
:dev_builds_url => %w[BEAKER_DEV_BUILDS_URL DEV_BUILDS_URL],
:vbguest_plugin => %w[BEAKER_VB_GUEST_PLUGIN BEAKER_vb_guest_plugin],
:test_tag_and => %w[BEAKER_TAG BEAKER_TEST_TAG_AND],
:test_tag_or => ['BEAKER_TEST_TAG_OR'],
:test_tag_exclude => ['BEAKER_EXCLUDE_TAG', 'BEAKER_TEST_TAG_EXCLUDE'],
:test_tag_exclude => %w[BEAKER_EXCLUDE_TAG BEAKER_TEST_TAG_EXCLUDE],
:run_in_parallel => ['BEAKER_RUN_IN_PARALLEL'],
}

Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/perf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def print_perf_info
def get_perf_data(host, perf_start, perf_end)
@logger.perf_output("Getting perf data for host: " + host)
if PERF_SUPPORTED_PLATFORMS.match?(host['platform']) # All flavours of Linux
host.exec(Command.new("sar -A -s #{perf_start.strftime("%H:%M:%S")} -e #{perf_end.strftime("%H:%M:%S")}"), :acceptable_exit_codes => [0, 1, 2]) if not @options[:collect_perf_data]&.include?('aggressive')
host.exec(Command.new("sar -A -s #{perf_start.strftime('%H:%M:%S')} -e #{perf_end.strftime('%H:%M:%S')}"), :acceptable_exit_codes => [0, 1, 2]) if not @options[:collect_perf_data]&.include?('aggressive')
if (defined? @options[:graphite_server] and not @options[:graphite_server].nil?) and
(defined? @options[:graphite_perf_data] and not @options[:graphite_perf_data].nil?)
export_perf_data_to_graphite(host)
Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/shared.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
['repetition', 'error_handler', 'host_manager', 'timed', 'semvar', 'options_resolver', 'fog_credentials'].each do |lib|
%w[repetition error_handler host_manager timed semvar options_resolver fog_credentials].each do |lib|
require "beaker/shared/#{lib}"
end
module Beaker
Expand Down
Loading