system_test.sh: nsxt routes affects nsxv tests

NSXt project uses additional routes, but NSXv tests runned
on the same labs have been failed because doesn't handle
the routing issue provided by NSXt suite.

Some unused parts of code were deleted and code has been
refactored regarding maintainability issues.

Closes-Bug: #1644880
Change-Id: I82702524102d50abba36591bba72aca7f5e30cef
This commit is contained in:
Ruslan Khozinov 2016-11-30 19:38:41 +03:00
parent ef3158edfe
commit ed224fa123
1 changed files with 226 additions and 447 deletions

View File

@ -1,26 +1,19 @@
#!/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# functions
# Errors
INVALIDOPTS_ERR=100
NOJOBNAME_ERR=101
NOISOPATH_ERR=102
NOTASKNAME_ERR=103
NOWORKSPACE_ERR=104
DEEPCLEAN_ERR=105
MAKEISO_ERR=106
NOISOFOUND_ERR=107
COPYISO_ERR=108
SYMLINKISO_ERR=109
CDWORKSPACE_ERR=110
ISODOWNLOAD_ERR=111
INVALIDTASK_ERR=112
# Defaults
export REBOOT_TIMEOUT=${REBOOT_TIMEOUT:-5000}
export ALWAYS_CREATE_DIAGNOSTIC_SNAPSHOT=${ALWAYS_CREATE_DIAGNOSTIC_SNAPSHOT:-true}
export CHECK_TIMEOUT=5
ShowHelp() {
cat << EOF
@ -40,25 +33,14 @@ if you do need to override them.
-V (dir) - Path to python virtual environment
-i (file) - Full path to ISO file to build or use for tests.
Made from iso dir and name if not set.
-t (name) - Name of task this script should perform. Should be one of defined ones.
Taken from Jenkins' job's suffix if not set.
-o (str) - Allows you any extra command line option to run test job if you
want to use some parameters.
-a (str) - Allows you to path NOSE_ATTR to the test job if you want
to use some parameters.
-A (str) - Allows you to path NOSE_EVAL_ATTR if you want to enter attributes
as python expressions.
-m (name) - Use this mirror to build ISO from.
Uses 'srt' if not set.
-U - ISO URL for tests.
Null by default.
-r (yes/no) - Should built ISO file be places with build number tag and
symlinked to the last build or just copied over the last file.
-b (num) - Allows you to override Jenkins' build number if you need to.
-l (dir) - Path to logs directory. Can be set by LOGS_DIR evironment variable.
Uses WORKSPACE/logs if not set.
-d - Dry run mode. Only show what would be done and do nothing.
Useful for debugging.
-k - Keep previously created test environment before tests run
-K - Keep test environment after tests are finished
-h - Show this help page
@ -94,45 +76,6 @@ Then you can ran mytest.somestring.node job to start tests using mytest.iso and
EOF
}
GlobalVariables() {
# where built iso's should be placed
# use hardcoded default if not set before by export
ISO_DIR="${ISO_DIR:=/var/www/fuelweb-iso}"
# name of iso file
# taken from jenkins job prefix
# if not set before by variable export
if [ -z "${ISO_NAME}" ]; then
ISO_NAME="${JOB_NAME%.*}.iso"
fi
# full path where iso file should be placed
# make from iso name and path to iso shared directory
# if was not overriden by options or export
if [ -z "${ISO_PATH}" ]; then
ISO_PATH="${ISO_DIR}/${ISO_NAME}"
fi
# what task should be ran
# it's taken from jenkins job name suffix if not set by options
if [ -z "${TASK_NAME}" ]; then
TASK_NAME="${JOB_NAME##*.}"
fi
# do we want to keep iso's for each build or just copy over single file
ROTATE_ISO="${ROTATE_ISO:=yes}"
# choose mirror to build iso from. Default is 'srt' for Saratov's mirror
# you can change mirror by exporting USE_MIRROR variable before running this script
USE_MIRROR="${USE_MIRROR:=srt}"
# only show what commands would be executed but do nothing
# this feature is usefull if you want to debug this script's behaviour
DRY_RUN="${DRY_RUN:=no}"
VENV="${VENV:=yes}"
}
GetoptsVariables() {
while getopts ":w:j:i:t:o:a:A:m:U:r:b:V:l:dkKe:v:h" opt; do
case $opt in
@ -145,9 +88,6 @@ GetoptsVariables() {
i)
ISO_PATH="${OPTARG}"
;;
t)
TASK_NAME="${OPTARG}"
;;
o)
TEST_OPTIONS="${TEST_OPTIONS} ${OPTARG}"
;;
@ -157,18 +97,6 @@ GetoptsVariables() {
A)
NOSE_EVAL_ATTR="${OPTARG}"
;;
m)
USE_MIRROR="${OPTARG}"
;;
U)
ISO_URL="${OPTARG}"
;;
r)
ROTATE_ISO="${OPTARG}"
;;
b)
BUILD_NUMBER="${OPTARG}"
;;
V)
VENV_PATH="${OPTARG}"
;;
@ -184,9 +112,6 @@ GetoptsVariables() {
e)
ENV_NAME="${OPTARG}"
;;
d)
DRY_RUN="yes"
;;
v)
VENV="no"
;;
@ -210,68 +135,29 @@ GetoptsVariables() {
CheckVariables() {
if [ -z "${JOB_NAME}" ]; then
echo "Error! JOB_NAME is not set!"
exit $NOJOBNAME_ERR
fi
VENV="${VENV:=yes}"
if [ -z "${ISO_PATH}" ]; then
echo "Error! ISO_PATH is not set!"
exit $NOISOPATH_ERR
fi
if [ -z "${TASK_NAME}" ]; then
echo "Error! TASK_NAME is not set!"
exit $NOTASKNAME_ERR
if [ ! -f "${ISO_PATH}" ]; then
echo "Error! ${ISO_PATH} not found!"
exit $NOISOFOUND_ERR
fi
if [ -z "${JOB_NAME}" ]; then
echo "Error! JOB_NAME is not set!"
exit $NOJOBNAME_ERR
fi
if [ -z "${WORKSPACE}" ]; then
echo "Error! WORKSPACE is not set!"
exit $NOWORKSPACE_ERR
fi
if [ -z "${POOL_PUBLIC}" ]; then
export POOL_PUBLIC='172.16.0.0/24:24'
fi
if [ -z "${POOL_MANAGEMENT}" ]; then
export POOL_MANAGEMENT='172.16.1.0/24:24'
fi
if [ -z "${POOL_PRIVATE}" ]; then
export POOL_PRIVATE='192.168.0.0/24:24'
fi
# Vcenter variables
if [ -z "${DISABLE_SSL}" ]; then
export DISABLE_SSL="true"
fi
if [ -z "${VCENTER_USE}" ]; then
export VCENTER_USE="true"
fi
if [ -z "${VCENTER_IP}" ]; then
export VCENTER_IP="172.16.0.254"
fi
if [ -z "${VCENTER_USERNAME}" ]; then
export VCENTER_USERNAME="administrator@vsphere.local"
fi
if [ -z "${VCENTER_PASSWORD}" ]; then
echo "Error! VCENTER_PASSWORD is not set!"
exit 1
fi
if [ -z "${VC_DATACENTER}" ]; then
export VC_DATACENTER="Datacenter"
fi
if [ -z "${VC_DATASTORE}" ]; then
export VC_DATASTORE="nfs"
fi
if [ -z "${VCENTER_IMAGE_DIR}" ]; then
export VCENTER_IMAGE_DIR="/openstack_glance"
fi
if [ -z "${WORKSTATION_NODES}" ]; then
export WORKSTATION_NODES="esxi1 esxi2 esxi3 vcenter trusty"
fi
if [ -z "${WORKSTATION_IFS}" ]; then
export WORKSTATION_IFS="vmnet1 vmnet5"
fi
if [ -z "${VCENTER_CLUSTERS}" ]; then
export VCENTER_CLUSTERS="Cluster1,Cluster2"
fi
if [ -z "${WORKSTATION_SNAPSHOT}" ]; then
echo "Error! WORKSTATION_SNAPSHOT is not set!"
exit 1
@ -285,280 +171,165 @@ CheckVariables() {
exit 1
fi
# NSXv variables
if [ -z "${NSXV_PLUGIN_PATH}" ]; then
echo "Error! NSXV_PLUGIN_PATH is not set!"
exit 1
fi
if [ -z "${NEUTRON_SEGMENT_TYPE}" ]; then
export NEUTRON_SEGMENT_TYPE="tun"
fi
if [ -z "${NSXV_MANAGER_IP}" ]; then
export NSXV_MANAGER_IP="172.16.0.249"
fi
if [ -z "${NSXV_USER}" ]; then
export NSXV_USER='admin'
fi
if [ -z "${NSXV_PASSWORD}" ]; then
echo "Error! NSXV_PASSWORD is not set!"
exit 1
fi
if [ -z "${NSXV_DATACENTER_MOID}" ]; then
export NSXV_DATACENTER_MOID='datacenter-126'
fi
if [ -z "${NSXV_RESOURCE_POOL_ID}" ]; then
export NSXV_RESOURCE_POOL_ID='resgroup-134'
fi
if [ -z "${NSXV_DATASTORE_ID}" ]; then
export NSXV_DATASTORE_ID='datastore-138'
fi
if [ -z "${NSXV_EXTERNAL_NETWORK}" ]; then
export NSXV_EXTERNAL_NETWORK='dvportgroup-319'
fi
if [ -z "${NSXV_VDN_SCOPE_ID}" ]; then
export NSXV_VDN_SCOPE_ID='vdnscope-1'
fi
if [ -z "${NSXV_DVS_ID}" ]; then
export NSXV_DVS_ID='dvs-309'
fi
if [ -z "${NSXV_BACKUP_EDGE_POOL}" ]; then
export NSXV_BACKUP_EDGE_POOL='service:compact:1:2,vdr:compact:1:2'
fi
if [ -z "${NSXV_MGT_NET_MOID}" ]; then
export NSXV_MGT_NET_MOID=${NSXV_EXTERNAL_NETWORK:?}
fi
if [ -z "${NSXV_MGT_NET_PROXY_IPS}" ]; then
export NSXV_MGT_NET_PROXY_IPS='172.16.212.99'
fi
if [ -z "${NSXV_MGT_NET_PROXY_NETMASK}" ]; then
export NSXV_MGT_NET_PROXY_NETMASK='255.255.255.0'
fi
if [ -z "${NSXV_MGT_NET_DEFAULT_GW}" ]; then
export NSXV_MGT_NET_DEFAULT_GW='172.16.212.1'
fi
if [ -z "${NSXV_EDGE_HA}" ]; then
export NSXV_EDGE_HA='false'
fi
if [ -z "${NSXV_FLOATING_IP_RANGE}" ]; then
[ -z "${VENV_PATH}" ] && \
export VENV_PATH="/home/jenkins/venv-nailgun-tests"
[ -z "${POOL_PUBLIC}" ] && \
export POOL_PUBLIC='172.16.0.0/24:24'
[ -z "${POOL_MANAGEMENT}" ] && \
export POOL_MANAGEMENT='172.16.1.0/24:24'
[ -z "${POOL_PRIVATE}" ] && \
export POOL_PRIVATE='192.168.0.0/24:24'
# vCenter variables
[ -z "${DISABLE_SSL}" ] && \
export DISABLE_SSL="true"
[ -z "${VCENTER_USE}" ] && \
export VCENTER_USE="true"
[ -z "${VCENTER_IP}" ] && \
export VCENTER_IP="172.16.0.254"
[ -z "${VCENTER_USERNAME}" ] && \
export VCENTER_USERNAME="administrator@vsphere.local"
[ -z "${VC_DATACENTER}" ] && \
export VC_DATACENTER="Datacenter"
[ -z "${VC_DATASTORE}" ] && \
export VC_DATASTORE="nfs"
[ -z "${VCENTER_IMAGE_DIR}" ] && \
export VCENTER_IMAGE_DIR="/openstack_glance"
[ -z "${WORKSTATION_NODES}" ] && \
export WORKSTATION_NODES="esxi1 esxi2 esxi3 vcenter trusty"
[ -z "${WORKSTATION_IFS}" ] && \
export WORKSTATION_IFS="vmnet1 vmnet5"
[ -z "${VCENTER_CLUSTERS}" ] && \
export VCENTER_CLUSTERS="Cluster1,Cluster2"
# NSXv variables
[ -z "${NEUTRON_SEGMENT_TYPE}" ] && \
export NEUTRON_SEGMENT_TYPE="tun"
[ -z "${NSXV_MANAGER_IP}" ] && \
export NSXV_MANAGER_IP="172.16.0.249"
[ -z "${NSXV_USER}" ] && \
export NSXV_USER='administrator@vsphere.local'
[ -z "${NSXV_DATACENTER_MOID}" ] && \
export NSXV_DATACENTER_MOID='datacenter-126'
[ -z "${NSXV_RESOURCE_POOL_ID}" ] && \
export NSXV_RESOURCE_POOL_ID='resgroup-134'
[ -z "${NSXV_DATASTORE_ID}" ] && \
export NSXV_DATASTORE_ID='datastore-138'
[ -z "${NSXV_EXTERNAL_NETWORK}" ] && \
export NSXV_EXTERNAL_NETWORK='dvportgroup-319'
[ -z "${NSXV_VDN_SCOPE_ID}" ] && \
export NSXV_VDN_SCOPE_ID='vdnscope-1'
[ -z "${NSXV_DVS_ID}" ] && \
export NSXV_DVS_ID='dvs-309'
[ -z "${NSXV_BACKUP_EDGE_POOL}" ] && \
export NSXV_BACKUP_EDGE_POOL='service:compact:1:2,vdr:compact:1:2'
[ -z "${NSXV_MGT_NET_MOID}" ] && \
export NSXV_MGT_NET_MOID=${NSXV_EXTERNAL_NETWORK:?}
[ -z "${NSXV_MGT_NET_PROXY_IPS}" ] && \
export NSXV_MGT_NET_PROXY_IPS='172.16.212.99'
[ -z "${NSXV_MGT_NET_PROXY_NETMASK}" ] && \
export NSXV_MGT_NET_PROXY_NETMASK='255.255.255.0'
[ -z "${NSXV_MGT_NET_DEFAULT_GW}" ] && \
export NSXV_MGT_NET_DEFAULT_GW='172.16.212.1'
[ -z "${NSXV_EDGE_HA}" ] && \
export NSXV_EDGE_HA='false'
[ -z "${NSXV_FLOATING_IP_RANGE}" ] && \
export NSXV_FLOATING_IP_RANGE='172.16.212.100-172.16.212.150'
fi
if [ -z "${NSXV_FLOATING_NET_CIDR}" ]; then
[ -z "${NSXV_FLOATING_NET_CIDR}" ] && \
export NSXV_FLOATING_NET_CIDR='172.16.212.0/24'
fi
if [ -z "${NSXV_FLOATING_NET_GW}" ]; then
[ -z "${NSXV_FLOATING_NET_GW}" ] && \
export NSXV_FLOATING_NET_GW=${NSXV_MGT_NET_DEFAULT_GW:?}
fi
if [ -z "${NSXV_INTERNAL_NET_CIDR}" ]; then
[ -z "${NSXV_INTERNAL_NET_CIDR}" ] && \
export NSXV_INTERNAL_NET_CIDR='192.168.0.0/24'
fi
if [ -z "${NSXV_INTERNAL_NET_DNS}" ]; then
[ -z "${NSXV_INTERNAL_NET_DNS}" ] && \
export NSXV_INTERNAL_NET_DNS='8.8.8.8'
fi
# Export settings
if [ -z "${NODE_VOLUME_SIZE}" ]; then
[ -z "${NODE_VOLUME_SIZE}" ] && \
export NODE_VOLUME_SIZE=350
fi
if [ -z "${ADMIN_NODE_MEMORY}" ]; then
[ -z "${ADMIN_NODE_MEMORY}" ] && \
export ADMIN_NODE_MEMORY=4096
fi
if [ -z "${ADMIN_NODE_CPU}" ]; then
[ -z "${ADMIN_NODE_CPU}" ] && \
export ADMIN_NODE_CPU=4
fi
if [ -z "${SLAVE_NODE_MEMORY}" ]; then
[ -z "${SLAVE_NODE_MEMORY}" ] && \
export SLAVE_NODE_MEMORY=4096
fi
if [ -z "${SLAVE_NODE_CPU}" ]; then
[ -z "${SLAVE_NODE_CPU}" ] && \
export SLAVE_NODE_CPU=4
fi
}
MakeISO() {
# Create iso file to be used in tests
# clean previous garbage
if [ "${DRY_RUN}" = "yes" ]; then
echo make deep_clean
else
make deep_clean
fi
ec="${?}"
if [ "${ec}" -gt "0" ]; then
echo "Error! Deep clean failed!"
exit $DEEPCLEAN_ERR
fi
# create ISO file
export USE_MIRROR
if [ "${DRY_RUN}" = "yes" ]; then
echo make iso
else
make iso
fi
ec=$?
if [ "${ec}" -gt "0" ]; then
echo "Error making ISO!"
exit $MAKEISO_ERR
fi
if [ "${DRY_RUN}" = "yes" ]; then
ISO="${WORKSPACE}/build/iso/fuel.iso"
else
ISO="$(find ${WORKSPACE}/build/iso/ -maxdepth 1 -type f -name '*.iso'|sort -d| head -n 1)"
# check that ISO file exists
if [ ! -f "${ISO}" ]; then
echo "Error! ISO file not found!"
exit $NOISOFOUND_ERR
fi
fi
# copy ISO file to storage dir
# if rotation is enabled and build number is aviable
# save iso to tagged file and symlink to the last build
# if rotation is not enabled just copy iso to iso_dir
if [ "${ROTATE_ISO}" = "yes" -a "${BUILD_NUMBER}" != "" ]; then
# copy iso file to shared dir with revision tagged name
NEW_BUILD_ISO_PATH="${ISO_PATH#.iso}_${BUILD_NUMBER}.iso"
if [ "${DRY_RUN}" = "yes" ]; then
echo cp "${ISO}" "${NEW_BUILD_ISO_PATH}"
else
cp "${ISO}" "${NEW_BUILD_ISO_PATH}"
fi
ec=$?
if [ "${ec}" -gt "0" ]; then
echo "Error! Copy ${ISO} to ${NEW_BUILD_ISO_PATH} failed!"
exit $COPYISO_ERR
fi
# create symlink to the last built ISO file
if [ "${DRY_RUN}" = "yes" ]; then
echo ln -sf "${NEW_BUILD_ISO_PATH}" "${ISO_PATH}"
else
ln -sf "${NEW_BUILD_ISO_PATH}" "${ISO_PATH}"
fi
ec=$?
if [ "${ec}" -gt "0" ]; then
echo "Error! Create symlink from ${NEW_BUILD_ISO_PATH} to ${ISO_PATH} failed!"
exit $SYMLINKISO_ERR
fi
else
# just copy file to shared dir
if [ "${DRY_RUN}" = "yes" ]; then
echo cp "${ISO}" "${ISO_PATH}"
else
cp "${ISO}" "${ISO_PATH}"
fi
ec=$?
if [ "${ec}" -gt "0" ]; then
echo "Error! Copy ${ISO} to ${ISO_PATH} failed!"
exit $COPYISO_ERR
fi
fi
if [ "${ec}" -gt "0" ]; then
echo "Error! Copy ISO from ${ISO} to ${ISO_PATH} failed!"
exit $COPYISO_ERR
fi
echo "Finished building ISO: ${ISO_PATH}"
exit 0
}
CdWorkSpace() {
# chdir into workspace or fail if could not
if [ "${DRY_RUN}" != "yes" ]; then
cd "${WORKSPACE}"
ec=$?
if [ "${ec}" -gt "0" ]; then
echo "Error! Cannot cd to WORKSPACE!"
exit $CDWORKSPACE_ERR
fi
else
echo cd "${WORKSPACE}"
fi
}
RunTest() {
# Run test selected by task name
# check if iso file exists
if [ ! -f "${ISO_PATH}" ]; then
if [ -z "${ISO_URL}" -a "${DRY_RUN}" != "yes" ]; then
echo "Error! File ${ISO_PATH} not found and no ISO_URL (-U key) for downloading!"
exit $NOISOFOUND_ERR
else
if [ "${DRY_RUN}" = "yes" ]; then
echo wget -c ${ISO_URL} -O ${ISO_PATH}
else
echo "No ${ISO_PATH} found. Trying to download file."
wget -c ${ISO_URL} -O ${ISO_PATH}
rc=$?
if [ $rc -ne 0 ]; then
echo "Failed to fetch ISO from ${ISO_URL}"
exit $ISODOWNLOAD_ERR
fi
fi
fi
fi
cd "${WORKSPACE}" || \
{ echo "Error! Cannot cd to WORKSPACE!"; exit $CDWORKSPACE_ERR; }
if [ -z "${VENV_PATH}" ]; then
VENV_PATH="/home/jenkins/venv-nailgun-tests"
fi
# run python virtualenv
if [ "${VENV}" = "yes" ]; then
if [ "${DRY_RUN}" = "yes" ]; then
echo . $VENV_PATH/bin/activate
else
. $VENV_PATH/bin/activate
fi
fi
if [ "${ENV_NAME}" = "" ]; then
ENV_NAME="${JOB_NAME}_system_test"
fi
if [ "${LOGS_DIR}" = "" ]; then
LOGS_DIR="${WORKSPACE}/logs"
fi
if [ ! -f "$LOGS_DIR" ]; then
mkdir -p $LOGS_DIR
fi
[ "${VENV}" = "yes" ] && . $VENV_PATH/bin/activate
[ -z "${ENV_NAME}" ] && ENV_NAME="${JOB_NAME}_system_test"
mkdir -p ${LOGS_DIR:-"${WORKSPACE}/logs"}
export ENV_NAME
export LOGS_DIR
export ISO_PATH
if [ "${KEEP_BEFORE}" != "yes" ]; then
# remove previous environment
if [ "${DRY_RUN}" = "yes" ]; then
echo dos.py erase "${ENV_NAME}"
else
if dos.py list | grep -q "^${ENV_NAME}\$" ; then
dos.py erase "${ENV_NAME}"
fi
fi
dos.py list | grep -q "^${ENV_NAME}\$" && dos.py erase "${ENV_NAME}"
fi
# gather additional option for this nose test run
OPTS=""
if [ -n "${NOSE_ATTR}" ]; then
OPTS="${OPTS} -a ${NOSE_ATTR}"
fi
if [ -n "${NOSE_EVAL_ATTR}" ]; then
OPTS="${OPTS} -A ${NOSE_EVAL_ATTR}"
fi
if [ -n "${TEST_OPTIONS}" ]; then
OPTS="${OPTS} ${TEST_OPTIONS}"
fi
[ -n "${NOSE_ATTR}" ] && \
OPTS="${OPTS} -a ${NOSE_ATTR}"
[ -n "${NOSE_EVAL_ATTR}" ] && \
OPTS="${OPTS} -A ${NOSE_EVAL_ATTR}"
[ -n "${TEST_OPTIONS}" ] && \
OPTS="${OPTS} ${TEST_OPTIONS}"
clean_old_bridges
@ -566,86 +337,53 @@ RunTest() {
export WORKSPACE="${PLUGIN_WORKSPACE}/fuel-qa"
export PYTHONPATH="${PYTHONPATH:+${PYTHONPATH}:}${WORKSPACE}:${PLUGIN_WORKSPACE}"
# run python test set to create environments, deploy and test product
if [ "${DRY_RUN}" = "yes" ]; then
echo export PYTHONPATH="${PYTHONPATH:+${PYTHONPATH}:}${WORKSPACE}"
echo python plugin_test/run_tests.py -q --nologcapture --with-xunit ${OPTS}
else
python $PLUGIN_WORKSPACE/run_tests.py -q --nologcapture --with-xunit ${OPTS} &
[[ "${DEBUG}" == "true" ]] && \
echo -e "PYTHONPATH:${PYTHONPATH}\nPATH:${PATH}\nPLUGIN_WORKSPACE:${PLUGIN_WORKSPACE}"
fi
python $PLUGIN_WORKSPACE/run_tests.py -q --nologcapture --with-xunit ${OPTS} &
SYSTEST_PID=$!
if ! ps -p $SYSTEST_PID > /dev/null
then
echo System tests exited prematurely, aborting
exit 1
fi
while [ "$(virsh net-list | grep -c $ENV_NAME)" -ne 5 ];do sleep 10
if ! ps -p $SYSTEST_PID > /dev/null
then
echo System tests exited prematurely, aborting
exit 1
fi
while [ "$(virsh net-list | grep -c $ENV_NAME)" -ne 5 ]; do
sleep $CHECK_TIMEOUT
if ! ps -p $SYSTEST_PID > /dev/null
then
echo System tests exited prematurely, aborting
exit 1
fi
done
sleep 10
# Configre vcenter nodes and interfaces
setup_net $ENV_NAME
clean_iptables
setup_management_net $ENV_NAME # clean_iptables need call before setup_management_net
revert_ws "$WORKSTATION_NODES" || { echo "killing $SYSTEST_PID and its childs" && pkill --parent $SYSTEST_PID && kill $SYSTEST_PID && exit 1; }
echo waiting for system tests to finish
# clean_iptables need call before setup_management_net
setup_management_net $ENV_NAME
revert_ws $SYSTEST_PID
echo "Waiting for system tests to finish"
wait $SYSTEST_PID
export RES=$?
echo ENVIRONMENT NAME is $ENV_NAME
virsh net-dumpxml ${ENV_NAME}_admin | grep -P "(\d+\.){3}" -o | awk '{print "Fuel master node IP: "$0"2"}'
echo "ENVIRONMENT NAME is $ENV_NAME"
dos.py list --ips ${ENV_NAME}
if [ "${KEEP_AFTER}" != "yes" ]; then
# remove environment after tests
if [ "${DRY_RUN}" = "yes" ]; then
echo dos.py destroy "${ENV_NAME}"
else
dos.py destroy "${ENV_NAME}"
fi
fi
exit "${RES}"
}
RouteTasks() {
# this selector defines task names that are recognised by this script
# and runs corresponding jobs for them
# running any jobs should exit this script
case "${TASK_NAME}" in
test)
RunTest
;;
iso)
MakeISO
;;
*)
echo "Unknown task: ${TASK_NAME}!"
exit $INVALIDTASK_ERR
;;
esac
exit 0
}
add_interface_to_bridge() {
env=$1
net_name=$2
nic=$3
ip=$4
for net in $(virsh net-list |grep ${env}_${net_name} |awk '{print $1}');do
bridge=$(virsh net-info $net |grep -i bridge |awk '{print $2}')
for net in $(virsh net-list | grep ${env}_${net_name} | awk '{print $1}'); do
bridge=$(virsh net-info $net | grep -i bridge | awk '{print $2}')
setup_bridge $bridge $nic $ip && echo $net_name bridge $bridge ready
done
}
@ -656,17 +394,30 @@ setup_bridge() {
ip=$3
sudo /sbin/brctl stp $bridge off
sudo /sbin/brctl addif $bridge $nic
# set if with existing ip down
for itf in $(sudo ip -o addr show to $ip |cut -d' ' -f2); do
echo deleting $ip from $itf
sudo ip addr del dev $itf $ip
if sudo /sbin/brctl show $bridge | grep -q $nic; then
echo "$nic is already in the $bridge bridge"
else
sudo /sbin/brctl addif $bridge $nic
fi
for itf in $(sudo ip -o route show to ${NSXV_FLOATING_NET_CIDR} | cut -d' ' -f5); do
echo "deleting route to ${NSXV_FLOATINV_NET_CIDR} dev $itf"
sudo ip route del ${NSXV_FLOATING_NET_CIDR} dev $itf
done
echo adding $ip to $bridge
# set if with existing ip down
for itf in $(sudo ip -o addr show to $ip | cut -d' ' -f2); do
echo "deleting $ip from $itf"
sudo ip addr del dev $itf $ip
done
echo "adding $ip to $bridge"
sudo /sbin/ip addr add $ip dev $bridge
echo $nic added to $bridge
echo "$nic added to $bridge"
sudo /sbin/ip link set dev $bridge up
if sudo /sbin/iptables-save |grep $bridge | grep -i reject| grep -q FORWARD;then
if sudo /sbin/iptables-save | grep $bridge | grep -i reject | grep -q FORWARD; then
sudo /sbin/iptables -D FORWARD -o $bridge -j REJECT --reject-with icmp-port-unreachable
sudo /sbin/iptables -D FORWARD -i $bridge -j REJECT --reject-with icmp-port-unreachable
fi
@ -687,24 +438,59 @@ clean_iptables() {
sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
}
revert_ws() {
for i in $1
do
vmrun -T ws-shared -h https://localhost:443/sdk -u $WORKSTATION_USERNAME -p $WORKSTATION_PASSWORD listRegisteredVM | grep -q $i || { echo "VM $i does not exist"; continue; }
echo vmrun: reverting $i to $WORKSTATION_SNAPSHOT
vmrun -T ws-shared -h https://localhost:443/sdk -u $WORKSTATION_USERNAME -p $WORKSTATION_PASSWORD revertToSnapshot "[standard] $i/$i.vmx" $WORKSTATION_SNAPSHOT || { echo "Error: revert of $i failed"; return 1; }
done
for i in $1
do
echo vmrun: starting $i
vmrun -T ws-shared -h https://localhost:443/sdk -u $WORKSTATION_USERNAME -p $WORKSTATION_PASSWORD start "[standard] $i/$i.vmx" || { echo "Error: $i failed to start"; return 1; }
done
# waiting for ending of parallel processes
wait_revert() {
while [ $(pgrep vmrun | wc -l) -ne 0 ]; do sleep $CHECK_TIMEOUT; done
}
setup_net() {
env=$1
add_interface_to_bridge $env public vmnet1 172.16.0.1/24
kill_test(){
pid=$1
[ ! -z $pid ] && \
{ echo "killing $pid and its childs"; pkill -9 --parent $pid; } || \
echo "test process id doesn't exist"
exit 1
}
revert_ws() {
set -x
systest_pid=$1
[ -z "${WORKSTATION_USERNAME}" ] && { echo "WORKSTATION_USERNAME is not set"; kill_test $systest_pid; }
[ -z "${WORKSTATION_PASSWORD}" ] && { echo "WORKSTATION_PASSWORD is not set"; kill_test $systest_pid; }
[ -z "${WORKSTATION_SNAPSHOT}" ] && { echo "WORKSTATION_SNAPSHOT is not set"; kill_test $systest_pid; }
[ -z "${WORKSTATION_NODES}" ] && { echo "WORKSTATION_NODES is not set"; kill_test $systest_pid; }
cmd="vmrun -T ws-shared -h https://localhost:443/sdk -u $WORKSTATION_USERNAME -p $WORKSTATION_PASSWORD"
nodes="${WORKSTATION_NODES}"
snapshot="${WORKSTATION_SNAPSHOT}"
# checking that required vms are existing
for node in $nodes; do
$cmd listRegisteredVM | grep -q $node || \
{ echo "Error: $node does not exist or does not registered"; kill_test $systest_pid; }
done
# reverting vms to the required snapshot
for node in $nodes; do
echo "Reverting $node to $snapshot"
$cmd revertToSnapshot "[standard] $node/$node.vmx" $snapshot || \
{ echo "Error: reverting of $node has failed"; kill_test $systest_pid; } &
done
wait_revert
# starting vms from suspending state
for node in $nodes; do
echo "Starting $node"
$cmd start "[standard] $node/$node.vmx" || \
{ echo "Error: $node failed to start"; kill_test $systest_pid; } &
done
wait_revert
}
setup_management_net() {
@ -723,14 +509,7 @@ setup_management_net() {
# first we want to get variable from command line options
GetoptsVariables "${@}"
# then we define global variables and there defaults when needed
GlobalVariables
# check do we have all critical variables set
CheckVariables
# first we chdir into our working directory unless we dry run
CdWorkSpace
# finally we can choose what to do according to TASK_NAME
RouteTasks
RunTest