Skip to content

Commit

Permalink
rubocop: fix layout cops
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed May 5, 2023
1 parent 18907af commit 1faf326
Show file tree
Hide file tree
Showing 54 changed files with 2,533 additions and 2,427 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ inherit_from: .rubocop_todo.yml

inherit_gem:
voxpupuli-rubocop: rubocop.yml

Layout:
Enabled: false
23 changes: 20 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-05-05 11:59:19 UTC using RuboCop version 1.50.2.
# on 2023-05-05 13:27:13 UTC using RuboCop version 1.50.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -336,10 +336,10 @@ RSpec/EmptyLineAfterHook:
- 'spec/beaker-puppet/helpers/tk_helpers_spec.rb'
- 'spec/beaker-puppet/install_utils/foss_utils_spec.rb'

# Offense count: 130
# Offense count: 138
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 33
Max: 34

# Offense count: 24
# This cop supports safe autocorrection (--autocorrect).
Expand Down Expand Up @@ -694,6 +694,16 @@ Style/IdenticalConditionalBranches:
- 'lib/beaker-puppet/helpers/tk_helpers.rb'
- 'lib/beaker-puppet/install_utils/ezbake_utils.rb'

# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'lib/beaker-puppet/helpers/puppet_helpers.rb'
- 'lib/beaker-puppet/install_utils/foss_utils.rb'
- 'lib/beaker-puppet/install_utils/module_utils.rb'
- 'lib/beaker-puppet/install_utils/puppet5.rb'
- 'lib/beaker-puppet/install_utils/windows_utils.rb'

# Offense count: 18
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/LineEndConcatenation:
Expand Down Expand Up @@ -823,3 +833,10 @@ Style/ZeroLengthPredicate:
Exclude:
- 'lib/beaker-puppet/helpers/puppet_helpers.rb'
- 'lib/beaker-puppet/install_utils/foss_utils.rb'

# Offense count: 121
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 428
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ group :release do
gem 'github_changelog_generator', require: false
end

group :coverage, optional: ENV['COVERAGE']!='yes' do
group :coverage, optional: ENV['COVERAGE'] != 'yes' do
gem 'codecov', require: false
gem 'simplecov-console', require: false
end
65 changes: 29 additions & 36 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ require 'rspec/core/rake_task'
require 'securerandom'
require 'beaker-hostgenerator'


namespace :test do

namespace :spec do

desc 'Run spec tests'
RSpec::Core::RakeTask.new(:run) do |t|
t.rspec_opts = ['--color']
Expand All @@ -19,47 +16,46 @@ namespace :test do
t.rspec_opts = ['--color']
t.pattern = 'spec/'
end

end

namespace :acceptance do
USAGE = <<-EOS
You may set BEAKER_HOSTS=config/nodes/foo.yaml or include it in an acceptance-options.rb for Beaker,
or specify TEST_TARGET in a form beaker-hostgenerator accepts, e.g. ubuntu1504-64a.
You may override the default master test target by specifying MASTER_TEST_TARGET.
You may set TESTS=path/to/test,and/more/tests.
You may set additional Beaker OPTIONS='--more --options'
If there is a Beaker options hash in a ./acceptance/local_options.rb, it will be included.
Commandline options set through the above environment variables will override settings in this file.
USAGE = <<~EOS
You may set BEAKER_HOSTS=config/nodes/foo.yaml or include it in an acceptance-options.rb for Beaker,
or specify TEST_TARGET in a form beaker-hostgenerator accepts, e.g. ubuntu1504-64a.
You may override the default master test target by specifying MASTER_TEST_TARGET.
You may set TESTS=path/to/test,and/more/tests.
You may set additional Beaker OPTIONS='--more --options'
If there is a Beaker options hash in a ./acceptance/local_options.rb, it will be included.
Commandline options set through the above environment variables will override settings in this file.
EOS

desc <<-EOS
Run the puppet beaker acceptance tests on a puppet gem install.
#{USAGE}
desc <<~EOS
Run the puppet beaker acceptance tests on a puppet gem install.
#{USAGE}
EOS
task gem: 'gen_hosts' do
beaker_test(:gem)
end

desc <<-EOS
Run the puppet beaker acceptance tests on a puppet git install.
#{USAGE}
desc <<~EOS
Run the puppet beaker acceptance tests on a puppet git install.
#{USAGE}
EOS
task git: 'gen_hosts' do
beaker_test(:git)
end

desc <<-EOS
Run the puppet beaker acceptance tests on a puppet package install.
#{USAGE}
desc <<~EOS
Run the puppet beaker acceptance tests on a puppet package install.
#{USAGE}
EOS
task pkg: 'gen_hosts' do
beaker_test(:pkg)
end

