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
This commit is contained in:
Xingchao Yu 2017-07-13 16:09:20 +08:00
parent 759f10331a
commit 8380976e33
4 changed files with 23 additions and 1 deletions

View File

@ -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'],

View File

@ -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'])

View File

@ -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.

View File

@ -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',