Merge "Refactor rpc backend configuration logic"
diff --git a/exercises/euca.sh b/exercises/euca.sh
index 76df254..46e4025 100755
--- a/exercises/euca.sh
+++ b/exercises/euca.sh
@@ -169,7 +169,7 @@
 # case changed with bug/836978. Requesting the status of an invalid instance
 # will now return an error message including the instance id, so we need to
 # filter that out.
-if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE |grep -v \"InstanceNotFound\" | grep -q $INSTANCE; do sleep 1; done"; then
+if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -ve \"\\\(InstanceNotFound\\\|InvalidInstanceId\[.\]NotFound\\\)\" | grep -q $INSTANCE; do sleep 1; done"; then
     echo "server didn't terminate within $TERMINATE_TIMEOUT seconds"
     exit 1
 fi
diff --git a/functions b/functions
index 4795042..7948378 100644
--- a/functions
+++ b/functions
@@ -224,6 +224,7 @@
         os_VENDOR=$(lsb_release -i -s)
         os_RELEASE=$(lsb_release -r -s)
         os_UPDATE=""
+        os_PACKAGE="rpm"
         if [[ "Debian,Ubuntu" =~ $os_VENDOR ]]; then
             os_PACKAGE="deb"
         elif [[ "SUSE LINUX" =~ $os_VENDOR ]]; then
@@ -231,9 +232,8 @@
             if [[ $? -eq 0 ]]; then
                 os_VENDOR="openSUSE"
             fi
-            os_PACKAGE="rpm"
-        else
-            os_PACKAGE="rpm"
+        elif [[ $os_VENDOR =~ Red.*Hat ]]; then
+            os_VENDOR="Red Hat"
         fi
         os_CODENAME=$(lsb_release -c -s)
     elif [[ -r /etc/redhat-release ]]; then
diff --git a/lib/databases/mysql b/lib/databases/mysql
index 1c0f5eb..965df6e 100644
--- a/lib/databases/mysql
+++ b/lib/databases/mysql
@@ -63,6 +63,21 @@
 default-storage-engine = InnoDB" $MY_CONF
     fi
 
+    # Turn on slow query log
+    sudo sed -i '/log.slow.queries/d' $MY_CONF
+    sudo sed -i -e "/^\[mysqld\]/ a \
+log-slow-queries = /var/log/mysql/mysql-slow.log" $MY_CONF
+
+    # Log any query taking longer than a second
+    sudo sed -i '/long.query.time/d' $MY_CONF
+    sudo sed -i -e "/^\[mysqld\]/ a \
+long-query-time = 1" $MY_CONF
+
+    # Log all non-indexed queries
+    sudo sed -i '/log.queries.not.using.indexes/d' $MY_CONF
+    sudo sed -i -e "/^\[mysqld\]/ a \
+log-queries-not-using-indexes" $MY_CONF
+
     restart_service $MYSQL
 }
 
diff --git a/lib/quantum b/lib/quantum
index 19df499..7c2df91 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 fa637c1..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):
@@ -129,33 +133,41 @@
     ALT_USERNAME=${ALT_USERNAME:-alt_demo}
     ALT_TENANT_NAME=${ALT_TENANT_NAME:-alt_demo}
 
-    # Check Nova for existing flavors and, if set, look for the
-    # ``DEFAULT_INSTANCE_TYPE`` and use that. Otherwise, just use the first flavor.
-    flavor_lines=`nova flavor-list`
-    IFS=$'\r\n'
-    flavors=""
-    if [[ -n "$DEFAULT_INSTANCE_TYPE" ]]; then
+    # If the ``DEFAULT_INSTANCE_TYPE`` not declared, use the new behavior
+    # Tempest creates instane types for himself
+    if  [[ -z "$DEFAULT_INSTANCE_TYPE" ]]; then
+        nova flavor-create m1.nano 42 64 0 1
+        flavor_ref=42
+        nova flavor-create m1.micro 84 128 0 1
+        flavor_ref_alt=84
+    else
+        # Check Nova for existing flavors and, if set, look for the
+        # ``DEFAULT_INSTANCE_TYPE`` and use that.
+        flavor_lines=`nova flavor-list`
+        IFS=$'\r\n'
+        flavors=""
         for line in $flavor_lines; do
             f=$(echo $line | awk "/ $DEFAULT_INSTANCE_TYPE / { print \$2 }")
             flavors="$flavors $f"
         done
-    fi
-    for line in $flavor_lines; do
-        flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`"
-    done
 
-    IFS=" "
-    flavors=($flavors)
-    num_flavors=${#flavors[*]}
-    echo "Found $num_flavors flavors"
-    if [[ $num_flavors -eq 0 ]]; then
-        echo "Found no valid flavors to use!"
-        exit 1
-    fi
-    flavor_ref=${flavors[0]}
-    flavor_ref_alt=$flavor_ref
-    if [[ $num_flavors -gt 1 ]]; then
-        flavor_ref_alt=${flavors[1]}
+        for line in $flavor_lines; do
+            flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`"
+        done
+
+        IFS=" "
+        flavors=($flavors)
+        num_flavors=${#flavors[*]}
+        echo "Found $num_flavors flavors"
+        if [[ $num_flavors -eq 0 ]]; then
+            echo "Found no valid flavors to use!"
+            exit 1
+        fi
+        flavor_ref=${flavors[0]}
+        flavor_ref_alt=$flavor_ref
+        if [[ $num_flavors -gt 1 ]]; then
+            flavor_ref_alt=${flavors[1]}
+        fi
     fi
 
     if [ "$Q_USE_NAMESPACE" != "False" ]; then
@@ -167,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
@@ -235,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"