From 8380976e338783ab006ae9e0f95c5164833919fb Mon Sep 17 00:00:00 2001 From: Xingchao Yu Date: Thu, 13 Jul 2017 16:09:20 +0800 Subject: [PATCH] Support to pass external args in parted command Currently facter only support to fetch the partition's uuid, If users want to mount device by uuid, then partitions should be made in the disks. This patch aims to add new param $ext_args in swift::storage::disk to enable passing making partitions arguments in parted command. Change-Id: I26dcfe73d2791a9033b555323847ddd211f02ceb --- manifests/storage/disk.pp | 7 ++++++- manifests/storage/xfs.pp | 5 +++++ .../add-parted-external-command-c89bcce3b3ea54dc.yaml | 4 ++++ spec/defines/swift_storage_disk_spec.rb | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add-parted-external-command-c89bcce3b3ea54dc.yaml diff --git a/manifests/storage/disk.pp b/manifests/storage/disk.pp index 6fc64d48..2707d36f 100644 --- a/manifests/storage/disk.pp +++ b/manifests/storage/disk.pp @@ -29,6 +29,10 @@ # (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 # +# [*ext_args*] +# (optional) The external command that will be used in parted command. +# Default to ''. For making partitions, it would be 'mkpart primary 0% 100%'. +# # =Example= # # Simply add one disk sdb: @@ -47,6 +51,7 @@ define swift::storage::disk( $base_dir = '/dev', $mnt_base_dir = '/srv/node', $byte_size = '1024', + $ext_args = '', ) { include ::swift::deps @@ -62,7 +67,7 @@ define swift::storage::disk( } exec { "create_partition_label-${name}": - command => "parted -s ${base_dir}/${name} mklabel gpt", + command => "parted -s ${base_dir}/${name} mklabel gpt ${ext_args}", path => ['/usr/bin/', '/sbin','/bin'], onlyif => ["test -b ${base_dir}/${name}","parted ${base_dir}/${name} print|tail -1|grep 'Error'"], before => Anchor['swift::config::end'], diff --git a/manifests/storage/xfs.pp b/manifests/storage/xfs.pp index 372eeaf1..ab036e49 100644 --- a/manifests/storage/xfs.pp +++ b/manifests/storage/xfs.pp @@ -50,6 +50,11 @@ define swift::storage::xfs( $target_device = $device } + # Currently, facter doesn't support to fetch the device's uuid, only the partition's. + # If you want to mount device by uuid, you should set $ext_args to 'mkpart primary 0% 100%' + # in swift::storage::disk to make a partition. Also, the device name should change accordingly. + # For example: from 'sda' to 'sda1'. + # The code does NOT work in existing Swift cluster. case $mount_type { 'path': { $mount_device = $target_device } 'uuid': { $mount_device = dig44($facts, ['partitions', $target_device, 'uuid']) diff --git a/releasenotes/notes/add-parted-external-command-c89bcce3b3ea54dc.yaml b/releasenotes/notes/add-parted-external-command-c89bcce3b3ea54dc.yaml new file mode 100644 index 00000000..e850073e --- /dev/null +++ b/releasenotes/notes/add-parted-external-command-c89bcce3b3ea54dc.yaml @@ -0,0 +1,4 @@ +--- +features: + - Add support of external args in running parted command. When mounting device by uuid, + this param should be set to a appropriate value. diff --git a/spec/defines/swift_storage_disk_spec.rb b/spec/defines/swift_storage_disk_spec.rb index 61aeff05..7243e7a0 100644 --- a/spec/defines/swift_storage_disk_spec.rb +++ b/spec/defines/swift_storage_disk_spec.rb @@ -12,9 +12,17 @@ describe 'swift::storage::disk' do :base_dir => '/dev', :mnt_base_dir => '/srv/node', :byte_size => '1024', + :ext_args => 'mkpart primary 0% 100%', } end + it { is_expected.to contain_exec("create_partition_label-sdb").with( + :command => "parted -s #{params[:base_dir]}/sdb mklabel gpt #{params[:ext_args]}", + :path => ["/usr/bin/", "/sbin", "/bin"], + :onlyif => ["test -b #{params[:base_dir]}/sdb","parted #{params[:base_dir]}/sdb print|tail -1|grep 'Error'"], + :before => 'Anchor[swift::config::end]' + )} + it { is_expected.to contain_swift__storage__xfs('sdb').with( :device => '/dev/sdb', :mnt_base_dir => '/srv/node',