#!/bin/bash set -ex PACKAGE=$1 UBUNTU=false FAILURE=false FAILED_TESTS="" SERVICE_STARTED=false PLATFORM=$(python -mplatform) TOKEN=$(openssl rand -hex 10) MYSQL_PASS=mysql_pass AUTH="--os-auth-url http://127.0.0.1:35357 --os-token $TOKEN --os-endpoint http://127.0.0.1:35357/v2.0/" NEUTRON_AUTH="--os-username neutron --os-password neutron --os-tenant-name neutron --os-auth-url http://127.0.0.1:35357/v2.0" CORE_PLUGIN="neutron.plugins.ml2.plugin.Ml2Plugin" if [[ $PLATFORM =~ Ubuntu ]] then UBUNTU=true else setenforce 0 fi if [ -z $PACKAGE ]; then echo "Package for testing is not specified"; exit 1; fi echo "127.0.10.1 $(hostname)" >> /etc/hosts install_packages() { #Install packages if $UBUNTU then echo "mysql-server mysql-server/root_password select $MYSQL_PASS" | debconf-set-selections echo "mysql-server mysql-server/root_password_again select $MYSQL_PASS" | debconf-set-selections DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes rabbitmq-server mysql-server mysql-client-core-5.5 python-mysqldb keystone else #yum install -y openstack-keystone rabbitmq-server mysql-server MySQL-client python-oslo-utils yum install -y openstack-keystone rabbitmq-server python-oslo-utils #CentOS 7 temporary workaround yum install -y http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm yum install -y mysql-community-server mysql-community-client #Install some plugins because they are required for db-migration scripts (bug #1371184) #Ubuntu neutron-server package include them #yum install -y openstack-neutron-bigswitch openstack-neutron-brocade openstack-neutron-cisco openstack-neutron-hyperv openstack-neutron-vmware openstack-neutron-openvswitch \ # openstack-neutron-ryu openstack-neutron-linuxbridge openstack-neutron-metaplugin openstack-neutron-mellanox openstack-neutron-nec openstack-neutron-nuage fi } install_neutron_server () { if $UBUNTU then DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes neutron-server else yum install -y openstack-neutron openstack-neutron-ml2 fi } setup_rabbitmq () { #Setup firewall on CentOS 7 if ! $UBUNTU ; then firewall-cmd --permanent --add-port=5672/tcp firewall-cmd --reload setsebool -P nis_enabled 1 fi restart_service rabbitmq-server if [ $? -ne 0 ]; then echo "RabbitMQ server failed to start" cat /var/log/rabbitmq/startup_err cat /var/log/rabbitmq/startup_log fi } setup_database() { #Setup databases restart_service mysql if ! $UBUNTU then mysqladmin -u root password $MYSQL_PASS fi mysql -uroot -p$MYSQL_PASS -Bse "drop database if exists keystone" mysql -uroot -p$MYSQL_PASS -Bse "drop database if exists neutron" mysql -uroot -p$MYSQL_PASS -Bse "create database keystone" mysql -uroot -p$MYSQL_PASS -Bse "create database neutron" mysql -uroot -p$MYSQL_PASS -Bse "GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'neutron'" mysql -uroot -p$MYSQL_PASS -Bse "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'keystone'" mysql -uroot -p$MYSQL_PASS -Bse "flush privileges" } setup_keystone() { #Setup Keystone cat > /etc/keystone/keystone.conf << EOF [DEFAULT] admin_token=$TOKEN [database] connection=mysql://keystone:keystone@localhost/keystone [token] provider=keystone.token.providers.uuid.Provider EOF keystone-manage db_sync keystone-manage bootstrap --bootstrap-password $TOKEN chown -R keystone:keystone /var/log/keystone/ if $UBUNTU then service keystone restart else systemctl restart openstack-keystone fi sleep 10 #Setup Neutron credentials keystone $AUTH user-create --name neutron --pass neutron keystone $AUTH tenant-create --name neutron keystone $AUTH user-role-add --user neutron --role admin --tenant neutron NEUTRON_SERVICE=`keystone $AUTH service-create --name=neutron --type=network --description="Neutron Networking Service" | grep id | awk -F '|' '{print $3}' | tr -d ' '` keystone $AUTH endpoint-create --region RegionOne --service-id=$NEUTRON_SERVICE --publicurl=http://localhost:9696 --internalurl=http://localhost:9696 --adminurl=http://localhost:9696 } setup_neutron_services() { #Setup Neutron cat > /etc/neutron/neutron.conf << EOF [DEFAULT] auth_strategy = keystone debug = True verbose = True service_plugins = neutron.services.l3_router.l3_router_plugin.L3RouterPlugin core_plugin = $CORE_PLUGIN rabbit_password = guest rabbit_hosts = 127.0.0.1 rpc_backend = neutron.openstack.common.rpc.impl_kombu state_path = /var/lib/neutron lock_path = $state_path/lock [keystone_authtoken] auth_host = 127.0.0.1 auth_port = 35357 auth_protocol = http admin_tenant_name = neutron admin_user = neutron admin_password = neutron auth_url=http://127.0.0.1:35357/v2.0 [matchmaker_redis] [matchmaker_ring] [quotas] [agent] root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf [database] connection = mysql://neutron:neutron@127.0.0.1/neutron?charset=utf8 [service_providers] EOF cat > /etc/neutron/l3_agent.ini << EOF [DEFAULT] interface_driver =neutron.agent.linux.interface.OVSInterfaceDriver root_helper=sudo neutron-rootwrap /etc/neutron/rootwrap.conf EOF if ! $UBUNTU then cp /usr/share/neutron/api-paste.ini /etc/neutron/ chown neutron:neutron /etc/neutron/api-paste.ini fi touch /etc/neutron/plugin.ini setup_rabbitmq } upgrade_neutron_db () { neutron-db-manage --config-file /etc/neutron/neutron.conf upgrade head || (echo "DB migration failed" && exit 1) } start_neutron_server () { restart_service neutron-server # Sleep is to let Neutron server successfully reconnect to AMQP sleep 10 } try () { TEST_FUNCTION=$1 SERVICE_STARTED=false for i in {1..5} do FAILURE=false $TEST_FUNCTION if ! $FAILURE then break elif [ $i -eq 5 ] then FAILED_TESTS+="$TEST_FUNCTION " fi done } restart_service () { local SERVICE=$1 if $UBUNTU; then service $SERVICE restart else systemctl restart $SERVICE fi } check_neutron_server() { #Execute tests neutron $NEUTRON_AUTH net-create mynet1 CHECK=$(neutron $NEUTRON_AUTH net-list | grep id) if [ -z "$CHECK" ]; then echo "Network listing failed" && FAILURE=true; fi } check_neutron_openvswitch () { # Workaround for bug #1371184 if ! $UBUNTU then chown root:neutron /etc/neutron/plugins/ml2/openvswitch_agent.ini fi if ! $SERVICE_STARTED ; then if $UBUNTU; then restart_service openvswitch-switch restart_service neutron-openvswitch-agent else restart_service openvswitch restart_service neutron-openvswitch-agent fi SERVICE_STARTED=true fi sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Open vSwitch agent" | awk -F "|" '{print $6}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "OVS agent check failed"; FAILURE=true; fi } check_neutron_l3_agent () { if ! $SERVICE_STARTED ; then restart_service neutron-l3-agent SERVICE_STARTED=true fi #This sleep here and in other functions is intended to let the agent add information to the queue sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "L3 agent" | awk -F "|" '{print $6}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "L3 agent check failed"; FAILURE=true; fi } check_neutron_dhcp_agent () { if ! $SERVICE_STARTED ; then restart_service neutron-dhcp-agent SERVICE_STARTED=true fi sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "DHCP agent" | awk -F "|" '{print $6}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "DHCP agent check failed"; FAILURE=true; fi } check_neutron_metadata_agent () { if ! $SERVICE_STARTED ; then restart_service neutron-metadata-agent SERVICE_STARTED=true fi sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Metadata agent" | awk -F "|" '{print $6}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "Metadata agent check failed"; FAILURE=true; fi } check_neutron_metering_agent () { if ! $SERVICE_STARTED ; then restart_service neutron-metering-agent SERVICE_STARTED=true fi sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Metering agent" | awk -F "|" '{print $6}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "Metering agent check failed"; FAILURE=true; fi } check_neutron_client () { neutron --help > /dev/null if [ $? -ne 0 ]; then echo "Neutron client check failed"; FAILURE=true; fi } check_error () { if [ "$FAILED_TESTS" != "" ] then grep TRACE /var/log/neutron/* grep ERROR /var/log/neutron/* echo "Failed tests are: $FAILED_TESTS" exit 1 fi } case $PACKAGE in neutron-server) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_server check_error ;; openstack-neutron) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_server try check_neutron_l3_agent try check_neutron_dhcp_agent try check_neutron_metadata_agent check_error ;; openstack-neutron-ml2) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_server check_error ;; openstack-neutron-openvswitch|neutron-openvswitch-agent) install_packages install_neutron_server setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_openvswitch check_error ;; python-neutronclient) check_neutron_client check_error ;; neutron-l3-agent) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_l3_agent check_error ;; neutron-dhcp-agent) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_dhcp_agent check_error ;; neutron-metadata-agent) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_metadata_agent check_error ;; openstack-neutron-metering-agent|neutron-metering-agent) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server try check_neutron_metering_agent check_error ;; esac exit 0