Skip to content

Commit 62eb781

Browse files
committed
(RUBOCOP) Resolve Rubocop Issues
Resolved: - Layout:ClosingHeredocIndentation - Lint/RedundantCopEnableDirective - Naming/MemoizedInstanceVariableName - RSpec/ContextWording - RSpec/EmptyLineAfterExample - RSpec/EmptyLineAfterExampleGroup - RSpec/EmptyLineAfterHook - RSpec/ImplicitSubject - RSpec/RepeatedExampleGroupBody - Style/IfUnlessModifier - Style/RedundantArgument - Style/RescueStandardError - Style/SlicingWithRange - Style/TrailingCommaInHashLiteral Left in Place: - RSpec/NoExpectationExample: Unable to properly wrap applies in such a way as to serve as an expectation. - Style/GlobalVars: Replacing global variables with Constants causes warnings to be thrown by puppet applies.
1 parent cc46895 commit 62eb781

12 files changed

+153
-272
lines changed

Diff for: .rubocop_todo.yml

+8-107
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-08-29 15:24:31 UTC using RuboCop version 1.48.1.
3+
# on 2023-08-29 15:26:08 UTC using RuboCop version 1.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 1
10-
# This cop supports safe autocorrection (--autocorrect).
11-
Layout/ClosingHeredocIndentation:
12-
Exclude:
13-
- 'spec/spec_helper_acceptance_local.rb'
14-
15-
# Offense count: 1
16-
# This cop supports safe autocorrection (--autocorrect).
17-
Lint/RedundantCopEnableDirective:
18-
Exclude:
19-
- 'spec/unit/classes/firewall_spec.rb'
20-
219
# Offense count: 20
2210
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
2311
Metrics/AbcSize:
@@ -49,69 +37,29 @@ Metrics/MethodLength:
4937
Metrics/PerceivedComplexity:
5038
Max: 122
5139

52-
# Offense count: 1
53-
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
54-
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
55-
Naming/MemoizedInstanceVariableName:
56-
Exclude:
57-
- 'spec/spec_helper_acceptance_local.rb'
58-
59-
# Offense count: 7
60-
# Configuration parameters: Prefixes, AllowedPatterns.
61-
# Prefixes: when, with, without
62-
RSpec/ContextWording:
63-
Exclude:
64-
- 'spec/acceptance/firewall_attributes_exceptions_spec.rb'
65-
- 'spec/unit/classes/firewall_linux_redhat_spec.rb'
66-
- 'spec/unit/classes/firewall_linux_spec.rb'
67-
6840
# Offense count: 18
6941
# Configuration parameters: IgnoredMetadata.
7042
RSpec/DescribeClass:
7143
Enabled: false
7244

73-
# Offense count: 8
74-
# This cop supports safe autocorrection (--autocorrect).
75-
# Configuration parameters: AllowConsecutiveOneLiners.
76-
RSpec/EmptyLineAfterExample:
77-
Exclude:
78-
- 'spec/unit/classes/firewall_linux_archlinux_spec.rb'
79-
- 'spec/unit/classes/firewall_linux_debian_spec.rb'
80-
- 'spec/unit/classes/firewall_linux_redhat_spec.rb'
81-
82-
# Offense count: 1
83-
# This cop supports safe autocorrection (--autocorrect).
84-
RSpec/EmptyLineAfterExampleGroup:
85-
Exclude:
86-
- 'spec/unit/classes/firewall_spec.rb'
87-
88-
# Offense count: 7
89-
# This cop supports safe autocorrection (--autocorrect).
90-
# Configuration parameters: AllowConsecutiveOneLiners.
91-
RSpec/EmptyLineAfterHook:
92-
Exclude:
93-
- 'spec/unit/facter/iptables_persistent_version_spec.rb'
94-
- 'spec/unit/facter/iptables_spec.rb'
95-
9645
# Offense count: 9
9746
# Configuration parameters: CountAsOne.
9847
RSpec/ExampleLength:
9948
Max: 8
10049

