Skip to content

Commit 23d7c5a

Browse files
Merge pull request #249 from puppetlabs/CAT-1688-Upgrade_rubocop
(CAT-1688) Upgrade rubocop
2 parents 113c01a + 52f278b commit 23d7c5a

File tree

8 files changed

+58
-56
lines changed

8 files changed

+58
-56
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ require:
55
- rubocop-performance
66
- rubocop-rspec
77
AllCops:
8+
NewCops: enable
89
DisplayCopNames: true
910
TargetRubyVersion: '2.6'
1011
Include:
@@ -81,3 +82,6 @@ Style/Documentation:
8182
- spec/**/*
8283
Style/WordArray:
8384
EnforcedStyle: brackets
85+
Style/FileWrite:
86+
Description: Enforcing this rule might break the code in unexpected ways.
87+
Enabled: false

.rubocop_todo.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-04-28 12:30:24 UTC using RuboCop version 1.48.1.
3+
# on 2024-01-17 17:28:36 UTC using RuboCop version 1.50.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 12
9+
# Offense count: 13
1010
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1111
Metrics/AbcSize:
1212
Max: 94
1313

14-
# Offense count: 1
14+
# Offense count: 2
1515
# Configuration parameters: CountComments, CountAsOne.
1616
Metrics/ClassLength:
17-
Max: 200
17+
Max: 155
1818

19-
# Offense count: 9
19+
# Offense count: 8
2020
# Configuration parameters: AllowedMethods, AllowedPatterns.
2121
Metrics/CyclomaticComplexity:
22-
Max: 25
22+
Max: 23
2323

24-
# Offense count: 19
24+
# Offense count: 20
2525
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
2626
Metrics/MethodLength:
27-
Max: 69
27+
Max: 70
2828

2929
# Offense count: 3
3030
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
@@ -34,7 +34,7 @@ Metrics/ParameterLists:
3434
# Offense count: 7
3535
# Configuration parameters: AllowedMethods, AllowedPatterns.
3636
Metrics/PerceivedComplexity:
37-
Max: 30
37+
Max: 25
3838

3939
# Offense count: 2
4040
# Configuration parameters: IgnoredMetadata.
@@ -48,30 +48,29 @@ RSpec/DescribeClass:
4848
- 'spec/tasks/abs_spec.rb'
4949
- 'spec/unit/task_helper_spec.rb'
5050

51-
# Offense count: 4
51+
# Offense count: 12
5252
# Configuration parameters: CountAsOne.
5353
RSpec/ExampleLength:
54-
Max: 30
54+
Max: 27
5555

56-
# Offense count: 6
56+
# Offense count: 13
5757
RSpec/MultipleExpectations:
5858
Max: 13
5959

60-
# Offense count: 2
60+
# Offense count: 6
6161
# Configuration parameters: AllowSubject.
6262
RSpec/MultipleMemoizedHelpers:
6363
Max: 6
6464

65-
# Offense count: 4
65+
# Offense count: 6
6666
RSpec/StubbedMock:
6767
Exclude:
6868
- 'spec/tasks/abs_spec.rb'
6969

70-
# Offense count: 8
70+
# Offense count: 7
7171
Style/MixinUsage:
7272
Exclude:
7373
- 'spec/spec_helper.rb'
7474
- 'tasks/docker.rb'
7575
- 'tasks/docker_exp.rb'
76-
- 'tasks/provision_service.rb'
7776
- 'tasks/vagrant.rb'

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ group :development do
3131
gem "pry", '~> 0.10', require: false
3232
gem "simplecov-console", '~> 0.5', require: false
3333
gem "puppet-debugger", '~> 1.0', require: false
34-
gem "rubocop", '= 1.48.1', require: false
34+
gem "rubocop", '~> 1.50.0', require: false
3535
gem "rubocop-performance", '= 1.16.0', require: false
3636
gem "rubocop-rspec", '= 2.19.0', require: false
3737
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]

tasks/abs.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def abs_host
2626
def provision(platform, inventory_location, vars)
2727
uri = URI.parse("https://#{abs_host}/api/v2/request")
2828
jenkins_build_url = if ENV['CI'] == 'true' && ENV['TRAVIS'] == 'true'
29-
ENV['TRAVIS_JOB_WEB_URL']
29+
ENV.fetch('TRAVIS_JOB_WEB_URL', nil)
3030
elsif ENV['CI'] == 'True' && ENV['APPVEYOR'] == 'True'
31-
"https://ci.appveyor.com/project/#{ENV['APPVEYOR_REPO_NAME']}/build/job/#{ENV['APPVEYOR_JOB_ID']}"
31+
"https://ci.appveyor.com/project/#{ENV.fetch('APPVEYOR_REPO_NAME', nil)}/build/job/#{ENV.fetch('APPVEYOR_JOB_ID', nil)}"
3232
elsif ENV['GITHUB_ACTIONS'] == 'true'
33-
"https://github.com/#{ENV['GITHUB_REPOSITORY']}/actions/runs/#{ENV['GITHUB_RUN_ID']}"
33+
"https://github.com/#{ENV.fetch('GITHUB_REPOSITORY', nil)}/actions/runs/#{ENV.fetch('GITHUB_RUN_ID', nil)}"
3434
else
3535
'https://litmus_manual'
3636
end
@@ -91,17 +91,18 @@ def provision(platform, inventory_location, vars)
9191
data.each do |host|
9292
if platform_uses_ssh(host['type'])
9393
node = { 'uri' => host['hostname'],
94-
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => ENV['ABS_USER'], 'host-key-check' => false, 'connect-timeout' => 120 } },
94+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => ENV.fetch('ABS_USER', nil), 'host-key-check' => false, 'connect-timeout' => 120 } },
9595
'facts' => { 'provisioner' => 'abs', 'platform' => host['type'], 'job_id' => job_id } }
9696
if !ENV['ABS_SSH_PRIVATE_KEY'].nil? && !ENV['ABS_SSH_PRIVATE_KEY'].empty?
97-
node['config']['ssh']['private-key'] = ENV['ABS_SSH_PRIVATE_KEY']
97+
node['config']['ssh']['private-key'] = ENV.fetch('ABS_SSH_PRIVATE_KEY', nil)
9898
else
99-
node['config']['ssh']['password'] = ENV['ABS_PASSWORD']
99+
node['config']['ssh']['password'] = ENV.fetch('ABS_PASSWORD', nil)
100100
end
101101
group_name = 'ssh_nodes'
102102
else
103103
node = { 'uri' => host['hostname'],
104-
'config' => { 'transport' => 'winrm', 'winrm' => { 'user' => ENV['ABS_WIN_USER'], 'password' => ENV['ABS_PASSWORD'], 'ssl' => false, 'connect-timeout' => 120 } },
104+
'config' => { 'transport' => 'winrm',
105+
'winrm' => { 'user' => ENV.fetch('ABS_WIN_USER', nil), 'password' => ENV.fetch('ABS_PASSWORD', nil), 'ssl' => false, 'connect-timeout' => 120 } },
105106
'facts' => { 'provisioner' => 'abs', 'platform' => host['type'], 'job_id' => job_id } }
106107
group_name = 'winrm_nodes'
107108
end

tasks/docker.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ def install_ssh_components(distro, version, container)
2323
# sometimes the redhat 6 variant containers like to eat their rpmdb, leading to
2424
# issues with "rpmdb: unable to join the environment" errors
2525
# This "fix" is from https://www.srv24x7.com/criticalyum-main-error-rpmdb-open-failed/
26-
run_local_command("docker exec #{container} bash -exc \"rm -f /var/lib/rpm/__db*; "\
27-
'db_verify /var/lib/rpm/Packages; '\
28-
'rpm --rebuilddb; '\
29-
'yum clean all; '\
30-
'yum install -y sudo openssh-server openssh-clients"')
26+
run_local_command("docker exec #{container} bash -exc \"rm -f /var/lib/rpm/__db*; " \
27+
'db_verify /var/lib/rpm/Packages; ' \
28+
'rpm --rebuilddb; ' \
29+
'yum clean all; ' \
30+
'yum install -y sudo openssh-server openssh-clients"')
3131
else
3232
# If systemd is running for init, ensure systemd has finished starting up before proceeding:
33-
check_init_cmd = 'if [[ "$(readlink /proc/1/exe)" == "/usr/lib/systemd/systemd" ]]; then '\
34-
'count=0 ; while ! [[ "$(systemctl is-system-running)" =~ ^running|degraded$ && $count > 20 ]]; '\
35-
'do sleep 0.1 ; count=$((count+1)) ; done ; fi'
33+
check_init_cmd = 'if [[ "$(readlink /proc/1/exe)" == "/usr/lib/systemd/systemd" ]]; then ' \
34+
'count=0 ; while ! [[ "$(systemctl is-system-running)" =~ ^running|degraded$ && $count > 20 ]]; ' \
35+
'do sleep 0.1 ; count=$((count+1)) ; done ; fi'
3636
run_local_command("docker exec #{container} bash -c '#{check_init_cmd}'")
3737
run_local_command("docker exec #{container} yum install -y sudo openssh-server openssh-clients")
3838
end
@@ -74,10 +74,10 @@ def fix_ssh(distro, version, container)
7474
# https://bugzilla.redhat.com/show_bug.cgi?id=1728777
7575
run_local_command("docker exec #{container} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd") if distro =~ %r{redhat|centos} && version =~ %r{^7}
7676

