Skip to content

Commit 06c8bb1

Browse files
Andreas Unterkircherunki
Andreas Unterkircher
authored andcommitted
manifests/logical_volume.pp, add support for filesystem-labels
1 parent d1e02ad commit 06c8bb1

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ If you need a more complex configuration, you'll need to build the
142142
resources out yourself.
143143
144144
## Optional Values
145-
The `unless_vg` (physical_volume) and `createonly` (volume_group) will check
145+
The `unless_vg` (physical_volume) and `createonly` (volume_group) will check
146146
to see if "myvg" exists. If "myvg" does exist then they will not modify
147147
the physical volume or volume_group. This is useful if your environment
148148
is built with certain disks but they change while the server grows, shrinks
149149
or moves.
150-
150+
151151
Example:
152152
```puppet
153153
physical_volume { "/dev/hdc":
@@ -200,6 +200,7 @@ resources out yourself.
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.
202202
* thinpool (Parameter) - Default value: `false` - Set to true to create a thin pool or to pool name to create thin volume
203+
* use_fs_label (Parameter) - Default value: `false` - Set to true to create and mount the filesystem with a label (e.g. `mkfs.ext4 -L foobar` and `mount LABEL=foobar /mnt`). The value is taken from the resource-title.
203204
* 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.
204205

205206
### physical_volume

manifests/logical_volume.pp

+15-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Boolean $mountpath_require = false,
1515
Boolean $mounted = true,
1616
Boolean $createfs = true,
17+
Boolean $use_fs_label = false,
1718
$extents = undef,
1819
$stripes = undef,
1920
$stripesize = undef,
@@ -32,6 +33,17 @@
3233

3334
$lvm_device_path = "/dev/${volume_group}/${name}"
3435

36+
$mount_device = $use_fs_label ? {
37+
false => $lvm_device_path,
38+
true => "LABEL=${name}",
39+
}
40+
41+
$mkfs_label = $use_fs_label ? {
42+
false => '',
43+
# the ending whitespace is required
44+
true => "-L ${name} ",
45+
}
46+
3547
if $mountpath_require and $fs_type != 'swap' {
3648
Mount {
3749
require => File[$mountpath],
@@ -40,7 +52,7 @@
4052

4153
if $fs_type == 'swap' {
4254
$mount_title = $lvm_device_path
43-
$fixed_mountpath = "swap_${lvm_device_path}"
55+
$fixed_mountpath = "swap_${mount_device}"
4456
$fixed_pass = 0
4557
$fixed_dump = 0
4658
$mount_ensure = $ensure ? {
@@ -96,7 +108,7 @@
96108
filesystem { $lvm_device_path:
97109
ensure => $ensure,
98110
fs_type => $fs_type,
99-
options => $mkfs_options,
111+
options => "${mkfs_label}${mkfs_options}",
100112
}
101113
}
102114

@@ -113,7 +125,7 @@
113125
mount { $mount_title:
114126
ensure => $mount_ensure,
115127
name => $fixed_mountpath,
116-
device => $lvm_device_path,
128+
device => $mount_device,
117129
fstype => $fs_type,
118130
options => $options,
119131
pass => $fixed_pass,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require 'master_manipulator'
2+
require 'lvm_helper'
3+
require 'securerandom'
4+
5+
test_name "FM-4615 - C96570 - create filesystem with parameter 'use_fs_label'"
6+
7+
# initilize
8+
pv = '/dev/sdc'
9+
vg = ('VolumeGroup_' + SecureRandom.hex(2))
10+
lv = ('fslabel' + SecureRandom.hex(3))
11+
12+
# Teardown
13+
teardown do
14+
confine_block(:except, roles: ['master', 'dashboard', 'database']) do
15+
agents.each do |agent|
16+
remove_all(agent, pv, vg, lv)
17+
end
18+
end
19+
end
20+
21+
pp = <<-MANIFEST
22+
physical_volume {'#{pv}':
23+
ensure => present,
24+
}
25+
->
26+
volume_group {'#{vg}':
27+
ensure => present,
28+
physical_volumes => '#{pv}',
29+
}
30+
->
31+
logical_volume{'#{lv}':
32+
ensure => present,
33+
volume_group => '#{vg}',
34+
size => '20M',
35+
use_fs_label => true,
36+
createfs => true,
37+
fs_type => 'ext4',
38+
options => '-b 4096 -E stride=32,stripe-width=64',
39+
}
40+
MANIFEST
41+
42+
step 'Inject "site.pp" on Master'
43+
site_pp = create_site_pp(master, manifest: pp)
44+
inject_site_pp(master, get_site_pp_path(master), site_pp)
45+
46+
step 'Run Puppet Agent to create logical volumes'
47+
confine_block(:except, roles: ['master', 'dashboard', 'database']) do
48+
agents.each do |agent|
49+
on(agent, puppet('agent -t --environment production'), acceptable_exit_codes: [0, 2]) do |result|
50+
assert_no_match(%r{Error:}, result.stderr, 'Unexpected error was detected!')
51+
end
52+
53+
step "Verify the logical volume has correct format type: #{lv}"
54+
is_correct_format?(agent, vg, lv, 'ext4')
55+
end
56+
end

0 commit comments

Comments
 (0)