From 4ba33cdff2925e9dff9510ff2d4e1c9b5e505c4f Mon Sep 17 00:00:00 2001 From: Xingchao Yu Date: Wed, 28 Jun 2017 17:31:19 +0800 Subject: [PATCH] Add Support of mounting devices by UUIDs In currently, swift::storage::xfs will mount device by its file path, like /dev/sda1. But the device file path will change when the computer reboots. This will lead Swift services fails to boot. This patch introduces $device_type param to support mount disk by UUIDs. By default, it will set to 'path' to keep compatiable. Change-Id: I1782c0b18a27203e90d27473d94fa16968c3f913 --- manifests/storage/xfs.pp | 18 ++++++++++++++++-- ...ce-mount-type-support-2a5f1df26c2d1e68.yaml | 4 ++++ spec/defines/swift_storage_xfs_spec.rb | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/add-device-mount-type-support-2a5f1df26c2d1e68.yaml diff --git a/manifests/storage/xfs.pp b/manifests/storage/xfs.pp index 3de40dce..372eeaf1 100644 --- a/manifests/storage/xfs.pp +++ b/manifests/storage/xfs.pp @@ -17,11 +17,16 @@ # (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 or UUID. +# Defaults to 'path'. +# # Sample usage: # # swift::storage::xfs { # ['sdb', 'sdc', 'sde', 'sdf', 'sdg', 'sdh', 'sdi', 'sdj', 'sdk']: # mnt_base_dir => '/srv/node', +# mount_type => 'uuid', # require => Class['swift']; # } # @@ -32,7 +37,8 @@ define swift::storage::xfs( $device = '', $byte_size = '1024', $mnt_base_dir = '/srv/node', - $loopback = false + $loopback = false, + $mount_type = 'path', ) { include ::swift::deps @@ -44,6 +50,14 @@ define swift::storage::xfs( $target_device = $device } + case $mount_type { + 'path': { $mount_device = $target_device } + 'uuid': { $mount_device = dig44($facts, ['partitions', $target_device, 'uuid']) + unless $mount_device { fail("Unable to fetch uuid of ${target_device}") } + } + default: { fail("Unsupported mount_type parameter value: '${mount_type}'. Should be 'path' or 'uuid'.") } + } + if(!defined(File[$mnt_base_dir])) { file { $mnt_base_dir: ensure => directory, @@ -67,7 +81,7 @@ define swift::storage::xfs( } swift::storage::mount { $name: - device => $target_device, + device => $mount_device, mnt_base_dir => $mnt_base_dir, subscribe => Exec["mkfs-${name}"], loopback => $loopback, diff --git a/releasenotes/notes/add-device-mount-type-support-2a5f1df26c2d1e68.yaml b/releasenotes/notes/add-device-mount-type-support-2a5f1df26c2d1e68.yaml new file mode 100644 index 00000000..08aaf33f --- /dev/null +++ b/releasenotes/notes/add-device-mount-type-support-2a5f1df26c2d1e68.yaml @@ -0,0 +1,4 @@ +--- +features: + - Add device_type param to support mount disk partitions by UUID, + this is more helpful than device path in production environment. diff --git a/spec/defines/swift_storage_xfs_spec.rb b/spec/defines/swift_storage_xfs_spec.rb index 517789da..47c1698b 100644 --- a/spec/defines/swift_storage_xfs_spec.rb +++ b/spec/defines/swift_storage_xfs_spec.rb @@ -10,7 +10,8 @@ describe 'swift::storage::xfs' do :device => "/dev/#{title}", :byte_size => '1024', :mnt_base_dir => '/srv/node', - :loopback => false + :loopback => false, + :device_type => 'path' } end