Skip to content

(CAT-2254) Remove puppet 7 / Ruby 2.7 related code #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
strategy:
matrix:
cfg:
- {puppet_version: '7', ruby: '2.7'}
- {puppet_version: '7', ruby: 'jruby-9.3.7.0'}
- {puppet_version: '8', ruby: '3.2'}
- {puppet_version: '8', ruby: 'jruby-9.4.2.0'}
env:
Expand Down Expand Up @@ -51,7 +49,6 @@ jobs:
strategy:
matrix:
cfg:
- {puppet_version: '7', ruby: '2.7'}
- {puppet_version: '8', ruby: '3.2', extra: 'bundle config set with integration'}
env:
PUPPET_GEM_VERSION: ~> ${{ matrix.cfg.puppet_version }}
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
strategy:
matrix:
cfg:
- {puppet_version: '7', ruby: '2.7'}
- {puppet_version: '7', ruby: 'jruby-9.3.7.0'}
- {puppet_version: '8', ruby: '3.2'}
- {puppet_version: '8', ruby: 'jruby-9.4.2.0'}
env:
Expand Down Expand Up @@ -49,7 +47,6 @@ jobs:
strategy:
matrix:
cfg:
- {puppet_version: '7', ruby: '2.7'}
- {puppet_version: '8', ruby: '3.2', extra: 'bundle config set with integration'}
env:
PUPPET_GEM_VERSION: ~> ${{ matrix.cfg.puppet_version }}
Expand Down
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ inherit_from: .rubocop_todo.yml

require: rubocop-rspec
AllCops:
TargetRubyVersion: '2.5'
NewCops: enable
TargetRubyVersion: '3.1'
Include:
- "**/*.rb"
Exclude:
Expand Down
68 changes: 65 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-12-19 10:44:38 UTC using RuboCop version 1.48.1.
# on 2025-03-10 20:03:26 UTC using RuboCop version 1.70.0.
# 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 19
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'lib/puppet/resource_api/value_creator.rb'
- 'spec/puppet/resource_api/base_context_spec.rb'

# Offense count: 12
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Exclude:
- 'lib/puppet/resource_api/type_definition.rb'
- 'lib/puppet/util/network_device/simple/device.rb'
- 'spec/puppet/provider/test_provider/test_provider.rb'
- 'spec/puppet/resource_api/transport/wrapper_spec.rb'
- 'spec/puppet/resource_api/transport_spec.rb'
- 'spec/puppet/resource_api_spec.rb'

# Offense count: 25
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Enabled: false

# Offense count: 33
# Offense count: 37
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 16
Expand All @@ -23,7 +41,7 @@ RSpec/InstanceVariable:
- 'spec/acceptance/namevar_spec.rb'
- 'spec/puppet/resource_api/data_type_handling_spec.rb'

# # Offense count: 15
# Offense count: 15
RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/puppet/resource_api/base_context_spec.rb'
Expand All @@ -49,3 +67,47 @@ RSpec/NestedGroups:
RSpec/SubjectStub:
Exclude:
- 'spec/puppet/resource_api/base_context_spec.rb'

# Offense count: 24
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: constant, string
RSpec/VerifiedDoubleReference:
Exclude:
- 'spec/integration/resource_api_spec.rb'
- 'spec/puppet/resource_api/property_spec.rb'
- 'spec/puppet/resource_api/puppet_context_spec.rb'
- 'spec/puppet/resource_api/simple_provider_spec.rb'
- 'spec/puppet/resource_api/transport_spec.rb'
- 'spec/puppet/resource_api/type_definition_spec.rb'
- 'spec/puppet/resource_api_spec.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
Style/CollectionCompact:
Exclude:
- 'lib/puppet/resource_api.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSplatArgument.
Style/HashConversion:
Exclude:
- 'lib/puppet/resource_api.rb'
- 'lib/puppet/resource_api/glue.rb'
- 'lib/puppet/resource_api/simple_provider.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
# AllowedReceivers: Thread.current
Style/HashEachMethods:
Exclude:
- 'lib/puppet/resource_api/type_definition.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- 'lib/puppet/resource_api.rb'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ group :tests do
# since the Resource API runs inside the puppetserver, test against the JRuby versions we ship
# these require special dependencies to have everything load properly
# rubocop 1.48 supports JRuby 9.3+, which includes coverage for versions we support
gem 'rubocop', '~> 1.48.1', require: false
gem 'rubocop', '~> 1.70.0', require: false
gem 'rubocop-rspec', '~> 2.20.0', require: false
gem 'rubocop-performance', '~> 1.17.1', require: false
end
Expand Down
2 changes: 1 addition & 1 deletion contrib/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Code modified from: https://gist.github.com/hanloong/9849098
require 'English'