desc <<-EOS
Run the puppet beaker acceptance tests on a base system (no install).
#{USAGE}
desc <<~EOS
Run the puppet beaker acceptance tests on a base system (no install).
#{USAGE}
EOS
task base: 'gen_hosts' do
beaker_test
Expand All @@ -68,20 +64,21 @@ Run the puppet beaker acceptance tests on a base system (no install).
desc 'Generate Beaker Host Config File'
task :gen_hosts do
next if hosts_file_env

cli = BeakerHostGenerator::CLI.new([test_targets])
FileUtils.mkdir_p('tmp') # -p ignores when dir already exists
File.open("tmp/#{HOSTS_FILE}", 'w') do |fh|
fh.print(cli.execute)
end
end

def hosts_opt(use_preserved_hosts=false)
def hosts_opt(use_preserved_hosts = false)
if use_preserved_hosts
"--hosts=#{HOSTS_PRESERVED}"
elsif hosts_file_env
"--hosts=#{hosts_file_env}"
else
"--hosts=tmp/#{HOSTS_FILE}"
else
"--hosts=tmp/#{HOSTS_FILE}"
end
end

Expand All @@ -102,24 +99,23 @@ Run the puppet beaker acceptance tests on a base system (no install).
end

HOSTS_FILE = "#{test_targets}-#{SecureRandom.uuid}.yaml"
HOSTS_PRESERVED = 'log/latest/hosts_preserved.yml'
HOSTS_PRESERVED = 'log/latest/hosts_preserved.yml'

def beaker_test(mode = :base, options = {})

preserved_hosts_mode = options[:hosts] == HOSTS_PRESERVED
final_options = HarnessOptions.final_options(mode, options)

options_opt = ''
options_opt = ''
# preserved hosts can not be used with an options file (BKR-670)
# one can still use OPTIONS

unless preserved_hosts_mode
options_file = 'merged_options.rb'
options_opt = "--options-file=#{options_file}"
File.open(options_file, 'w') do |merged|
merged.puts <<-EOS
# Copy this file to local_options.rb and adjust as needed if you wish to run
# with some local overrides.
merged.puts <<~EOS
# Copy this file to local_options.rb and adjust as needed if you wish to run
# with some local overrides.
EOS
merged.puts(final_options)
end
Expand Down Expand Up @@ -171,11 +167,8 @@ Run the puppet beaker acceptance tests on a base system (no install).
final_options.merge!(intermediary_options)
final_options.merge!(local_overrides)
end

end

end

end

# namespace-named default tasks.
Expand Down
14 changes: 7 additions & 7 deletions acceptance/config/gem/acceptance-options.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
type: 'foss',
add_el_extras: 'true',
is_puppetserver: false,
puppetservice: 'puppet.service',
pre_suite: 'acceptance/pre_suite/gem/install.rb',
tests: 'acceptance/tests',
'master-start-curl-retries': 30,
type: 'foss',
add_el_extras: 'true',
is_puppetserver: false,
puppetservice: 'puppet.service',
pre_suite: 'acceptance/pre_suite/gem/install.rb',
tests: 'acceptance/tests',
'master-start-curl-retries': 30,
}.merge(eval(File.read('acceptance/config/acceptance-options.rb')))
14 changes: 7 additions & 7 deletions acceptance/config/git/acceptance-options.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
type: 'foss',
add_el_extras: 'true',
is_puppetserver: false,
puppetservice: 'puppet.service',
pre_suite: 'acceptance/pre_suite/git/install.rb',
tests: 'acceptance/tests',
'master-start-curl-retries': 30,
type: 'foss',
add_el_extras: 'true',
is_puppetserver: false,
puppetservice: 'puppet.service',
pre_suite: 'acceptance/pre_suite/git/install.rb',
tests: 'acceptance/tests',
'master-start-curl-retries': 30,
}.merge(eval(File.read('acceptance/config/acceptance-options.rb')))
12 changes: 6 additions & 6 deletions acceptance/config/pkg/acceptance-options.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
type: 'foss',
is_puppetserver: false,
puppetservice: 'puppet.service',
pre_suite: 'acceptance/pre_suite/pkg/install.rb',
tests: 'acceptance/tests',
'master-start-curl-retries': 30,
type: 'foss',
is_puppetserver: false,
puppetservice: 'puppet.service',
pre_suite: 'acceptance/pre_suite/pkg/install.rb',
tests: 'acceptance/tests',
'master-start-curl-retries': 30,
}.merge(eval(File.read('acceptance/config/acceptance-options.rb')))
5 changes: 3 additions & 2 deletions acceptance/pre_suite/gem/install.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'beaker-puppet'

hosts.each do |host|
install_puppet_from_gem(host, {version: '3.8.7'})
install_puppet_from_gem(host, { version: '3.8.7' })
next if host['platform'] =~ /windows/
on(host, "touch #{File.join(host.puppet['confdir'],'puppet.conf')}")

