diff --git a/lib/puppet/provider/logical_volume/lvm.rb b/lib/puppet/provider/logical_volume/lvm.rb index aa19d5e1..6110bd17 100644 --- a/lib/puppet/provider/logical_volume/lvm.rb +++ b/lib/puppet/provider/logical_volume/lvm.rb @@ -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) diff --git a/lib/puppet/type/logical_volume.rb b/lib/puppet/type/logical_volume.rb index 57ebd6ec..9232ce00 100644 --- a/lib/puppet/type/logical_volume.rb +++ b/lib/puppet/type/logical_volume.rb @@ -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) diff --git a/spec/acceptance/create_filesystem_spec.rb b/spec/acceptance/create_filesystem_spec.rb index d9b50fec..13b70856 100755 --- a/spec/acceptance/create_filesystem_spec.rb +++ b/spec/acceptance/create_filesystem_spec.rb @@ -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 @@ -116,6 +116,7 @@ ensure => present, volume_group => '#{vg}', size => '20M', + stripes => 1, } -> filesystem {'Create_filesystem': @@ -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