Skip to content

Commit 1d1a3c2

Browse files
author
Ciprian Badescu
committed
(MODULES-11244) rubocop fixes
1 parent 9cd56b8 commit 1d1a3c2

40 files changed

+2070
-1900
lines changed

acceptance/helpers.rb

+349-355
Large diffs are not rendered by default.

acceptance/options.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
'use-service': true,
1111
'puppetservice': 'puppetserver',
1212
'puppetserver-confdir': '/etc/puppetlabs/puppetserver/conf.d',
13-
'puppetserver-config':'/etc/puppetlabs/puppetserver/conf.d/puppetserver.conf'
13+
'puppetserver-config': '/etc/puppetlabs/puppetserver/conf.d/puppetserver.conf'
1414
}

acceptance/pre_suite/00_master_setup.rb

+10-11
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
step 'Install puppetserver' do
3232
# puppetserver is distributed in "release streams" instead of collections.
33-
if install_options[:puppet_collection] =~ /^pc1$/i
34-
# There is no release stream that's equivalent to the PC1 (puppet-agent
35-
# 1.y.z/puppet 4) collection; This version is fine.
36-
opts = { version: '2.8.1' }
37-
else
38-
# puppet collections _do_ match with server release streams from puppet 5 onward.
39-
opts = { release_stream: install_options[:puppet_collection] }
40-
end
33+
opts = if %r{^pc1$}i.match?(install_options[:puppet_collection])
34+
# There is no release stream that's equivalent to the PC1 (puppet-agent
35+
# 1.y.z/puppet 4) collection; This version is fine.
36+
{ version: '2.8.1' }
37+
else
38+
# puppet collections _do_ match with server release streams from puppet 5 onward.
39+
{ release_stream: install_options[:puppet_collection] }
40+
end
4141

4242
install_puppetserver_on(master, opts)
4343

@@ -54,12 +54,12 @@
5454
'dns_alt_names' => "puppet,#{master_hostname},#{master_fqdn}",
5555
'server' => master_fqdn,
5656
'verbose' => true,
57-
}}
57+
} }
5858

5959
lay_down_new_puppet_conf(master, puppet_conf, create_tmpdir_on(master))
6060

6161
unless version_is_less(server_version, '6.0.0')
62-
tk_config = { 'certificate-authority' => { 'allow-subject-alt-names' => true }}
62+
tk_config = { 'certificate-authority' => { 'allow-subject-alt-names' => true } }
6363
path = '/etc/puppetlabs/puppetserver/conf.d/puppetserver.conf'
6464
modify_tk_config(master, path, tk_config)
6565
end
@@ -73,7 +73,6 @@
7373
# will not work when installing the old version of agents.
7474
end
7575

76-
7776
step 'Start puppetserver' do
7877
on(master, puppet('resource', 'service', master['puppetservice'], 'ensure=running', 'enable=true'))
7978
end

acceptance/tests/test_upgrade_puppet5_to_puppet6.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
puppet_testing_environment = new_puppet_testing_environment
1212