77-
if !%r{^(7|8|9|2)}.match?(version)
78-
run_local_command("docker exec #{container} service sshd restart")
79-
else
77+
if %r{^(7|8|9|2)}.match?(version)
8078
run_local_command("docker exec #{container} /usr/sbin/sshd")
79+
else
80+
run_local_command("docker exec #{container} service sshd restart")
8181
end
8282
when %r{sles}
8383
run_local_command("docker exec #{container} /usr/sbin/sshd")
@@ -161,7 +161,7 @@ def provision(image, inventory_location, vars)
161161
distro = os_release_facts['ID']
162162
version = os_release_facts['VERSION_ID']
163163

164-
hostname = (ENV['DOCKER_HOST'].nil? || ENV['DOCKER_HOST'].empty?) ? 'localhost' : URI.parse(ENV['DOCKER_HOST']).host || ENV['DOCKER_HOST']
164+
hostname = (ENV['DOCKER_HOST'].nil? || ENV['DOCKER_HOST'].empty?) ? 'localhost' : URI.parse(ENV.fetch('DOCKER_HOST', nil)).host || ENV.fetch('DOCKER_HOST', nil)
165165
begin
166166
# Use the current docker context to determine the docker hostname
167167
docker_context = JSON.parse(run_local_command('docker context inspect'))[0]

tasks/provision_service.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def invoke_cloud_request(params, uri, job_url, verb, retry_attempts)
4646
request.body = if job_url
4747
{ url: job_url, VMs: machines }.to_json
4848
else
49-
{ github_token: ENV['GITHUB_TOKEN'], VMs: machines }.to_json
49+
{ github_token: ENV.fetch('GITHUB_TOKEN', nil), VMs: machines }.to_json
5050
end
5151
when 'delete'
5252
request = Net::HTTP::Delete.new(uri, headers)
@@ -89,14 +89,14 @@ def provision(platform, inventory_location, vars, retry_attempts)
8989
# Call the provision service with the information necessary and write the inventory file locally
9090

9191
if ENV['GITHUB_RUN_ID']
92-
job_url = ENV['GITHUB_URL'] || "https://api.github.com/repos/#{ENV['GITHUB_REPOSITORY']}/actions/runs/#{ENV['GITHUB_RUN_ID']}"
92+
job_url = ENV['GITHUB_URL'] || "https://api.github.com/repos/#{ENV.fetch('GITHUB_REPOSITORY', nil)}/actions/runs/#{ENV['GITHUB_RUN_ID']}"
9393
else
9494
puts 'Using GITHUB_TOKEN as no GITHHUB_RUN_ID found'
9595
end
9696
uri = URI.parse(ENV['SERVICE_URL'] || default_uri)
97-
cloud = ENV['CLOUD']
98-
region = ENV['REGION']
99-
zone = ENV['ZONE']
97+
cloud = ENV.fetch('CLOUD', nil)
98+
region = ENV.fetch('REGION', nil)
99+
zone = ENV.fetch('ZONE', nil)
100100
if job_url.nil? && vars
101101
data = JSON.parse(vars.tr(';', ','))
102102
job_url = data['job_url']

tasks/update_node_pp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def update_file(manifest, target_node)
1717
# remove the last bracket in the manifest
1818
existing_manifest.pop
1919
existing_manifest.push("\n #{manifest}\n}")
20-
final_manifest = existing_manifest.join('')
20+
final_manifest = existing_manifest.join
2121
else
2222
final_manifest = "node '#{target_node}' \n{\n #{manifest} \n}"
2323
end

