diff options
-rwxr-xr-x | docker/run_tests.sh | 5 | ||||
-rwxr-xr-x | testcases/VIM/OpenStack/CI/libraries/healthcheck.sh | 170 | ||||
-rwxr-xr-x | testcases/VIM/OpenStack/CI/libraries/test_openstack.sh | 117 |
3 files changed, 175 insertions, 117 deletions
diff --git a/docker/run_tests.sh b/docker/run_tests.sh index ff0f1bfd8..52d1b25e8 100755 --- a/docker/run_tests.sh +++ b/docker/run_tests.sh @@ -95,6 +95,11 @@ function run_test(){ fi case $test_name in + "healthcheck") + info "Running health check test..." + ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/healthcheck.sh + clean_openstack + ;; "vping_ssh") info "Running vPing-SSH test..." python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing_ssh.py \ diff --git a/testcases/VIM/OpenStack/CI/libraries/healthcheck.sh b/testcases/VIM/OpenStack/CI/libraries/healthcheck.sh new file mode 100755 index 000000000..9d3559b20 --- /dev/null +++ b/testcases/VIM/OpenStack/CI/libraries/healthcheck.sh @@ -0,0 +1,170 @@ +# +# OpenStack Health Check +# This script is meant for really basic API operations on OpenStack +# Services tested: Keystone, Glance, Cinder, Neutron, Nova +# +# +# Author: +# jose.lausuch@ericsson.com +# +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +# + +set -e + +if [ -z $OS_AUTH_URL ]; then + echo "Source credentials first." + exit 1 +fi + +#Redirect all the output (stdout) to a log file and show only possible errors. +LOG_FILE=/home/opnfv/functest/results/healthcheck.log +exec 1<>$LOG_FILE + +echo "Using following credentials:" +env | grep OS + +## Variables: +project_1="opnfv-tenant1" +project_2="opnfv-tenant2" +user_1="opnfv_user1" +user_2="opnfv_user2" +user_3="opnfv_user3" +user_4="opnfv_user4" +user_5="opnfv_user5" +user_6="opnfv_user6" +image_1="opnfv-image1" +image_2="opnfv-image2" +volume_1="opnfv-volume1" +volume_2="opnfv-volume2" +net_1="opnfv-network1" +net_2="opnfv-network2" +subnet_1="opnfv-subnet1" +subnet_2="opnfv-subnet2" +port_1="opnfv-port1" +port_2="opnfv-port2" +router_1="opnfv-router1" +router_2="opnfv-router2" +instance_1="opnfv-instance1" +instance_2="opnfv-instance2" +instance_3="opnfv-instance3" +instance_4="opnfv-instance4" + + + +function wait_for_ip() { + # $1 is the instance name + # $2 is the first octet of the subnet ip + timeout=60 + while [[ ${timeout} > 0 ]]; do + if [[ $(nova console-log $1|grep "No lease, failing") ]]; then + echo "ERROR: The instance $1 couldn't get an IP from the DHCP agent." | tee -a $LOG_FILE 1>&2 + exit 1 + elif [[ $(nova console-log $1|grep "^Lease"|grep "obtained") ]]; then + echo "The instance $1 got an IP successfully from the DHCP agent." + break + fi + let timeout=timeout-1 + sleep 1 + done +} + + +################################# +echo "Testing Keystone API..." | tee -a $LOG_FILE 1>&2 +################################# +openstack project create ${project_1} +openstack project create ${project_2} + +openstack user create ${user_1} --project ${project_1} +openstack user create ${user_2} --project ${project_1} +openstack user create ${user_3} --project ${project_1} +openstack user create ${user_4} --project ${project_2} +openstack user create ${user_5} --project ${project_2} +openstack user create ${user_6} --project ${project_2} + +echo "...OK" | tee -a $LOG_FILE 1>&2 + +################################# +echo "Testing Glance API..." | tee -a $LOG_FILE 1>&2 +################################# +image=/home/opnfv/functest/data/cirros-0.3.4-x86_64-disk.img +glance image-create --name ${image_1} --disk-format qcow2 --container-format bare < ${image} +glance image-create --name ${image_2} --disk-format qcow2 --container-format bare < ${image} + +echo "...OK" | tee -a $LOG_FILE 1>&2 + +################################# +echo "Testing Cinder API..." | tee -a $LOG_FILE 1>&2 +################################# +cinder create --display_name ${volume_1} 1 +cinder create --display_name ${volume_2} 10 + +echo "...OK" | tee -a $LOG_FILE 1>&2 + +################################# +echo "Testing Neutron API..." | tee -a $LOG_FILE 1>&2 +################################# + +network_ids=($(neutron net-list|grep -v "+"|grep -v name|awk '{print $2}')) +for id in ${network_ids[@]}; do + [[ $(neutron net-show ${id}|grep 'router:external'|grep -i "true") != "" ]] && ext_net_id=${id} +done +if [[ "${ext_net_id}" == "" ]]; then + echo "ERROR: No external network found. Exiting Health Check..." | tee -a $LOG_FILE 1>&2 + exit 1 +else + echo "External network found. ${ext_net_id}" +fi + +echo "1. Create Networks..." +neutron net-create ${net_1} +neutron net-create ${net_2} +net1_id=$(neutron net-list | grep ${net_1} | awk '{print $2}') +net2_id=$(neutron net-list | grep ${net_2} | awk '{print $2}') + +echo "2. Create subnets..." +neutron subnet-create --name ${subnet_1} --allocation-pool start=10.6.0.2,end=10.6.0.253 --gateway 10.6.0.254 ${net_1} 10.6.0.0/24 +neutron subnet-create --name ${subnet_2} --allocation-pool start=10.7.0.2,end=10.7.0.253 --gateway 10.7.0.254 ${net_2} 10.7.0.0/24 + +echo "4. Create Routers..." +neutron router-create ${router_1} +neutron router-create ${router_2} + +neutron router-gateway-set ${router_1} ${ext_net_id} +neutron router-gateway-set ${router_2} ${ext_net_id} + +neutron router-interface-add ${router_1} ${subnet_1} +neutron router-interface-add ${router_2} ${subnet_2} + +echo "...OK" | tee -a $LOG_FILE 1>&2 + +################################# +echo "Testing Nova API..." | tee -a $LOG_FILE 1>&2 +################################# + +nova boot --flavor 2 --image ${image_1} --nic net-id=${net1_id} ${instance_1} +nova boot --flavor 2 --image ${image_1} --nic net-id=${net1_id} ${instance_2} +nova boot --flavor 2 --image ${image_2} --nic net-id=${net2_id} ${instance_3} +nova boot --flavor 2 --image ${image_2} --nic net-id=${net2_id} ${instance_4} + +vm1_id=$(nova list | grep ${instance_1} | awk '{print $2}') +vm2_id=$(nova list | grep ${instance_2} | awk '{print $2}') +vm3_id=$(nova list | grep ${instance_3} | awk '{print $2}') +vm4_id=$(nova list | grep ${instance_4} | awk '{print $2}') + +echo "...OK" | tee -a $LOG_FILE 1>&2 + +echo "Checking if instances get an IP from DHCP..." | tee -a $LOG_FILE 1>&2 + +wait_for_ip ${instance_1} "10.6" +wait_for_ip ${instance_2} "10.6" +wait_for_ip ${instance_3} "10.7" +wait_for_ip ${instance_4} "10.7" + +echo "Health check passed!" | tee -a $LOG_FILE 1>&2 +exit 0 diff --git a/testcases/VIM/OpenStack/CI/libraries/test_openstack.sh b/testcases/VIM/OpenStack/CI/libraries/test_openstack.sh deleted file mode 100755 index fa1f0fa04..000000000 --- a/testcases/VIM/OpenStack/CI/libraries/test_openstack.sh +++ /dev/null @@ -1,117 +0,0 @@ -# -# Script to test clean_openstack.py -# -# Author: -# jose.lausuch@ericsson.com -# -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# - -if [ -z $OS_AUTH_URL ]; then - echo "Source credentials first" - exit 1 -fi - -echo "Using following credentials:" -env | grep OS - -################################# -echo "Creating keystone stuff.." -################################# -keystone tenant-create --name tenant_test1 -keystone tenant-create --name tenant_test2 -tenant1_id=$(keystone tenant-list | grep tenant_test1 | awk '{print $2}') -tenant2_id=$(keystone tenant-list | grep tenant_test2 | awk '{print $2}') -keystone user-create --name user_test11 --tenant $tenant1_id -keystone user-create --name user_test12 --tenant $tenant1_id -keystone user-create --name user_test13 --tenant $tenant1_id -keystone user-create --name user_test21 --tenant $tenant2_id -keystone user-create --name user_test22 --tenant $tenant2_id - - -################################# -echo "Creating glance stuff.." -################################# -wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img -glance image-create --name image_test1 --disk-format qcow2 --container-format bare < cirros-0.3.4-x86_64-disk.img -glance image-create --name image_test2 --disk-format qcow2 --container-format bare < cirros-0.3.4-x86_64-disk.img -#glance image-create --name test --visibility public --disk-format qcow2 --container-format bare --file cirros-0.3.4-x86_64-disk.img - - -################################# -echo "Creating cinder stuff.." -################################# -cinder create --display_name volume-test1 1 -cinder create --display_name volume-test2 2 - - -################################# -echo "Creating NEUTRON stuff.." -################################# -echo "1. Create Networks." -neutron net-create net-test1 -neutron net-create net-test2 - -echo "2. Create subnets." -neutron subnet-create --name subnet-test11 --allocation-pool start=10.7.0.2,end=10.7.0.253 --gateway 10.7.0.254 net-test1 10.7.0.0/24 -neutron subnet-create --name subnet-test21 --allocation-pool start=10.6.0.2,end=10.6.0.253 --gateway 10.6.0.254 net-test2 10.6.0.0/24 - -echo "3. Create Ports." -neutron port-create --name port-test11 --fixed-ip ip_address=10.7.0.10 net-test1 -neutron port-create --name port-test21 --fixed-ip ip_address=10.6.0.60 net-test2 - - -echo "4. Create Routers." -neutron router-create router-test1 -neutron router-create router-test2 -router1_id=$(neutron router-list | grep router-test1 | awk '{print $2}') -router1_id=$(neutron router-list | grep router-test2 | awk '{print $2}') - -neutron router-gateway-set router-test1 net04_ext -neutron router-gateway-set router-test2 net04_ext - -neutron router-interface-add router-test1 subnet-test11 -neutron router-interface-add router-test2 subnet-test21 - -echo "5. Floating IPs." -neutron floatingip-create net04_ext -neutron floatingip-create net04_ext -neutron floatingip-create net04_ext -neutron floatingip-create net04_ext - -floating_ip1_id=$(neutron floatingip-list | awk 'FNR == 4 {print}' | awk '{print $2}') -floating_ip2_id=$(neutron floatingip-list | awk 'FNR == 5 {print}' | awk '{print $2}') -floating_ip3_id=$(neutron floatingip-list | awk 'FNR == 6 {print}' | awk '{print $2}') -floating_ip4_id=$(neutron floatingip-list | awk 'FNR == 7 {print}' | awk '{print $2}') - -floating_ip1=$(neutron floatingip-list | awk 'FNR == 4 {print}' | awk '{print $5}') -floating_ip2=$(neutron floatingip-list | awk 'FNR == 5 {print}' | awk '{print $5}') -floating_ip3=$(neutron floatingip-list | awk 'FNR == 6 {print}' | awk '{print $5}') -floating_ip4=$(neutron floatingip-list | awk 'FNR == 7 {print}' | awk '{print $5}') - -################################# -echo "Creating NOVA stuff.." -################################# -net1_id=$(neutron net-list | grep net-test1 | awk '{print $2}') -net2_id=$(neutron net-list | grep net-test2 | awk '{print $2}') - -nova boot --flavor 2 --image image_test1 --nic net-id=$net1_id nova-test11 -nova boot --flavor 2 --image image_test1 --nic net-id=$net1_id nova-test12 -nova boot --flavor 2 --image image_test2 --nic net-id=$net2_id nova-test21 -nova boot --flavor 2 --image image_test2 --nic net-id=$net2_id nova-test22 - -vm1_id=$(nova list | grep nova-test11 | awk '{print $2}') -vm2_id=$(nova list | grep nova-test12 | awk '{print $2}') -vm3_id=$(nova list | grep nova-test21 | awk '{print $2}') -vm4_id=$(nova list | grep nova-test22 | awk '{print $2}') - -nova floating-ip-associate $vm1_id $floating_ip1 -nova floating-ip-associate $vm2_id $floating_ip2 -nova floating-ip-associate $vm3_id $floating_ip3 -nova floating-ip-associate $vm4_id $floating_ip4 - -#neutron floatingip-associate --fixed-ip-address $floating_ip2 <PORT> |