commit 92ddeee46af075d917bdc291ffba4402fb28950e
parent de6e15e8634be2ea815ee94e8279e98bcf2e9efd
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Thu, 19 Jun 2014 21:03:09 +0200
print test failure reason, nicer fstab
Diffstat:
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/bin/confz b/bin/confz
@@ -7,7 +7,7 @@ setopt extended_glob warn_create_global
typeset -gA vars vars_prev
typeset -ga do_command
-typeset -g confz_indent check_only verbose
+typeset -g confz_indent check_only verbose fail_reason
: ${check_only:=0}
: ${verbose:=0}
@@ -128,6 +128,9 @@ require() {
do_command_prev=( "${do_command[@]}" )
do_command=( confz_${name}_do )
+ # clear fail_reason
+ fail_reason=''
+
# perform check - run - check
if confz_${name}_check "$@"; then
confz_check_ok $name
@@ -142,17 +145,21 @@ require() {
# confz_${name}_check
# set -x
# fi
- die "$name: check failed with error $check_ret"
+ die "$name: check failed with error $check_ret" $fail_reason
else
confz_do "${do_command[@]}" "$@"
# print check start
confz_check_start $name "$@" ...again
+ # clear fail_reason
+ fail_reason=''
+
# perform check once again
check_only_prev=$check_only
check_only=1
- confz_${name}_check "$@" || die "$name: check failed with error $?"
+ confz_${name}_check "$@" || \
+ die "$name: check failed with error $?" $fail_reason
confz_check_ok $name
check_only=$check_only_prev
fi
diff --git a/zsh-functions/confz_fs_init b/zsh-functions/confz_fs_init
@@ -26,6 +26,7 @@ confz_logical_volume_check() {
${vars[vg_name]}
)
+ fail_reason="not a block device: ${vars[device]}"
[[ -b ${vars[device]} ]]
}
@@ -58,6 +59,7 @@ confz_filesystem_check() {
tries=$[$tries - 1]
done
+ fail_reason="no blkid signature found on $vars[device]"
[[ -z $blk_out ]] && return 1 # nothing found on the device
eval $blk_out
[[ $LABEL == ${vars[label]} && $TYPE == xfs ]] && return 0
@@ -99,11 +101,13 @@ confz_fstab_check() {
return 0 # found matching entry
fi
done
+
+ fail_reason="no entry for ${(qqq)vars[mountpoint]} in /etc/fstab"
return 1 # did not find matching entry
}
confz_fstab_do() {
- print -r - >>/etc/fstab "${vars[device]} ${vars[mountpoint]} ${vars[filesystem]} ${vars[opts]} ${vars[dump]} ${vars[pass]}"
+ print -r - >>/etc/fstab ${vars[device]}$'\t'${vars[mountpoint]}$'\t'${vars[filesystem]}$'\t'${vars[opts]}$'\t'${vars[dump]}' '${vars[pass]}
}
@@ -111,6 +115,7 @@ confz_fstab_do() {
confz_mounted_check() {
checkvars device mountpoint
+ fail_reason="could not find ${vars[device]} ${vars[mountpoint]} in /proc/mounts"
grep -q "^${vars[device]} ${vars[mountpoint]} " /proc/mounts
}
diff --git a/zsh-functions/confz_vserver_init b/zsh-functions/confz_vserver_init
@@ -15,6 +15,7 @@ confz_deployed_system_check() {
do_command=( tar -pC ${vars[path]} -f ${vars[source]} )
fi
+ fail_reason="${vars[path]}/bin missing"
[[ -e ${vars[path]}/bin ]]
}
@@ -28,7 +29,6 @@ confz_vserver_check() {
setvar vdir /vservers/${vars[name]}
local ctx ret
- ret=1
if [[ -e ${vars[etcdir]}/context ]]; then
if [[ $(<${vars[etcdir]}/context) == ${vars[context_id]} ]]; then
@@ -38,13 +38,18 @@ confz_vserver_check() {
"has context different from ${(qqq)vars[context_id]}"
fi
else
+ ret=1
+ fail_reason="$(<${vars[etcdir]}/context) missing"
for ctx in /etc/vservers/*/context; do
if [[ $(<$ctx) == ${vars[context_id]} ]]; then
die "$0: context id already used by $ctx"
fi
done
fi
- [[ -h ${vars[etcdir]}/vdir ]] || ret=1
+ if ! [[ -h ${vars[etcdir]}/vdir ]]; then
+ fail_reason="${vars[etcdir]}/vdir missing"
+ ret=1
+ fi
require mounted_volume :size :filesystem \
lv_name=vs_$vars[name] \