From 59d25cc29e96d7cdbca763321c31da0b801bac26 Mon Sep 17 00:00:00 2001 From: Francesco Santoro Date: Thu, 7 Apr 2016 09:10:59 +0200 Subject: [PATCH] 6wind-virtual-accelerator-plugin: adding scripts for simple testing This patch adds a "tests" folder that includes scripts to be used for plugin testing. Signed-off-by: Francesco Santoro Change-Id: I18d2db1137d1fe76bc1b409f20275a45e09454e7 --- tests/README | 8 +++ tests/cloud.cfg | 16 +++++ tests/compute_check_stats_after.sh | 28 ++++++++ tests/compute_check_stats_before.sh | 14 ++++ tests/compute_verify_driver.sh | 11 +++ tests/controller_cleanup.sh | 15 +++++ tests/controller_configure_floating.sh | 13 ++++ tests/controller_create_image_and_flavor.sh | 15 +++++ tests/controller_launch_instance.sh | 21 ++++++ tests/controller_send_traffic.sh | 10 +++ tests/run_tests.sh | 74 +++++++++++++++++++++ 11 files changed, 225 insertions(+) create mode 100644 tests/README create mode 100644 tests/cloud.cfg create mode 100644 tests/compute_check_stats_after.sh create mode 100644 tests/compute_check_stats_before.sh create mode 100644 tests/compute_verify_driver.sh create mode 100644 tests/controller_cleanup.sh create mode 100644 tests/controller_configure_floating.sh create mode 100644 tests/controller_create_image_and_flavor.sh create mode 100644 tests/controller_launch_instance.sh create mode 100644 tests/controller_send_traffic.sh create mode 100644 tests/run_tests.sh diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..5abea9b --- /dev/null +++ b/tests/README @@ -0,0 +1,8 @@ +.. Copyright 2016, 6WIND S.A. + +Introduction +============ + +This folder contains scripts to be used when testing the 6WIND virtual accelerator Fuel plugin. +Please refer to TestPlan document for more details on how to use these scripts. + diff --git a/tests/cloud.cfg b/tests/cloud.cfg new file mode 100644 index 0000000..160907c --- /dev/null +++ b/tests/cloud.cfg @@ -0,0 +1,16 @@ +#cloud-config +disable_root: false +ssh_pwauth: True +chpasswd: + list: | + root:root + expire: False +packages: + - iperf +runcmd: + - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config + - sed -i -e '/^#UseDNS/s/^.*$/UseDNS no/' /etc/ssh/sshd_config + - sed -i -e '/^GSSAPIAuthentication/s/^.*$/GSSAPIAuthentication no/' /etc/ssh/sshd_config + - restart ssh + - systemctl restart sshd + - iperf -s -p 6000 -D diff --git a/tests/compute_check_stats_after.sh b/tests/compute_check_stats_after.sh new file mode 100644 index 0000000..52fa8ef --- /dev/null +++ b/tests/compute_check_stats_after.sh @@ -0,0 +1,28 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +TAP_IFACE=$(ip link | grep tap | awk '{print $2}' | sed 's#:##' | tail -n1) + +NB_TAP_PACKETS_BEFORE=$(cat /tmp/6WIND_va_nb_tap_before) +NB_FP_VSWITCH_PACKETS_BEFORE=$(cat /tmp/6WIND_va_fp_vswitch_before) +NB_EXCEPTIONS_BEFORE=$(cat /tmp/6WIND_va_nb_exc_before) + +NB_TAP_PACKETS_AFTER=$(ethtool -S $TAP_IFACE | grep rx.good_packets | awk '{print $2}') +NB_FP_VSWITCH_PACKETS_AFTER=$(fp-cli dump-stats | grep output_ok | sed 's#:# ##' | awk '{print $2}') +NB_EXCEPTIONS_AFTER=$(fp-cli dump-stats | grep LocalBasicExceptions | sed 's#:# ##' | awk '{print $2}') + +NB_TAP_PACKETS=$(expr $NB_TAP_PACKETS_AFTER - $NB_TAP_PACKETS_BEFORE) +NB_FP_VSWITCH_PACKETS=$(expr $NB_FP_VSWITCH_PACKETS_AFTER - $NB_FP_VSWITCH_PACKETS_BEFORE) +NB_EXCEPTIONS=$(expr $NB_EXCEPTIONS_AFTER - $NB_EXCEPTIONS_BEFORE) + +# Here we verify 2 things. +# The first check wants to assure that the packets received by the spawned vm +# were processed by 6WIND virtual accelerator and not sent to slow path (exception). +# The second check wants to assure that this traffic towards the vm correctly +# passed via the accelerated ovs. +# This is a simple heuristics but it should be enough. +if [[ ${NB_EXCEPTIONS} -lt ${NB_TAP_PACKETS} && ${NB_TAP_PACKETS} -le ${NB_FP_VSWITCH_PACKETS} ]]; then + exit 0 +fi +exit 1 diff --git a/tests/compute_check_stats_before.sh b/tests/compute_check_stats_before.sh new file mode 100644 index 0000000..fcd2d92 --- /dev/null +++ b/tests/compute_check_stats_before.sh @@ -0,0 +1,14 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +TAP_IFACE=$(ip link | grep tap | awk '{print $2}' | sed 's#:##' | tail -n1) + +NB_TAP_PACKETS_BEFORE=$(ethtool -S $TAP_IFACE | grep rx.good_packets | awk '{print $2}') +NB_FP_VSWITCH_PACKETS_BEFORE=$(fp-cli dump-stats non-zero | grep output_ok | sed 's#:# ##' | awk '{print $2}') +NB_EXCEPTIONS_BEFORE=$(fp-cli dump-stats non-zero | grep LocalBasicExceptions | sed 's#:# ##' | awk '{print $2}') + +echo $NB_TAP_PACKETS_BEFORE > /tmp/6WIND_va_nb_tap_before +echo $NB_FP_VSWITCH_PACKETS_BEFORE > /tmp/6WIND_va_fp_vswitch_before +echo $NB_EXCEPTIONS_BEFORE > /tmp/6WIND_va_nb_exc_before + diff --git a/tests/compute_verify_driver.sh b/tests/compute_verify_driver.sh new file mode 100644 index 0000000..c4620b5 --- /dev/null +++ b/tests/compute_verify_driver.sh @@ -0,0 +1,11 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +TAP_IFACE=$(ip link | grep tap | awk '{print $2}' | sed 's#:##' | tail -n1) +DRIVER=$(ethtool -i $TAP_IFACE | grep driver | awk '{print $2}') + +if [[ ${DRIVER} -eq "dpvi" ]]; then + exit 0 +fi +exit 1 diff --git a/tests/controller_cleanup.sh b/tests/controller_cleanup.sh new file mode 100644 index 0000000..69a8f58 --- /dev/null +++ b/tests/controller_cleanup.sh @@ -0,0 +1,15 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +source openrc + +glance image-delete ubuntu-cloud +nova flavor-delete m1.vm_hugepages + +STATUS=$(nova show test_vm | grep status | awk '{print $4}') +if [[ ${STATUS} == "ACTIVE" ]] || [[ ${STATUS} == "ERROR" ]]; then + nova delete test_vm +fi +nova secgroup-delete-rule default tcp 1 65535 0.0.0.0/0 + diff --git a/tests/controller_configure_floating.sh b/tests/controller_configure_floating.sh new file mode 100644 index 0000000..54991da --- /dev/null +++ b/tests/controller_configure_floating.sh @@ -0,0 +1,13 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +source openrc + +FLOATING_IP=$(nova floating-ip-create net04_ext | grep net04_ext | tail -n1 | awk '{print $4}') + +if [[ ! -z ${FLOATING_IP} ]]; then + nova floating-ip-associate test_vm ${FLOATING_IP} + nova secgroup-add-rule default tcp 1 65535 0.0.0.0/0 +fi + diff --git a/tests/controller_create_image_and_flavor.sh b/tests/controller_create_image_and_flavor.sh new file mode 100644 index 0000000..2ba8513 --- /dev/null +++ b/tests/controller_create_image_and_flavor.sh @@ -0,0 +1,15 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +UBUNTU_IMAGE="ubuntu-14.04-server-cloudimg-amd64-disk1.img" +IMAGE_NAME="ubuntu-cloud" + +source openrc + +#Required to be able to install iperf package since Cirros image does not provide it +curl https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img -o $UBUNTU_IMAGE +glance image-create --name $IMAGE_NAME --file $UBUNTU_IMAGE --disk-format qcow2 --container-format bare --is-public True --progress +nova flavor-create m1.vm_hugepages auto 512 3 1 +nova flavor-key m1.vm_hugepages set hw:mem_page_size=large + diff --git a/tests/controller_launch_instance.sh b/tests/controller_launch_instance.sh new file mode 100644 index 0000000..e12ab8e --- /dev/null +++ b/tests/controller_launch_instance.sh @@ -0,0 +1,21 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +source openrc + +NET_ID=$(neutron net-list | grep 192 | tail -n1 | awk '{print $2}') +nova boot --flavor m1.vm_hugepages --image ubuntu-cloud test_vm --nic net-id=$NET_ID --user-data /root/cloud.cfg + +while [ $(nova list | grep test_vm | grep BUILD | wc -l) -eq 1 ]; do + sleep 1; +done + +STATUS=$(nova show test_vm | grep status | awk '{print $4}') + +if [[ ${STATUS} == "ACTIVE" ]]; then + echo "Wait 2 minutes to make sure that vm cloud-init has finished" + sleep 120 + exit 0 +fi +exit 1 diff --git a/tests/controller_send_traffic.sh b/tests/controller_send_traffic.sh new file mode 100644 index 0000000..ddb8219 --- /dev/null +++ b/tests/controller_send_traffic.sh @@ -0,0 +1,10 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +source openrc +floating_ip=$(nova floating-ip-list | grep net04_ext | awk '{print $4}') + +apt-get install -y iperf +iperf -c $floating_ip -p 6000 + diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100644 index 0000000..bb06092 --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,74 @@ +# Copyright 2016 6WIND S.A. +# +#!/bin/bash + +echo "Upload scripts to controller node" +scp controller_* cloud.cfg root@$CONTROLLER:/root/ + +echo "Upload scripts to compute node" +scp compute_* root@$COMPUTE:/root/ + +function cleanup { + echo "Cleanup of testing resources" + ssh root@$CONTROLLER 'bash /root/controller_cleanup.sh' +} + +echo "Download the ubuntu cloud image to spawn vms and create flavor for hugepages support" +ssh root@$CONTROLLER 'bash /root/controller_create_image_and_flavor.sh' +if [[ $? -eq 1 ]]; then + echo "TEST FAILED: Failed to download test cloud image. Exiting..." + cleanup + exit 1 +fi + +echo "Spawn an accelerated vm" +ssh root@$CONTROLLER 'bash /root/controller_launch_instance.sh' +if [[ $? -eq 1 ]]; then + echo "TEST FAILED: Unable to launch accelerated instance. Exiting..." + cleanup + exit 1 +fi + +echo "Verify that network interface is managed by virtual accelerator" +ssh root@$COMPUTE 'bash /root/compute_verify_driver.sh' +if [[ $? -eq 1 ]]; then + echo "TEST FAILED: Virtual machine network interface is not managed by 6WIND virtual accelerator. Exiting..." + cleanup + exit 1 +fi + +echo "Add security group tcp rule and associate floating ip" +ssh root@$CONTROLLER 'bash /root/controller_configure_floating.sh' +if [[ $? -eq 1 ]]; then + echo "TEST FAILED: Unable to correctly configure floating ip and security group. Exiting..." + cleanup + exit 1 +fi + +echo "Check virtual accelerator statistics before traffic" +ssh root@$COMPUTE 'bash /root/compute_check_stats_before.sh' +if [[ $? -eq 1 ]]; then + echo "TEST FAILED: Unable to retrieve virtual interface pre-stats. Exiting..." + cleanup + exit 1 +fi + +echo "Send traffic from controller to virtual machine" +ssh root@$CONTROLLER 'bash /root/controller_send_traffic.sh' +if [[ $? -eq 1 ]]; then + echo "TEST FAILED: Unable to correctly send traffic to virtual machine. Exiting..." + cleanup + exit 1 +fi + +echo "Check virtual accelerator statistics after traffic" +ssh root@$COMPUTE 'bash /root/compute_check_stats_after.sh' +if [[ $? -eq 1 ]]; then + echo "TEST FAILED: A part or all the traffic sent was not accelerated" + cleanup + exit 1 +fi + +echo "TEST PASSED" +cleanup +exit 0