Quantum cleanups

* Set base default env vars in lib/quantum
* Rename common dirs to match devstack conventions
  Q_CONF_FILE -> QUANTUM_CONF
  QUANTUM_CLIENT_* -> QUANTUMCLIENT_*

Change-Id: I7a2a92b50ef953195f078ac62cb975f28892c05c
diff --git a/lib/quantum b/lib/quantum
index cb68339..4e9f298 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -1,17 +1,69 @@
 # lib/quantum
 # functions - funstions specific to quantum
 
+# Dependencies:
+# ``functions`` file
+# ``DEST`` must be defined
+
+
+# Quantum Networking
+# ------------------
+
+# Make sure that quantum is enabled in ``ENABLED_SERVICES``.  If you want
+# to run Quantum on this host, make sure that q-svc is also in
+# ``ENABLED_SERVICES``.
+#
+# If you're planning to use the Quantum openvswitch plugin, set
+# ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
+# in ``ENABLED_SERVICES``.  If you're planning to use the Quantum
+# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
+# q-agt service is enabled in ``ENABLED_SERVICES``.
+#
+# See "Quantum Network Configuration" below for additional variables
+# that must be set in localrc for connectivity across hosts with
+# Quantum.
+#
+# With Quantum networking the NET_MAN variable is ignored.
+
+
 # Save trace setting
 XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
+
+# Defaults
+# --------
+
+# Set up default directories
 QUANTUM_DIR=$DEST/quantum
-export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"/etc/quantum/debug.ini"}
+QUANTUMCLIENT_DIR=$DEST/python-quantumclient
 QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum}
 
+QUANTUM_CONF_DIR=/etc/quantum
+QUANTUM_CONF=$QUANTUM_CONF_DIR/quantum.conf
+export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"$QUANTUM_CONF_DIR/debug.ini"}
+
+# Default Quantum Plugin
+Q_PLUGIN=${Q_PLUGIN:-openvswitch}
+# Default Quantum Port
+Q_PORT=${Q_PORT:-9696}
+# Default Quantum Host
+Q_HOST=${Q_HOST:-$HOST_IP}
+# Which Quantum API nova should use
+# Default admin username
+Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
+# Default auth strategy
+Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
+# Use namespace or not
+Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
+Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
+# Meta data IP
+Q_META_DATA_IP=${Q_META_DATA_IP:-$HOST_IP}
+# Use quantum-debug command
+Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
+
 if is_service_enabled quantum; then
-    Q_CONF_FILE=/etc/quantum/quantum.conf
-    Q_RR_CONF_FILE=/etc/quantum/rootwrap.conf
+    Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf
     if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
         Q_RR_COMMAND="sudo"
     else
@@ -20,6 +72,10 @@
     fi
 fi
 
+
+# Entry Points
+# ------------
+
 # configure_quantum_rootwrap() - configure Quantum's rootwrap
 function configure_quantum_rootwrap() {
     if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
@@ -27,16 +83,16 @@
     fi
     # Deploy new rootwrap filters files (owned by root).
     # Wipe any existing rootwrap.d files first
-    Q_CONF_ROOTWRAP_D=/etc/quantum/rootwrap.d
+    Q_CONF_ROOTWRAP_D=$QUANTUM_CONF_DIR/rootwrap.d
     if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
         sudo rm -rf $Q_CONF_ROOTWRAP_D
     fi
-    # Deploy filters to /etc/quantum/rootwrap.d
+    # Deploy filters to $QUANTUM_CONF_DIR/rootwrap.d
     mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
     cp -pr $QUANTUM_DIR/etc/quantum/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
     sudo chown -R root:root $Q_CONF_ROOTWRAP_D
     sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
-    # Set up rootwrap.conf, pointing to /etc/quantum/rootwrap.d
+    # Set up rootwrap.conf, pointing to $QUANTUM_CONF_DIR/rootwrap.d
     sudo cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
     sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
     sudo chown root:root $Q_RR_CONF_FILE
@@ -52,7 +108,6 @@
     sudo mv $TEMPFILE /etc/sudoers.d/quantum-rootwrap
 }
 
