Allow use of device aliases for OSDs

Resolves $data paths using readlink, as ceph-disk does, so we don't
fail if the two mismatch.

Closes-Bug: #1677605
Change-Id: I13c2776dbbfd9c7cb91dc272e8a3405cd60210b0
This commit is contained in:
Joe Talerico 2017-03-30 09:41:03 -04:00 committed by Giulio Fidente
parent f98c196e22
commit ff2b2e6898
2 changed files with 84 additions and 68 deletions

View File

@ -50,7 +50,7 @@
#
define ceph::osd (
$ensure = present,
$journal = undef,
$journal = "''",
$cluster = undef,
$exec_timeout = $::ceph::params::exec_timeout,
$selinux_file_context = 'ceph_var_lib_t',
@ -91,7 +91,7 @@ mv -f ${udev_rules_file} ${udev_rules_file}.disabled && udevadm control --reload
",
onlyif => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
DISABLE_UDEV=\$(ceph --version | awk 'match(\$3, /[0-9]+\\.[0-9]+/) {if (substr(\$3, RSTART, RLENGTH) <= 0.94) {print 1}}')
DISABLE_UDEV=$(ceph --version | awk 'match(\$3, /[0-9]+\\.[0-9]+/) {if (substr(\$3, RSTART, RLENGTH) <= 0.94) {print 1}}')
test -f ${udev_rules_file} && test \$DISABLE_UDEV -eq 1
",
logoutput => true,
@ -102,15 +102,15 @@ test -f ${udev_rules_file} && test \$DISABLE_UDEV -eq 1
$ceph_check_fsid_mismatch = "ceph-osd-check-fsid-mismatch-${name}"
Exec[$ceph_check_udev] -> Exec[$ceph_check_fsid_mismatch]
Exec[$ceph_check_fsid_mismatch] -> Exec[$ceph_prepare]
# return error if ${data} has fsid differing from ${fsid}, unless there is no fsid
# return error if $(readlink -f ${data}) has fsid differing from ${fsid}, unless there is no fsid
exec { $ceph_check_fsid_mismatch:
command => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
test ${fsid} = \$(ceph-disk list ${data} | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
test ${fsid} = $(ceph-disk list $(readlink -f ${data}) | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
",
unless => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
test -z \$(ceph-disk list ${data} | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
test -z $(ceph-disk list $(readlink -f ${data}) | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
",
logoutput => true,
timeout => $exec_timeout,
@ -122,20 +122,22 @@ test -z \$(ceph-disk list ${data} | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a
exec { $ceph_prepare:
command => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
if ! test -b ${data} ; then
echo ${data} | egrep -e '^/dev' -q -v
mkdir -p ${data}
disk=$(readlink -f ${data})
if ! test -b \$disk ; then
echo \$disk | egrep -e '^/dev' -q -v
mkdir -p \$disk
if getent passwd ceph >/dev/null 2>&1; then
chown -h ceph:ceph ${data}
chown -h ceph:ceph \$disk
fi
fi
ceph-disk prepare ${cluster_option} ${fsid_option} ${data} ${journal}
ceph-disk prepare ${cluster_option} ${fsid_option} $(readlink -f ${data}) $(readlink -f ${journal})
udevadm settle
",
unless => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ceph-disk list | grep -E ' *${data}1? .*ceph data, (prepared|active)' ||
{ test -f ${data}/fsid && test -f ${data}/ceph_fsid && test -f ${data}/magic ;}
disk=$(readlink -f ${data})
ceph-disk list | egrep \" *\${disk}1? .*ceph data, (prepared|active)\" ||
{ test -f \$disk/fsid && test -f \$disk/ceph_fsid && test -f \$disk/magic ;}
",
logoutput => true,
timeout => $exec_timeout,
@ -144,11 +146,14 @@ ceph-disk list | grep -E ' *${data}1? .*ceph data, (prepared|active)' ||
if (str2bool($::selinux) == true) {
ensure_packages($::ceph::params::pkg_policycoreutils, {'ensure' => 'present'})
exec { "fcontext_${name}":
command => "semanage fcontext -a -t ${selinux_file_context} '${data}(/.*)?' && restorecon -R ${data}",
path => ['/usr/sbin', '/sbin', '/usr/bin', '/bin'],
command => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
semanage fcontext -a -t ${selinux_file_context} \"$(readlink -f ${data})(/.*)?\"
restorecon -R $(readlink -f ${data})
",
require => [Package[$::ceph::params::pkg_policycoreutils],Exec[$ceph_prepare]],
before => Exec[$ceph_activate],
unless => "test -b ${data} || (semanage fcontext -l | grep ${data})",
unless => "/usr/bin/test -b $(readlink -f ${data}) || (semanage fcontext -l | grep $(readlink -f ${data}))",
}
}
@ -156,24 +161,25 @@ ceph-disk list | grep -E ' *${data}1? .*ceph data, (prepared|active)' ||
exec { $ceph_activate:
command => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
if ! test -b ${data} ; then
echo ${data} | egrep -e '^/dev' -q -v
mkdir -p ${data}
disk=$(readlink -f ${data})
if ! test -b \$disk ; then
echo \$disk | egrep -e '^/dev' -q -v
mkdir -p \$disk
if getent passwd ceph >/dev/null 2>&1; then
chown -h ceph:ceph ${data}
chown -h ceph:ceph \$disk
fi
fi
# activate happens via udev when using the entire device
if ! test -b ${data} || ! test -b ${data}1 ; then
ceph-disk activate ${data} || true
if ! test -b \$disk || ! test -b \${disk}1 ; then
ceph-disk activate \$disk || true
fi
if test -f ${udev_rules_file}.disabled && test -b ${data}1 ; then
ceph-disk activate ${data}1 || true
if test -f ${udev_rules_file}.disabled && test -b \${disk}1 ; then
ceph-disk activate \${disk}1 || true
fi
",
unless => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ls -ld /var/lib/ceph/osd/${cluster_name}-* | grep ' ${data}\$'
ls -ld /var/lib/ceph/osd/${cluster_name}-* | grep \" $(readlink -f ${data})\$\"
",
logoutput => true,
tag => 'activate',
@ -185,11 +191,12 @@ ls -ld /var/lib/ceph/osd/${cluster_name}-* | grep ' ${data}\$'
exec { "remove-osd-${name}":
command => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
disk=$(readlink -f ${data})
if [ -z \"\$id\" ] ; then
id=\$(ceph-disk list | sed -nEe 's:^ *${data}1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p')
id=$(ceph-disk list | sed -nEe \"s:^ *\${disk}1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p\")
fi
if [ -z \"\$id\" ] ; then
id=\$(ls -ld /var/lib/ceph/osd/${cluster_name}-* | sed -nEe 's:.*/${cluster_name}-([0-9]+) *-> *${data}\$:\\1:p' || true)
id=$(ls -ld /var/lib/ceph/osd/${cluster_name}-* | sed -nEe \"s:.*/${cluster_name}-([0-9]+) *-> *\${disk}\$:\\1:p\" || true)
fi
if [ \"\$id\" ] ; then
stop ceph-osd cluster=${cluster_name} id=\$id || true
@ -205,11 +212,12 @@ fi
",
unless => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
disk=$(readlink -f ${data})
if [ -z \"\$id\" ] ; then
id=\$(ceph-disk list | sed -nEe 's:^ *${data}1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p')
id=$(ceph-disk list | sed -nEe \"s:^ *\${disk}1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p\")
fi
if [ -z \"\$id\" ] ; then
id=\$(ls -ld /var/lib/ceph/osd/${cluster_name}-* | sed -nEe 's:.*/${cluster_name}-([0-9]+) *-> *${data}\$:\\1:p' || true)
id=$(ls -ld /var/lib/ceph/osd/${cluster_name}-* | sed -nEe \"s:.*/${cluster_name}-([0-9]+) *-> *\${disk}\$:\\1:p\" || true)
fi
if [ \"\$id\" ] ; then
test ! -d /var/lib/ceph/osd/${cluster_name}-\$id

View File

@ -37,7 +37,7 @@ mv -f /usr/lib/udev/rules.d/95-ceph-osd.rules /usr/lib/udev/rules.d/95-ceph-osd.
",
'onlyif' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
DISABLE_UDEV=\$(ceph --version | awk 'match(\$3, /[0-9]+\\.[0-9]+/) {if (substr(\$3, RSTART, RLENGTH) <= 0.94) {print 1}}')
DISABLE_UDEV=$(ceph --version | awk 'match(\$3, /[0-9]+\\.[0-9]+/) {if (substr(\$3, RSTART, RLENGTH) <= 0.94) {print 1}}')
test -f /usr/lib/udev/rules.d/95-ceph-osd.rules && test \$DISABLE_UDEV -eq 1
",
'logoutput' => true,
@ -45,44 +45,47 @@ test -f /usr/lib/udev/rules.d/95-ceph-osd.rules && test \$DISABLE_UDEV -eq 1
it { is_expected.to contain_exec('ceph-osd-prepare-/srv').with(
'command' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
if ! test -b /srv ; then
echo /srv | egrep -e '^/dev' -q -v
mkdir -p /srv
disk=$(readlink -f /srv)
if ! test -b $disk ; then
echo $disk | egrep -e '^/dev' -q -v
mkdir -p $disk
if getent passwd ceph >/dev/null 2>&1; then
chown -h ceph:ceph /srv
chown -h ceph:ceph $disk
fi
fi
ceph-disk prepare --cluster ceph /srv
ceph-disk prepare --cluster ceph $(readlink -f /srv) $(readlink -f '')
udevadm settle
",
'unless' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ceph-disk list | grep -E ' */srv1? .*ceph data, (prepared|active)' ||
{ test -f /srv/fsid && test -f /srv/ceph_fsid && test -f /srv/magic ;}
disk=$(readlink -f /srv)
ceph-disk list | egrep \" *${disk}1? .*ceph data, (prepared|active)\" ||
{ test -f $disk/fsid && test -f $disk/ceph_fsid && test -f $disk/magic ;}
",
'logoutput' => true
) }
it { is_expected.to contain_exec('ceph-osd-activate-/srv').with(
'command' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
if ! test -b /srv ; then
echo /srv | egrep -e '^/dev' -q -v
mkdir -p /srv
disk=$(readlink -f /srv)
if ! test -b $disk ; then
echo $disk | egrep -e '^/dev' -q -v
mkdir -p $disk
if getent passwd ceph >/dev/null 2>&1; then
chown -h ceph:ceph /srv
chown -h ceph:ceph $disk
fi
fi
# activate happens via udev when using the entire device
if ! test -b /srv || ! test -b /srv1 ; then
ceph-disk activate /srv || true
if ! test -b $disk || ! test -b ${disk}1 ; then
ceph-disk activate $disk || true
fi
if test -f /usr/lib/udev/rules.d/95-ceph-osd.rules.disabled && test -b /srv1 ; then
ceph-disk activate /srv1 || true
if test -f /usr/lib/udev/rules.d/95-ceph-osd.rules.disabled && test -b ${disk}1 ; then
ceph-disk activate ${disk}1 || true
fi
",
'unless' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ls -ld /var/lib/ceph/osd/ceph-* | grep ' /srv\$'
ls -ld /var/lib/ceph/osd/ceph-* | grep \" $(readlink -f /srv)\$\"
",
'logoutput' => true
) }
@ -110,7 +113,7 @@ mv -f /usr/lib/udev/rules.d/95-ceph-osd.rules /usr/lib/udev/rules.d/95-ceph-osd.
",
'onlyif' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
DISABLE_UDEV=\$(ceph --version | awk 'match(\$3, /[0-9]+\\.[0-9]+/) {if (substr(\$3, RSTART, RLENGTH) <= 0.94) {print 1}}')
DISABLE_UDEV=$(ceph --version | awk 'match(\$3, /[0-9]+\\.[0-9]+/) {if (substr(\$3, RSTART, RLENGTH) <= 0.94) {print 1}}')
test -f /usr/lib/udev/rules.d/95-ceph-osd.rules && test \$DISABLE_UDEV -eq 1
",
'logoutput' => true,
@ -118,55 +121,58 @@ test -f /usr/lib/udev/rules.d/95-ceph-osd.rules && test \$DISABLE_UDEV -eq 1
it { is_expected.to contain_exec('ceph-osd-check-fsid-mismatch-/srv/data').with(
'command' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
test f39ace04-f967-4c3d-9fd2-32af2d2d2cd5 = \$(ceph-disk list /srv/data | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
test f39ace04-f967-4c3d-9fd2-32af2d2d2cd5 = $(ceph-disk list $(readlink -f /srv/data) | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
",
'unless' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
test -z \$(ceph-disk list /srv/data | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
test -z $(ceph-disk list $(readlink -f /srv/data) | egrep -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
",
'logoutput' => true
) }
it { is_expected.to contain_exec('ceph-osd-prepare-/srv/data').with(
'command' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
if ! test -b /srv/data ; then
echo /srv/data | egrep -e '^/dev' -q -v
mkdir -p /srv/data
disk=$(readlink -f /srv/data)
if ! test -b $disk ; then
echo $disk | egrep -e '^/dev' -q -v
mkdir -p $disk
if getent passwd ceph >/dev/null 2>&1; then
chown -h ceph:ceph /srv/data
chown -h ceph:ceph $disk
fi
fi
ceph-disk prepare --cluster testcluster --cluster-uuid f39ace04-f967-4c3d-9fd2-32af2d2d2cd5 /srv/data /srv/journal
ceph-disk prepare --cluster testcluster --cluster-uuid f39ace04-f967-4c3d-9fd2-32af2d2d2cd5 $(readlink -f /srv/data) $(readlink -f /srv/journal)
udevadm settle
",
'unless' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ceph-disk list | grep -E ' */srv/data1? .*ceph data, (prepared|active)' ||
{ test -f /srv/data/fsid && test -f /srv/data/ceph_fsid && test -f /srv/data/magic ;}
disk=$(readlink -f /srv/data)
ceph-disk list | egrep \" *${disk}1? .*ceph data, (prepared|active)\" ||
{ test -f $disk/fsid && test -f $disk/ceph_fsid && test -f $disk/magic ;}
",
'logoutput' => true
) }
it { is_expected.to contain_exec('ceph-osd-activate-/srv/data').with(
'command' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
if ! test -b /srv/data ; then
echo /srv/data | egrep -e '^/dev' -q -v
mkdir -p /srv/data
disk=$(readlink -f /srv/data)
if ! test -b $disk ; then
echo $disk | egrep -e '^/dev' -q -v
mkdir -p $disk
if getent passwd ceph >/dev/null 2>&1; then
chown -h ceph:ceph /srv/data
chown -h ceph:ceph $disk
fi
fi
# activate happens via udev when using the entire device
if ! test -b /srv/data || ! test -b /srv/data1 ; then
ceph-disk activate /srv/data || true
if ! test -b $disk || ! test -b ${disk}1 ; then
ceph-disk activate $disk || true
fi
if test -f /usr/lib/udev/rules.d/95-ceph-osd.rules.disabled && test -b /srv/data1 ; then
ceph-disk activate /srv/data1 || true
if test -f /usr/lib/udev/rules.d/95-ceph-osd.rules.disabled && test -b ${disk}1 ; then
ceph-disk activate ${disk}1 || true
fi
",
'unless' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ls -ld /var/lib/ceph/osd/testcluster-* | grep ' /srv/data\$'
ls -ld /var/lib/ceph/osd/testcluster-* | grep \" $(readlink -f /srv/data)\$\"
",
'logoutput' => true
) }
@ -187,11 +193,12 @@ ls -ld /var/lib/ceph/osd/testcluster-* | grep ' /srv/data\$'
it { is_expected.to contain_exec('remove-osd-/srv').with(
'command' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
disk=$(readlink -f /srv)
if [ -z \"\$id\" ] ; then
id=\$(ceph-disk list | sed -nEe 's:^ */srv1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p')
id=$(ceph-disk list | sed -nEe \"s:^ *${disk}1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p\")
fi
if [ -z \"\$id\" ] ; then
id=\$(ls -ld /var/lib/ceph/osd/ceph-* | sed -nEe 's:.*/ceph-([0-9]+) *-> */srv\$:\\1:p' || true)
id=$(ls -ld /var/lib/ceph/osd/ceph-* | sed -nEe \"s:.*/ceph-([0-9]+) *-> *${disk}\$:\\1:p\" || true)
fi
if [ \"\$id\" ] ; then
stop ceph-osd cluster=ceph id=\$id || true
@ -207,11 +214,12 @@ fi
",
'unless' => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
disk=$(readlink -f /srv)
if [ -z \"\$id\" ] ; then
id=\$(ceph-disk list | sed -nEe 's:^ */srv1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p')
id=$(ceph-disk list | sed -nEe \"s:^ *${disk}1? .*(ceph data|mounted on).*osd\\.([0-9]+).*:\\2:p\")
fi
if [ -z \"\$id\" ] ; then
id=\$(ls -ld /var/lib/ceph/osd/ceph-* | sed -nEe 's:.*/ceph-([0-9]+) *-> */srv\$:\\1:p' || true)
id=$(ls -ld /var/lib/ceph/osd/ceph-* | sed -nEe \"s:.*/ceph-([0-9]+) *-> *${disk}\$:\\1:p\" || true)
fi
if [ \"\$id\" ] ; then
test ! -d /var/lib/ceph/osd/ceph-\$id