Skip to content

Commit

Permalink
Merge pull request #343 from puppetlabs/CAT-1912_2
Browse files Browse the repository at this point in the history
CAT-1912 : Adding new getters and setters for stripes & not allowing change of stripes for an existing lvm
  • Loading branch information
malikparvez authored Jul 11, 2024
2 parents 7aa4c0d + 0f74517 commit 48b2604
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lib/puppet/provider/logical_volume/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ def size=(new_size)
end
end

def stripes
# Run the lvs command with the -o option to get only the stripes count
raw = (lvs '-o', 'stripes', '--noheadings', path)

output_array = raw.strip
output_array
end

def stripes=(new_stripes_count)
current_stripes = stripes.to_i

# Changing stripes is not supported for existing logical volumes
return unless new_stripes_count.to_i != current_stripes
raise(Puppet::Error, "Changing stripes from #{current_stripes} to #{new_stripes_count} is not supported for existing logical volumes")
end

# Look up the current number of mirrors (0=no mirroring, 1=1 spare, 2=2 spares....). Return the number as string.
def mirror
raw = lvdisplay(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/logical_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def insync?(is)
end
end

newparam(:stripes) do
newproperty(:stripes) do
desc 'The number of stripes to allocate for the new logical volume.'
validate do |value|
raise ArgumentError, "#{value} is not a valid stripe count" unless %r{^[0-9]+$}i.match?(value.to_s)
Expand Down
21 changes: 19 additions & 2 deletions spec/acceptance/create_filesystem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
end
end

describe 'create_filesystem_with_ensure_property_ext4' do
describe 'create_filesystem_with_ensure_property_ext4 & check stripes change' do
let(:pv) do
"/dev/#{device_name}"
end
Expand All @@ -116,6 +116,7 @@
ensure => present,
volume_group => '#{vg}',
size => '20M',
stripes => 1,
}
->
filesystem {'Create_filesystem':
Expand All @@ -126,9 +127,25 @@
MANIFEST
end

it 'applies the manifest' do
let(:pp1) do
<<~MANIFEST
logical_volume{'#{lv}':
ensure => present,
volume_group => '#{vg}',
size => '20M',
stripes => 2,
}
MANIFEST
end

it 'applies the manifest and creates an ext4 filesystem' do
apply_manifest(pp)
expect(run_shell("file -sL /dev/#{vg}/#{lv}").stdout).to match %r{ext4}
end

it 'change the stripes and re-applies the manifest' do
# It is expected to fail as number of stripes cannot be changed on a existing logical volume
apply_manifest(pp1, expect_failures: true)
remove_all(pv, vg, lv)
end
end
Expand Down

0 comments on commit 48b2604

Please sign in to comment.