Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAT-1912 : Adding new getters and setters for stripes & not allowing change of stripes for an existing lvm #343

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading