Skip to content

Commit 8bb29fd

Browse files
afalkohunner
authored andcommitted
Add support for thin provisioning and setting poolmetadatasize (#154)
* Add support for thin provisioning and setting poolmetadatasize * Additional fixes and testing/docs This commit fixes the comments raised in PR/154 and adds testing and documentation; * Inherit the thin attribute from Puppet::Parameter::Boolean * Conditionally add -n flag to provider args rather than drop later * Fixed hard tab spaces in provider * Added documentation for new attributes * Added rspec tests * added thin and poolmetadatasize to lvm::volume_group defined type * Changed thin attribute to thinpool * changed error message for poolmetadatasize validation * Document that poolmetadatasize currently only sets on creation * changed $thin to $thinpool, ommitted after attribute rename (#3)
1 parent 1653533 commit 8bb29fd

File tree

5 files changed

+99
-18
lines changed

5 files changed

+99
-18
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,14 @@ resources out yourself.
167167
* mounted - If puppet should mount the volume. This only affects what puppet will do, and not what will be mounted at boot-time.
168168
* no_sync (Parameter) - An optimization in lvcreate, at least on Linux.
169169
* persistent (Parameter) - Set to true to make the block device persistent
170+
* poolmetadatasize (Parameter) - Set the initial size of the logical volume pool metadata on creation
170171
* readahead (Parameter) - The readahead count to use for the new logical volume.
171172
* region_size (Parameter) - A mirror is divided into regions of this size (in MB), the mirror log uses this granularity to track which regions are in sync. CAN NOT BE CHANGED on already mirrored volume. Take your mirror size in terabytes and round up that number to the next power of 2, using that number as the -R argument.
172173
* size (Property) - The size of the logical volume. Set to undef to use all available space
173174
* size_is_minsize (Parameter) Default value: `:false` - Set to true if the ‘size’ parameter specified, is just the minimum size you need (if the LV found is larger then the size requests this is just logged not causing a FAIL)
174175
* stripes (Parameter) - The number of stripes to allocate for the new logical volume.
175176
* stripesize (Parameter) - The stripesize to use for the new logical volume.
177+
* thinpool (Parameter) - Default value: `:false` - Set to true to create a thin pool
176178
* volume_group (Parameter) - The volume group name associated with this logical volume. This will automatically set this volume group as a dependency, but it must be defined elsewhere using the volume_group resource type.
177179

178180
### physical_volume

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ def self.get_logical_volume_properties(logical_volumes_line)
5252
end
5353

5454
def create
55-
args = ['-n', @resource[:name]]
55+
args = []
56+
57+
args.push('-n', @resource[:name]) unless @resource[:thinpool]
58+
5659
if @resource[:size]
5760
args.push('--size', @resource[:size])
5861
elsif @resource[:initial_size]
@@ -74,6 +77,11 @@ def create
7477
args.push('--stripesize', @resource[:stripesize])
7578
end
7679

80+
81+
82+
if @resource[:poolmetadatasize]
83+
args.push('--poolmetadatasize', @resource[:poolmetadatasize])
84+
end
7785

7886
if @resource[:mirror]
7987
args.push('--mirrors', @resource[:mirror])
@@ -110,7 +118,12 @@ def create
110118
args.push('--type', @resource[:type])
111119
end
112120

113-
args << @resource[:volume_group]
121+
if @resource[:thinpool]
122+
args.push('--thin')
123+
args << @resource[:volume_group] + "/" + @resource[:name]
124+
else
125+
args << @resource[:volume_group]
126+
end
114127
lvcreate(*args)
115128
end
116129

lib/puppet/type/logical_volume.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'puppet/parameter/boolean'
2+
13
Puppet::Type.newtype(:logical_volume) do
24

35
ensurable
@@ -74,6 +76,20 @@ def insync?(is)
7476
end
7577
end
7678

79+
newparam(:thinpool, :boolean => true, :parent => Puppet::Parameter::Boolean) do
80+
desc "Set to true to create a thin pool"
81+
defaultto false
82+
end
83+
84+
newparam(:poolmetadatasize) do
85+
desc "Change the size of logical volume pool metadata"
86+
validate do |value|
87+
unless value =~ /^[0-9]+(\.[0-9]+)?[KMGTPE]/i
88+
raise ArgumentError , "#{value} is not a valid size for pool metadata"
89+
end
90+
end
91+
end
92+
7793
newparam(:minor) do
7894
desc "Set the minor number"
7995
validate do |value|

manifests/logical_volume.pp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
$range = undef,
2222
$size_is_minsize = undef,
2323
$type = undef,
24+
$thinpool = undef,
25+
$poolmetadatasize = undef,
2426
$mirror = undef,
2527
$mirrorlog = undef,
2628
$no_sync = undef,
@@ -76,22 +78,24 @@
7678
}
7779

7880
logical_volume { $name:
79-
ensure => $ensure,
80-
volume_group => $volume_group,
81-
size => $size,
82-
initial_size => $initial_size,
83-
stripes => $stripes,
84-
stripesize => $stripesize,
85-
readahead => $readahead,
86-
extents => $extents,
87-
range => $range,
88-
size_is_minsize => $size_is_minsize,
89-
type => $type,
90-
mirror => $mirror,
91-
mirrorlog => $mirrorlog,
92-
no_sync => $no_sync,
93-
region_size => $region_size,
94-
alloc => $alloc
81+
ensure => $ensure,
82+
volume_group => $volume_group,
83+
size => $size,
84+
initial_size => $initial_size,
85+
stripes => $stripes,
86+
stripesize => $stripesize,
87+
readahead => $readahead,
88+
extents => $extents,
89+
range => $range,
90+
size_is_minsize => $size_is_minsize,
91+
type => $type,
92+
thinpool => $thinpool,
93+
poolmetadatasize => $poolmetadatasize,
94+
mirror => $mirror,
95+
mirrorlog => $mirrorlog,
96+
no_sync => $no_sync,
97+
region_size => $region_size,
98+
alloc => $alloc
9599
}
96100

97101
if $createfs {

spec/unit/puppet/type/logical_volume_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
:size_is_minsize => :false,
1313
:persistent => :false,
1414
:minor => 100,
15+
:thinpool => false,
16+
:poolmetadatasize => '10M',
1517
}
1618
stub_default_provider!
1719
end
@@ -47,6 +49,7 @@
4749
end
4850
end
4951

52+
5053
describe "when specifying the 'size_is_minsize' parameter" do
5154
it "should exist" do
5255
@type.attrclass(:size_is_minsize).should_not be_nil
@@ -90,6 +93,49 @@
9093

9194
end
9295

96+
describe "when specifying the 'thinpool' parameter" do
97+
it "should exist" do
98+
@type.attrclass(:thinpool).should_not be_nil
99+
end
100+
it 'should support setting a value' do
101+
with(valid_params)[:thinpool].should == valid_params[:thinpool]
102+
end
103+
it "should support 'true' as a value" do
104+
with(valid_params.merge(:thinpool => :true)) do |resource|
105+
resource[:thinpool].should == true
106+
end
107+
end
108+
it "should support 'false' as a value" do
109+
with(valid_params.merge(:thinpool => :false)) do |resource|
110+
resource[:thinpool].should == false
111+
end
112+
end
113+
it "should not support other values" do
114+
specifying(valid_params.merge(:thinpool => :moep)).should raise_error(Puppet::Error)
115+
end
116+
end
117+
118+
describe "when specifying the 'poolmetadatasize' parameter" do
119+
it "should exist" do
120+
@type.attrclass(:poolmetadatasize).should_not be_nil
121+
end
122+
it 'should support setting a value' do
123+
with(valid_params)[:poolmetadatasize].should == valid_params[:poolmetadatasize]
124+
end
125+
126+
it 'should support K, M, G, T, P and E as extensions' do
127+
['K', 'M', 'G', 'T', 'P', 'E'].each do |ext|
128+
with(valid_params.merge(:poolmetadatasize => "10#{ext}")) do |resource|
129+
resource[:poolmetadatasize].should == "10#{ext}"
130+
end
131+
end
132+
end
133+
134+
it "should not support other values" do
135+
specifying(valid_params.merge(:poolmetadatasize => "100X")).should raise_error(Puppet::Error)
136+
end
137+
end
138+
93139
describe "when specifying the 'extents' parameter" do
94140
it "should exist" do
95141
@type.attrclass(:extents).should_not be_nil

0 commit comments

Comments
 (0)