Browse code

Devstack support for Quantum L3 agent

Fixes bug #1036910

Starts the L3 agent for Quantum, if the corresponding service is enabled.
Supports L3 agent with or without namespaces.
Available with openvswitch plugin only at this time.

Change-Id: Ic2dd7a2d32e985c5df0a94eee1ecb602f555cd14

Salvatore Orlando authored on 2012/08/31 20:55:20
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+# lib/quantum
1
+# functions - funstions specific to quantum
2
+
3
+# Save trace setting
4
+XTRACE=$(set +o | grep xtrace)
5
+set +o xtrace
6
+
7
+# Configures keystone integration for quantum service and agents
8
+function quantum_setup_keystone() {
9
+    local conf_file=$1
10
+    local section=$2
11
+    local use_auth_url=$3
12
+    if [[ -n $use_auth_url ]]; then
13
+        iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
14
+    else
15
+        iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
16
+        iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
17
+        iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
18
+    fi
19
+    iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
20
+    iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
21
+    iniset $conf_file $section admin_password $SERVICE_PASSWORD
22
+}
23
+
24
+function quantum_setup_ovs_bridge() {
25
+    local bridge=$1
26
+    for PORT in `sudo ovs-vsctl --no-wait list-ports $bridge`; do
27
+        if [[ "$PORT" =~ tap* ]]; then echo `sudo ip link delete $PORT` > /dev/null; fi
28
+        sudo ovs-vsctl --no-wait del-port $bridge $PORT
29
+    done
30
+    sudo ovs-vsctl --no-wait -- --if-exists del-br $bridge
31
+    sudo ovs-vsctl --no-wait add-br $bridge
32
+    sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
33
+}
34
+
35
+# Restore xtrace
36
+$XTRACE
... ...
@@ -268,6 +268,7 @@ sudo chown `whoami` $DATA_DIR
268 268
 source $TOP_DIR/lib/cinder
269 269
 source $TOP_DIR/lib/ceilometer
270 270
 source $TOP_DIR/lib/heat
271
+source $TOP_DIR/lib/quantum
271 272
 
272 273
 # Set the destination directories for OpenStack projects
273 274
 NOVA_DIR=$DEST/nova
... ...
@@ -298,6 +299,8 @@ Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
298 298
 Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
299 299
 # Use namespace or not
300 300
 Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
301
+# Meta data IP
302
+Q_META_DATA_IP=${Q_META_DATA_IP:-}
301 303
 
302 304
 # Name of the LVM volume group to use/create for iscsi volumes
303 305
 VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
... ...
@@ -1179,7 +1182,7 @@ if is_service_enabled quantum; then
1179 1179
     Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
1180 1180
     cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
1181 1181
 
1182
-    sudo sed -i -e "s/^sql_connection =.*$/sql_connection = mysql:\/\/$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST\/$Q_DB_NAME?charset=utf8/g" /$Q_PLUGIN_CONF_FILE
1182
+    iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection mysql:\/\/$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST\/$Q_DB_NAME?charset=utf8
1183 1183
 
1184 1184
     OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-True}
1185 1185
     if [[ "$Q_PLUGIN" = "openvswitch" && "$OVS_ENABLE_TUNNELING" = "True" ]]; then
... ...
@@ -1221,12 +1224,7 @@ if is_service_enabled q-svc; then
1221 1221
     iniset $Q_CONF_FILE DEFAULT core_plugin $Q_PLUGIN_CLASS
1222 1222
 
1223 1223
     iniset $Q_CONF_FILE DEFAULT auth_strategy $Q_AUTH_STRATEGY
1224
-    iniset $Q_API_PASTE_FILE filter:authtoken auth_host $KEYSTONE_SERVICE_HOST
1225
-    iniset $Q_API_PASTE_FILE filter:authtoken auth_port $KEYSTONE_AUTH_PORT
1226
-    iniset $Q_API_PASTE_FILE filter:authtoken auth_protocol $KEYSTONE_SERVICE_PROTOCOL
1227
-    iniset $Q_API_PASTE_FILE filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
1228
-    iniset $Q_API_PASTE_FILE filter:authtoken admin_user $Q_ADMIN_USERNAME
1229
-    iniset $Q_API_PASTE_FILE filter:authtoken admin_password $SERVICE_PASSWORD
1224
+    quantum_setup_keystone $Q_API_PASTE_FILE filter:authtoken
1230 1225
 fi
