Skip to content

Commit 677977b

Browse files
jordanbreen28jordanbreen28
authored andcommitted
(CONT-971) - Correct Style/IfUnlessModifier
1 parent 222fa7f commit 677977b

File tree

13 files changed

+54
-178
lines changed

13 files changed

+54
-178
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,6 @@ Style/ClassAndModuleChildren:
191191
Exclude:
192192
- 'lib/puppet_x/lvm/output.rb'
193193

194-
# Offense count: 56
195-
# This cop supports safe autocorrection (--autocorrect).
196-
Style/IfUnlessModifier:
197-
Exclude:
198-
- 'lib/facter/lvm_support.rb'
199-
- 'lib/puppet/provider/filesystem/aix.rb'
200-
- 'lib/puppet/provider/filesystem/lvm.rb'
201-
- 'lib/puppet/provider/logical_volume/aix.rb'
202-
- 'lib/puppet/provider/logical_volume/lvm.rb'
203-
- 'lib/puppet/provider/physical_volume/lvm.rb'
204-
- 'lib/puppet/type/filesystem.rb'
205-
- 'lib/puppet/type/logical_volume.rb'
206-
- 'lib/puppet/type/physical_volume.rb'
207-
- 'spec/lib/helpers.rb'
208-
- 'spec/spec_helper_acceptance_local.rb'
209-
- 'tests/beaker/lib/lvm_helper.rb'
210194

211195
# Offense count: 2
212196
# Configuration parameters: AllowedMethods.

lib/facter/lvm_support.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
confine lvm_support: true
1818

1919
setcode do
20-
if Facter.value(:lvm_support)
21-
vgs = Facter::Core::Execution.execute('vgs -o name --noheadings 2>/dev/null', timeout: 30)
22-
end
20+
vgs = Facter::Core::Execution.execute('vgs -o name --noheadings 2>/dev/null', timeout: 30) if Facter.value(:lvm_support)
2321

2422
if vgs.nil?
2523
0
@@ -34,9 +32,7 @@
3432
setcode do
3533
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
3634
res = nil
37-
unless pvs.nil?
38-
res = pvs.split("\n").grep(%r{^\s+/}).collect(&:strip).sort.join(',')
39-
end
35+
res = pvs.split("\n").grep(%r{^\s+/}).collect(&:strip).sort.join(',') unless pvs.nil?
4036
res
4137
end
4238
end
@@ -53,9 +49,7 @@
5349
confine lvm_support: true
5450

5551
setcode do
56-
if Facter.value(:lvm_support)
57-
pvs = Facter::Core::Execution.execute('pvs -o name --noheadings 2>/dev/null', timeout: 30)
58-
end
52+
pvs = Facter::Core::Execution.execute('pvs -o name --noheadings 2>/dev/null', timeout: 30) if Facter.value(:lvm_support)
5953

6054
if pvs.nil?
6155
0

lib/puppet/provider/filesystem/aix.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def size
104104
Open3.popen3("lsfs -q #{@resource[:name]}") do |_stdin, stdout, _stderr|
105105
stdout.each do |line|
106106
elements = line.split(%r{\s+})
107-
if elements[2] == @resource[:name]
108-
cursize = elements[4].to_i
109-
end
107+
cursize = elements[4].to_i if elements[2] == @resource[:name]
110108
end
111109
end
112110

lib/puppet/provider/filesystem/lvm.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def mkfs(fs_type, name)
4141

4242
mkfs_cmd << name
4343

44-
if mkfs_params[fs_type]
45-
mkfs_cmd << mkfs_params[fs_type]
46-
end
44+
mkfs_cmd << mkfs_params[fs_type] if mkfs_params[fs_type]
4745

4846
if resource[:options]
4947
mkfs_options = Array.new(resource[:options].split)

lib/puppet/provider/logical_volume/aix.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ def create
2222
end
2323
end
2424

25-
if @resource[:type]
26-
args.push('-t', @resource[:type])
27-
end
25+
args.push('-t', @resource[:type]) if @resource[:type]
2826

