Skip to content

Commit

Permalink
Rubocop fixes
Browse files Browse the repository at this point in the history
This commit addresses Rubocop offenses from:

- Performance/StringInclude
- Style/TernaryParentheses
  • Loading branch information
mhashizume committed Jan 10, 2024
1 parent 572d395 commit aad6fce
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions acceptance/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def wait_for_installation_pid(host)
return
end

unless %r{windows}.match?(host['platform'])
unless host['platform'].include?('windows')
step '(Agent) waiting for upgrade pid file to be created...' do
retry_on(host, "cat #{upgrade_pidfile}", { max_retries: 5, retry_interval: 2 })
end
Expand All @@ -355,7 +355,7 @@ def remove_installed_agent(host)
end

step "Teardown: (Agent) Uninstall the puppet-agent package on agent #{host_to_info_s(host)}" do
if %r{windows}.match?(host['platform'])
if host['platform'].include?('windows')
install_dir = on(host, 'facter.bat env_windows_installdir').output.tr('\\', '/').chomp
scp_to(host, "#{SUPPORTING_FILES}/uninstall.ps1", 'uninstall.ps1')
on(host, 'rm -rf C:/ProgramData/PuppetLabs')
Expand Down
14 changes: 7 additions & 7 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def redhat_familly_supported_os

def global_facts(facts, os)
facts.merge(
if %r{sles}.match?(os)
if os.include?('sles')
{
is_pe: true,
env_temp_variable: '/tmp',
Expand All @@ -36,17 +36,17 @@ def global_facts(facts, os)
{
env_temp_variable: '/tmp',
}
elsif %r{solaris}.match?(os)
elsif os.include?('solaris')
{
is_pe: true,
puppet_agent_pid: 298,
}
elsif %r{aix}.match?(os)
elsif os.include?('aix')
{
is_pe: true,
platform_tag: "aix-#{AIX_VERSION[facts.dig(:os, 'release', 'major')]}-power",
}
elsif %r{windows}.match?(os)
elsif os.include?('windows')
{
puppet_agent_appdata: 'C:\\ProgramData',
puppet_confdir: 'C:\\ProgramData\\Puppetlabs\\puppet\\etc',
Expand Down Expand Up @@ -289,7 +289,7 @@ def global_facts(facts, os)
end

let(:expected_package_install_options) do
if %r{aix}.match?(os)
if os.include?('aix')
['--ignoreos', 'OPTION1=value1', 'OPTION2=value2']
else
['OPTION1=value1', 'OPTION2=value2']
Expand All @@ -305,7 +305,7 @@ def global_facts(facts, os)
it { is_expected.to contain_package('puppet-agent') .with_install_options(expected_package_install_options) }
end

if %r{solaris-10}.match?(os)
if os.include?('solaris-10')
it do
is_expected.to contain_exec('solaris_install script')
.with_command(
Expand Down Expand Up @@ -347,7 +347,7 @@ def global_facts(facts, os)
it { is_expected.to contain_package('puppet-agent').with_ensure(package_version) }
end

unless %r{windows}.match?(os)
unless os.include?('windows')
unless %r{sles|solaris|aix}.match?(os)
it { is_expected.to contain_class('puppet_agent::service').that_requires('Class[puppet_agent::configure]') }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def teardown_puppet_on(host)
clean_repo = ''
end

if %r{windows}.match?(host['platform'])
if host['platform'].include?('windows')
install_dir = on(host, 'facter.bat env_windows_installdir').output.tr('\\', '/').chomp
scp_to host, "#{TEST_FILES}/uninstall.ps1", 'uninstall.ps1'
on host, 'rm -rf C:/ProgramData/PuppetLabs'
Expand Down
8 changes: 4 additions & 4 deletions task_spec/spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def bolt_config
def bolt_inventory
host_data = hosts_to_inventory
host_data['targets'].each do |node_data|
node_data['config']['winrm']['connect-timeout'] = 120 if %r{win}.match?(target_platform)
node_data['config']['winrm']['connect-timeout'] = 120 if target_platform.include?('win')
end

host_data
Expand Down Expand Up @@ -97,7 +97,7 @@ def log_output_errors(result)

# extra request is needed on windows hosts
# this will fail with "execution expired"
run_task('puppet_agent::version', 'target', {}) if %r{win}.match?(target_platform)
run_task('puppet_agent::version', 'target', {}) if target_platform.include?('win')

# Test the agent isn't already installed and that the version task works
results = run_task('puppet_agent::version', 'target', {})
Expand Down Expand Up @@ -131,7 +131,7 @@ def log_output_errors(result)
end

# Check that puppet agent service has been stopped due to 'stop_service' parameter set to true
service = if %r{win}.match?(target_platform)
service = if target_platform.include?('win')
run_command('c:/"program files"/"puppet labs"/puppet/bin/puppet resource service puppet', 'target')
else
run_command('/opt/puppetlabs/bin/puppet resource service puppet', 'target')
Expand Down Expand Up @@ -190,7 +190,7 @@ def log_output_errors(result)
end

# Puppet Agent can't be upgraded on Windows nodes while 'puppet agent' service or 'pxp-agent' service are running
if %r{win}.match?(target_platform)
if target_platform.include?('win')
# Try to upgrade from puppet6 to puppet7 but fail due to puppet agent service already running
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet7', 'version' => 'latest' })
results.each do |res|
Expand Down
2 changes: 1 addition & 1 deletion tasks/facts_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run
run_result = Puppet::Util::Execution.execute(command, options)

minified_run_result = run_result.delete("\n").delete(' ')
minified_run_result == '{}' ? 'No differences found' : run_result
(minified_run_result == '{}') ? 'No differences found' : run_result
end

private
Expand Down
4 changes: 2 additions & 2 deletions tasks/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ def config_print(*keys)
end

def noop(params)
params['noop'] == true ? '--noop' : ''
(params['noop'] == true) ? '--noop' : ''
end

def environment(params)
params['environment'].length > 1 ? "--environment=#{params['environment']}" : ''
(params['environment'].length > 1) ? "--environment=#{params['environment']}" : ''
end

# Attempts to run the Puppet agent, returning the mtime for the last run report
Expand Down

0 comments on commit aad6fce

Please sign in to comment.