-
 # Configures keystone integration for quantum service and agents
 function quantum_setup_keystone() {
     local conf_file=$1
diff --git a/stack.sh b/stack.sh
index 4807182..d58f5f5 100755
--- a/stack.sh
+++ b/stack.sh
@@ -321,26 +321,6 @@
 OPENSTACKCLIENT_DIR=$DEST/python-openstackclient
 NOVNC_DIR=$DEST/noVNC
 SWIFT3_DIR=$DEST/swift3
-QUANTUM_CLIENT_DIR=$DEST/python-quantumclient
-
-# Default Quantum Plugin
-Q_PLUGIN=${Q_PLUGIN:-openvswitch}
-# Default Quantum Port
-Q_PORT=${Q_PORT:-9696}
-# Default Quantum Host
-Q_HOST=${Q_HOST:-$HOST_IP}
-# Which Quantum API nova should use
-# Default admin username
-Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
-# Default auth strategy
-Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
-# Use namespace or not
-Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
-Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
-# Meta data IP
-Q_META_DATA_IP=${Q_META_DATA_IP:-$HOST_IP}
-# Use quantum-debug command
-Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
 
 RYU_DIR=$DEST/ryu
 # Ryu API Host
@@ -458,26 +438,6 @@
 ## FIXME(ja): should/can we check that FLAT_INTERFACE is sane?
 
 
-# Quantum Networking
-# ------------------
-
-# Make sure that quantum is enabled in ENABLED_SERVICES.  If you want
-# to run Quantum on this host, make sure that q-svc is also in
-# ENABLED_SERVICES.
-#
-# If you're planning to use the Quantum openvswitch plugin, set
-# Q_PLUGIN to "openvswitch" and make sure the q-agt service is enabled
-# in ENABLED_SERVICES.  If you're planning to use the Quantum
-# linuxbridge plugin, set Q_PLUGIN to "linuxbridge" and make sure the
-# q-agt service is enabled in ENABLED_SERVICES.
-#
-# See "Quantum Network Configuration" below for additional variables
-# that must be set in localrc for connectivity across hosts with
-# Quantum.
-#
-# With Quantum networking the NET_MAN variable is ignored.
-
-
 # Database Configuration
 # ----------------------
 
@@ -805,7 +765,7 @@
     install_horizon
 fi
 if is_service_enabled quantum; then
-    git_clone $QUANTUM_CLIENT_REPO $QUANTUM_CLIENT_DIR $QUANTUM_CLIENT_BRANCH
+    git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH
 fi
 if is_service_enabled quantum; then
     # quantum
@@ -864,7 +824,7 @@
     configure_horizon
 fi
 if is_service_enabled quantum; then
-    setup_develop $QUANTUM_CLIENT_DIR
+    setup_develop $QUANTUMCLIENT_DIR
     setup_develop $QUANTUM_DIR
 fi
 if is_service_enabled heat; then
@@ -1119,11 +1079,11 @@
     # Example: ``OVS_ENABLE_TUNNELING=True``
     OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
 
-    # Put config files in ``/etc/quantum`` for everyone to find
-    if [[ ! -d /etc/quantum ]]; then
-        sudo mkdir -p /etc/quantum
+    # Put config files in ``QUANTUM_CONF_DIR`` for everyone to find
+    if [[ ! -d $QUANTUM_CONF_DIR ]]; then
+        sudo mkdir -p $QUANTUM_CONF_DIR
     fi
-    sudo chown `whoami` /etc/quantum
+    sudo chown `whoami` $QUANTUM_CONF_DIR
 
     if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
         Q_PLUGIN_CONF_PATH=etc/quantum/plugins/openvswitch
@@ -1147,7 +1107,7 @@
         exit 1
     fi
 
-    # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``/etc/quantum``
+    # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR``
     mkdir -p /$Q_PLUGIN_CONF_PATH
     Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
     cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
@@ -1156,14 +1116,14 @@
     iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection $dburl
     unset dburl
 
-    cp $QUANTUM_DIR/etc/quantum.conf $Q_CONF_FILE
+    cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF
     configure_quantum_rootwrap
 fi
 
 # Quantum service (for controller node)
 if is_service_enabled q-svc; then
-    Q_API_PASTE_FILE=/etc/quantum/api-paste.ini
-    Q_POLICY_FILE=/etc/quantum/policy.json
+    Q_API_PASTE_FILE=$QUANTUM_CONF_DIR/api-paste.ini
+    Q_POLICY_FILE=$QUANTUM_CONF_DIR/policy.json
 
     cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
     cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE
@@ -1176,9 +1136,9 @@
     fi
 
     # Update either configuration file with plugin
-    iniset $Q_CONF_FILE DEFAULT core_plugin $Q_PLUGIN_CLASS
+    iniset $QUANTUM_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
 
-    iniset $Q_CONF_FILE DEFAULT auth_strategy $Q_AUTH_STRATEGY
+    iniset $QUANTUM_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
     quantum_setup_keystone $Q_API_PASTE_FILE filter:authtoken
 
     # Configure plugin
@@ -1295,7 +1255,7 @@
 if is_service_enabled q-dhcp; then
     AGENT_DHCP_BINARY="$QUANTUM_DIR/bin/quantum-dhcp-agent"
 
-    Q_DHCP_CONF_FILE=/etc/quantum/dhcp_agent.ini
+    Q_DHCP_CONF_FILE=$QUANTUM_CONF_DIR/dhcp_agent.ini
 
     cp $QUANTUM_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
 
@@ -1325,7 +1285,7 @@
 if is_service_enabled q-l3; then
     AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent"
     PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
-    Q_L3_CONF_FILE=/etc/quantum/l3_agent.ini
+    Q_L3_CONF_FILE=$QUANTUM_CONF_DIR/l3_agent.ini
 
     cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
 
@@ -1361,7 +1321,7 @@
 #Quantum Metadata
 if is_service_enabled q-meta; then
     AGENT_META_BINARY="$QUANTUM_DIR/bin/quantum-metadata-agent"
-    Q_META_CONF_FILE=/etc/quantum/metadata_agent.ini
+    Q_META_CONF_FILE=$QUANTUM_CONF_DIR/metadata_agent.ini
 
     cp $QUANTUM_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
 
@@ -1381,14 +1341,14 @@
 
 # Quantum RPC support - must be updated prior to starting any of the services
 if is_service_enabled quantum; then
-    iniset $Q_CONF_FILE DEFAULT control_exchange quantum
+    iniset $QUANTUM_CONF DEFAULT control_exchange quantum
     if is_service_enabled qpid ; then
-        iniset $Q_CONF_FILE DEFAULT rpc_backend quantum.openstack.common.rpc.impl_qpid
+        iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_qpid
     elif is_service_enabled zeromq; then
-        iniset $Q_CONF_FILE DEFAULT rpc_backend quantum.openstack.common.rpc.impl_zmq
+        iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_zmq
     elif [ -n "$RABBIT_HOST" ] &&  [ -n "$RABBIT_PASSWORD" ]; then
-        iniset $Q_CONF_FILE DEFAULT rabbit_host $RABBIT_HOST
-        iniset $Q_CONF_FILE DEFAULT rabbit_password $RABBIT_PASSWORD
+        iniset $QUANTUM_CONF DEFAULT rabbit_host $RABBIT_HOST
+        iniset $QUANTUM_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
     fi
     if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
         cp $QUANTUM_DIR/etc/l3_agent.ini $QUANTUM_TEST_CONFIG_FILE
@@ -1598,7 +1558,7 @@
 if is_service_enabled q-svc; then
     echo_summary "Starting Quantum"
     # Start the Quantum service
-    screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
+    screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
     echo "Waiting for Quantum to start..."
     if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:9696; do sleep 1; done"; then
       echo "Quantum did not start"
@@ -1650,10 +1610,10 @@
 fi
 
 # Start up the quantum agents if enabled
-screen_it q-agt "python $AGENT_BINARY --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
-screen_it q-dhcp "python $AGENT_DHCP_BINARY --config-file $Q_CONF_FILE --config-file=$Q_DHCP_CONF_FILE"
-screen_it q-meta "python $AGENT_META_BINARY --config-file $Q_CONF_FILE --config-file=$Q_META_CONF_FILE"
-screen_it q-l3 "python $AGENT_L3_BINARY --config-file $Q_CONF_FILE --config-file=$Q_L3_CONF_FILE"
+screen_it q-agt "python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
+screen_it q-dhcp "python $AGENT_DHCP_BINARY --config-file $QUANTUM_CONF --config-file=$Q_DHCP_CONF_FILE"
+screen_it q-meta "python $AGENT_META_BINARY --config-file $QUANTUM_CONF --config-file=$Q_META_CONF_FILE"
+screen_it q-l3 "python $AGENT_L3_BINARY --config-file $QUANTUM_CONF --config-file=$Q_L3_CONF_FILE"
 
 if is_service_enabled nova; then
     echo_summary "Starting Nova"
diff --git a/stackrc b/stackrc
index 39d34b0..8ac6ec5 100644
--- a/stackrc
+++ b/stackrc
@@ -89,8 +89,8 @@
 QUANTUM_BRANCH=master
 
 # quantum client
-QUANTUM_CLIENT_REPO=${GIT_BASE}/openstack/python-quantumclient
-QUANTUM_CLIENT_BRANCH=master
+QUANTUMCLIENT_REPO=${GIT_BASE}/openstack/python-quantumclient
+QUANTUMCLIENT_BRANCH=master
 
 # Tempest test suite
 TEMPEST_REPO=${GIT_BASE}/openstack/tempest.git