Skip to content

Commit

Permalink
Updates for Ruby 3
Browse files Browse the repository at this point in the history
* Various fixes for Ruby 3 compatibility
* Update rubocop configuration
* Clean up Gemfile for rubocop
* Update gem dependencies

Closes simp#192
  • Loading branch information
silug committed Oct 18, 2023
1 parent 05cd8d5 commit 1922060
Show file tree
Hide file tree
Showing 14 changed files with 553 additions and 220 deletions.
695 changes: 514 additions & 181 deletions .rubocop.yml

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
gem_sources = ENV.fetch('GEM_SERVERS','https://rubygems.org').split(/[, ]+/)
# frozen_string_literal: true

gem_sources = ENV.fetch('GEM_SERVERS', 'https://rubygems.org').split(%r{[, ]+})

gem_sources.each { |gem_source| source gem_source }

Expand All @@ -9,12 +11,11 @@ gemspec
gem 'bundler'
gem 'facter'
gem 'highline', :path => 'ext/gems/highline'
gem 'puppet', ENV.fetch('PUPPET_VERSION', '~>7')
gem 'rake', '>= 12.3.3'
gem 'puppet', ENV.fetch('PUPPET_VERSION', ['>= 7', '< 9'])
gem 'simp-rake-helpers', ENV['SIMP_RAKE_HELPERS_VERSION'] || ['>= 5.12.1', '< 6']

gem 'r10k', ENV.fetch('R10k_VERSION', '~> 4')
gem 'simp-beaker-helpers', ENV['SIMP_BEAKER_HELPERS_VERSION'] || ['>= 1.28.0', '< 2']
gem 'r10k', ENV.fetch('R10k_VERSION', '~>3')

group :testing do
# to parse YUM repo files in `simp config` test
Expand All @@ -40,6 +41,7 @@ group :development do

gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'rubocop-rspec'
end

Expand All @@ -48,10 +50,10 @@ extra_gemfiles = [
ENV['EXTRA_GEMFILE'] || '',
"#{__FILE__}.project",
"#{__FILE__}.local",
File.join(Dir.home, '.gemfile'),
File.join(Dir.home, '.gemfile')
]
extra_gemfiles.each do |gemfile|
if File.file?(gemfile) && File.readable?(gemfile)
eval(File.read(gemfile), binding)
eval(File.read(gemfile), binding) # rubocop:disable Security/Eval
end
end
12 changes: 6 additions & 6 deletions lib/simp/cli/commands/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def configure_bootstrap_puppetserver
]

conf_files.each do |file|
if File.exists?(file)
if File.exist?(file)
backup_dir = File.join(@bootstrap_backup, File.dirname(file))
FileUtils.mkdir_p(backup_dir)
FileUtils.cp(file, backup_dir)
Expand All @@ -212,7 +212,7 @@ def configure_bootstrap_puppetserver
# /etc/puppetlabs/puppet/auth.conf is installed by some versions of puppet-agent.
# SIMP manages auth.conf in /etc/puppetlabs/puppetserver/conf.d. Back up and
# remove existing /etc/puppetlabs/puppet/auth.conf file.
if File.exists?('/etc/puppetlabs/puppet/auth.conf')
if File.exist?('/etc/puppetlabs/puppet/auth.conf')
FileUtils.rm('/etc/puppetlabs/puppet/auth.conf')
info("Removed /etc/puppetlabs/puppet/auth.conf", 'green')
end
Expand Down Expand Up @@ -325,7 +325,7 @@ def ensure_puppet_agent_stopped
FileUtils.rm_f(agent_run_lockfile)
info("Successfully removed agent lock file #{agent_run_lockfile}", 'green')
else
run_locked = File.exists?(agent_run_lockfile)
run_locked = File.exist?(agent_run_lockfile)
# TODO: make the following spinner a function; it's used in ensure_puppetserver_running as well.
if run_locked
info("Detected puppet agent run lockfile #{agent_run_lockfile}", 'magenta')
Expand All @@ -335,7 +335,7 @@ def ensure_puppet_agent_stopped
stages = ["\\",'|','/','-']
rest = 0.1
while run_locked do
run_locked = File.exists?(agent_run_lockfile)
run_locked = File.exist?(agent_run_lockfile)
stages.each{ |x|
$stdout.flush
print "> #{x}\r"
Expand Down Expand Up @@ -365,7 +365,7 @@ def ensure_puppet_processes_stopped

confdir = Simp::Cli::Utils.puppet_info[:config]['confdir']
routes_yaml = File.join(confdir, 'routes.yaml')
if File.exists?(routes_yaml)
if File.exist?(routes_yaml)
backup_dir = File.join(@bootstrap_backup, confdir)
FileUtils.mkdir_p(backup_dir)
backup_routes_yaml = File.join(backup_dir, 'routes.yaml')
Expand Down Expand Up @@ -677,7 +677,7 @@ def print_intro
def set_up_logger
# Open log file
logfilepath = File.dirname(File.expand_path(@bootstrap_log))
FileUtils.mkpath(logfilepath) unless File.exists?(logfilepath)
FileUtils.mkpath(logfilepath) unless File.exist?(logfilepath)
@logfile = File.open(@bootstrap_log, 'w')
end

Expand Down
2 changes: 1 addition & 1 deletion lib/simp/cli/commands/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(args)

main_page = %x{rpm -ql simp-doc | grep html/index.html$ | head -1}.strip.chomp

unless File.exists?(main_page)
unless File.exist?(main_page)
err_msg = "Could not find the SIMP documentation. Please ensure that you can access '#{main_page}'."
raise Simp::Cli::ProcessingError.new(err_msg)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def apply
@host_yaml = File.join( File.dirname( @template_file ), "#{fqdn}.yaml" )
@applied_status = :failed

if !File.exists?(@template_file) && !File.exists?(@host_yaml) && File.exists?(@alt_file)
if !File.exist?(@template_file) && !File.exist?(@host_yaml) && File.exist?(@alt_file)
# Can get here if
# (1) RPM/ISO install (so /usr/share/simp exists)
# (2) Operator runs simp config more than once but with different hostnames
Expand All @@ -55,8 +55,8 @@ def apply
end
info( "Creating #{File.basename(@host_yaml)} from #{File.basename(@template_file)} template" )

if File.exists?(@template_file)
if File.exists?( @host_yaml )
if File.exist?(@template_file)
if File.exist?( @host_yaml )
diff = `diff #{@host_yaml} #{@template_file}`
if diff.empty?
@applied_status = :succeeded
Expand Down Expand Up @@ -91,7 +91,7 @@ def apply
end
end
else
if File.exists?(@host_yaml)
if File.exist?(@host_yaml)
@applied_status = :unnecessary
@applied_status_detail = "Template already moved to #{File.basename(@host_yaml)}"
message = "#{File.basename(@host_yaml)} creation not required:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def apply

simp_scenario = get_item('cli::simp::scenario').value
site_pp = File.join(@puppet_env_info[:puppet_env_dir], 'manifests', 'site.pp')
if File.exists?(site_pp)
if File.exist?(site_pp)
backup_file = "#{site_pp}.#{@start_time.strftime('%Y%m%dT%H%M%S')}"
info( "Backing up #{site_pp} to #{backup_file}" )
FileUtils.cp(site_pp, backup_file)
Expand Down
2 changes: 1 addition & 1 deletion lib/simp/cli/config/items/data/simp_options_ntp_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_os_value( chronydfile = '/etc/chrony.conf', ntpdfile = '/etc/ntp.conf' )
file = chronydfile
elsif Simp::Cli::Utils.systemctl_running?('ntpd')
file = ntpdfile
elsif File.exists?(chronydfile)
elsif File.exist?(chronydfile)
file = chronydfile
else
file = ntpdfile
Expand Down
5 changes: 3 additions & 2 deletions lib/simp/cli/config/items/yes_no_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def validate( v )
# REJECTED: Override #query_ask using Highline's #agree? *** no, can't bool
def highline_question_type
lambda do |str|
return true if ( str =~ /^(y(es)?|true)$/i ? true : false || str.class == TrueClass )
return false if ( str =~ /^(n(o)?|false)$/i ? true : false || str.class == FalseClass )
return str if str.class == TrueClass || str.class == FalseClass
return true if str.to_s =~ /^(y(es)?|true)$/i
return false if str.to_s =~ /^(n(o)?|false)$/i
nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/simp/cli/environment/puppet_dir_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def puppetfile_generate
f.puts puppetfile_modules.to_puppetfile
end

if File.exists? @puppetfile_path
if File.exist? @puppetfile_path
info "Skipping generation of Puppetfile (to include Puppetfile.simp) in '#{File.dirname(@puppetfile_path)}'".cyan
info '>> File already exists'.cyan
else
Expand Down
13 changes: 5 additions & 8 deletions simp-cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ Gem::Specification.new do |s|
### When the environment variable $SIMP_RPM_BUILD is set, the following
### dependencies will not be included in the .gemspec dependencies:
#### ------------
unless (
ENV.fetch( 'SIMP_RPM_BUILD', false ) || \
ENV.fetch( 'SIMP_CLI_GEMSPEC_NO_PUPPET_VERSION', false ) =~ /yes|true/
)
s.add_runtime_dependency 'puppet', '>= 6.22', '< 8'
unless ['yes', 'true'].intersect?([ENV['SIMP_RPM_BUILD'], ENV['SIMP_CLI_GEMSPEC_NO_PUPPET_VERSION']])
s.add_runtime_dependency 'puppet', '>= 7', '< 9'
end
#### ------------

Expand All @@ -60,9 +57,9 @@ Gem::Specification.new do |s|
s.add_development_dependency 'guard-shell', '~> 0'
s.add_development_dependency 'guard-rspec', '~> 4'
s.add_development_dependency 'pry', '~> 0'
s.add_development_dependency 'pry-doc', '~> 0'
s.add_development_dependency 'dotenv', '~> 1'
s.add_development_dependency 'rubocop', '~> 0.49'
s.add_development_dependency 'pry-doc', '~> 1'
s.add_development_dependency 'dotenv', '~> 2'
s.add_development_dependency 'rubocop', '~> 1'

# simple text description of external requirements (for humans to read)
s.requirements << 'SIMP OS installation'
Expand Down
8 changes: 4 additions & 4 deletions spec/bin/simp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def execute(command, input_file = nil)
# in case we have screwed up our test
Timeout::timeout(30) { Process.wait(pid) }
exitstatus = $?.nil? ? nil : $?.exitstatus
stdout = IO.read(stdout_file) if File.exists?(stdout_file)
stderr = IO.read(stderr_file) if File.exists?(stderr_file)
stdout = IO.read(stdout_file) if File.exist?(stdout_file)
stderr = IO.read(stderr_file) if File.exist?(stderr_file)
{ :exitstatus => exitstatus, :stdout => stdout, :stderr => stderr }
ensure
FileUtils.remove_entry_secure(log_tmp_dir) if log_tmp_dir
Expand All @@ -43,8 +43,8 @@ def execute_and_signal(command, signal_type)
Process.kill(signal_type, pid)
Timeout::timeout(10) { Process.wait(pid) }
exitstatus = $?.nil? ? nil : $?.exitstatus
stdout = IO.read(stdout_file) if File.exists?(stdout_file)
stderr = IO.read(stderr_file) if File.exists?(stderr_file)
stdout = IO.read(stdout_file) if File.exist?(stdout_file)
stderr = IO.read(stderr_file) if File.exist?(stderr_file)
pipe_w.close
{ :exitstatus => exitstatus, :stdout => stdout, :stderr => stderr }
ensure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end

after :each do
FileUtils.chmod 0777, @yaml_file if File.exists?(@yaml_file)
FileUtils.chmod 0777, @yaml_file if File.exist?(@yaml_file)
FileUtils.remove_entry_secure @tmp_dir
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

it 'writes a file' do
@ci.apply
expect( File.exists?( @tmp_file ) ).to be true
expect( File.exist?( @tmp_file ) ).to be true
expect( @ci.applied_status ).to eq :succeeded
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@ci.apply
expect( @ci.applied_status ).to eq :succeeded
dir = File.join( @tmp_dirs[:keydist], @fqdn )
expect( File.exists? dir ).to be true
expect( File.exist? dir ).to be true
end

it 'reports :failed status on failure' do
Expand All @@ -61,7 +61,7 @@
it 'reports :unnecessary status' do
@ci.generate_certificates(@fqdn)
dir = File.join( @tmp_dirs[:keydist], @fqdn )
expect( File.exists? dir ).to be true
expect( File.exist? dir ).to be true
@ci.apply
expect( @ci.applied_status ).to eq :unnecessary
expect(@ci.apply_summary).to match /Interim certificate generation for 'puppet.testing.fqdn' unnecessary:\n Certificates already exist/m
Expand Down Expand Up @@ -108,7 +108,7 @@
end

dir = File.join( @tmp_dirs[:keydist], @fqdn )
expect( File.exists? dir ).to be true
expect( File.exist? dir ).to be true
end
end
end
Expand Down

0 comments on commit 1922060

Please sign in to comment.