Improve quantum l3 and tempest config.

 * Previously, configuration for the q-l3 agent was creating a
   tenant-owned router.  This change maintains that behaviour if
   namespaces are enabled, but creates a public (not tenant-owned)
   router if namespaces are disabled.  Since the L3 agent can only
   manage a single router if namespaces are disabled, the change
   ensures that the single router can be shared by multiple tenants.
 * Add tempest configuration for the public router.

Change-Id: I2878a7eb9797bfd71082a55d4773519dc5198abc
diff --git a/lib/quantum b/lib/quantum
index 343e5a9..9c06f45 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -92,6 +92,8 @@
 Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-False}
 # Use quantum-debug command
 Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
+# The name of the default q-l3 router
+Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
 
 if is_service_enabled quantum; then
     Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf
@@ -277,7 +279,14 @@
 
     if is_service_enabled q-l3; then
         # Create a router, and add the private subnet as one of its interfaces
-        ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID router1 | grep ' id ' | get_field 2)
+        if [[ "$Q_USE_NAMESPACE" == "True" ]]; then
+            # If namespaces are enabled, create a tenant-owned router.
+            ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
+        else
+            # If namespaces are disabled, the L3 agent can only target
+            # a single router, which should not be tenant-owned.
+            ROUTER_ID=$(quantum router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
+        fi
         quantum router-interface-add $ROUTER_ID $SUBNET_ID
         # Create an external network, and a subnet. Configure the external network as router gw
         EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
diff --git a/lib/tempest b/lib/tempest
index 84afc09..0835234 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -11,6 +11,9 @@
 # - ``S3_SERVICE_PORT``
 # - ``SERVICE_HOST``
 # - ``BASE_SQL_CONN`` ``lib/database`` declares
+# - ``PUBLIC_NETWORK_NAME``
+# - ``Q_USE_NAMESPACE``
+# - ``Q_ROUTER_NAME``
 # Optional Dependencies:
 # IDENTITY_USE_SSL, IDENTITY_HOST, IDENTITY_PORT, IDENTITY_PATH
 # ALT_* (similar vars exists in keystone_data.sh)
@@ -61,6 +64,7 @@
     local flavors_ref
     local flavor_lines
     local public_network_id
+    local public_router_id
     local tenant_networks_reachable
 
     # TODO(afazekas):
@@ -175,6 +179,12 @@
     if is_service_enabled q-l3; then
         public_network_id=$(quantum net-list | grep $PUBLIC_NETWORK_NAME | \
             awk '{print $2}')
+        if [ "$Q_USE_NAMESPACE" == "False" ]; then
+            # If namespaces are disabled, devstack will create a single
+            # public router that tempest should be configured to use.
+            public_router_id=$(quantum router-list | awk "/ $Q_ROUTER_NAME / \
+               { print \$2 }")
+        fi
     fi
 
     # Timeouts
@@ -243,6 +253,7 @@
     iniset $TEMPEST_CONF network password "$password"
     iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable"
     iniset $TEMPEST_CONF network public_network_id "$public_network_id"
+    iniset $TEMPEST_CONF network public_router_id "$public_router_id"
 
     #boto
     iniset $TEMPEST_CONF boto ec2_url "http://$SERVICE_HOST:8773/services/Cloud"