Skip to content

Commit 120218a

Browse files
authored
Merge pull request #210 from glorpen/lvmthin
Added support for LVM Thin Volumes
2 parents 189949a + d3a8cb9 commit 120218a

File tree

6 files changed

+91
-34
lines changed

6 files changed

+91
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ resources out yourself.
199199
* 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)
200200
* stripes (Parameter) - The number of stripes to allocate for the new logical volume.
201201
* stripesize (Parameter) - The stripesize to use for the new logical volume.
202-
* thinpool (Parameter) - Default value: `false` - Set to true to create a thin pool
202+
* thinpool (Parameter) - Default value: `false` - Set to true to create a thin pool or to pool name to create thin volume
203203
* 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.
204204

205205
### physical_volume

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ def self.get_logical_volume_properties(logical_volumes_line)
5454
def create
5555
args = []
5656

57-
args.push('-n', @resource[:name]) unless @resource[:thinpool]
57+
args.push('-n', @resource[:name]) unless @resource[:thinpool] == true
58+
59+
size_option = '--size'
60+
if @resource[:thinpool].is_a? String
61+
size_option = '--virtualsize'
62+
end
5863

5964
if @resource[:size]
60-
args.push('--size', @resource[:size])
65+
args.push(size_option, @resource[:size])
6166
elsif @resource[:initial_size]
62-
args.push('--size', @resource[:initial_size])
67+
args.push(size_option, @resource[:initial_size])
6368
end
6469
if @resource[:extents]
6570
args.push('--extents', @resource[:extents])
@@ -120,7 +125,11 @@ def create
120125

121126
if @resource[:thinpool]
122127
args.push('--thin')
123-
args << @resource[:volume_group] + "/" + @resource[:name]
128+
if @resource[:thinpool].is_a? String
129+
args << @resource[:volume_group] + "/" + @resource[:thinpool]
130+
else
131+
args << @resource[:volume_group] + "/" + @resource[:name]
132+
end
124133
else
125134
args << @resource[:volume_group]
126135
end

lib/puppet/type/logical_volume.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,23 @@ def insync?(is)
7676
end
7777
end
7878

79-
newparam(:thinpool, :boolean => true, :parent => Puppet::Parameter::Boolean) do
80-
desc "Set to true to create a thin pool"
81-
defaultto false
79+
newparam(:thinpool) do
80+
desc "Set to true to create a thin pool or to pool name to create thin volume"
81+
defaultto false
82+
validate do |value|
83+
unless value.is_a? String or [:true, true, "true", :false, false, "false"].include?(value)
84+
raise ArgumentError , "thinpool must be either be true, false or string"
85+
end
86+
end
87+
munge do |value|
88+
if [:true, true, "true"].include?(value)
89+
true
90+
elsif value.is_a? String and value != "false"
91+
value
92+
else
93+
false
94+
end
95+
end
8296
end
8397

8498
newparam(:poolmetadatasize) do
@@ -194,4 +208,9 @@ def insync?(is)
194208
autorequire(:volume_group) do
195209
@parameters[:volume_group].value
196210
end
211+
autorequire(:logical_volume) do
212+
if @parameters[:thinpool].is_a? String
213+
@parameters[:thinpool].value
214+
end
215+
end
197216
end

