Skip to content

Commit 36291db

Browse files
authored
Ruby 3 support (#288)
* Support stdlib 9 * Update gem dependencies
1 parent bcbb098 commit 36291db

12 files changed

Lines changed: 77 additions & 60 deletions

File tree

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Mon Aug 28 2023 Steven Pritchard <steve@sicura.us> - 4.12.0
2+
- Fixed
3+
- Ruby 3 support
4+
- puppetlabs-stdlib 9 support
5+
- Updated gem dependencies
6+
17
* Mon Jun 12 2023 Chris Tessmer <chris.tessmer@onyxpoint.com> - 4.11.0
28
- Add RockyLinux 8 support
39

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ENV['PDK_DISABLE_ANALYTICS'] ||= 'true'
1111
gem_sources.each { |gem_source| source gem_source }
1212

1313
group :test do
14-
puppet_version = ENV['PUPPET_VERSION'] || '~> 7'
14+
puppet_version = ENV['PUPPET_VERSION'] || '~> 8'
1515
major_puppet_version = puppet_version.scan(/(\d+)(?:\.|\Z)/).flatten.first.to_i
1616
gem 'rake'
1717
gem 'puppet', puppet_version
@@ -24,8 +24,8 @@ group :test do
2424
gem 'puppet-lint-trailing_comma-check', :require => false
2525
gem 'simp-rspec-puppet-facts', ENV['SIMP_RSPEC_PUPPET_FACTS_VERSION'] || '~> 3.1'
2626
gem 'simp-rake-helpers', ENV['SIMP_RAKE_HELPERS_VERSION'] || ['>= 5.12.1', '< 6']
27-
gem( 'pdk', ENV['PDK_VERSION'] || '~> 2.0', :require => false) if major_puppet_version > 5
28-
gem 'pathspec', '~> 0.2' if Gem::Requirement.create('< 2.6').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
27+
gem( 'pdk', ENV['PDK_VERSION'] || ['>= 2.0', '<= 4.0'], :require => false) if major_puppet_version > 5
28+
gem 'pathspec', '~> 1.0' if Gem::Requirement.create('< 2.6').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
2929
end
3030

3131
group :development do

lib/facter/ipa.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
# We won't know if we are connected to a server until later
7070
defaults['connected'] = false
7171

72-
Facter::Core::Execution.execute("#{klist} -s")
73-
unless $?.success?
72+
klist_retval = Puppet::Util::Execution.execute("#{klist} -s")
73+
unless klist_retval.exitstatus.zero?
7474
# Obtain host Kerberos token so we can use IPA API
7575
kinit_msg = Facter::Core::Execution.execute("#{kinit} -k 2>&1", options = {:timeout => kinit_timeout})
7676
end
@@ -101,5 +101,7 @@
101101
end
102102

103103
defaults.merge(ipa_response)
104+
rescue => e
105+
Facter.warn(e)
104106
end
105107
end

lib/facter/simplib__networkmanager.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
nmcli_cmd = @nmcli_cmd + ' -t'
1111

12-
general_status = Facter::Core::Execution.execute(%(#{nmcli_cmd} -m multiline general status))
12+
general_status = Puppet::Util::Execution.execute(%(#{nmcli_cmd} -m multiline general status))
1313

14-
if $?.success?
14+
if general_status.exitstatus.zero?
1515
general_status = general_status.lines.map{|line| line.strip.split(':') }
1616

1717
info['enabled'] = true
@@ -22,17 +22,17 @@
2222
}
2323
end
2424

25-
general_hostname = Facter::Core::Execution.execute(%{#{nmcli_cmd} general hostname})
25+
general_hostname = Puppet::Util::Execution.execute(%{#{nmcli_cmd} general hostname})
2626

27-
if $?.success?
27+
if general_hostname.exitstatus.zero?
2828
info['enabled'] = true
2929
info['general'] ||= {}
3030
info['general']['hostname'] = general_hostname.strip
3131
end
3232

33-
connections = Facter::Core::Execution.execute(%(#{nmcli_cmd} connection show))
33+
connections = Puppet::Util::Execution.execute(%(#{nmcli_cmd} connection show))
3434

35-
if $?.success?
35+
if connections.exitstatus.zero?
3636
info['enabled'] = true
3737
info['connection'] = {}
3838

@@ -48,5 +48,7 @@
4848
end
4949

5050
info
51+
rescue => e
52+
Facter.warn(e)
5153
end
5254
end

lib/puppet/functions/simplib/debug/inspect.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def inspect(scope, to_inspect, print=true)
2222
data = {
2323
:type => to_inspect.class,
24-
:content => to_inspect.to_pson
24+
:content => to_inspect.to_json
2525
}
2626

2727
if scope

lib/puppet/functions/simplib/passgen/legacy/passgen.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def passgen(identifier, modifier_hash={})
107107

108108
unless File.directory?(settings['keydir'])
109109
begin
110-
FileUtils.mkdir_p(settings['keydir'],{:mode => 0750})
110+
FileUtils.mkdir_p(settings['keydir'], mode: 0750)
111111
# This chown is applicable as long as it is applied
112112
# by puppet, not puppetserver.
113113
FileUtils.chown(settings['user'],
@@ -294,15 +294,15 @@ def get_current_password(identifier, options, settings)
294294
# 'password' in options or had to generate a password.
295295
def get_last_password(identifier, options, settings)
296296
toread = nil
297-
if File.exists?("#{settings['keydir']}/#{identifier}.last")
297+
if File.exist?("#{settings['keydir']}/#{identifier}.last")
298298
toread = "#{settings['keydir']}/#{identifier}.last"
299299
else
300300
toread = "#{settings['keydir']}/#{identifier}"
301301
end
302302

303303
passwd = ''
304304
salt = ''
305-
if File.exists?(toread)
305+
if File.exist?(toread)
306306
passwd = IO.readlines(toread)[0].to_s.chomp
307307
sf = "#{File.dirname(toread)}/#{File.basename(toread,'.last')}.salt.last"
308308
saltfile = File.open(sf,'a+',0640)

lib/puppet/functions/simplib/passgen/legacy/set.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def move_files(files, source_prefix, dest_prefix)
8585
FileUtils.mv(files["#{source_prefix}password"], files["#{dest_prefix}password"],
8686
:force => true)
8787

88-
if File.exists?(files["#{source_prefix}salt"])
88+
if File.exist?(files["#{source_prefix}salt"])
8989
FileUtils.mv(files["#{source_prefix}salt"], files["#{dest_prefix}salt"],
9090
:force => true)
9191
else
@@ -104,7 +104,7 @@ def set_password_info(settings, identifier, password, salt)
104104
# @raise RuntimeError if fails to create or set permissions on keydir
105105
def set_up_keydir(settings)
106106
begin
107-
FileUtils.mkdir_p(settings['keydir'], {:mode => settings['dir_mode']})
107+
FileUtils.mkdir_p(settings['keydir'], mode: settings['dir_mode'])
108108
FileUtils.chown(settings['user'], settings['group'], settings['keydir'])
109109
rescue SystemCallError => e
110110
err_msg = "simplib::passgen::legacy::set: Could not make directory" +

metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simp-simplib",
3-
"version": "4.11.0",
3+
"version": "4.12.0",
44
"author": "SIMP Team",
55
"summary": "A collection of common SIMP functions, facts, and types",
66
"license": "Apache-2.0",
@@ -18,7 +18,7 @@
1818
"dependencies": [
1919
{
2020
"name": "puppetlabs/stdlib",
21-
"version_requirement": ">= 8.0.0 < 9.0.0"
21+
"version_requirement": ">= 8.0.0 < 10.0.0"
2222
},
2323
{
2424
"name": "simp/simpkv",
@@ -96,7 +96,7 @@
9696
"requirements": [
9797
{
9898
"name": "puppet",
99-
"version_requirement": ">= 6.22.1 < 8.0.0"
99+
"version_requirement": ">= 7.0.0 < 9.0.0"
100100
}
101101
],
102102
"package_release_version": "0"

spec/functions/simplib/gen_random_password_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
# This test is timing sensitive. It may not fail if the test machine
6565
# processes faster than the dev machine.
6666
it 'raises timeout error if password cannot be generated in specified interval' do
67-
is_expected.to run.with_params(10**20, 2, false, 0.01).and_raise_error(TimeoutError)
67+
is_expected.to run.with_params(10**20, 2, false, 0.01).and_raise_error(Timeout::Error)
6868
end
6969

7070
it 'fails if length is outside of specified range' do

spec/functions/simplib/validate_net_list_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
end
2727

2828
it 'rejects CIDR missing network mask' do
29-
pending "IPAddr allows empty network mask '1.2.3.4/'"
29+
pending "IPAddr allows empty network mask '1.2.3.4/'" if Gem::Version.new(Puppet.version) < Gem::Version.new('8')
3030
is_expected.to run.with_params('1.2.3.4/').and_raise_error(RuntimeError)
3131
end
3232

@@ -73,7 +73,7 @@
7373
end
7474

7575
it 'rejects CIDR missing network mask' do
76-
pending "IPAddr allows empty network mask '2001:db8:a::/'"
76+
pending "IPAddr allows empty network mask '2001:db8:a::/'" if Gem::Version.new(Puppet.version) < Gem::Version.new('8')
7777
is_expected.to run.with_params('2001:db8:a::/').and_raise_error(RuntimeError)
7878
end
7979

0 commit comments

Comments
 (0)