aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGwenael Lambrouin <gwenael.lambrouin@orange.com>2022-07-18 15:49:51 +0200
committerGwenael Lambrouin <gwenael.lambrouin@orange.com>2022-11-10 14:56:15 +0100
commit1278ef65bd3422c0684007535742c3ef28d645ef (patch)
tree649433267c15c39878458e14dcfed90367131400
parent87d88eab6fe50101abc607857f13af9273aef80a (diff)
nfvbenchvm: refactor wait for VPP service
Sleeping for 10s and hoping that VPP service will be ready to accept vppctl commands does not work all the times. Instead of increasing the sleep time, poll every second until "vppctl show int" returns something. Wait at most 30 seconds. By the way, exit with a clear error message if "vppctl show int" does not report two network interfaces as expected. Change-Id: I6f0f053378c0bee8fd28a231dc1041c94642f5b3 Signed-off-by: Gwenael Lambrouin <gwenael.lambrouin@orange.com>
-rw-r--r--nfvbenchvm/dib/elements/nfvbenchvm/static/etc/rc.d/rc.local.loopvm45
1 files changed, 39 insertions, 6 deletions
diff --git a/nfvbenchvm/dib/elements/nfvbenchvm/static/etc/rc.d/rc.local.loopvm b/nfvbenchvm/dib/elements/nfvbenchvm/static/etc/rc.d/rc.local.loopvm
index 608c2c7..181ff2a 100644
--- a/nfvbenchvm/dib/elements/nfvbenchvm/static/etc/rc.d/rc.local.loopvm
+++ b/nfvbenchvm/dib/elements/nfvbenchvm/static/etc/rc.d/rc.local.loopvm
@@ -182,6 +182,29 @@ else
logger "NFVBENCHVM ERROR: VM MAC Addresses missing in $NFVBENCH_CONF"
fi
+wait_vpp_service() {
+ # Wait for at most wait_max=$1 seconds until VPP service is ready. Exit
+ # with code 1 if timeout is reached.
+ #
+ # Because VPP systemd unit has Type=simple, systemctl will report the
+ # service to be active has soon as it is forked. This does not mean that
+ # the service is ready, and actually it takes some times before vppctl can
+ # succesfully connect to VPP client socket /run/vpp/cli.sock.
+ local wait_max=$1
+
+ local wait_time=0
+ while ! vppctl show int; do
+ if [[ $wait_time -ge $wait_max ]]; then
+ # Log error to both system log and standard error output
+ logger -s "NFVBENCHVM ERROR: VPP service still not ready after $wait_max seconds." \
+ "Exiting $(basename $0)."
+ exit 1
+ fi
+ sleep 1
+ wait_time=$(( wait_time + 1 ))
+ done
+}
+
if [ $PCI_ADDRESS_1 ] && [ $PCI_ADDRESS_2 ]; then
logger "NFVBENCHVM: Using pci $PCI_ADDRESS_1 ($INTF_MAC1)"
logger "NFVBENCHVM: Using pci $PCI_ADDRESS_2 ($INTF_MAC2)"
@@ -223,12 +246,22 @@ if [ $PCI_ADDRESS_1 ] && [ $PCI_ADDRESS_2 ]; then
sed -i "s/{{WORKER_CORES}}/$WORKER_CORES/g" /etc/vpp/startup.conf
sed -i "s/{{VIF_MQ_SIZE}}/${VIF_MQ_SIZE}/g" /etc/vpp/startup.conf
sed -i "s/{{NUM_MBUFS}}/${NUM_MBUFS}/g" /etc/vpp/startup.conf
- service vpp start
- sleep 10
+ systemctl start vpp
+ # Wait until VPP service is ready for at most 30 seconds
+ wait_vpp_service 30
- INTFS=`vppctl show int | grep Ethernet | xargs`
- INTF_1=`echo $INTFS | awk '{ print $1 }'`
- INTF_2=`echo $INTFS | awk '{ print $4 }'`
+ VPPCTL_OUTPUT=$(vppctl show int)
+ INTFS=$(echo "$VPPCTL_OUTPUT" | grep Ethernet | xargs)
+ INTF_1=$(echo $INTFS | awk '{ print $1 }')
+ INTF_2=$(echo $INTFS | awk '{ print $4 }')
+ if [[ -z "$INTF_1" ]] || [[ -z "$INTF_2" ]]; then
+ # Log error to both system log and standard error output
+ logger -s "NFVBENCHVM DEBUG: \"vppctl show int\" output:"
+ logger -s "NFVBENCHVM DEBUG: $VPPCTL_OUTPUT"
+ logger -s "NFVBENCHVM ERROR: vppctl does not show the two Ethernet interfaces we expect." \
+ "Exiting $(basename $0)."
+ exit 1
+ fi
if [ -z "${TG_MAC1}" ]; then
# vm.conf does not support lines commented with #, so
# we need to remove the line to set the static ARP entry.
@@ -249,7 +282,7 @@ if [ $PCI_ADDRESS_1 ] && [ $PCI_ADDRESS_2 ]; then
sed -i "s/{{TG_NET2}}/${TG_NET2//\//\/}/g" /etc/vpp/vm.conf
sed -i "s/{{TG_GATEWAY1_IP}}/${TG_GATEWAY1_IP}/g" /etc/vpp/vm.conf
sed -i "s/{{TG_GATEWAY2_IP}}/${TG_GATEWAY2_IP}/g" /etc/vpp/vm.conf
- service vpp restart
+ systemctl restart vpp
logger "NFVBENCHVM: vpp service restarted"
else
echo "ERROR: Unknown forwarder value. Accepted values: testpmd or vpp"