2 # OpenStack Health Check
3 # This script is meant for really basic API operations on OpenStack
4 # Services tested: Keystone, Glance, Cinder, Neutron, Nova
8 # jose.lausuch@ericsson.com
11 # All rights reserved. This program and the accompanying materials
12 # are made available under the terms of the Apache License, Version 2.0
13 # which accompanies this distribution, and is available at
14 # http://www.apache.org/licenses/LICENSE-2.0
19 if [ -z $OS_AUTH_URL ]; then
20 echo "Source credentials first."
24 #Redirect all the output (stdout) to a log file and show only possible errors.
25 LOG_FILE=/home/opnfv/functest/results/healthcheck.log
28 echo "Using following credentials:"
32 project_1="opnfv-tenant1"
33 project_2="opnfv-tenant2"
40 image_1="opnfv-image1"
41 image_2="opnfv-image2"
42 volume_1="opnfv-volume1"
43 volume_2="opnfv-volume2"
44 net_1="opnfv-network1"
45 net_2="opnfv-network2"
46 subnet_1="opnfv-subnet1"
47 subnet_2="opnfv-subnet2"
50 router_1="opnfv-router1"
51 router_2="opnfv-router2"
52 instance_1="opnfv-instance1"
53 instance_2="opnfv-instance2"
54 instance_3="opnfv-instance3"
55 instance_4="opnfv-instance4"
59 function wait_for_ip() {
60 # $1 is the instance name
61 # $2 is the first octet of the subnet ip
63 while [[ ${timeout} > 0 ]]; do
64 if [[ $(nova console-log $1|grep "No lease, failing") ]]; then
65 echo "ERROR: The instance $1 couldn't get an IP from the DHCP agent." | tee -a $LOG_FILE 1>&2
67 elif [[ $(nova console-log $1|grep "^Lease"|grep "obtained") ]]; then
68 echo "The instance $1 got an IP successfully from the DHCP agent."
77 #################################
78 echo "Testing Keystone API..." | tee -a $LOG_FILE 1>&2
79 #################################
80 openstack project create ${project_1}
81 openstack project create ${project_2}
83 openstack user create ${user_1} --project ${project_1}
84 openstack user create ${user_2} --project ${project_1}
85 openstack user create ${user_3} --project ${project_1}
86 openstack user create ${user_4} --project ${project_2}
87 openstack user create ${user_5} --project ${project_2}
88 openstack user create ${user_6} --project ${project_2}
90 echo "...OK" | tee -a $LOG_FILE 1>&2
92 #################################
93 echo "Testing Glance API..." | tee -a $LOG_FILE 1>&2
94 #################################
95 image=/home/opnfv/functest/data/cirros-0.3.4-x86_64-disk.img
96 glance image-create --name ${image_1} --disk-format qcow2 --container-format bare < ${image}
97 glance image-create --name ${image_2} --disk-format qcow2 --container-format bare < ${image}
99 echo "...OK" | tee -a $LOG_FILE 1>&2
101 #################################
102 echo "Testing Cinder API..." | tee -a $LOG_FILE 1>&2
103 #################################
104 cinder create --display_name ${volume_1} 1
105 cinder create --display_name ${volume_2} 10
107 echo "...OK" | tee -a $LOG_FILE 1>&2
109 #################################
110 echo "Testing Neutron API..." | tee -a $LOG_FILE 1>&2
111 #################################
113 network_ids=($(neutron net-list|grep -v "+"|grep -v name|awk '{print $2}'))
114 for id in ${network_ids[@]}; do
115 [[ $(neutron net-show ${id}|grep 'router:external'|grep -i "true") != "" ]] && ext_net_id=${id}
117 if [[ "${ext_net_id}" == "" ]]; then
118 echo "ERROR: No external network found. Exiting Health Check..." | tee -a $LOG_FILE 1>&2
121 echo "External network found. ${ext_net_id}"
124 echo "1. Create Networks..."
125 neutron net-create ${net_1}
126 neutron net-create ${net_2}
127 net1_id=$(neutron net-list | grep ${net_1} | awk '{print $2}')
128 net2_id=$(neutron net-list | grep ${net_2} | awk '{print $2}')
130 echo "2. Create subnets..."
131 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
132 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
134 echo "4. Create Routers..."
135 neutron router-create ${router_1}
136 neutron router-create ${router_2}
138 neutron router-gateway-set ${router_1} ${ext_net_id}
139 neutron router-gateway-set ${router_2} ${ext_net_id}
141 neutron router-interface-add ${router_1} ${subnet_1}
142 neutron router-interface-add ${router_2} ${subnet_2}
144 echo "...OK" | tee -a $LOG_FILE 1>&2
146 #################################
147 echo "Testing Nova API..." | tee -a $LOG_FILE 1>&2
148 #################################
150 nova boot --flavor 2 --image ${image_1} --nic net-id=${net1_id} ${instance_1}
151 nova boot --flavor 2 --image ${image_1} --nic net-id=${net1_id} ${instance_2}
152 nova boot --flavor 2 --image ${image_2} --nic net-id=${net2_id} ${instance_3}
153 nova boot --flavor 2 --image ${image_2} --nic net-id=${net2_id} ${instance_4}
155 vm1_id=$(nova list | grep ${instance_1} | awk '{print $2}')
156 vm2_id=$(nova list | grep ${instance_2} | awk '{print $2}')
157 vm3_id=$(nova list | grep ${instance_3} | awk '{print $2}')
158 vm4_id=$(nova list | grep ${instance_4} | awk '{print $2}')
160 echo "...OK" | tee -a $LOG_FILE 1>&2
162 echo "Checking if instances get an IP from DHCP..." | tee -a $LOG_FILE 1>&2
164 wait_for_ip ${instance_1} "10.6"
165 wait_for_ip ${instance_2} "10.6"
166 wait_for_ip ${instance_3} "10.7"
167 wait_for_ip ${instance_4} "10.7"
169 echo "Health check passed!" | tee -a $LOG_FILE 1>&2