Skip to content

Commit

Permalink
Merge pull request #485 from puppetlabs/CONT-806-add_ruby_3
Browse files Browse the repository at this point in the history
(CONT-806) Add Ruby 3.2 support
  • Loading branch information
jordanbreen28 authored Apr 6, 2023
2 parents a0b9b00 + 0b8e1df commit b0bd892
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 172 deletions.
81 changes: 4 additions & 77 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
require: rubocop-rspec
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: '2.5'
TargetRubyVersion: '2.7'
NewCops: enable
ExtraDetails: true
DisplayStyleGuide: true
Include:
- "**/*.rb"
Exclude:
Expand Down Expand Up @@ -65,47 +68,6 @@ Style/TrailingCommaInArguments:
Style/SymbolArray:
Description: Using percent style obscures symbolic intent of array's contents.
EnforcedStyle: brackets
Layout/EndOfLine:
Enabled: false
Style/CollectionMethods:
Enabled: true
Style/MethodCalledOnDoEndBlock:
Enabled: true
Style/StringMethods:
Enabled: true
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/ParameterLists:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
RSpec/DescribeClass:
Enabled: false
RSpec/ExampleLength:
Enabled: false
RSpec/MessageExpectation:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
RSpec/NestedGroups:
Enabled: false
Style/AsciiComments:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/SymbolProc:
Enabled: false

# local overrides

# overridden for local conventions
Expand All @@ -118,15 +80,6 @@ Lint/NestedMethodDefinition:
Exclude:
- 'lib/puppet/resource_api.rb'

# Interacting with external API makes message spies pretty useless
RSpec/MessageSpies:
Enabled: false

# requires 2.3's squiggly HEREDOC support, which we can't use, yet
# see http://www.virtuouscode.com/2016/01/06/about-the-ruby-squiggly-heredoc-syntax/
Layout/HeredocIndentation:
Enabled: false

# Updated in 0.53 (or thereabouts)
Style/TrailingCommaInArrayLiteral:
Description: Prefer always trailing comma on multiline literals. This makes diffs,
Expand All @@ -149,29 +102,3 @@ Naming/MethodParameterName:
- id
- is
ForbiddenNames: []

# This cop breaks syntax highlighting in VSCode
Layout/ClosingHeredocIndentation:
Enabled: false

# This cop breaks code coverage :(
RSpec/AnyInstance:
Enabled: false

Style/HashEachMethods:
Enabled: true

Style/HashTransformKeys:
Enabled: true

Style/HashTransformValues:
Enabled: true

RSpec/FactoryBot/CreateList:
Description: "errors nastily on rubocop-rspec 1.42.0 and is not relevant to us anyways"
Enabled: false

RSpec/StubbedMock:
Enabled: false
RSpec/MultipleMemoizedHelpers:
Enabled: false
104 changes: 104 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-04-06 13:31:56 UTC using RuboCop version 1.48.1.
# 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: 17
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 116

# Offense count: 8
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 345

# Offense count: 8
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 33

# Offense count: 20
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 79

# Offense count: 3
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 324

# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 38

# Offense count: 22
RSpec/AnyInstance:
Exclude:
- 'spec/lib/puppet_litmus/puppet_helpers_spec.rb'
- 'spec/lib/puppet_litmus/rake_helper_spec.rb'
- 'spec/lib/puppet_litmus/rake_tasks_spec.rb'

# Offense count: 2
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/exe/matrix_from_metadata_v2_spec.rb'
- 'spec/lib/puppet_litmus/rake_tasks_spec.rb'

# Offense count: 31
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 19

# Offense count: 129
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 38
RSpec/MultipleExpectations:
Max: 8

# Offense count: 12
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 9

# Offense count: 5
# Configuration parameters: AllowedPatterns.
# AllowedPatterns: ^expect_, ^assert_
RSpec/NoExpectationExample:
Exclude:
- 'spec/lib/puppet_litmus/rake_helper_spec.rb'

# Offense count: 113
RSpec/StubbedMock:
Exclude:
- 'spec/lib/puppet_litmus/puppet_helpers_spec.rb'
- 'spec/lib/puppet_litmus/rake_helper_spec.rb'
- 'spec/lib/puppet_litmus/rake_tasks_spec.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: .
# SupportedStyles: constant, string
RSpec/VerifiedDoubleReference:
EnforcedStyle: string

# Offense count: 6
Style/OpenStructUse:
Exclude:
- 'lib/puppet_litmus/puppet_helpers.rb'
- 'spec/spec_helper.rb'
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ group :test do
gem 'rspec', '~> 3.0'
gem 'rspec-collection_matchers', '~> 1.0'
gem 'rspec-its', '~> 1.0'
gem 'rubocop', '~> 1.2'
gem 'rubocop-rspec', '~> 2.0'
gem 'rubocop', '~> 1.48.1'
gem 'rubocop-rspec', '~> 2.19'
gem 'rubocop-performance', '~> 1.16'
gem 'codecov', '~> 0.1'
gem 'simplecov', '~> 0.18'
end
Expand Down
10 changes: 3 additions & 7 deletions exe/matrix_from_metadata
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ metadata = JSON.parse(File.read('metadata.json'))
# Set platforms based on declared operating system support
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
os = sup['operatingsystem']
sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
sup['operatingsystemrelease'].sort_by(&:to_i).each do |ver|
image_key = "#{os}-#{ver}"
if IMAGE_TABLE.key? image_key
matrix[:platform] << IMAGE_TABLE[image_key]
Expand Down Expand Up @@ -95,17 +95,13 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
reqs = ["#{cmp_one} #{ver_one}", "#{cmp_two} #{ver_two}"]