10150
# Offense count: 41
102-
# This cop supports safe autocorrection (--autocorrect).
103-
# Configuration parameters: EnforcedStyle.
104-
# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit
105-
RSpec/ImplicitSubject:
51+
RSpec/MultipleExpectations:
52+
Max: 2
53+
54+
# Offense count: 38
55+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
56+
# SupportedStyles: always, named_only
57+
RSpec/NamedSubject:
10658
Exclude:
10759
- 'spec/unit/classes/firewall_linux_archlinux_spec.rb'
10860
- 'spec/unit/classes/firewall_linux_debian_spec.rb'
10961
- 'spec/unit/classes/firewall_linux_redhat_spec.rb'
11062

111-
# Offense count: 41
112-
RSpec/MultipleExpectations:
113-
Max: 2
114-
11563
# Offense count: 38
11664
# Configuration parameters: AllowedGroups.
11765
RSpec/NestedGroups:
@@ -129,61 +77,14 @@ RSpec/NoExpectationExample:
12977
- 'spec/acceptance/rules_spec.rb'
13078
- 'spec/acceptance/standard_usage_spec.rb'
13179

132-
# Offense count: 3
133-
RSpec/RepeatedExampleGroupBody:
134-
Exclude:
135-
- 'spec/unit/classes/firewall_linux_debian_spec.rb'
136-
13780
# Offense count: 83
13881
# Configuration parameters: AllowedVariables.
13982
Style/GlobalVars:
14083
Exclude:
14184
- 'lib/puppet/provider/firewall/firewall.rb'
14285
- 'lib/puppet/provider/firewallchain/firewallchain.rb'
14386

144-
# Offense count: 2
145-
# This cop supports safe autocorrection (--autocorrect).
146-
Style/IfUnlessModifier:
147-
Exclude:
148-
- 'spec/spec_helper_acceptance_local.rb'
149-
15087
# Offense count: 1
15188
Style/MixinUsage:
15289
Exclude:
15390
- 'spec/spec_helper.rb'
154-
155-
# Offense count: 1
156-
# This cop supports unsafe autocorrection (--autocorrect-all).
157-
# Configuration parameters: Methods.
158-
Style/RedundantArgument:
159-
Exclude:
160-
- 'spec/spec_helper_acceptance_local.rb'
161-
162-
# Offense count: 2
163-
# This cop supports safe autocorrection (--autocorrect).
164-
# Configuration parameters: EnforcedStyle.
165-
# SupportedStyles: implicit, explicit
166-
Style/RescueStandardError:
167-
Exclude:
168-
- 'spec/spec_helper.rb'
169-
- 'spec/spec_helper_acceptance_local.rb'
170-
171-
# Offense count: 1
172-
# This cop supports unsafe autocorrection (--autocorrect-all).
173-
Style/SlicingWithRange:
174-
Exclude:
175-
- 'spec/spec_helper_acceptance_local.rb'
176-
177-
# Offense count: 33
178-
# This cop supports safe autocorrection (--autocorrect).
179-
# Configuration parameters: EnforcedStyleForMultiline.
180-
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
181-
Style/TrailingCommaInHashLiteral:
182-
Exclude:
183-
- 'spec/spec_helper.rb'
184-
- 'spec/spec_helper_local.rb'
185-
- 'spec/unit/classes/firewall_linux_archlinux_spec.rb'
186-
- 'spec/unit/classes/firewall_linux_debian_spec.rb'
187-
- 'spec/unit/classes/firewall_linux_redhat_spec.rb'
188-
- 'spec/unit/classes/firewall_linux_spec.rb'
189-
- 'spec/unit/facter/iptables_persistent_version_spec.rb'

