Skip to content

Commit 48b2604

Browse files
authored
Merge pull request #343 from puppetlabs/CAT-1912_2
CAT-1912 : Adding new getters and setters for stripes & not allowing change of stripes for an existing lvm
2 parents 7aa4c0d + 0f74517 commit 48b2604

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ def size=(new_size)
221221
end
222222
end
223223

224+
def stripes
225+
# Run the lvs command with the -o option to get only the stripes count
226+
raw = (lvs '-o', 'stripes', '--noheadings', path)
227+
228+
output_array = raw.strip
229+
output_array
230+
end
231+
232+
def stripes=(new_stripes_count)
233+
current_stripes = stripes.to_i
234+
235+
# Changing stripes is not supported for existing logical volumes
236+
return unless new_stripes_count.to_i != current_stripes
237+
raise(Puppet::Error, "Changing stripes from #{current_stripes} to #{new_stripes_count} is not supported for existing logical volumes")
238+
end
239+
224240
# Look up the current number of mirrors (0=no mirroring, 1=1 spare, 2=2 spares....). Return the number as string.
225241
def mirror
226242
raw = lvdisplay(path)

lib/puppet/type/logical_volume.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def insync?(is)
119119
end
120120
end
121121

122-
newparam(:stripes) do
122+
newproperty(:stripes) do
123123
desc 'The number of stripes to allocate for the new logical volume.'
124124
validate do |value|
125125
raise ArgumentError, "#{value} is not a valid stripe count" unless %r{^[0-9]+$}i.match?(value.to_s)

spec/acceptance/create_filesystem_spec.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
end
9292
end
9393

94-
describe 'create_filesystem_with_ensure_property_ext4' do
94+
describe 'create_filesystem_with_ensure_property_ext4 & check stripes change' do
9595
let(:pv) do
9696
"/dev/#{device_name}"
9797
end
@@ -116,6 +116,7 @@
116116
ensure => present,
117117
volume_group => '#{vg}',
118118
size => '20M',
119+
stripes => 1,
119120
}
120121
->
121122
filesystem {'Create_filesystem':
@@ -126,9 +127,25 @@
126127
MANIFEST
127128
end
128129

129-
it 'applies the manifest' do
130+
let(:pp1) do
131+
<<~MANIFEST
132+
logical_volume{'#{lv}':
133+
ensure => present,
134+
volume_group => '#{vg}',
135+
size => '20M',
136+
stripes => 2,
137+
}
138+
MANIFEST
139+
end
140+
141+
it 'applies the manifest and creates an ext4 filesystem' do
130142
apply_manifest(pp)
131143
expect(run_shell("file -sL /dev/#{vg}/#{lv}").stdout).to match %r{ext4}
144+
end
145+
146+
it 'change the stripes and re-applies the manifest' do
147+
# It is expected to fail as number of stripes cannot be changed on a existing logical volume
148+
apply_manifest(pp1, expect_failures: true)
132149
remove_all(pv, vg, lv)
133150
end
134151
end

0 commit comments

Comments
 (0)