Browse code

Nicira plugin: do not die if NVP gateway IP is missing

Devstack should not die if the IP and prefix len for establishing
a connection to the public network are not provided.
In this case, the public gateway IP address used to configure
Neutron's public network should be used, together with the prefix
length of the public network's CIDR.

This patch also ensures $PUBLIC_BRIDGE is created, even if
Q_USE_DEBUG_COMMAND is disabled. Finally this patch also adds
the teardown operation for restoring the original IP addresses
on the interface used for connectivity to the public network
implemented on the NVP gateway.

Bug #1227750

Change-Id: Ib58738a578c46f2183d503cabfdc6039bfbeb702

Salvatore Orlando authored on 2013/09/21 08:17:06
Showing 1 changed files
... ...
@@ -18,22 +18,38 @@ set +o xtrace
18 18
 # to an network that allows it to talk to the gateway for
19 19
 # testing purposes
20 20
 NVP_GATEWAY_NETWORK_INTERFACE=${NVP_GATEWAY_NETWORK_INTERFACE:-eth2}
21
+# Re-declare floating range as it's needed also in stop_nicira, which
22
+# is invoked by unstack.sh
23
+FLOATING_RANGE=${FLOATING_RANGE:-172.24.4.224/28}
21 24
 
22 25
 function configure_nicira() {
23 26
     :
24 27
 }
25 28
 
26 29
 function init_nicira() {
27
-    die_if_not_set $LINENO NVP_GATEWAY_NETWORK_CIDR "Please, specify CIDR for the gateway network interface."
30
+    if ! is_set NVP_GATEWAY_NETWORK_CIDR; then
31
+        NVP_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/}
32
+        echo "The IP address to set on br-ex was not specified. "
33
+        echo "Defaulting to "$NVP_GATEWAY_NETWORK_CIDR
34
+    fi
28 35
     # Make sure the interface is up, but not configured
29
-    sudo ifconfig $NVP_GATEWAY_NETWORK_INTERFACE up
36
+    sudo ip link dev $NVP_GATEWAY_NETWORK_INTERFACE set up
37
+    # Save and then flush the IP addresses on the interface
38
+    addresses=$(ip addr show dev $NVP_GATEWAY_NETWORK_INTERFACE | grep inet | awk {'print $2'})
30 39
     sudo ip addr flush $NVP_GATEWAY_NETWORK_INTERFACE
31 40
     # Use the PUBLIC Bridge to route traffic to the NVP gateway
32 41
     # NOTE(armando-migliaccio): if running in a nested environment this will work
33 42
     # only with mac learning enabled, portsecurity and security profiles disabled
43
+    # The public bridge might not exist for the NVP plugin if Q_USE_DEBUG_COMMAND is off
44
+    # Try to create it anyway
45
+    sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE
34 46
     sudo ovs-vsctl -- --may-exist add-port $PUBLIC_BRIDGE $NVP_GATEWAY_NETWORK_INTERFACE
35 47
     nvp_gw_net_if_mac=$(ip link show $NVP_GATEWAY_NETWORK_INTERFACE | awk '/ether/ {print $2}')
36
-    sudo ifconfig $PUBLIC_BRIDGE $NVP_GATEWAY_NETWORK_CIDR hw ether $nvp_gw_net_if_mac
48
+    sudo ip link dev $PUBLIC_BRIDGE set address $nvp_gw_net_if_mac
49
+    for address in $addresses; do
50
+        sudo ip addr add dev $PUBLIC_BRIDGE $address
51
+    done
52
+    sudo ip addr add dev $PUBLIC_BRIDGE $NVP_GATEWAY_NETWORK_CIDR
37 53
 }
38 54
 
39 55
 function install_nicira() {
... ...
@@ -45,7 +61,21 @@ function start_nicira() {
45 45
 }
46 46
 
47 47
 function stop_nicira() {
48
-    :
48
+    if ! is_set NVP_GATEWAY_NETWORK_CIDR; then
49
+        NVP_GATEWAY_NETWORK_CIDR=$PUBLIC_NETWORK_GATEWAY/${FLOATING_RANGE#*/}
50
+        echo "The IP address expected on br-ex was not specified. "
51
+        echo "Defaulting to "$NVP_GATEWAY_NETWORK_CIDR
52
+    fi
53
+    sudo ip addr del $NVP_GATEWAY_NETWORK_CIDR dev $PUBLIC_BRIDGE
54
+    # Save and then flush remaining addresses on the interface
55
+    addresses=$(ip addr show dev $PUBLIC_BRIDGE | grep inet | awk {'print $2'})
56
+    sudo ip addr flush $PUBLIC_BRIDGE
57
+    # Try to detach physical interface from PUBLIC_BRIDGE
58
+    sudo ovs-vsctl del-port $NVP_GATEWAY_NETWORK_INTERFACE
59
+    # Restore addresses on NVP_GATEWAY_NETWORK_INTERFACE
60
+    for address in $addresses; do
61
+        sudo ip addr add dev $NVP_GATEWAY_NETWORK_INTERFACE $address
62
+    done
49 63
 }
50 64
 
51 65
 # Restore xtrace