Diff for: spec/acceptance/firewall_attributes_exceptions_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
(fetch_os_name == 'oraclelinux' && os[:release][0] <= '7') ||
2525
(os[:family] == 'ubuntu') do
2626
describe 'bytecode' do
27-
context '4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0' do
27+
context 'when 4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0' do
2828
pp = <<-PUPPETCODE
2929
class { '::firewall': }
3030
firewall { '102 - test':
@@ -1292,7 +1292,7 @@ class { '::firewall': }
12921292
end
12931293

12941294
describe 'condition', condition_parameter_test: false do
1295-
context 'is set' do
1295+
context 'when is set' do
12961296
pp = <<-PUPPETCODE
12971297
if $facts['os']['name'] == 'Ubuntu' {
12981298
firewall { '010 isblue ipv4':

Diff for: spec/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
default_facts = {
1515
puppetversion: Puppet.version,
16-
facterversion: Facter.version,
16+
facterversion: Facter.version
1717
}
1818

1919
default_fact_files = [
@@ -26,7 +26,7 @@
2626

2727
begin
2828
default_facts.merge!(YAML.safe_load(File.read(f), [], [], true))
29-
rescue => e
29+
rescue StandardError => e
3030
RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}"
3131
end
3232
end

Diff for: spec/spec_helper_acceptance_local.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def ip6tables_flush_all_tables
2121

2222
def install_iptables
2323
LitmusHelper.instance.run_shell('iptables -V')
24-
rescue
24+
rescue StandardError
2525
if os[:family] == 'redhat'
2626
if fetch_os_name == 'oraclelinux' && os[:release].to_i == 7
2727
LitmusHelper.instance.run_shell('yum install iptables -y')
@@ -36,7 +36,7 @@ def install_iptables
3636
def iptables_version
3737
install_iptables
3838
x = LitmusHelper.instance.run_shell('iptables -V')
39-
x.stdout.split(' ')[1][1..-1]
39+
x.stdout.split[1][1..]
4040
end
4141

4242
def pre_setup
@@ -51,7 +51,7 @@ def update_profile_file
5151
end
5252

5353
def fetch_os_name
54-
@facter_os_name ||= LitmusHelper.instance.run_shell('facter os.name').stdout.delete("\n").downcase
54+
@fetch_os_name ||= LitmusHelper.instance.run_shell('facter os.name').stdout.delete("\n").downcase
5555
end
5656

5757
RSpec.configure do |c|
@@ -61,9 +61,7 @@ def fetch_os_name
6161
c.filter_run_excluding condition_parameter_test: false
6262
c.before :suite do
6363
# Depmod is not availible by default on our AlmaLinux/CentOS 8 docker image
64-
if ['almalinux-8', 'centos-8'].include?("#{fetch_os_name}-#{os[:release].to_i}")
65-
LitmusHelper.instance.run_shell('yum install kmod -y')
66-
end
64+
LitmusHelper.instance.run_shell('yum install kmod -y') if ['almalinux-8', 'centos-8'].include?("#{fetch_os_name}-#{os[:release].to_i}")
6765
if ['centos-6', 'centos-7', 'oraclelinux-6', 'scientific-6', 'scientific-7'].include?("#{fetch_os_name}-#{os[:release].to_i}")
6866
LitmusHelper.instance.run_shell('yum update -y')
6967
LitmusHelper.instance.run_shell('depmod -a')
@@ -94,7 +92,7 @@ def fetch_os_name
9492
package { 'net-tools':
9593
ensure => 'latest',
9694
}
97-
PUPPETCODE
95+
PUPPETCODE
9896
LitmusHelper.instance.apply_manifest(pp)
9997
LitmusHelper.instance.run_shell('update-alternatives --set iptables /usr/sbin/iptables-legacy', expect_failures: true)
10098
LitmusHelper.instance.run_shell('update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy', expect_failures: true)
@@ -115,8 +113,6 @@ def fetch_os_name
115113
# Ensure that policycoreutils is present. In the future we could probably refactor
116114
# this so that policycoreutils is installed on platform where the os.family fact
117115
# is set to 'redhat'
118-
if ['almalinux-8', 'rocky-8'].include?("#{fetch_os_name}-#{os[:release].to_i}")
119-
LitmusHelper.instance.run_shell('yum install policycoreutils -y')
120-
end
116+
LitmusHelper.instance.run_shell('yum install policycoreutils -y') if ['almalinux-8', 'rocky-8'].include?("#{fetch_os_name}-#{os[:release].to_i}")
121117
end
122118
end

Diff for: spec/spec_helper_local.rb

+41-3
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,53 @@
2929
end
3030
end
3131

32-
def with_debian_facts
32+
shared_context 'when ArchLinux' do
3333
let :facts do
3434
{
3535
kernel: 'Linux',
3636
os: {
37-
name: 'Debian',
38-
release: { full: '8.0' },
37+
name: 'ArchLinux',
38+
family: 'ArchLinux'
39+
},
40+
identity: {
41+
uid: 'root'
42+
}
43+
}
44+
end
45+
end
46+
47+
shared_context 'when Debian 10' do
48+
let(:facts) { on_supported_os['debian-10-x86_64'] }
49+
end
50+
51+
shared_context 'when Debian 11' do
52+
let(:facts) { on_supported_os['debian-11-x86_64'] }
53+
end
54+
55+
shared_context 'when Debian Unstable' do
56+
let(:facts) do
57+
{
58+
kernel: 'Linux',
59+
os: {
3960
family: 'Debian',
61+
name: 'Debian',
62+
release: { full: 'unstable' }
4063
},
64+
identity: {
65+
uid: 'root'
66+
}
4167
}
4268
end
4369
end
70+
71+
shared_context 'when Ubuntu 18.04' do
72+
let(:facts) { on_supported_os['ubuntu-18.04-x86_64'] }
73+
end
74+
75+
shared_context 'when RedHat 7' do
76+
let(:facts) { on_supported_os['redhat-7-x86_64'] }
77+
end
78+
79+
shared_context 'when RedHat 8' do
80+
let(:facts) { on_supported_os['redhat-8-x86_64'] }
81+
end

Diff for: spec/unit/classes/firewall_linux_archlinux_spec.rb

+10-14
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@
33
require 'spec_helper'
44

55
describe 'firewall::linux::archlinux', type: :class do
6-
let(:facts) do
7-
{
8-
os: {
9-
family: 'ArchLinux',
10-
name: 'ArchLinux',
11-
},
12-
}
13-
end
6+
include_examples 'when ArchLinux'
147

158
it {
16-
is_expected.to contain_service('iptables').with(
9+
expect(subject).to contain_service('iptables').with(
1710
ensure: 'running',
1811
enable: 'true',
1912
)
2013
}
14+
2115
it {
22-
is_expected.to contain_service('ip6tables').with(
16+
expect(subject).to contain_service('ip6tables').with(
2317
ensure: 'running',
2418
enable: 'true',
2519
)
@@ -29,12 +23,13 @@
2923
let(:params) { { ensure: 'stopped' } }
3024

3125
it {
32-
is_expected.to contain_service('iptables').with(
26+
expect(subject).to contain_service('iptables').with(
3327
ensure: 'stopped',
3428
)
3529
}
30+
3631
it {
37-
is_expected.to contain_service('ip6tables').with(
32+
expect(subject).to contain_service('ip6tables').with(
3833
ensure: 'stopped',
3934
)
4035
}
@@ -44,12 +39,13 @@
4439
let(:params) { { enable: 'false' } }
4540

4641
it {
47-
is_expected.to contain_service('iptables').with(
42+
expect(subject).to contain_service('iptables').with(
4843
enable: 'false',
4944
)
5045
}
46+
5147
it {
52-
is_expected.to contain_service('ip6tables').with(
48+
expect(subject).to contain_service('ip6tables').with(
5349
enable: 'false',
5450
)
5551
}

0 commit comments

Comments
 (0)