summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVu Tran <vu.tran@windriver.com>2014-05-23 22:10:37 -0400
committerBruce Ashfield <bruce.ashfield@windriver.com>2014-05-26 11:30:08 -0400
commit7ac076bc61edce7788442e4750d3b5b5545a29c1 (patch)
tree0d452dbb71379cba1d3219bd1410884dc4c01fcf
parent0f728e306634535cbef82aad2024d5044d4fc032 (diff)
downloadmeta-cloud-services-7ac076bc61edce7788442e4750d3b5b5545a29c1.tar.gz
neutron controller test config
Tempest requires a shared network to exist prior to start the tempest test. Change neutron settings to first search for an existing a shared network, if there is none then prepare a simple real flat network that is based on openvswith. Signed-off-by: Vu Tran <vu.tran@windriver.com>
-rw-r--r--meta-openstack-controller-test-config/recipes-devtools/python/python-neutron/neutron-test-config.init142
-rw-r--r--meta-openstack-controller-test-config/recipes-devtools/python/python-neutron_git.bbappend20
2 files changed, 162 insertions, 0 deletions
diff --git a/meta-openstack-controller-test-config/recipes-devtools/python/python-neutron/neutron-test-config.init b/meta-openstack-controller-test-config/recipes-devtools/python/python-neutron/neutron-test-config.init
new file mode 100644
index 0000000..976bf76
--- /dev/null
+++ b/meta-openstack-controller-test-config/recipes-devtools/python/python-neutron/neutron-test-config.init
@@ -0,0 +1,142 @@
1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides:
5# Required-Start: $remote_fs $network $syslog
6# Required-Stop: $remote_fs $syslog
7# Default-Start: 2 3 4 5
8# Default-Stop: 0 1 6
9# Short-Description: Neutron Test Config
10# Description: OpenStack Neutron Test Config
11### END INIT INFO
12
13
14TEMPEST_CONF_FILE=/etc/tempest/tempest.conf
15OVS_NEUTRON_PLUGIN=/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini
16temp_file="/tmp/do_note_delete_me.temp"
17temp_file_1="/tmp/do_note_delete_me_1.temp"
18
19
20function get_field() {
21 while read data; do
22 if [ "$1" -lt 0 ]; then
23 field="(\$(NF$1))"
24 else
25 field="\$$(($1 + 1))"
26 fi
27 echo "$data" | awk -F'[ \t]*\\|[ \t]*' "{print $field}"
28 done
29}
30
31function setup_default_flat_net() {
32 local tempest_net_name="TEMPEST_NET"
33 local eth_dev="%NEUTRON_CONF_EXT_ETH_IF%"
34 local ip="%CONTROLLER_IP%"
35 local ip_subnet="`echo $ip | cut -d '.' -f 1`.`echo $ip | cut -d '.' -f 2`.`echo $ip | cut -d '.' -f 3`"
36 if [ -z "$gate_way" ]; then
37 local gate_way="${ip_subnet}.1"
38 fi
39
40 sed -i "s/^# Example: network_vlan_ranges = physnet1:1000:2999/network_vlan_ranges = ph-eth0:1:1/" $OVS_NEUTRON_PLUGIN
41 sed -i "s/^network_vlan_ranges = .*/network_vlan_ranges = ph-eth0:1:1/" $OVS_NEUTRON_PLUGIN
42 sed -i "s/^# Example: bridge_mappings = physnet1:br-eth1/bridge_mappings = ph-eth0:br-eth0/" $OVS_NEUTRON_PLUGIN
43 sed -i "s/^bridge_mappings = .*/bridge_mappings = ph-eth0:br-eth0/" $OVS_NEUTRON_PLUGIN
44 sed -i "s/^local_ip = .*/local_ip = ${ip}/" $OVS_NEUTRON_PLUGIN
45
46 # Setup host OVS
47 ovs-vsctl add-br br-${eth_dev}
48 ovs-vsctl add-port br-${eth_dev} ${eth_dev}
49 ifconfig ${eth_dev} 0.0.0.0
50 ifconfig br-${eth_dev} ${ip}/16
51 route add default gw $gate_way
52
53 /etc/init.d/neutron-openvswitch-agent stop
54 /etc/init.d/neutron-dhcp-agent stop
55 /etc/init.d/neutron-server reload
56 /etc/init.d/neutron-dhcp-agent start
57 /etc/init.d/neutron-openvswitch-agent start
58 sleep 5
59
60 EXTERNAL_NET_ID=`neutron net-create ${tempest_net_name} --provider:physical_network=ph-eth0 --provider:network_type=flat --router:external=True | grep " id " | get_field 2`
61 neutron subnet-create ${tempest_net_name} ${ip_subnet}.0/24 \
62 --name ${tempest_net_name}_SUBNET --no-gateway \
63 --host-route destination=0.0.0.0/0,nexthop=$gate_way
64 EXT_TO_INT_ROUTER_ID=`neutron router-create ext-to-int | grep " id " | get_field 2`
65 neutron router-gateway-set $EXT_TO_INT_ROUTER_ID $EXTERNAL_NET_ID
66}
67
68start()
69{
70 if [ -e $TEMPEST_CONF_FILE ]; then
71 sleep 5
72 source /etc/nova/openrc
73 neutron net-list > $temp_file 2>&1
74 if [ "$?" != "0" ]; then
75 echo "Neutron service is not running"
76 exit 1
77 fi
78 shared_net_found=0
79 while read line; do
80 net_id=`echo $line | get_field 1`
81 neutron net-show $net_id > $temp_file_1 2>&1
82 if [ "$?" == "0" ]; then
83 is_external=`grep -F '| router:external' $temp_file_1 | get_field 2`
84 is_shared=`grep -F '| shared' $temp_file_1 | get_field 2`
85 if [ "$is_external" == "True" ] && [ "$is_shared" == "False" ] ; then
86 shared_net_found=1
87 break
88 fi
89 fi
90 done < $temp_file
91
92 if [ "$shared_net_found" == "0" ]; then
93 echo "Cannot find shared network, create default one"
94 setup_default_flat_net
95 fi
96
97 neutron net-list > $temp_file 2>&1
98 while read line; do
99 net_id=`echo $line | get_field 1`
100 neutron net-show $net_id > $temp_file_1 2>&1
101 if [ "$?" == "0" ]; then
102 is_external=`grep -F '| router:external' $temp_file_1 | get_field 2`
103 is_shared=`grep -F '| shared' $temp_file_1 | get_field 2`
104 shared_net_name=`grep -F '| name' $temp_file_1 | get_field 2`
105 if [ "$is_external" == "True" ] && [ "$is_shared" == "False" ] ; then
106 sed -i "s/^public_network_id = .*/public_network_id = ${net_id}/" $TEMPEST_CONF_FILE
107 sed -i "s/^fixed_network_name = .*/fixed_network_name = ${shared_net_name}/" $TEMPEST_CONF_FILE
108 break
109 fi
110 fi
111 done < $temp_file
112
113 neutron router-list > $temp_file 2>&1
114 while read line; do
115 router_id=`echo $line | get_field 1`
116 neutron router-show $router_id > $temp_file_1 2>&1
117 res=`grep -F "$net_id" $temp_file_1`
118 if [ ! -z "$res" ]; then
119 sed -i "s/^public_router_id = .*/public_router_id = ${router_id}/" $TEMPEST_CONF_FILE
120 break
121 fi
122 done < $temp_file
123
124 rm -f $temp_file > /dev/null 2>&1
125 rm -f $temp_file_1 > /dev/null 2>&1
126 fi
127}
128
129case "$1" in
130 start)
131 start
132 ;;
133 stop|force-reload|restart|reload|status)
134 echo "WARNING: command $1 is not supported"
135 ;;
136 *)
137 echo "Usage: $0 {start|stop|force-reload|restart|reload|status}"
138 exit 1
139 ;;
140esac
141
142exit 0
diff --git a/meta-openstack-controller-test-config/recipes-devtools/python/python-neutron_git.bbappend b/meta-openstack-controller-test-config/recipes-devtools/python/python-neutron_git.bbappend
new file mode 100644
index 0000000..2276456
--- /dev/null
+++ b/meta-openstack-controller-test-config/recipes-devtools/python/python-neutron_git.bbappend
@@ -0,0 +1,20 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
2
3SRC_URI += " file://neutron-test-config.init"
4
5NEUTRON_CONF_EXT_ETH_IF ?= "eth0"
6
7do_install_append() {
8 sed -e "s:%NEUTRON_CONF_EXT_ETH_IF%:${NEUTRON_CONF_EXT_ETH_IF}:g" -i ${WORKDIR}/neutron-test-config.init
9 sed -e "s:%CONTROLLER_IP%:${CONTROLLER_IP}:g" -i ${WORKDIR}/neutron-test-config.init
10 install -m 0755 ${WORKDIR}/neutron-test-config.init ${D}${sysconfdir}/init.d/neutron-test-config
11}
12
13PACKAGES += " ${SRCNAME}-test-config"
14FILES_${SRCNAME}-test-config = "${sysconfdir}/init.d/neutron-test-config"
15
16RDEPENDS_${SRCNAME}-tests += " ${SRCNAME}-test-config"
17
18INITSCRIPT_PACKAGES += " ${SRCNAME}-test-config"
19INITSCRIPT_NAME_${SRCNAME}-test-config = "neutron-test-config"
20INITSCRIPT_PARAMS_${SRCNAME}-test-config = "defaults 95 10"