2927
args.push(@resource[:volume_group], @resource[:initial_size])
3028

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -71,68 +71,42 @@ def create
7171
args.push('-n', @resource[:name]) unless @resource[:thinpool] == true
7272

7373
size_option = '--size'
74-
if @resource[:thinpool].is_a? String
75-
size_option = '--virtualsize'
76-
end
74+
size_option = '--virtualsize' if @resource[:thinpool].is_a? String
7775

7876
if @resource[:size]
7977
args.push(size_option, @resource[:size])
8078
elsif @resource[:initial_size]
8179
args.push(size_option, @resource[:initial_size])
8280
end
83-
if @resource[:extents]
84-
args.push('--extents', @resource[:extents])
85-
end
81+
args.push('--extents', @resource[:extents]) if @resource[:extents]
8682

87-
if !@resource[:extents] && !@resource[:size] && !@resource[:initial_size]
88-
args.push('--extents', '100%FREE')
89-
end
83+
args.push('--extents', '100%FREE') if !@resource[:extents] && !@resource[:size] && !@resource[:initial_size]
9084

91-
if @resource[:stripes]
92-
args.push('--stripes', @resource[:stripes])
93-
end
85+
args.push('--stripes', @resource[:stripes]) if @resource[:stripes]
9486

95-
if @resource[:stripesize]
96-
args.push('--stripesize', @resource[:stripesize])
97-
end
87+
args.push('--stripesize', @resource[:stripesize]) if @resource[:stripesize]
9888

99-
if @resource[:poolmetadatasize]
100-
args.push('--poolmetadatasize', @resource[:poolmetadatasize])
101-
end
89+
args.push('--poolmetadatasize', @resource[:poolmetadatasize]) if @resource[:poolmetadatasize]
10290

10391
if @resource[:mirror]
10492
args.push('--mirrors', @resource[:mirror])
105-
if @resource[:mirrorlog]
106-
args.push('--mirrorlog', @resource[:mirrorlog])
107-
end
108-
if @resource[:region_size]
109-
args.push('--regionsize', @resource[:region_size])
110-
end
111-
if @resource[:no_sync]
112-
args.push('--nosync')
113-
end
93+
args.push('--mirrorlog', @resource[:mirrorlog]) if @resource[:mirrorlog]
94+
args.push('--regionsize', @resource[:region_size]) if @resource[:region_size]
95+
args.push('--nosync') if @resource[:no_sync]
11496
end
11597

116-
if @resource[:alloc]
117-
args.push('--alloc', @resource[:alloc])
118-
end
98+
args.push('--alloc', @resource[:alloc]) if @resource[:alloc]
11999

120-
if @resource[:readahead]
121-
args.push('--readahead', @resource[:readahead])
122-
end
100+
args.push('--readahead', @resource[:readahead]) if @resource[:readahead]
123101

124102
if @resource[:persistent]
125103
# if persistent param is true, set arg to "y", otherwise set to "n"
126104
args.push('--persistent', [:true, true, 'true'].include?(@resource[:persistent]) ? 'y' : 'n')
127105
end
128106

129-
if @resource[:minor]
130-
args.push('--minor', @resource[:minor])
131-
end
107+
args.push('--minor', @resource[:minor]) if @resource[:minor]
132108

133-
if @resource[:type]
134-
args.push('--type', @resource[:type])
135-
end
109+
args.push('--type', @resource[:type]) if @resource[:type]
136110

137111
if @resource[:thinpool]
138112
args.push('--thin')
@@ -149,9 +123,7 @@ def create
149123

150124
def destroy
151125
name_escaped = "#{@resource[:volume_group].gsub('-', '--')}-#{@resource[:name].gsub('-', '--')}"
152-
if %r{\bTYPE="(swap)"}.match?(blkid(path))
153-
swapoff(path)
154-
end
126+
swapoff(path) if %r{\bTYPE="(swap)"}.match?(blkid(path))
155127
dmsetup('remove', name_escaped)
156128
lvremove('-f', path)
157129
end
@@ -199,21 +171,15 @@ def size=(new_size)
199171
end
200172