COLLECTION_TABLE.each do |key, val|
if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
matrix[:collection] << val
end
matrix[:collection] << val if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
end
end
end

# Set to defaults (all collections) if no matches are found
if matrix[:collection].empty?
matrix[:collection] = COLLECTION_TABLE.values
end
matrix[:collection] = COLLECTION_TABLE.values if matrix[:collection].empty?

# Just to make sure there aren't any duplicates
matrix[:platform] = matrix[:platform].uniq.sort
Expand Down
12 changes: 3 additions & 9 deletions exe/matrix_from_metadata_v2
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ DOCKER_PLATFORMS = {
# This table uses the latest version in each collection for accurate
# comparison when evaluating puppet requirements from the metadata
COLLECTION_TABLE = [
{
puppet_maj_version: 6,
ruby_version: 2.5,
},
{
puppet_maj_version: 7,
ruby_version: 2.7,
Expand Down Expand Up @@ -90,7 +86,7 @@ if ARGV.include?('--exclude-platforms')
raise 'you need to provide a list of platforms in JSON format' if exclude_platforms_list.nil?

begin
exclude_list = JSON.parse(exclude_platforms_list).map { |platform| platform.downcase }
exclude_list = JSON.parse(exclude_platforms_list).map(&:downcase)
rescue JSON::ParserError
raise 'the exclude platforms list must valid JSON'
end
Expand All @@ -103,7 +99,7 @@ metadata = JSON.parse(File.read(metadata_path))
# Set platforms based on declared operating system support
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
os = sup['operatingsystem']
sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
sup['operatingsystemrelease'].sort_by(&:to_i).each do |ver|
image_key = "#{os}-#{ver}"

if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase)
Expand Down Expand Up @@ -156,9 +152,7 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
end

# Set to defaults (all collections) if no matches are found
if matrix[:collection].empty?
matrix[:collection] = COLLECTION_TABLE.map { |collection| "puppet#{collection[:puppet_maj_version]}-nightly" }
end
matrix[:collection] = COLLECTION_TABLE.map { |collection| "puppet#{collection[:puppet_maj_version]}-nightly" } if matrix[:collection].empty?

# Just to make sure there aren't any duplicates
matrix[:platforms] = matrix[:platforms].uniq.sort { |a, b| a[:label] <=> b[:label] }
Expand Down
22 changes: 6 additions & 16 deletions lib/puppet_litmus/inventory_manipulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def nodes_with_role(role, inventory)
targets_in_inventory(inventory) do |target|
vars = target['vars']
roles = [(vars['role'] || vars['roles'])].flatten
roles = roles.map { |r| r.downcase }
roles = roles.map(&:downcase)
output_collector << target['uri'] if roles.include? role.downcase
end
output_collector unless output_collector.empty?
Expand Down Expand Up @@ -213,9 +213,7 @@ def add_node_to_group(inventory_hash, node, group_name)
# check if group exists
if inventory_hash['groups'].any? { |g| g['name'] == group_name }
inventory_hash['groups'].each do |group|
if group['name'] == group_name
group['targets'].push node
end
group['targets'].push node if group['name'] == group_name
end
else
# add new group
Expand Down Expand Up @@ -248,9 +246,7 @@ def add_feature_to_group(inventory_hash, feature_name, group_name)
i = 0
inventory_hash['groups'].each do |group|
if group['name'] == group_name
if group['features'].nil? == true
group = group.merge('features' => [])
end
group = group.merge('features' => []) if group['features'].nil? == true
group['features'].push feature_name unless group['features'].include?(feature_name)
inventory_hash['groups'][i] = group
end
Expand All @@ -268,9 +264,7 @@ def add_feature_to_group(inventory_hash, feature_name, group_name)
# @return [Hash] inventory_hash with feature added to group if group_name exists in inventory hash.
def remove_feature_from_group(inventory_hash, feature_name, group_name)
inventory_hash['groups'].each do |group|
if group['name'] == group_name && group['features'].nil? != true
group['features'].delete(feature_name)
end
group['features'].delete(feature_name) if group['name'] == group_name && group['features'].nil? != true
end
inventory_hash
end
Expand All @@ -288,9 +282,7 @@ def add_feature_to_node(inventory_hash, feature_name, node_name)
node_index = 0
group['targets'].each do |node|
if node['uri'] == node_name
if node['features'].nil? == true
node = node.merge('features' => [])
end
node = node.merge('features' => []) if node['features'].nil? == true
node['features'].push feature_name unless node['features'].include?(feature_name)
inventory_hash['groups'][group_index]['targets'][node_index] = node
end
Expand All @@ -311,9 +303,7 @@ def add_feature_to_node(inventory_hash, feature_name, node_name)
def remove_feature_from_node(inventory_hash, feature_name, node_name)
inventory_hash['groups'].each do |group|
group['targets'].each do |node|
if node['uri'] == node_name && node['features'].nil? != true
node['features'].delete(feature_name)
end
node['features'].delete(feature_name) if node['uri'] == node_name && node['features'].nil? != true
end
end
inventory_hash
Expand Down
Loading

0 comments on commit b0bd892

Please sign in to comment.