1231 1226
 
1232 1227
 # Quantum agent (for compute nodes)
... ...
@@ -1234,13 +1232,7 @@ if is_service_enabled q-agt; then
1234 1234
     if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
1235 1235
         # Set up integration bridge
1236 1236
         OVS_BRIDGE=${OVS_BRIDGE:-br-int}
1237
-        for PORT in `sudo ovs-vsctl --no-wait list-ports $OVS_BRIDGE`; do
1238
-            if [[ "$PORT" =~ tap* ]]; then echo `sudo ip link delete $PORT` > /dev/null; fi
1239
-            sudo ovs-vsctl --no-wait del-port $OVS_BRIDGE $PORT
1240
-        done
1241
-        sudo ovs-vsctl --no-wait -- --if-exists del-br $OVS_BRIDGE
1242
-        sudo ovs-vsctl --no-wait add-br $OVS_BRIDGE
1243
-        sudo ovs-vsctl --no-wait br-set-external-id $OVS_BRIDGE bridge-id br-int
1237
+        quantum_setup_ovs_bridge $OVS_BRIDGE
1244 1238
         if [[ "$OVS_ENABLE_TUNNELING" == "True" ]]; then
1245 1239
             iniset /$Q_PLUGIN_CONF_FILE OVS local_ip $HOST_IP
1246 1240
         else
... ...
@@ -1280,10 +1272,7 @@ if is_service_enabled q-dhcp; then
1280 1280
 
1281 1281
     # Update database
1282 1282
     iniset $Q_DHCP_CONF_FILE DEFAULT db_connection "mysql:\/\/$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST\/$Q_DB_NAME?charset=utf8"
1283
-    iniset $Q_DHCP_CONF_FILE DEFAULT auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
1284
-    iniset $Q_DHCP_CONF_FILE DEFAULT admin_tenant_name $SERVICE_TENANT_NAME
1285
-    iniset $Q_DHCP_CONF_FILE DEFAULT admin_user $Q_ADMIN_USERNAME
1286
-    iniset $Q_DHCP_CONF_FILE DEFAULT admin_password $SERVICE_PASSWORD
1283
+    quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url
1287 1284
 
1288 1285
     if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
1289 1286
         iniset $Q_DHCP_CONF_FILE DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
... ...
@@ -1292,6 +1281,45 @@ if is_service_enabled q-dhcp; then
1292 1292
     fi
1293 1293
 fi
1294 1294
 
1295
+# Quantum L3
1296
+if is_service_enabled q-l3; then
1297
+    AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent"
1298
+    PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
1299
+    Q_L3_CONF_FILE=/etc/quantum/l3_agent.ini
1300
+
1301
+    cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
1302
+
1303
+    # Set verbose
1304
+    iniset $Q_L3_CONF_FILE DEFAULT verbose True
1305
+    # Set debug
1306
+    iniset $Q_L3_CONF_FILE DEFAULT debug True
1307
+
1308
+    iniset $Q_L3_CONF_FILE DEFAULT metadata_ip $Q_META_DATA_IP
1309
+    iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
1310
+    iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
1311
+
1312
+    quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url
1313
+    if [[ "$Q_PLUGIN" == "openvswitch" ]]; then
1314
+        iniset $Q_L3_CONF_FILE DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
1315
+        # Set up external bridge
1316
+        # Create it if it does not exist
1317
+        sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE
1318
+        sudo ovs-vsctl --no-wait br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE
1319
+        # remove internal ports
1320
+        for PORT in `sudo ovs-vsctl --no-wait list-ports $PUBLIC_BRIDGE`; do
1321
+            TYPE=$(sudo ovs-vsctl get interface $PORT type)
1322
+            if [[ "$TYPE" == "internal" ]]; then
1323
+                echo `sudo ip link delete $PORT` > /dev/null
1324
+                sudo ovs-vsctl --no-wait del-port $bridge $PORT
1325
+            fi
1326
+        done
1327
+        # ensure no IP is configured on the public bridge
1328
+        sudo ip addr flush dev $PUBLIC_BRIDGE
1329
+    elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
1330
+        iniset $Q_L3_CONF_FILE DEFAULT interface_driver quantum.agent.linux.interface.BridgeInterfaceDriver
1331
+    fi
1332
+fi
1333
+
1295 1334
 # Quantum RPC support - must be updated prior to starting any of the services
