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 #Redirect all the output (stdout) to a log file and show only possible errors.
20 LOG_FILE=/home/opnfv/functest/results/healthcheck.log
25 echo -e "$(date '+%Y-%m-%d %H:%M:%S,%3N') - healtcheck - INFO - " "$*" | tee -a $LOG_FILE 1>&2
29 if [[ "${CI_DEBUG,,}" == "true" ]]; then
30 echo -e "$(date '+%Y-%m-%d %H:%M:%S,%3N') - healtcheck - DEBUG - " "$*" | tee -a $LOG_FILE 1>&2
35 echo -e "$(date '+%Y-%m-%d %H:%M:%S,%3N') - healtcheck - ERROR - " "$*" | tee -a $LOG_FILE 1>&2
39 if [ -z $OS_AUTH_URL ]; then
40 echo "Source credentials first."
45 echo "Using following credentials:"
49 project_1="opnfv-tenant1"
50 project_2="opnfv-tenant2"
57 image_1="opnfv-image1"
58 image_2="opnfv-image2"
59 volume_1="opnfv-volume1"
60 volume_2="opnfv-volume2"
61 net_1="opnfv-network1"
62 net_2="opnfv-network2"
63 subnet_1="opnfv-subnet1"
64 subnet_2="opnfv-subnet2"
67 router_1="opnfv-router1"
68 router_2="opnfv-router2"
70 instance_1="opnfv-instance1"
71 instance_2="opnfv-instance2"
72 instance_3="opnfv-instance3"
73 instance_4="opnfv-instance4"
77 function wait_for_ip() {
78 # $1 is the instance name
79 # $2 is the first octet of the subnet ip
81 while [[ ${timeout} > 0 ]]; do
82 if [[ $(nova console-log $1|grep "No lease, failing") ]]; then
83 error "The instance $1 couldn't get an IP from the DHCP agent." | tee -a $LOG_FILE 1>&2
85 elif [[ $(nova console-log $1|grep "^Lease"|grep "obtained") ]]; then
86 debug "The instance $1 got an IP successfully from the DHCP agent." | tee -a $LOG_FILE 1>&2
95 #################################
96 info "Testing Keystone API..." | tee -a $LOG_FILE 1>&2
97 #################################
98 openstack project create ${project_1}
99 debug "project '${project_1}' created."
100 openstack project create ${project_2}
101 debug "project '${project_2}' created."
102 openstack user create ${user_1} --project ${project_1}
103 debug "user '${user_1}' created in project ${project_1}."
104 openstack user create ${user_2} --project ${project_1}
105 debug "user '${user_2}' created in project ${project_1}."
106 openstack user create ${user_3} --project ${project_1}
107 debug "user '${user_3}' created in project ${project_1}."
108 openstack user create ${user_4} --project ${project_2}
109 debug "user '${user_4}' created in project ${project_2}."
110 openstack user create ${user_5} --project ${project_2}
111 debug "user '${user_5}' created in project ${project_2}."
112 openstack user create ${user_6} --project ${project_2}
113 debug "user '${user_6}' created in project ${project_2}."
114 info "...Keystone OK!"
116 #################################
117 info "Testing Glance API..."
118 #################################
119 image=/home/opnfv/functest/data/cirros-0.3.4-x86_64-disk.img
120 glance image-create --name ${image_1} --disk-format qcow2 --container-format bare < ${image}
121 debug "image '${image_1}' created."
122 glance image-create --name ${image_2} --disk-format qcow2 --container-format bare < ${image}
123 debug "image '${image_2}' created."
124 info "... Glance OK!"
126 #################################
127 info "Testing Cinder API..."
128 #################################
129 cinder create --display_name ${volume_1} 1
130 debug "volume '${volume_1}' created."
131 cinder create --display_name ${volume_2} 10
132 debug "volume '${volume_2}' created."
135 #################################
136 info "Testing Neutron API..."
137 #################################
139 network_ids=($(neutron net-list|grep -v "+"|grep -v name|awk '{print $2}'))
140 for id in ${network_ids[@]}; do
141 [[ $(neutron net-show ${id}|grep 'router:external'|grep -i "true") != "" ]] && ext_net_id=${id}
143 if [[ "${ext_net_id}" == "" ]]; then
144 error "No external network found. Exiting Health Check..."
147 info "External network found. ${ext_net_id}"
150 info "1. Create Networks..."
151 neutron net-create ${net_1}
152 debug "net '${net_1}' created."
153 neutron net-create ${net_2}
154 debug "net '${net_2}' created."
155 net1_id=$(neutron net-list | grep ${net_1} | awk '{print $2}')
156 net2_id=$(neutron net-list | grep ${net_2} | awk '{print $2}')
158 info "2. Create subnets..."
159 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
160 debug "subnet '${subnet_1}' created."
161 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
162 debug "subnet '${subnet_2}' created."
164 info "3. Create Routers..."
165 neutron router-create ${router_1}
166 debug "router '${router_1}' created."
167 neutron router-create ${router_2}
168 debug "router '${router_2}' created."
170 neutron router-gateway-set ${router_1} ${ext_net_id}
171 debug "router '${router_1}' gateway set to ${ext_net_id}."
172 neutron router-gateway-set ${router_2} ${ext_net_id}
173 debug "router '${router_2}' gateway set to ${ext_net_id}."
175 neutron router-interface-add ${router_1} ${subnet_1}
176 debug "router '${router_1}' interface added ${subnet_1}."
177 neutron router-interface-add ${router_2} ${subnet_2}
178 debug "router '${router_2}' interface added ${subnet_2}."
180 info "...Neutron OK!"
182 #################################
183 info "Testing Nova API..."
184 #################################
186 # This delay should be removed after resolving Jira case APEX-149.
187 # The purpose is to give some time to populate openflow rules
188 # by SDN controller in case of odl_l2 scenario.
192 # Check if flavor exists
193 if [[ -z $(nova flavor-list|grep $flavor) ]]; then
194 # if given flavor doesn't exist, we create one
195 debug "Flavor $flavor doesn't exist. Creating a new flavor."
196 nova flavor-create --is-public false ${flavor} auto 512 1 1 --is-public True
198 debug "Using flavor $flavor to boot the instances."
201 nova boot --flavor ${flavor} --image ${image_1} --nic net-id=${net1_id} ${instance_1}
202 debug "nova instance '${instance_1}' booted on ${net_1}."
203 nova boot --flavor ${flavor} --image ${image_1} --nic net-id=${net1_id} ${instance_2}
204 debug "nova instance '${instance_2}' booted on ${net_1}."
205 nova boot --flavor ${flavor} --image ${image_2} --nic net-id=${net2_id} ${instance_3}
206 debug "nova instance '${instance_3}' booted on ${net_2}."
207 nova boot --flavor ${flavor} --image ${image_2} --nic net-id=${net2_id} ${instance_4}
208 debug "nova instance '${instance_4}' booted on ${net_2}."
210 vm1_id=$(nova list | grep ${instance_1} | awk '{print $2}')
211 vm2_id=$(nova list | grep ${instance_2} | awk '{print $2}')
212 vm3_id=$(nova list | grep ${instance_3} | awk '{print $2}')
213 vm4_id=$(nova list | grep ${instance_4} | awk '{print $2}')
216 info "Checking if instances get an IP from DHCP..."
217 wait_for_ip ${instance_1} "10.6"
218 wait_for_ip ${instance_2} "10.6"
219 wait_for_ip ${instance_3} "10.7"
220 wait_for_ip ${instance_4} "10.7"
223 info "Health check passed!"