on(host, "touch #{File.join(host.puppet['confdir'], 'puppet.conf')}")
on(host, puppet('resource user puppet ensure=present'))
on(host, puppet('resource group puppet ensure=present'))
end
5 changes: 3 additions & 2 deletions acceptance/pre_suite/git/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
windows: [
'git',
# there isn't a need for json on windows because it is bundled in ruby 1.9
# there isn't a need for json on windows because it is bundled in ruby 1.9
],
sles: [
'git-core',
Expand Down Expand Up @@ -86,7 +86,8 @@
install_from_git(host, SourcePath, repo)
end
next if host['platform'] =~ /windows/
on(host, "touch #{File.join(host.puppet['confdir'],'puppet.conf')}")

on(host, "touch #{File.join(host.puppet['confdir'], 'puppet.conf')}")
on(host, puppet('resource user puppet ensure=present'))
on(host, puppet('resource group puppet ensure=present'))
end
6 changes: 3 additions & 3 deletions acceptance/pre_suite/pkg/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# all versions are required for osx
hosts.each do |host|
install_puppet_on(host, {
version: ENV['BEAKER_PUPPET_VERSION'] || '5.5.20',
puppet_agent_version: ENV['BEAKER_PUPPET_AGENT_VERSION'] || '5.5.20',
})
version: ENV['BEAKER_PUPPET_VERSION'] || '5.5.20',
puppet_agent_version: ENV['BEAKER_PUPPET_AGENT_VERSION'] || '5.5.20',
})

on(host, puppet('resource user puppet ensure=present'))
on(host, puppet('resource group puppet ensure=present'))
Expand Down
13 changes: 6 additions & 7 deletions acceptance/tests/backwards_compatible.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
test_name 'backwards compatible test' do

step 'calls the new FOSSUtils even if I require & include the old path' do
require 'beaker/dsl/install_utils/foss_utils'
assert( !Beaker::DSL::InstallUtils::FOSSUtils::SourcePath.nil? )
assert( Beaker::DSL::InstallUtils::FOSSUtils.method_defined?(:lookup_in_env) )
assert(!Beaker::DSL::InstallUtils::FOSSUtils::SourcePath.nil?)
assert(Beaker::DSL::InstallUtils::FOSSUtils.method_defined?(:lookup_in_env))
end

step 'require old Helpers path, get helpers from new location' do
require 'beaker/dsl/helpers/puppet_helpers'
assert( Beaker::DSL::Helpers::PuppetHelpers.method_defined?(:puppet_user) )
assert( Beaker::DSL::Helpers::PuppetHelpers.method_defined?(:resolve_hostname_on) )
assert(Beaker::DSL::Helpers::PuppetHelpers.method_defined?(:puppet_user))
assert(Beaker::DSL::Helpers::PuppetHelpers.method_defined?(:resolve_hostname_on))
end

step 'require old Helpers module, get from new location' do
require 'beaker/dsl/helpers'
assert( Beaker::DSL::Helpers.is_a?( Module ) )
assert(Beaker::DSL::Helpers.is_a?(Module))
end
end
end
4 changes: 1 addition & 3 deletions acceptance/tests/clone_git_repo_on_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
confine :except, platform: /^solaris-10/

test_name 'Clone from git' do

PACKAGES = {
redhat: [
'git',
Expand All @@ -27,7 +26,6 @@
],
}


install_packages_on(hosts, PACKAGES, check_if_exists: true)

# implicitly tests build_giturl() and lookup_in_env()
Expand All @@ -38,7 +36,7 @@
step 'should be able to successfully clone a git repo' do
results = clone_git_repo_on(host, "#{testdir}", extract_repo_info_from(build_git_url('hiera')))

assert_match( %r{From.*github\.com[:/]puppetlabs/hiera}, result.output, 'Did not find clone')
assert_match(%r{From.*github\.com[:/]puppetlabs/hiera}, result.output, 'Did not find clone')
end
end
end
2 changes: 1 addition & 1 deletion acceptance/tests/install_smoke_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

hosts.each do |host|
assert(!host.puppet['server'].empty?, 'can get a configprint of the puppet server setting')
end
end
7 changes: 4 additions & 3 deletions acceptance/tests/stub_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ def get_hosts_file(host)
'C:\\\\Windows\\\\System32\\\\Drivers\\\\etc\\\\hosts'
else
'/etc/hosts'
end

end
end

step 'verify stub_host_on' do
Expand All @@ -34,7 +33,9 @@ def get_hosts_file(host)
step 'should add entry to hosts file' do
hosts.each do |host|
hosts_file = get_hosts_file(host)
result = with_host_stubbed_on(host, { 'sleepy' => '1.1.1.2' }, { 'sleepy' => %w[grumpy dopey] }) { on host, "cat #{hosts_file}" }
result = with_host_stubbed_on(host, { 'sleepy' => '1.1.1.2' }, { 'sleepy' => %w[grumpy dopey] }) do
on host, "cat #{hosts_file}"
end
assert_match(/sleepy/, result.stdout)
end
end
Expand Down
Loading

0 comments on commit 1faf326

Please sign in to comment.