Skip to content

Commit

Permalink
Merge pull request #333 from glangloi/main
Browse files Browse the repository at this point in the history
Allow modifying the physical extent size for volume groups
  • Loading branch information
bastelfreak authored Apr 12, 2024
2 parents 471a41b + 04576a1 commit 2cb0893
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/puppet/provider/volume_group/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def self.get_logical_volume_properties(volume_groups_line)
end

def create
vgcreate(@resource[:name], *@resource.should(:physical_volumes))
vgcreate_args = [@resource[:name], *@resource.should(:physical_volumes)]
extent_args = @resource[:extent_size].nil? ? [] : ['-s', @resource[:extent_size]]

vgcreate_args.append(*extent_args)

vgcreate(*vgcreate_args)
end

def destroy
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet/type/volume_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
isnamevar
end

newparam(:extent_size) do
desc 'The physical extent size. Uses OS default if not provided. Only applicable on Linux.'
end

newproperty(:physical_volumes, array_matching: :all) do
desc "The list of physical volumes to be included in the volume group; this
will automatically set these as dependencies, but they must be defined elsewhere
Expand Down
23 changes: 18 additions & 5 deletions spec/unit/puppet/provider/volume_group/lvm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,24 @@
end

describe 'when creating' do
it "executes 'vgcreate'" do
@resource.expects(:[]).with(:name).returns('myvg')
@resource.expects(:should).with(:physical_volumes).returns(['/dev/hda'])
@provider.expects(:vgcreate).with('myvg', '/dev/hda')
@provider.create
context 'when an extent size is not provided' do
it "executes 'vgcreate'" do
@resource.expects(:[]).with(:name).returns('myvg')
@resource.expects(:[]).with(:extent_size).returns(nil)
@resource.expects(:should).with(:physical_volumes).returns(['/dev/hda'])
@provider.expects(:vgcreate).with('myvg', '/dev/hda')
@provider.create
end
end

context 'when an extent size is provided' do
it "executes 'vgcreate' with the desired extent size" do
@resource.expects(:[]).with(:name).returns('myvg')
@resource.expects(:[]).twice.with(:extent_size).returns('16M')
@resource.expects(:should).with(:physical_volumes).returns(['/dev/hda'])
@provider.expects(:vgcreate).with('myvg', '/dev/hda', '-s', '16M')
@provider.create
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/unit/puppet/type/volume_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
end
end

describe 'the extent_size parameter' do
it 'exists' do
@type.attrclass(:extent_size).should_not be_nil
end
end

describe "the 'ensure' parameter" do
it 'exists' do
@type.attrclass(:ensure).should_not be_nil
Expand Down

0 comments on commit 2cb0893

Please sign in to comment.