changed_files = `git diff --name-only --cached --diff-filter=ACM`.split(/\n/)
changed_files = `git diff --name-only --cached --diff-filter=ACM`.split("\n")
changed_files = changed_files.select do |file_name|
File.extname(file_name) == '.rb'
end.join(' ')
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/resource_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def initialize(attributes)
attributes[:title] = @title if attributes[:title].nil? && !type_definition.namevars.empty?
end

super(attributes)
super
end

def name
Expand Down Expand Up @@ -541,8 +541,8 @@ def load_provider(type_name)
end
rescue NameError
if device_name # line too long # rubocop:disable Style/GuardClause
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name}"\
" nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name} " \
"nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
else
raise Puppet::DevError, "provider class Puppet::Provider::#{class_name}::#{class_name} not found in puppet/provider/#{type_name}/#{type_name}"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/resource_api/data_type_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def self.boolean_munge(value)
# @private
def self.ambiguous_error_msg(error_msg_prefix, value, type)
"#{error_msg_prefix} #{value.inspect} is not unabiguously convertable to " \
"#{type}"
"#{type}"
end

# Validates the `value` against the specified `type`.
Expand Down Expand Up @@ -195,9 +195,9 @@ def self.parse_puppet_type(attr_name, type)
Puppet::Pops::Types::TypeParser.singleton.parse(type)
rescue Puppet::ParseErrorWithIssue => e
raise Puppet::DevError, "The type of the `#{attr_name}` attribute " \
"`#{type}` could not be parsed: #{e.message}"
"`#{type}` could not be parsed: #{e.message}"
rescue Puppet::ParseError => e
raise Puppet::DevError, "The type of the `#{attr_name}` attribute " \
"`#{type}` is not recognised: #{e.message}"
"`#{type}` is not recognised: #{e.message}"
end
end
2 changes: 1 addition & 1 deletion lib/puppet/resource_api/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def self.validate(name, connection_info)
transport_schema = transports[name]
raise Puppet::DevError, format('Transport for `%<target>s` not registered with `%<environment>s`', target: name, environment: current_environment_name) if transport_schema.nil?

clean_bolt_attributes(transport_schema, connection_info) if connection_info.key?(:"remote-transport")
clean_bolt_attributes(transport_schema, connection_info) if connection_info.key?(:'remote-transport')

apply_defaults(transport_schema, connection_info)
message_prefix = 'The connection info provided does not match the Transport Schema'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/resource_api/transport/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def respond_to_missing?(name, _include_private)
(@transport.respond_to? name) || super
end

def method_missing(method_name, *args, &block)
def method_missing(method_name, ...)
if @transport.respond_to? method_name
@transport.send(method_name, *args, &block)
@transport.send(method_name, ...)
else
super
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/resource_api/type_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def title_patterns
end

def validate_schema(definition, attr_key)
super(definition, attr_key)
super
%i[title provider alias audit before consume export loglevel noop notify require schedule stage subscribe tag].each do |name|
raise Puppet::DevError, format('must not define an attribute called `%<name>s`', name: name.inspect) if definition[attr_key].key? name
end
Expand Down Expand Up @@ -234,7 +234,7 @@ def check_schema_values(resource)
next unless attributes[key]

