Add systemd unit for vbmcd in devstack

Besides managing vbmcd from systemd, this patch fixes a bug
in vbmcd handling.

The bug was that devstack runs ironic plugin under user `stack`, but
preserving superuser environment by means of `su -p`. That makes
`vbmcd` expanding tilda into `/root`, attempting to write into that
directory and failing miserably.

On top of that, all this happens when `vbmc` tries to invoke `vbmcd`
under the hood to preserve backward compatibility of the `vbmc`
behaviour before `vbmcd` was introduced.

This patch:

* adds systemd unit file for vbmcd
* invokes `vbmcd` explicitly before everything else and
* does that before becoming root and `stack` again

The `vbmc` tool can still run in a broken environment
for as long as it does not depend on the config file.

Change-Id: I6670ea50d126065d0472e558943890d4f9313083
This commit is contained in:
Ilya Etingof 2019-02-19 19:51:30 +01:00
parent 1027dbab51
commit 62d40c17e5
3 changed files with 36 additions and 6 deletions

View File

@ -336,6 +336,7 @@ IRONIC_IS_HARDWARE=$(trueorfalse False IRONIC_IS_HARDWARE)
IRONIC_VBMC_PORT_RANGE_START=${IRONIC_VBMC_PORT_RANGE_START:-6230}
IRONIC_VBMC_CONFIG_FILE=${IRONIC_VBMC_CONFIG_FILE:-$HOME/.vbmc/virtualbmc.conf}
IRONIC_VBMC_LOGFILE=${IRONIC_VBMC_LOGFILE:-$IRONIC_VM_LOG_DIR/virtualbmc.log}
IRONIC_VBMC_SYSTEMD_SERVICE=devstack@virtualbmc.service
# Virtual PDU configs
IRONIC_VPDU_CONFIG_FILE=${IRONIC_VPDU_CONFIG_FILE:-$HOME/.vpdu/virtualpdu.conf}
@ -723,6 +724,25 @@ function setup_syslinux_modules {
fi
}
function start_virtualbmc {
$SYSTEMCTL start $IRONIC_VBMC_SYSTEMD_SERVICE
}
function stop_virtualbmc {
$SYSTEMCTL stop $IRONIC_VBMC_SYSTEMD_SERVICE
}
function cleanup_virtualbmc {
stop_virtualbmc
$SYSTEMCTL disable $IRONIC_VBMC_SYSTEMD_SERVICE
local unitfile="$SYSTEMD_DIR/$IRONIC_VBMC_SYSTEMD_SERVICE"
sudo rm -f $unitfile
$SYSTEMCTL daemon-reload
}
function setup_virtualbmc {
# Install pyghmi from source, if requested, otherwise it will be
# downloaded as part of the virtualbmc installation
@ -747,8 +767,18 @@ function setup_virtualbmc {
iniset $IRONIC_VBMC_CONFIG_FILE log debug True
iniset $IRONIC_VBMC_CONFIG_FILE log logfile $IRONIC_VBMC_LOGFILE
}
local cmd
cmd=$(which vbmcd)
cmd+=" --foreground"
write_user_unit_file $IRONIC_VBMC_SYSTEMD_SERVICE "$cmd" "" "root"
$SYSTEMCTL enable $IRONIC_VBMC_SYSTEMD_SERVICE
start_virtualbmc
}
function setup_virtualpdu {
if use_library_from_git "virtualpdu"; then
@ -2450,7 +2480,7 @@ function cleanup_baremetal_basic_ops {
done
done
sudo killall vbmc || true
cleanup_virtualbmc
sudo ovs-vsctl --if-exists del-br $IRONIC_VM_NETWORK_BRIDGE

View File

@ -23,7 +23,7 @@ virsh list --inactive | grep -q $NAME && virsh undefine $NAME --nvram
# Delete the Virtual BMC
if [[ $(type -P vbmc) != "" ]]; then
sudo vbmc list | grep -a $NAME && sudo vbmc delete $NAME
vbmc list | grep -a $NAME && vbmc delete $NAME
fi
if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then

View File

@ -129,10 +129,10 @@ if ! virsh list --all | grep -q $NAME; then
--disk-format $DISK_FORMAT $VM_LOGGING --engine $ENGINE $UEFI_OPTS $vm_opts \
--interface-count $INTERFACE_COUNT $MAC_ADDRESS >&2
# Createa Virtual BMC for the node if IPMI is used
# Create Virtual BMC for the node if IPMI is used
if [[ $(type -P vbmc) != "" ]]; then
sudo vbmc add $NAME --port $VBMC_PORT
sudo vbmc start $NAME
vbmc add $NAME --port $VBMC_PORT
vbmc start $NAME
fi
fi