diff --git a/manifests/storage/ext4.pp b/manifests/storage/ext4.pp index c8f7462e..35fd3515 100644 --- a/manifests/storage/ext4.pp +++ b/manifests/storage/ext4.pp @@ -1,7 +1,3 @@ -# follow the instructions for creating a loopback device -# for storage from: https://docs.openstack.org/swift/latest/development_saio.html -# -# this define needs to be sent a refresh signal to do anything # # === Parameters: # @@ -15,39 +11,76 @@ # Defaults to '/srv/node', base directory where disks are mounted to # # [*byte_size*] -# (optional) The byte size that dd uses when it creates the file system. -# Defaults to '1024', block size for the disk. For very large partitions, this should be larger -# It is recommend to use 1024 to ensure that the metadata can fit in a single inode. +# (optional) Byte size to use for every inode in the created filesystem. +# Defaults to '1024'. It is recommended to use 1024 to ensure that +# the metadata can fit in a single inode. # # [*loopback*] # (optional) Define if the device must be mounted as a loopback or not # Defaults to false. # +# [*mount_type*] +# (optional) Define if the device is mounted by the device partition path, +# UUID, or filesystem label. +# Defaults to 'path'. +# +# [*manage_filesystem*] +# (optional) If set to false, skip creationg of EXT4 filesystem. This is to +# set to false only after the server is fully setup, or if the filesystem was +# created outside of puppet. +# Defaults to true. +# +# [*label*] +# (optional) Filesystem label. +# Defaults to $name. +# define swift::storage::ext4( - Stdlib::Absolutepath $device = "/dev/${name}", - $byte_size = '1024', - Stdlib::Absolutepath $mnt_base_dir = '/srv/node', - Boolean $loopback = false + Stdlib::Absolutepath $device = "/dev/${name}", + $byte_size = '1024', + Stdlib::Absolutepath $mnt_base_dir = '/srv/node', + Boolean $loopback = false, + Enum['path', 'uuid', 'label'] $mount_type = 'path', + Boolean $manage_filesystem = true, + String[1] $label = $name, ) { include swift::deps - # does this have to be refreshonly? - # how can I know if this drive has been formatted? - exec { "mkfs-${name}": - command => ['mkfs.ext4', '-I', $byte_size, '-F', $device], - path => ['/sbin/'], - refreshonly => true, - before => Anchor['swift::config::end'], + + case $mount_type { + 'uuid': { + $mount_device = dig44($facts, ['partitions', $device, 'uuid']) + if !$mount_device { + fail("Unable to fetch uuid of ${device}") + } + } + 'label': { + $mount_device = "LABEL=${label}" + } + default: { # path + $mount_device = $device + } + } + + if $manage_filesystem { + $mkfs_command = ['mkfs.ext4', '-I', $byte_size, '-F'] + $mkfs_label_opt = $mount_type ? { + 'label' => ['-L', $label], + default => [] + } + exec { "mkfs-${name}": + command => $mkfs_command + $mkfs_label_opt + [$device], + path => ['/sbin/', '/usr/sbin/'], + refreshonly => true, + before => Anchor['swift::config::end'], + } + + Exec["mkfs-${name}"] ~> Swift::Storage::Mount<| title == $name |> } swift::storage::mount { $name: - device => $device, + device => $mount_device, mnt_base_dir => $mnt_base_dir, loopback => $loopback, fstype => 'ext4', } - - Exec<| title == "mkfs-${name}" |> - ~> Swift::Storage::Mount<| title == $name |> - } diff --git a/manifests/storage/xfs.pp b/manifests/storage/xfs.pp index fab3bf63..25795741 100644 --- a/manifests/storage/xfs.pp +++ b/manifests/storage/xfs.pp @@ -109,7 +109,7 @@ define swift::storage::xfs( before => Anchor['swift::config::end'], } Package<| title == 'xfsprogs' |> - ~> Exec<| title == "mkfs-${name}" |> + ~> Exec["mkfs-${name}"] ~> Swift::Storage::Mount<| title == $name |> } else { Package<| title == 'xfsprogs' |> diff --git a/releasenotes/notes/ext4-interface-sync-daaef41347bfe3e1.yaml b/releasenotes/notes/ext4-interface-sync-daaef41347bfe3e1.yaml new file mode 100644 index 00000000..024f5004 --- /dev/null +++ b/releasenotes/notes/ext4-interface-sync-daaef41347bfe3e1.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + The following parameters have been added to the ``swift::storage::ext4`` + defined resource type. + + - ``mount_type`` + - ``manage_filesystem`` + - ``label`` diff --git a/spec/defines/swift_storage_ext4_spec.rb b/spec/defines/swift_storage_ext4_spec.rb new file mode 100644 index 00000000..b6845c2c --- /dev/null +++ b/spec/defines/swift_storage_ext4_spec.rb @@ -0,0 +1,89 @@ +require 'spec_helper' + +describe 'swift::storage::ext4' do + let :title do + 'foo' + end + + shared_examples 'swift::storage::ext4' do + describe 'when a device is specified' do + let :default_params do + { + :device => "/dev/#{title}", + :byte_size => '1024', + :mnt_base_dir => '/srv/node', + :loopback => false, + :device_type => 'path' + } + end + + [{}, + { + :device => '/dev/foo', + :byte_size => 1, + :mnt_base_dir => '/mnt/bar', + :loopback => true + } + ].each do |param_set| + + describe "#{param_set == {} ? "using default" : "specifying"} class parameters" do + let :param_hash do + default_params.merge(param_set) + end + + let :params do + param_set + end + + it { is_expected.to contain_exec("mkfs-foo").with( + :command => ['mkfs.ext4', '-I', param_hash[:byte_size], '-F', param_hash[:device]], + :path => ['/sbin/', '/usr/sbin/'], + :refreshonly => true, + )} + + it { is_expected.to contain_swift__storage__mount(title).with( + :device => param_hash[:device], + :mnt_base_dir => param_hash[:mnt_base_dir], + :loopback => param_hash[:loopback], + )} + end + end + + context 'with mount type label' do + let :params do + { + :mount_type => :label + } + end + + let :param_hash do + default_params.merge(params) + end + + it { is_expected.to contain_exec("mkfs-foo").with( + :command => ['mkfs.ext4', '-I', param_hash[:byte_size], '-F', '-L', title, param_hash[:device]], + :path => ['/sbin/', '/usr/sbin/'], + :refreshonly => true, + )} + + it { is_expected.to contain_swift__storage__mount(title).with( + :device => "LABEL=#{title}", + :mnt_base_dir => param_hash[:mnt_base_dir], + :loopback => param_hash[:loopback], + )} + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge(OSDefaults.get_facts()) + end + + it_configures 'swift::storage::ext4' + end + end +end