13-
step "Create new site.pp with upgrade manifest" do
13+
step 'Create new site.pp with upgrade manifest' do
1414
manifest = <<-PP
1515
node default {
1616
if $::osfamily =~ /^(?i:windows|solaris|aix|darwin)$/ {
@@ -39,22 +39,22 @@ class { puppet_agent:
3939
set_up_initial_agent_on(agent, 'puppet5') do
4040
step '(Agent) Change agent environment to testing environment' do
4141
on(agent, puppet("config --section agent set environment #{puppet_testing_environment}"))
42-
on(agent, puppet("config --section user set environment production"))
42+
on(agent, puppet('config --section user set environment production'))
4343
end
4444
end
4545
end
4646

47-
step "Upgrade the agents from Puppet 5 to Puppet 6..." do
47+
step 'Upgrade the agents from Puppet 5 to Puppet 6...' do
4848
agents_only.each do |agent|
49-
on(agent, puppet("agent -t --debug"), acceptable_exit_codes: 2)
49+
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 2)
5050
wait_for_installation_pid(agent)
51-
assert_agent_version_on(agent, latest_version.scan(/6\.\d*\.\d*\.\d*/).first)
51+
assert_agent_version_on(agent, latest_version.scan(%r{6\.\d*\.\d*\.\d*}).first)
5252
end
5353
end
5454

55-
step "Run again for idempotency" do
55+
step 'Run again for idempotency' do
5656
agents_only.each do |agent|
57-
on(agent, puppet("agent -t --debug"), acceptable_exit_codes: 0)
57+
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 0)
5858
end
5959
end
6060
end

acceptance/tests/test_upgrade_puppet6_to_puppet7.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
require_master_collection 'puppet7-nightly'
88
exclude_pe_upgrade_platforms
99
latest_version = `curl http://builds.delivery.puppetlabs.net/passing-agent-SHAs/puppet-agent-main-version`
10-
10+
1111
puppet_testing_environment = new_puppet_testing_environment
1212

13-
step "Create new site.pp with upgrade manifest" do
13+
step 'Create new site.pp with upgrade manifest' do
1414
manifest = <<-PP
1515
node default {
1616
if $::osfamily =~ /^(?i:windows|solaris|aix|darwin)$/ {
@@ -40,22 +40,22 @@ class { puppet_agent:
4040
set_up_initial_agent_on(agent, 'puppet6-nightly') do
4141
step '(Agent) Change agent environment to testing environment' do
4242
on(agent, puppet("config --section agent set environment #{puppet_testing_environment}"))
43-
on(agent, puppet("config --section user set environment production"))
43+
on(agent, puppet('config --section user set environment production'))
4444
end
4545
end
4646
end
4747

48-
step "Upgrade the agents from Puppet 6 to Puppet 7..." do
48+
step 'Upgrade the agents from Puppet 6 to Puppet 7...' do
4949
agents_only.each do |agent|
50-
on(agent, puppet("agent -t --debug"), acceptable_exit_codes: 2)
50+
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 2)
5151
wait_for_installation_pid(agent)
52-
assert_agent_version_on(agent, latest_version.scan(/7\.\d*\.\d*\.\d*/).first)
52+
assert_agent_version_on(agent, latest_version.scan(%r{7\.\d*\.\d*\.\d*}).first)
5353
end
5454
end
5555

56-
step "Run again for idempotency" do
56+
step 'Run again for idempotency' do
5757
agents_only.each do |agent|
58-
on(agent, puppet("agent -t --debug"), acceptable_exit_codes: 0)
58+
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 0)
5959
end
6060
end
6161
end

files/rb_task_helper.rb

+52-53
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,59 @@
11
# frozen_string_literal: true
22

3-
module PuppetAgent
4-
module RbTaskHelper
5-
private
6-
7-
def error_result(error_type, error_message)
8-
{
9-
'_error' => {
10-
'msg' => error_message,
11-
'kind' => error_type,
12-
'details' => {},
13-
},
14-
}
15-
end
16-
17-
def puppet_bin_present?
18-
File.exist?(puppet_bin)
19-
end
20-
21-
# Returns the path to the Puppet agent executable
22-
def puppet_bin
23-
@puppet_bin ||= if Puppet.features.microsoft_windows?
24-
puppet_bin_windows
25-
else
26-
'/opt/puppetlabs/bin/puppet'
27-
end
28-
end
29-
30-
# Returns the path to the Puppet agent executable on Windows
31-
def puppet_bin_windows
32-
require 'win32/registry'
33-
34-
install_dir = begin
35-
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg|
36-
# Rescue missing key
37-
dir = begin
38-
reg['RememberedInstallDir64']
39-
rescue StandardError
40-
''
41-
end
42-
# Both keys may exist, make sure the dir exists
43-
break dir if File.exist?(dir)
44-
45-
# Rescue missing key
46-
begin
47-
reg['RememberedInstallDir']
48-
rescue StandardError
49-
''
50-
end
3+
# Puppet Agent task helper
4+
module PuppetAgent::RbTaskHelper
5+
private
6+
7+
def error_result(error_type, error_message)
8+
{
9+
'_error' => {
10+
'msg' => error_message,
11+
'kind' => error_type,
12+
'details' => {},
13+
},
14+
}
15+
end
16+
17+
def puppet_bin_present?
18+
File.exist?(puppet_bin)
19+
end
20+
21+
# Returns the path to the Puppet agent executable
22+
def puppet_bin
23+
@puppet_bin ||= if Puppet.features.microsoft_windows?
24+
puppet_bin_windows
25+
else
26+
'/opt/puppetlabs/bin/puppet'
27+
end
28+
end
29+
30+
# Returns the path to the Puppet agent executable on Windows
31+
def puppet_bin_windows
32+
require 'win32/registry'
33+
34+
install_dir = begin
35+
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg|
36+
# Rescue missing key
37+
dir = begin
38+
reg['RememberedInstallDir64']
39+
rescue StandardError
40+
''
41+
end
42+
# Both keys may exist, make sure the dir exists
43+
break dir if File.exist?(dir)
44+
45+
# Rescue missing key
46+
begin
47+
reg['RememberedInstallDir']
48+
rescue StandardError
49+
''
5150
end
52-
rescue Win32::Registry::Error
53-
# Rescue missing registry path
54-
''
5551
end
52+
rescue Win32::Registry::Error
53+
# Rescue missing registry path
54+
''
55+
end
5656

57-
File.join(install_dir, 'bin', 'puppet.bat')
58-
end
57+
File.join(install_dir, 'bin', 'puppet.bat')
5958
end
6059
end

lib/facter/mco_config.rb

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Facter.add("mco_#{node}_config") do
33
setcode do
44
config = nil
5-
if Facter.fact(:kernel).value =~ %r{windows}i
6-
config_dir = File.expand_path(File.join(Puppet.settings['confdir'],'../../mcollective/etc'))
5+
if %r{windows}i.match?(Facter.fact(:kernel).value)
6+
config_dir = File.expand_path(File.join(Puppet.settings['confdir'], '../../mcollective/etc'))
77
locations = ["#{config_dir}/#{node}.cfg"]
88
else
99
locations = ["/etc/puppetlabs/mcollective/#{node}.cfg", "/etc/mcollective/#{node}.cfg"]
@@ -21,16 +21,13 @@
2121
setcode do
2222
settings = nil
2323
config = Facter.fact("mco_#{node}_config".to_sym)
24-
if config and config.value
24+
if config&.value
2525
settings = {}
2626

27-
File.readlines(config.value).select {|v|
28-
v.lstrip =~ %r{[^#].+=.+}
29-
}.map {|x|
30-
x.split('=', 2).map {|s| s.strip}
31-
}.select {|k, v|
32-
k == 'libdir' || k == 'plugin.yaml'
33-
}.each do |k, v|
27+
File.readlines(config.value).select { |v| v.lstrip =~ %r{[^#].+=.+} }
28+
.map { |x| x.split('=', 2).map { |s| s.strip } }
29+
.select { |k, _v| ['libdir', 'plugin.yaml'].include?(k) }
30+
.each do |k, v|
3431
if settings[k]
3532
settings[k] += ':' + v
3633
else

lib/facter/puppet_agent_appdata.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Facter.add(:puppet_agent_appdata) do
22
setcode do
3-
if Dir.const_defined? 'COMMON_APPDATA' then
4-
Dir::COMMON_APPDATA.gsub(%r{\\\s}, " ").tr('/', '\\')
5-
elsif not ENV['ProgramData'].nil?
6-
ENV['ProgramData'].gsub(%r{\\\s}, " ").tr('/', '\\')
3+
if Dir.const_defined? 'COMMON_APPDATA'
4+
Dir::COMMON_APPDATA.gsub(%r{\\\s}, ' ').tr('/', '\\')
5+
elsif !ENV['ProgramData'].nil?
6+
ENV['ProgramData'].gsub(%r{\\\s}, ' ').tr('/', '\\')
77
end
88
end
99
end

lib/facter/settings.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
path = Puppet.settings[setting]
3333
exists = File.exist? path
3434
result[setting] = {
35-
'path' => path,
36-
'path_exists' => exists,
35+
'path' => path,
36+
'path_exists' => exists,
3737
}
3838
end
3939
result
@@ -70,6 +70,6 @@
7070

7171
Facter.add('mco_confdir') do
7272
setcode do
73-
File.expand_path(File.join(Puppet.settings['confdir'],'../../mcollective/etc'))
73+
File.expand_path(File.join(Puppet.settings['confdir'], '../../mcollective/etc'))
7474
end
7575
end

lib/puppet/functions/any_resources_of_type.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Puppet::Functions.create_function(:any_resources_of_type, Puppet::Functions::InternalFunction) do
1+
Puppet::Functions.create_function(:any_resources_of_type, Puppet::Functions::InternalFunction) do
22
dispatch :any_resources_of_type do
33
scope_param
44

@@ -22,4 +22,3 @@ def any_resources_of_type(scope, resource_type, parameters = nil)
2222
end
2323
end
2424
end
25-
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
require 'uri'
22

33
module Puppet::Parser::Functions
4-
newfunction(:uri_host_from_string, :arity => 1, :type => :rvalue, :doc => <<-EOS
4+
newfunction(:uri_host_from_string, arity: 1, type: :rvalue, doc: <<-EOS
55
Return a uri host from a string
66
EOS
77
) do |args|
8-
98
uri = URI(args[0])
109

1110
return uri.host
1211
end
1312
end
14-

lib/puppet/parser/functions/windows_msi_installargs.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module Puppet::Parser::Functions
2-
newfunction(:windows_msi_installargs, :arity => 1, :type => :rvalue, :doc => <<-EOS
2+
newfunction(:windows_msi_installargs, arity: 1, type: :rvalue, doc: <<-EOS
33
Return the $install_options parameter as a string usable in an msiexec command
44
EOS
55
) do |args|
6-
76
install_args = args[0]
87

98
arg_string = install_args.map do |option|
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module Puppet::Parser::Functions
2-
newfunction(:windows_native_path, :arity => 1, :type => :rvalue, :doc => <<-EOS
2+
newfunction(:windows_native_path, arity: 1, type: :rvalue, doc: <<-EOS
33
Return a windows native path
44
EOS
55
) do |args|
6-
76
path = args[0]
87

9-
return path.gsub(%r{\/\s}, ' ').tr('/', "\\")
8+
return path.gsub(%r{\/\s}, ' ').tr('/', '\\')
109
end
1110
end

lib/puppet/provider/puppet_agent_end_run/puppet_agent_end_run.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ def end_run
44
end
55

66
def stop
7-
if needs_upgrade?
8-
run_mode = Puppet.run_mode.name
7+
return unless needs_upgrade?
98

10-
# Handle CLI runs of `puppet agent` and `apply`
11-
if Puppet[:onetime] || run_mode != :agent
12-
Puppet.notice("Stopping run after puppet-agent upgrade. Run puppet agent -t or apply your manifest again to finish the transaction.")
13-
end
9+
run_mode = Puppet.run_mode.name
1410

15-
Puppet::Application.stop!
16-
17-
# Sending the HUP signal to the daemon causes it to restart and finish applying the catalog
18-
if Puppet[:daemonize] && run_mode == :agent
19-
at_exit { Process.kill(:HUP, Process.pid) }
20-
end
11+
# Handle CLI runs of `puppet agent` and `apply`
12+
if Puppet[:onetime] || run_mode != :agent
13+
Puppet.notice('Stopping run after puppet-agent upgrade. Run puppet agent -t or apply your manifest again to finish the transaction.')
2114
end
15+
16+
Puppet::Application.stop!
17+
18+
# Sending the HUP signal to the daemon causes it to restart and finish applying the catalog
19+
return unless Puppet[:daemonize] && run_mode == :agent
20+
21+
at_exit { Process.kill(:HUP, Process.pid) }
2222
end
2323

2424
private

0 commit comments

Comments
 (0)