type = @data_type_cache[attributes[key][:type]]
is_sensitive = (attributes[key].key?(:sensitive) && (attributes[key][:sensitive] == true))
is_sensitive = attributes[key].key?(:sensitive) && (attributes[key][:sensitive] == true)
error_message = Puppet::ResourceApi::DataTypeHandling.try_validate(
type,
value,
Expand Down
32 changes: 10 additions & 22 deletions spec/acceptance/device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@
RSpec.describe 'exercising a device provider' do
let(:common_args) { '--verbose --trace --strict=error --modulepath spec/fixtures' }
let(:default_type_values) do
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF '\
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 '\
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
end

before(:all) do # rubocop:disable RSpec/BeforeAfterAll
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.0') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('5.4.0')
# work around https://tickets.puppetlabs.com/browse/PUP-8632 and https://tickets.puppetlabs.com/browse/PUP-9047
FileUtils.mkdir_p(File.expand_path('~/.puppetlabs/opt/puppet/cache/devices/the_node/state'))
end
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF ' \
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 ' \
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
end

describe 'using `puppet resource`' do
Expand All @@ -32,8 +25,8 @@

it 'deals with canonicalized resources correctly' do
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
expect(stdout_str).to match(/#{stdmatch}/)
expect(status).not_to be_success
Expand All @@ -45,8 +38,8 @@

it 'deals with canonicalized resources correctly' do
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
expect(stdout_str).to match(/#{stdmatch}/)
expect(status).to be_success
Expand Down Expand Up @@ -103,12 +96,7 @@
DEVICE_CREDS
end

def is_device_apply_supported?
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
end

before do
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
device_conf.write(device_conf_content)
device_conf.close

Expand Down Expand Up @@ -155,9 +143,9 @@ def is_device_apply_supported?
it 'applies the catalog successfully' do
Tempfile.create('fact_set') do |f|
f.write 'device_provider{ "foo":' \
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", '\
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, '\
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", ' \
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, ' \
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
f.close

stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
Expand Down
5 changes: 0 additions & 5 deletions spec/acceptance/multi_device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
DEVICE_CONF
end

def is_device_apply_supported?
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
end

before do
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
device_conf.write(device_conf_content)
device_conf.close
end
Expand Down
12 changes: 6 additions & 6 deletions spec/acceptance/sensitive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
end

it 'is not exposed by a provider' do
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), "\
"optional_secret => Sensitive('optional sesitive_data'), array_secret => [Sensitive('array sesitive_data')] }\"")
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), " \
"optional_secret => Sensitive('optional sesitive_data'), array_secret => [Sensitive('array sesitive_data')] }\"")
expect(stdout_str).to match(/redacted/)
expect(stdout_str).not_to match(/sesitive_data/)
expect(stdout_str).not_to match(/warn|error/i)
end

context 'when a sensitive value is not the top level type' do
it 'is not exposed by a provider' do
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), "\
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive('variant sesitive_data')] }\"")
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), " \
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive('variant sesitive_data')] }\"")
expect(stdout_str).to match(/redacted/)
expect(stdout_str).not_to match(/variant sesitive_data/)
expect(stdout_str).not_to match(/warn|error/i)
end

it 'properly validates the sensitive type value' do
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), "\
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive(134679)] }\"")
stdout_str, _status = Open3.capture2e("puppet apply #{common_args} -e \"test_sensitive { test_resource: secret => Sensitive('sesitive_data'), " \
"optional_secret => Sensitive('optional sesitive_data'), variant_secret => [Sensitive(134679)] }\"")
expect(stdout_str).to match(/Sensitive\[String\]( value)?, got Sensitive\[Integer\]/)
expect(stdout_str).not_to match(/134679/)
end
Expand Down
5 changes: 0 additions & 5 deletions spec/acceptance/transport/transport_defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
end
let(:device_credentials) { Tempfile.new('credentials.txt') }

def is_device_apply_supported?
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
end

before do
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
device_conf.write(device_conf_content)
device_conf.close

Expand Down
5 changes: 0 additions & 5 deletions spec/acceptance/transport/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
end
let(:device_credentials) { Tempfile.new('credentials.txt') }

def is_device_apply_supported?
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
end

before do
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
device_conf.write(device_conf_content)
device_conf.close

Expand Down
2 changes: 1 addition & 1 deletion spec/puppet/resource_api/data_type_handling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
context "when validating #{valid_value.inspect}" do
let(:value) { valid_value }

it { expect(error_msg).to be nil }
it { expect(error_msg).to be_nil }
end
end
testcase[:invalid].each do |invalid_value|
Expand Down
Loading