1296 1335
 if is_service_enabled quantum; then
1297 1336
     iniset $Q_CONF_FILE DEFAULT control_exchange quantum
... ...
@@ -1305,16 +1333,6 @@ if is_service_enabled quantum; then
1305 1305
     fi
1306 1306
 fi
1307 1307
 
1308
-# Start the Quantum services
1309
-screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
1310
-
1311
-# Start up the quantum agent
1312
-screen_it q-agt "sudo python $AGENT_BINARY --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
1313
-
1314
-# Start up the quantum agent
1315
-screen_it q-dhcp "sudo python $AGENT_DHCP_BINARY --config-file $Q_CONF_FILE --config-file=$Q_DHCP_CONF_FILE"
1316
-
1317
-
1318 1308
 # Nova
1319 1309
 # ----
1320 1310
 
... ...
@@ -2140,7 +2158,6 @@ if is_service_enabled key; then
2140 2140
       echo "keystone did not start"
2141 2141
       exit 1
2142 2142
     fi
2143
-
2144 2143
     # ``keystone_data.sh`` creates services, admin and demo users, and roles.
2145 2144
     SERVICE_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0
2146 2145
 
... ...
@@ -2182,16 +2199,51 @@ if is_service_enabled n-api; then
2182 2182
     fi
2183 2183
 fi
2184 2184
 
2185
-# If we're using Quantum (i.e. q-svc is enabled), network creation has to
2186
-# happen after we've started the Quantum service.
2187 2185
 if is_service_enabled q-svc; then
2186
+    # Start the Quantum service
2187
+    screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
2188
+    echo "Waiting for Quantum to start..."
2189
+    if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:9696; do sleep 1; done"; then
2190
+      echo "Quantum did not start"
2191
+      exit 1
2192
+    fi
2193
+
2194
+    # Configure Quantum elements
2195
+    # Configure internal network & subnet
2196
+
2188 2197
     TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
2189 2198
 
2190 2199
     # Create a small network
2191 2200
     # Since quantum command is executed in admin context at this point,
2192 2201
     # ``--tenant_id`` needs to be specified.
2193 2202
     NET_ID=$(quantum net-create --tenant_id $TENANT_ID net1 | grep ' id ' | get_field 2)
2194
-    quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE
2203
+    SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
2204
+    if is_service_enabled q-l3; then
2205
+        # Create a router, and add the private subnet as one of its interfaces
2206
+        ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID router1 | grep ' id ' | get_field 2)
2207
+        quantum router-interface-add $ROUTER_ID $SUBNET_ID
2208
+        # Create an external network, and a subnet. Configure the external network as router gw
2209
+        EXT_NET_ID=$(quantum net-create ext_net -- --router:external=True | grep ' id ' | get_field 2)
2210
+        EXT_GW_IP=$(quantum subnet-create --ip_version 4 $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
2211
+        quantum router-gateway-set $ROUTER_ID $EXT_NET_ID
2212
+        if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
2213
+            CIDR_LEN=${FLOATING_RANGE#*/}
2214
+            sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
2215
+            sudo ip link set $PUBLIC_BRIDGE up
2216
+        fi
2217
+        if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
2218
+            # Explicitly set router id in l3 agent configuration
2219
+            iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
2220
+        fi
2221
+   fi
2222
+
2223
+   # Start up the quantum agent
2224
+   screen_it q-agt "sudo python $AGENT_BINARY --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
2225
+   # Start up the quantum dhcp agent
2226
+   screen_it q-dhcp "sudo python $AGENT_DHCP_BINARY --config-file $Q_CONF_FILE --config-file=$Q_DHCP_CONF_FILE"
2227
+   # Start up the quantum l3 agent
2228
+   screen_it q-l3 "sudo python $AGENT_L3_BINARY --config-file $Q_CONF_FILE --config-file=$Q_L3_CONF_FILE"
2229
+
2195 2230
 elif is_service_enabled mysql && is_service_enabled nova; then
2196 2231
     # Create a small network
2197 2232
     $NOVA_BIN_DIR/nova-manage network create private $FIXED_RANGE 1 $FIXED_NETWORK_SIZE $NETWORK_CREATE_ARGS