From 62d40c17e55901e80009c8f78f38f37abc6f665d Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Tue, 19 Feb 2019 19:51:30 +0100 Subject: [PATCH] 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 --- devstack/lib/ironic | 34 +++++++++++++++++-- devstack/tools/ironic/scripts/cleanup-node.sh | 2 +- devstack/tools/ironic/scripts/create-node.sh | 6 ++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/devstack/lib/ironic b/devstack/lib/ironic index 690bc00e42..5f25e8ddce 100644 --- a/devstack/lib/ironic +++ b/devstack/lib/ironic @@ -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 diff --git a/devstack/tools/ironic/scripts/cleanup-node.sh b/devstack/tools/ironic/scripts/cleanup-node.sh index e594c282be..466b7059b8 100755 --- a/devstack/tools/ironic/scripts/cleanup-node.sh +++ b/devstack/tools/ironic/scripts/cleanup-node.sh @@ -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 diff --git a/devstack/tools/ironic/scripts/create-node.sh b/devstack/tools/ironic/scripts/create-node.sh index a264522824..077d21246a 100755 --- a/devstack/tools/ironic/scripts/create-node.sh +++ b/devstack/tools/ironic/scripts/create-node.sh @@ -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