diff --git a/README.md b/README.md index bbe6a291..1056256d 100644 --- a/README.md +++ b/README.md @@ -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": @@ -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 diff --git a/manifests/logical_volume.pp b/manifests/logical_volume.pp index bd50a3f8..9fac2c01 100644 --- a/manifests/logical_volume.pp +++ b/manifests/logical_volume.pp @@ -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, @@ -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], @@ -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 ? { @@ -96,7 +108,7 @@ filesystem { $lvm_device_path: ensure => $ensure, fs_type => $fs_type, - options => $mkfs_options, + options => "${mkfs_label}${mkfs_options}", } } @@ -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, diff --git a/manifests/volume_group.pp b/manifests/volume_group.pp index f0bb6a9e..ca9a4d07 100644 --- a/manifests/volume_group.pp +++ b/manifests/volume_group.pp @@ -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, diff --git a/tests/beaker/tests/create_filesystem_with_fs_label.rb b/tests/beaker/tests/create_filesystem_with_fs_label.rb new file mode 100755 index 00000000..9fbe84aa --- /dev/null +++ b/tests/beaker/tests/create_filesystem_with_fs_label.rb @@ -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