]> review.fuel-infra Code Review - openstack-build/neutron-build.git/blob - tests/runtests.sh
Update to 8.0.0.0b1
[openstack-build/neutron-build.git] / tests / runtests.sh
1 #!/bin/bash
2
3 set -ex
4 PACKAGE=$1
5 UBUNTU=false
6 FAILURE=false
7 FAILED_TESTS=""
8 SERVICE_STARTED=false
9 PLATFORM=$(python -mplatform)
10 TOKEN=$(openssl rand -hex 10)
11 MYSQL_PASS=mysql_pass
12 AUTH="--os-auth-url http://127.0.0.1:35357 --os-token $TOKEN --os-endpoint http://127.0.0.1:35357/v2.0/"
13 NEUTRON_AUTH="--os-username neutron --os-password neutron --os-tenant-name neutron --os-auth-url http://127.0.0.1:35357/v2.0"
14 CORE_PLUGIN="neutron.plugins.ml2.plugin.Ml2Plugin"
15
16 if [[ $PLATFORM =~ Ubuntu ]]
17 then
18    UBUNTU=true
19 else
20    setenforce 0
21 fi
22
23 if [ -z $PACKAGE ]; then echo "Package for testing is not specified"; exit 1; fi
24 echo "127.0.10.1 $(hostname)" >> /etc/hosts
25
26 install_packages() {
27     #Install packages
28     if $UBUNTU
29     then
30         echo "mysql-server mysql-server/root_password select $MYSQL_PASS" | debconf-set-selections
31         echo "mysql-server mysql-server/root_password_again select $MYSQL_PASS" | debconf-set-selections
32         DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes rabbitmq-server mysql-server mysql-client-core-5.5 python-mysqldb keystone
33     else
34         #yum install -y openstack-keystone rabbitmq-server mysql-server MySQL-client python-oslo-utils
35         yum install -y openstack-keystone rabbitmq-server python-oslo-utils
36         #CentOS 7 temporary workaround
37         yum install -y http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
38         yum install -y mysql-community-server mysql-community-client
39         #Install some plugins because they are required for db-migration scripts (bug #1371184)
40         #Ubuntu neutron-server package include them
41         #yum install -y openstack-neutron-bigswitch openstack-neutron-brocade openstack-neutron-cisco openstack-neutron-hyperv openstack-neutron-vmware openstack-neutron-openvswitch \
42         #               openstack-neutron-ryu openstack-neutron-linuxbridge openstack-neutron-metaplugin openstack-neutron-mellanox openstack-neutron-nec openstack-neutron-nuage
43     fi
44 }
45
46 install_neutron_server () {
47     if $UBUNTU
48     then
49         DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes neutron-server
50     else
51         yum install -y openstack-neutron openstack-neutron-ml2
52     fi
53 }
54
55 setup_rabbitmq () {
56     #Setup firewall on CentOS 7
57     if ! $UBUNTU ; then
58         firewall-cmd --permanent --add-port=5672/tcp
59         firewall-cmd --reload
60         setsebool -P nis_enabled 1
61     fi
62
63     restart_service rabbitmq-server
64     if [ $? -ne 0 ]; then
65         echo "RabbitMQ server failed to start"
66         cat /var/log/rabbitmq/startup_err
67         cat /var/log/rabbitmq/startup_log
68     fi
69 }
70
71 setup_database() {
72     #Setup databases
73     restart_service mysql
74     if ! $UBUNTU
75     then
76        mysqladmin -u root password $MYSQL_PASS
77     fi
78     mysql -uroot -p$MYSQL_PASS -Bse "drop database if exists keystone"
79     mysql -uroot -p$MYSQL_PASS -Bse "drop database if exists neutron"
80     mysql -uroot -p$MYSQL_PASS -Bse "create database keystone"
81     mysql -uroot -p$MYSQL_PASS -Bse "create database neutron"
82     mysql -uroot -p$MYSQL_PASS -Bse "GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'neutron'"
83     mysql -uroot -p$MYSQL_PASS -Bse "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'keystone'"
84     mysql -uroot -p$MYSQL_PASS -Bse "flush privileges"
85 }
86
87 setup_keystone() {
88     #Setup Keystone
89     if ! $UBUNTU
90     then
91         cp /usr/share/keystone/keystone-dist-paste.ini /etc/keystone/keystone-paste.ini
92     fi
93     cat > /etc/keystone/keystone.conf << EOF
94 [DEFAULT]
95 admin_token=$TOKEN
96 [database]
97 connection=mysql://keystone:keystone@localhost/keystone
98 [token]
99 provider=keystone.token.providers.uuid.Provider
100 EOF
101     keystone-manage db_sync
102     chown -R keystone:keystone /var/log/keystone/
103     if $UBUNTU
104     then
105         service keystone restart
106     else
107         systemctl restart openstack-keystone
108     fi
109     sleep 10
110     #Setup Neutron credentials
111     keystone $AUTH user-create --name neutron --pass neutron
112     keystone $AUTH tenant-create --name neutron
113     keystone $AUTH role-create --name=admin
114     keystone $AUTH user-role-add --user neutron --role admin --tenant neutron
115     NEUTRON_SERVICE=`keystone $AUTH service-create --name=neutron --type=network --description="Neutron Networking Service" | grep id | awk -F '|' '{print $3}' | tr -d ' '`
116     keystone $AUTH endpoint-create --region RegionOne --service-id=$NEUTRON_SERVICE --publicurl=http://localhost:9696 --internalurl=http://localhost:9696 --adminurl=http://localhost:9696
117 }
118
119 setup_neutron_services() {
120 #Setup Neutron
121 cat > /etc/neutron/neutron.conf << EOF
122 [DEFAULT]
123 auth_strategy = keystone
124 debug = True
125 verbose = True
126 service_plugins = neutron.services.l3_router.l3_router_plugin.L3RouterPlugin
127 core_plugin = $CORE_PLUGIN
128 rabbit_password = guest
129 rabbit_hosts = 127.0.0.1
130 rpc_backend = neutron.openstack.common.rpc.impl_kombu
131 state_path = /var/lib/neutron
132 lock_path = $state_path/lock
133 [keystone_authtoken]
134 auth_host = 127.0.0.1
135 auth_port = 35357
136 auth_protocol = http
137 admin_tenant_name = neutron
138 admin_user = neutron
139 admin_password = neutron
140 auth_url=http://127.0.0.1:35357/v2.0
141 [matchmaker_redis]
142 [matchmaker_ring]
143 [quotas]
144 [agent]
145 root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf
146 [database]
147 connection = mysql://neutron:neutron@127.0.0.1/neutron?charset=utf8
148 [service_providers]
149 EOF
150
151 cat > /etc/neutron/l3_agent.ini << EOF
152 [DEFAULT]
153 interface_driver =neutron.agent.linux.interface.OVSInterfaceDriver
154 root_helper=sudo neutron-rootwrap /etc/neutron/rootwrap.conf
155 EOF
156
157     if ! $UBUNTU
158     then
159         cp /usr/share/neutron/api-paste.ini /etc/neutron/
160         chown neutron:neutron /etc/neutron/api-paste.ini
161     fi
162
163     touch /etc/neutron/plugin.ini
164     setup_rabbitmq
165 }
166
167 upgrade_neutron_db () {
168     neutron-db-manage --config-file /etc/neutron/neutron.conf upgrade head || (echo "DB migration failed" && exit 1)
169 }
170
171 start_neutron_server () {
172     restart_service neutron-server
173     # Sleep is to let Neutron server successfully reconnect to AMQP
174     sleep 10
175 }
176
177 try () {
178     TEST_FUNCTION=$1
179     SERVICE_STARTED=false
180     for i in {1..5}
181     do
182        FAILURE=false
183        $TEST_FUNCTION
184        if ! $FAILURE
185        then break
186        elif [ $i -eq 5 ]
187        then
188            FAILED_TESTS+="$TEST_FUNCTION "
189        fi
190     done
191 }
192
193 restart_service () {
194     local SERVICE=$1
195     if $UBUNTU; then
196         service $SERVICE restart
197     else
198         systemctl restart $SERVICE
199     fi
200 }
201
202 check_neutron_server() {
203     #Execute tests
204     neutron $NEUTRON_AUTH net-create mynet1
205     CHECK=$(neutron $NEUTRON_AUTH net-list | grep id)
206     if [ -z "$CHECK" ]; then echo "Network listing failed" && FAILURE=true; fi
207 }
208
209 check_neutron_openvswitch () {
210     # Workaround for bug #1371184
211     if ! $UBUNTU
212     then
213         chown root:neutron /etc/neutron/plugins/ml2/openvswitch_agent.ini
214     fi
215
216     if ! $SERVICE_STARTED ; then
217         if $UBUNTU; then
218             restart_service openvswitch-switch
219             restart_service neutron-openvswitch-agent
220         else
221             restart_service openvswitch
222             restart_service neutron-openvswitch-agent
223         fi
224         SERVICE_STARTED=true
225     fi
226
227     sleep 10
228     STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Open vSwitch agent" | awk -F "|" '{print $6}' | tr -d " ")
229     if [ "$STATUS" != ":-)" ]; then echo "OVS agent check failed"; FAILURE=true; fi
230 }
231
232 check_neutron_l3_agent () {
233     if ! $SERVICE_STARTED ; then
234         restart_service neutron-l3-agent
235         SERVICE_STARTED=true
236     fi
237     #This sleep here and in other functions is intended to let the agent add information to the queue
238     sleep 10
239     STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "L3 agent" | awk -F "|" '{print $6}' | tr -d " ")
240     if [ "$STATUS" != ":-)" ]; then echo "L3 agent check failed"; FAILURE=true; fi
241 }
242
243 check_neutron_dhcp_agent () {
244     if ! $SERVICE_STARTED ; then
245         restart_service neutron-dhcp-agent
246         SERVICE_STARTED=true
247     fi
248     sleep 10
249     STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "DHCP agent" | awk -F "|" '{print $6}' | tr -d " ")
250     if [ "$STATUS" != ":-)" ]; then echo "DHCP agent check failed"; FAILURE=true; fi
251 }
252
253 check_neutron_metadata_agent () {
254     if ! $SERVICE_STARTED ; then
255         restart_service neutron-metadata-agent
256         SERVICE_STARTED=true
257     fi
258     sleep 10
259     STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Metadata agent" | awk -F "|" '{print $6}' | tr -d " ")
260     if [ "$STATUS" != ":-)" ]; then echo "Metadata agent check failed"; FAILURE=true; fi
261 }
262
263 check_neutron_metering_agent () {
264     if ! $SERVICE_STARTED ; then
265         restart_service neutron-metering-agent
266         SERVICE_STARTED=true
267     fi
268     sleep 10
269     STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Metering agent" | awk -F "|" '{print $6}' | tr -d " ")
270     if [ "$STATUS" != ":-)" ]; then echo "Metering agent check failed"; FAILURE=true; fi
271 }
272
273 check_neutron_client () {
274     neutron --help > /dev/null
275     if [ $? -ne 0 ]; then echo "Neutron client check failed"; FAILURE=true; fi
276 }
277
278 check_error () {
279     if [ "$FAILED_TESTS" != "" ]
280     then
281         grep TRACE /var/log/neutron/*
282         grep ERROR /var/log/neutron/*
283         echo "Failed tests are: $FAILED_TESTS"
284         exit 1
285     fi
286 }
287
288 case $PACKAGE in
289   neutron-server)
290     install_neutron_server
291     install_packages
292     setup_database
293     setup_keystone
294     setup_neutron_services
295     upgrade_neutron_db
296     start_neutron_server
297     try check_neutron_server
298     check_error
299   ;;
300   openstack-neutron)
301     install_neutron_server
302     install_packages
303     setup_database
304     setup_keystone
305     setup_neutron_services
306     upgrade_neutron_db
307     start_neutron_server
308     try check_neutron_server
309     try check_neutron_l3_agent
310     try check_neutron_dhcp_agent
311     try check_neutron_metadata_agent
312     check_error
313   ;;
314   openstack-neutron-ml2)
315     install_neutron_server
316     install_packages
317     setup_database
318     setup_keystone
319     setup_neutron_services
320     upgrade_neutron_db
321     start_neutron_server
322     try check_neutron_server
323     check_error
324   ;;
325   openstack-neutron-openvswitch|neutron-openvswitch-agent)
326     install_packages
327     install_neutron_server
328     setup_database
329     setup_keystone
330     setup_neutron_services
331     upgrade_neutron_db
332     start_neutron_server
333     try check_neutron_openvswitch
334     check_error
335   ;;
336   python-neutronclient)
337     check_neutron_client
338     check_error
339   ;;
340   neutron-l3-agent)
341     install_neutron_server
342     install_packages
343     setup_database
344     setup_keystone
345     setup_neutron_services
346     upgrade_neutron_db
347     start_neutron_server
348     try check_neutron_l3_agent
349     check_error
350   ;;
351   neutron-dhcp-agent)
352     install_neutron_server
353     install_packages
354     setup_database
355     setup_keystone
356     setup_neutron_services
357     upgrade_neutron_db
358     start_neutron_server
359     try check_neutron_dhcp_agent
360     check_error
361   ;;
362   neutron-metadata-agent)
363     install_neutron_server
364     install_packages
365     setup_database
366     setup_keystone
367     setup_neutron_services
368     upgrade_neutron_db
369     start_neutron_server
370     try check_neutron_metadata_agent
371     check_error
372   ;;
373   openstack-neutron-metering-agent|neutron-metering-agent)
374     install_neutron_server
375     install_packages
376     setup_database
377     setup_keystone
378     setup_neutron_services
379     upgrade_neutron_db
380     start_neutron_server
381     try check_neutron_metering_agent
382     check_error
383   ;;
384 esac
385
386 exit 0