manifests/logical_volume.pp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
#
33
define lvm::logical_volume (
44
$volume_group,
5-
$size = undef,
6-
$initial_size = undef,
7-
Enum['absent', 'present'] $ensure = present,
8-
$options = 'defaults',
9-
$pass = '2',
10-
$dump = '0',
11-
$fs_type = 'ext4',
12-
$mkfs_options = undef,
13-
Stdlib::Absolutepath $mountpath = "/${name}",
14-
Boolean $mountpath_require = false,
15-
Boolean $mounted = true,
16-
Boolean $createfs = true,
17-
$extents = undef,
18-
$stripes = undef,
19-
$stripesize = undef,
20-
$readahead = undef,
21-
$range = undef,
22-
$size_is_minsize = undef,
23-
$type = undef,
24-
$thinpool = false,
25-
$poolmetadatasize = undef,
26-
$mirror = undef,
27-
$mirrorlog = undef,
28-
$no_sync = undef,
29-
$region_size = undef,
30-
$alloc = undef,
5+
$size = undef,
6+
$initial_size = undef,
7+
Enum['absent', 'present'] $ensure = present,
8+
$options = 'defaults',
9+
$pass = '2',
10+
$dump = '0',
11+
$fs_type = 'ext4',
12+
$mkfs_options = undef,
13+
Stdlib::Absolutepath $mountpath = "/${name}",
14+
Boolean $mountpath_require = false,
15+
Boolean $mounted = true,
16+
Boolean $createfs = true,
17+
$extents = undef,
18+
$stripes = undef,
19+
$stripesize = undef,
20+
$readahead = undef,
21+
$range = undef,
22+
$size_is_minsize = undef,
23+
$type = undef,
24+
Variant[Boolean, String] $thinpool = false,
25+
$poolmetadatasize = undef,
26+
$mirror = undef,
27+
$mirrorlog = undef,
28+
$no_sync = undef,
29+
$region_size = undef,
30+
$alloc = undef,
3131
) {
3232

3333
$lvm_device_path = "/dev/${volume_group}/${name}"

spec/unit/puppet/provider/logical_volume/lvm_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@
134134
@provider.create
135135
end
136136
end
137+
context 'with named thinpool option' do
138+
it "should execute 'lvcreate' with '--virtualsize 1g' and '--thin myvg/mythinpool' options" do
139+
@resource.expects(:[]).with(:name).returns('mylv')
140+
@resource.expects(:[]).with(:volume_group).returns('myvg')
141+
@resource.expects(:[]).with(:size).returns('1g').at_least_once
142+
@resource.expects(:[]).with(:thinpool).returns('mythinpool').at_least_once
143+
@provider.expects(:lvcreate).with('-n', 'mylv', '--virtualsize', '1g', '--thin', 'myvg/mythinpool')
144+
@provider.create
145+
end
146+
end
137147
end
138148

139149
describe "when modifying" do
@@ -189,6 +199,20 @@
189199
expect { @provider.size = '1100000k' }.not_to raise_error(Puppet::ExecutionFailure, /blkid/)
190200
end
191201
end
202+
context "with defined thin pool" do
203+
it "should execute 'lvextend' as with normal volume" do
204+
@resource.expects(:[]).with(:name).returns('mylv').at_least_once
205+
@resource.expects(:[]).with(:volume_group).returns('myvg').at_least_once
206+
@resource.expects(:[]).with(:size).returns('1g').at_least_once
207+
@resource.expects(:[]).with(:thinpool).returns('mythinpool').at_least_once
208+
@provider.expects(:lvcreate).with('-n', 'mylv', '--virtualsize', '1g', '--thin', 'myvg/mythinpool')
209+
@provider.create
210+
@provider.expects(:lvs).with('--noheading', '--unit', 'g', '/dev/myvg/mylv').returns(' 1.00g').at_least_once
211+
@provider.expects(:lvs).with('--noheading', '-o', 'vg_extent_size', '--units', 'k', '/dev/myvg/mylv').returns(' 1000.00k')
212+
@provider.expects(:lvextend).with('-L', '2000000k', '/dev/myvg/mylv').returns(true)
213+
@provider.size = '2000000k'
214+
end
215+
end
192216
end
193217
context "not in extent portions" do
194218
it "should raise an exception" do

spec/unit/puppet/type/logical_volume_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
resource[:thinpool].should == false
111111
end
112112
end
113+
it "should support 'thinpool name' as a value" do
114+
with(valid_params.merge(:thinpool => 'mythinpool')) do |resource|
115+
resource[:thinpool].should == 'mythinpool'
116+
end
117+
end
113118
it "should not support other values" do
114119
specifying(valid_params.merge(:thinpool => :moep)).should raise_error(Puppet::Error)
115120
end

0 commit comments

Comments
 (0)