201173
## Get the extend size
202-
if lvs('--noheading', '-o', 'vg_extent_size', '--units', 'k', path) =~ %r{\s+(\d+)\.\d+k}i
203-
vg_extent_size = Regexp.last_match(1).to_i
204-
end
174+
vg_extent_size = Regexp.last_match(1).to_i if lvs('--noheading', '-o', 'vg_extent_size', '--units', 'k', path) =~ %r{\s+(\d+)\.\d+k}i
205175

206176
## Verify that it's a extension: Reduce is potentially dangerous and should be done manually
207177
if lvm_size_units[current_size_unit] < lvm_size_units[new_size_unit]
208178
resizeable = true
209179
elsif lvm_size_units[current_size_unit] > lvm_size_units[new_size_unit]
210-
if (current_size_bytes * lvm_size_units[current_size_unit]) < (new_size_bytes * lvm_size_units[new_size_unit])
211-
resizeable = true
212-
end
180+
resizeable = true if (current_size_bytes * lvm_size_units[current_size_unit]) < (new_size_bytes * lvm_size_units[new_size_unit])
213181
elsif lvm_size_units[current_size_unit] == lvm_size_units[new_size_unit]
214-
if new_size_bytes > current_size_bytes
215-
resizeable = true
216-
end
182+
resizeable = true if new_size_bytes > current_size_bytes
217183
end
218184

219185
if resizeable
@@ -236,9 +202,7 @@ def size=(new_size)
236202
end
237203
rescue Puppet::ExecutionFailure => e
238204
## If blkid returned 2, there is no filesystem present or the file doesn't exist. This should not be a failure.
239-
if e.message.include?(' returned 2:') # rubocop:disable Metrics/BlockNesting
240-
Puppet.debug(e.message)
241-
end
205+
Puppet.debug(e.message) if e.message.include?(' returned 2:') # rubocop:disable Metrics/BlockNesting
242206
end
243207
end
244208

@@ -271,15 +235,11 @@ def mirror=(new_mirror_count)
271235

272236
puts "Change mirror from #{current_mirrors} to #{new_mirror_count}..."
273237
args = ['-m', new_mirror_count]
274-
if @resource[:mirrorlog]
275-
args.push('--mirrorlog', @resource[:mirrorlog])
276-
end
238+
args.push('--mirrorlog', @resource[:mirrorlog]) if @resource[:mirrorlog]
277239

278240
# Region size cannot be changed on an existing mirror (not even when changing to zero mirrors).
279241

280-
if @resource[:alloc]
281-
args.push('--alloc', @resource[:alloc])
282-
end
242+
args.push('--alloc', @resource[:alloc]) if @resource[:alloc]
283243
args.push(path)
284244
lvconvert(*args)
285245
end
@@ -310,9 +270,7 @@ def mirrorlog=(new_mirror_log_location)
310270

311271
# puts "Change mirror log location to #{new_mirror_log_location}..."
312272
args = ['--mirrorlog', new_mirror_log_location]
313-
if @resource[:alloc]
314-
args.push('--alloc', @resource[:alloc])
315-
end
273+
args.push('--alloc', @resource[:alloc]) if @resource[:alloc]
316274
args.push(path)
317275
lvconvert(*args)
318276
end

lib/puppet/provider/physical_volume/lvm.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ def self.get_physical_volume_properties(physical_volumes_line)
7777

7878
def create_physical_volume(path)
7979
args = []
80-
if @resource[:force] == :true
81-
args.push('--force')
82-
end
80+
args.push('--force') if @resource[:force] == :true
8381
args << path
8482
pvcreate(*args)
8583
end

lib/puppet/type/filesystem.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
newparam(:name) do
1515
isnamevar
1616
validate do |value|
17-
unless Pathname.new(value).absolute?
18-
raise ArgumentError, 'Filesystem names must be fully qualified'
19-
end
17+
raise ArgumentError, 'Filesystem names must be fully qualified' unless Pathname.new(value).absolute?
2018
end
2119
end
2220

0 commit comments

Comments
 (0)