#!/bin/bash -ex PACKAGE=$1 UBUNTU=false FAILURE=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; 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 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 python-oslo-utils #Install some plugins because they are required for db-migration scripts (bug #1371184) #Ubuntu neutron-server package include them if [ "$SOURCEBRANCH" == "master" ]; then 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 fi } install_neutron_server () { if $UBUNTU then apt-get install -y --force-yes neutron-server else yum install -y openstack-neutron openstack-neutron-ml2 fi } setup_database() { #Setup databases service mysql restart || service mysqld restart if ! $UBUNTU then mysqladmin -u root password $MYSQL_PASS fi 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 if ! $UBUNTU then cp /usr/share/keystone/keystone-dist-paste.ini /etc/keystone/keystone-paste.ini fi 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 chown -R keystone:keystone /var/log/keystone/ if $UBUNTU then service keystone restart else service openstack-keystone start fi sleep 10 #Setup Neutron credentials keystone $AUTH user-create --name neutron --pass neutron keystone $AUTH tenant-create --name neutron keystone $AUTH role-create --name=admin 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] service_provider=LOADBALANCER:Haproxy:neutron.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default service_provider=VPN:openswan:neutron.services.vpn.service_drivers.ipsec.IPsecVPNDriver:default 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 for i in {1..5} do service rabbitmq-server restart if [ $? -eq 0 ]; then break; fi echo "RabbitMQ server failed to start" cat /var/log/rabbitmq/startup_err cat /var/log/rabbitmq/startup_log done } upgrade_neutron_db () { neutron-db-manage --config-file /etc/neutron/neutron.conf upgrade head || (echo "DB migration failed" && exit 1) } start_neutron_server () { service neutron-server restart # Sleep is to let Neutron server successfully reconnect to AMQP sleep 10 } 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/openvswitch/ovs_neutron_plugin.ini fi if ! $UBUNTU then service openvswitch start service neutron-openvswitch-agent start else service openvswitch-switch restart service neutron-plugin-openvswitch-agent restart fi sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Open vSwitch agent" | awk -F "|" '{print $5}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "OVS agent check failed"; FAILURE=true; fi } check_neutron_l3_agent () { service neutron-l3-agent restart #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 $5}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "L3 agent check failed"; FAILURE=true; fi } check_neutron_dhcp_agent () { service neutron-dhcp-agent restart sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "DHCP agent" | awk -F "|" '{print $5}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "DHCP agent check failed"; FAILURE=true; fi } check_neutron_metadata_agent () { service neutron-metadata-agent restart sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Metadata agent" | awk -F "|" '{print $5}' | tr -d " ") if [ "$STATUS" != ":-)" ]; then echo "Metadata agent check failed"; FAILURE=true; fi } check_neutron_metering_agent () { service neutron-metering-agent restart sleep 10 STATUS=$(neutron $NEUTRON_AUTH agent-list | grep "Metering agent" | awk -F "|" '{print $5}' | 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 $FAILURE then grep TRACE /var/log/neutron/* grep ERROR /var/log/neutron/* 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 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 check_neutron_server check_neutron_l3_agent check_neutron_dhcp_agent 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 check_neutron_server check_error ;; openstack-neutron-openvswitch|neutron-plugin-openvswitch-agent) install_packages install_neutron_server setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server 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 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 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 check_neutron_metadata_agent check_error ;; openstack-neutron-metering-agent|neutron-plugin-metering-agent) install_neutron_server install_packages setup_database setup_keystone setup_neutron_services upgrade_neutron_db start_neutron_server check_neutron_metering_agent check_error ;; esac exit 0