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