tasks/vagrant.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def generate_vagrantfile(file_path, platform, enable_synced_folder, provider, cp
5454
''
5555
end
5656
vf = <<~VF
57-
Vagrant.configure(\"2\") do |config|
57+
Vagrant.configure("2") do |config|
5858
config.vm.box = '#{platform}'
5959
config.vm.boot_timeout = 600
6060
config.ssh.insert_key = false
@@ -86,7 +86,7 @@ def configure_remoting(platform, remoting_config_path, password)
8686
keys: remoting_config['identityfile'],
8787
password: password,
8888
verbose: :debug
89-
}.reject { |_k, v| v.nil? }
89+
}.compact
9090
Net::SSH.start(
9191
remoting_config['hostname'],
9292
remoting_config['user'],
@@ -213,18 +213,16 @@ def tear_down(node_name, inventory_location)
213213
action = params['action']
214214
node_name = params['node_name']
215215
inventory_location = sanitise_inventory_location(params['inventory'])
216-
enable_synced_folder = params['enable_synced_folder'].nil? ? ENV['VAGRANT_ENABLE_SYNCED_FOLDER'] : params['enable_synced_folder']
217-
if enable_synced_folder.is_a?(String)
218-
enable_synced_folder = enable_synced_folder.casecmp('true').zero? ? true : false
219-
end
220-
provider = params['provider'].nil? ? ENV['VAGRANT_PROVIDER'] : params['provider']
221-
cpus = params['cpus'].nil? ? ENV['VAGRANT_CPUS'] : params['cpus']
222-
memory = params['memory'].nil? ? ENV['VAGRANT_MEMORY'] : params['memory']
223-
hyperv_vswitch = params['hyperv_vswitch'].nil? ? ENV['VAGRANT_HYPERV_VSWITCH'] : params['hyperv_vswitch']
224-
hyperv_smb_username = params['hyperv_smb_username'].nil? ? ENV['VAGRANT_HYPERV_SMB_USERNAME'] : params['hyperv_smb_username']
225-
hyperv_smb_password = params['hyperv_smb_password'].nil? ? ENV['VAGRANT_HYPERV_SMB_PASSWORD'] : params['hyperv_smb_password']
226-
box_url = params['box_url'].nil? ? ENV['VAGRANT_BOX_URL'] : params['box_url']
227-
password = params['password'].nil? ? ENV['VAGRANT_PASSWORD'] : params['password']
216+
enable_synced_folder = params['enable_synced_folder'].nil? ? ENV.fetch('VAGRANT_ENABLE_SYNCED_FOLDER', nil) : params['enable_synced_folder']
217+
enable_synced_folder = enable_synced_folder.casecmp('true').zero? if enable_synced_folder.is_a?(String)
218+
provider = params['provider'].nil? ? ENV.fetch('VAGRANT_PROVIDER', nil) : params['provider']
219+
cpus = params['cpus'].nil? ? ENV.fetch('VAGRANT_CPUS', nil) : params['cpus']
220+
memory = params['memory'].nil? ? ENV.fetch('VAGRANT_MEMORY', nil) : params['memory']
221+
hyperv_vswitch = params['hyperv_vswitch'].nil? ? ENV.fetch('VAGRANT_HYPERV_VSWITCH', nil) : params['hyperv_vswitch']
222+
hyperv_smb_username = params['hyperv_smb_username'].nil? ? ENV.fetch('VAGRANT_HYPERV_SMB_USERNAME', nil) : params['hyperv_smb_username']
223+
hyperv_smb_password = params['hyperv_smb_password'].nil? ? ENV.fetch('VAGRANT_HYPERV_SMB_PASSWORD', nil) : params['hyperv_smb_password']
224+
box_url = params['box_url'].nil? ? ENV.fetch('VAGRANT_BOX_URL', nil) : params['box_url']
225+
password = params['password'].nil? ? ENV.fetch('VAGRANT_PASSWORD', nil) : params['password']
228226
raise 'specify a node_name when tearing down' if action == 'tear_down' && node_name.nil?
229227
raise 'specify a platform when provisioning' if action == 'provision' && platform.nil?
230228

0 commit comments

Comments
 (0)