Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add support for filesystem labels #251

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ If you need a more complex configuration, you'll need to build the
resources out yourself.

## Optional Values
The `unless_vg` (physical_volume) and `createonly` (volume_group) will check
The `unless_vg` (physical_volume) and `createonly` (volume_group) will check
to see if "myvg" exists. If "myvg" does exist then they will not modify
the physical volume or volume_group. This is useful if your environment
is built with certain disks but they change while the server grows, shrinks
or moves.

Example:
```puppet
physical_volume { "/dev/hdc":
Expand Down Expand Up @@ -200,6 +200,7 @@ resources out yourself.
* stripes (Parameter) - The number of stripes to allocate for the new logical volume.
* stripesize (Parameter) - The stripesize to use for the new logical volume.
* thinpool (Parameter) - Default value: `false` - Set to true to create a thin pool or to pool name to create thin volume
* 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.
* 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.

### physical_volume
Expand Down
18 changes: 15 additions & 3 deletions manifests/logical_volume.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Boolean $mountpath_require = false,
Boolean $mounted = true,
Boolean $createfs = true,
Boolean $use_fs_label = false,
$extents = undef,
$stripes = undef,
$stripesize = undef,
Expand All @@ -32,6 +33,17 @@

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

$mount_device = $use_fs_label ? {
false => $lvm_device_path,
true => "LABEL=${name}",
}

$mkfs_label = $use_fs_label ? {
false => '',
# the ending whitespace is required
true => "-L ${name} ",
}

if $mountpath_require and $fs_type != 'swap' {
Mount {
require => File[$mountpath],
Expand All @@ -40,7 +52,7 @@

if $fs_type == 'swap' {
$mount_title = $lvm_device_path
$fixed_mountpath = "swap_${lvm_device_path}"
$fixed_mountpath = "swap_${mount_device}"
$fixed_pass = 0
$fixed_dump = 0
$mount_ensure = $ensure ? {
Expand Down Expand Up @@ -96,7 +108,7 @@
filesystem { $lvm_device_path:
ensure => $ensure,
fs_type => $fs_type,
options => $mkfs_options,
options => "${mkfs_label}${mkfs_options}",
}
}

Expand All @@ -113,7 +125,7 @@
mount { $mount_title:
ensure => $mount_ensure,
name => $fixed_mountpath,
device => $lvm_device_path,
device => $mount_device,
fstype => $fs_type,
options => $options,
pass => $fixed_pass,
Expand Down
26 changes: 14 additions & 12 deletions manifests/volume_group.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
Enum['present', 'absent'] $ensure = present,
Hash $logical_volumes = {},
Boolean $followsymlinks = false,
Boolean $manage_pv = true,
) {

if is_hash($physical_volumes) {
create_resources(
'lvm::physical_volume',
$physical_volumes,
{
ensure => $ensure,
if $manage_pv {
if is_hash($physical_volumes) {
create_resources(
'lvm::physical_volume',
$physical_volumes,
{
ensure => $ensure,
}
)
}
else {
physical_volume { $physical_volumes:
ensure => $ensure,
}
)
}
else {
physical_volume { $physical_volumes:
ensure => $ensure,
}
}


volume_group { $name:
ensure => $ensure,
createonly => $createonly,
Expand Down
56 changes: 56 additions & 0 deletions tests/beaker/tests/create_filesystem_with_fs_label.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'master_manipulator'
require 'lvm_helper'
require 'securerandom'

test_name "FM-4615 - C96570 - create filesystem with parameter 'use_fs_label'"

# initilize
pv = '/dev/sdc'
vg = ('VolumeGroup_' + SecureRandom.hex(2))
lv = ('fslabel' + SecureRandom.hex(3))

# Teardown
teardown do
confine_block(:except, roles: ['master', 'dashboard', 'database']) do
agents.each do |agent|
remove_all(agent, pv, vg, lv)
end
end
end

pp = <<-MANIFEST
physical_volume {'#{pv}':
ensure => present,
}
->
volume_group {'#{vg}':
ensure => present,
physical_volumes => '#{pv}',
}
->
logical_volume{'#{lv}':
ensure => present,
volume_group => '#{vg}',
size => '20M',
use_fs_label => true,
createfs => true,
fs_type => 'ext4',
options => '-b 4096 -E stride=32,stripe-width=64',
}
MANIFEST

step 'Inject "site.pp" on Master'
site_pp = create_site_pp(master, manifest: pp)
inject_site_pp(master, get_site_pp_path(master), site_pp)

step 'Run Puppet Agent to create logical volumes'
confine_block(:except, roles: ['master', 'dashboard', 'database']) do
agents.each do |agent|
on(agent, puppet('agent -t --environment production'), acceptable_exit_codes: [0, 2]) do |result|
assert_no_match(%r{Error:}, result.stderr, 'Unexpected error was detected!')
end

step "Verify the logical volume has correct format type: #{lv}"
is_correct_format?(agent, vg, lv, 'ext4')
end
end