Merge "Exercise cleanup"
diff --git a/files/apts/n-cpu b/files/apts/n-cpu
index a40b659..ad2d6d7 100644
--- a/files/apts/n-cpu
+++ b/files/apts/n-cpu
@@ -3,3 +3,5 @@
 open-iscsi
 open-iscsi-utils
 genisoimage
+sysfsutils
+sg3-utils
diff --git a/files/rpms-suse/n-cpu b/files/rpms-suse/n-cpu
index 27d3254..7040b84 100644
--- a/files/rpms-suse/n-cpu
+++ b/files/rpms-suse/n-cpu
@@ -2,3 +2,5 @@
 genisoimage
 lvm2
 open-iscsi
+sysfsutils
+sg3_utils
diff --git a/files/rpms/n-cpu b/files/rpms/n-cpu
index f7054e8..149672a 100644
--- a/files/rpms/n-cpu
+++ b/files/rpms/n-cpu
@@ -2,3 +2,5 @@
 iscsi-initiator-utils
 lvm2
 genisoimage
+sysfsutils
+sg3_utils
diff --git a/functions b/functions
index 79c82a4..ae63436 100644
--- a/functions
+++ b/functions
@@ -747,17 +747,19 @@
         screen_rc "$1" "$2"
 
         screen -S $SCREEN_NAME -X screen -t $1
+
+        if [[ -n ${SCREEN_LOGDIR} ]]; then
+            screen -S $SCREEN_NAME -p $1 -X logfile ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log
+            screen -S $SCREEN_NAME -p $1 -X log on
+            ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log
+        fi
+
         if [[ "$SCREEN_DEV" = "True" ]]; then
             # sleep to allow bash to be ready to be send the command - we are
             # creating a new window in screen and then sends characters, so if
             # bash isn't running by the time we send the command, nothing happens
             sleep 1.5
 
-            if [[ -n ${SCREEN_LOGDIR} ]]; then
-                screen -S $SCREEN_NAME -p $1 -X logfile ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log
-                screen -S $SCREEN_NAME -p $1 -X log on
-                ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log
-            fi
             NL=`echo -ne '\015'`
             screen -S $SCREEN_NAME -p $1 -X stuff "$2 || touch \"$SERVICE_DIR/$SCREEN_NAME/$1.failure\"$NL"
         else
diff --git a/lib/baremetal b/lib/baremetal
index 7c31d1f..2659386 100644
--- a/lib/baremetal
+++ b/lib/baremetal
@@ -400,15 +400,10 @@
 }
 
 function clear_baremetal_of_all_nodes() {
-    list=$(nova-baremetal-manage node list | tail -n +2 | awk '{print $1}' )
+    list=$(nova baremetal-node-list | awk -F '| ' 'NR>3 {print $2}' )
     for node in $list
     do
-        nova-baremetal-manage node delete $node
-    done
-    list=$(nova-baremetal-manage interface list | tail -n +2 | awk '{print $1}' )
-    for iface in $list
-    do
-        nova-baremetal-manage interface delete $iface
+        nova baremetal-node-delete $node
     done
 }
 
@@ -420,16 +415,18 @@
     mac_1=${1:-$BM_FIRST_MAC}
     mac_2=${2:-$BM_SECOND_MAC}
 
-    id=$(nova-baremetal-manage node create \
-       --host=$BM_HOSTNAME --prov_mac=$mac_1 \
-       --cpus=$BM_FLAVOR_CPU --memory_mb=$BM_FLAVOR_RAM \
-       --local_gb=$BM_FLAVOR_ROOT_DISK --terminal_port=0 \
-       --pm_address=$BM_PM_ADDR --pm_user=$BM_PM_USER --pm_password=$BM_PM_PASS \
-       )
+    id=$(nova baremetal-node-create \
+       --pm_address="$BM_PM_ADDR" \
+       --pm_user="$BM_PM_USER" \
+       --pm_password="$BM_PM_PASS" \
+       "$BM_HOSTNAME" \
+       "$BM_FLAVOR_CPU" \
+       "$BM_FLAVOR_RAM" \
+       "$BM_FLAVOR_ROOT_DISK" \
+       "$mac_1" \
+       | grep ' id ' | get_field 2 )
     [ $? -eq 0 ] || [ "$id" ] || die "Error adding baremetal node"
-    id2=$(nova-baremetal-manage interface create \
-       --node_id=$id --mac_address=$mac_2 --datapath_id=0 --port_no=0 \
-       )
+    id2=$(nova baremetal-add-interface "$id" "$mac_2" )
     [ $? -eq 0 ] || [ "$id2" ] || die "Error adding interface to barmetal node $id"
 }
 
diff --git a/lib/cinder b/lib/cinder
index fd5f8cf..4d1ab42 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -254,37 +254,55 @@
     fi
 }
 
+# create_cinder_cache_dir() - Part of the init_cinder() process
+function create_cinder_cache_dir() {
+    # Create cache dir
+    sudo mkdir -p $CINDER_AUTH_CACHE_DIR
+    sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
+    rm -f $CINDER_AUTH_CACHE_DIR/*
+}
+
+create_cinder_volume_group() {
+    # Configure a default volume group called '`stack-volumes`' for the volume
+    # service if it does not yet exist.  If you don't wish to use a file backed
+    # volume group, create your own volume group called ``stack-volumes`` before
+    # invoking ``stack.sh``.
+    #
+    # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
+
+    if ! sudo vgs $VOLUME_GROUP; then
+        VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
+
+        # Only create if the file doesn't already exists
+        [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
+
+        DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
+
+        # Only create if the loopback device doesn't contain $VOLUME_GROUP
+        if ! sudo vgs $VOLUME_GROUP; then
+            sudo vgcreate $VOLUME_GROUP $DEV
+        fi
+    fi
+
+    mkdir -p $CINDER_STATE_PATH/volumes
+}
+
 # init_cinder() - Initialize database and volume group
 function init_cinder() {
     # Force nova volumes off
     NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
 
     if is_service_enabled $DATABASE_BACKENDS; then
-        # (re)create cinder database
+        # (Re)create cinder database
         recreate_database cinder utf8
 
-        # (re)create cinder database
+        # Migrate cinder database
         $CINDER_BIN_DIR/cinder-manage db sync
     fi
 
     if is_service_enabled c-vol; then
-        # Configure a default volume group called '`stack-volumes`' for the volume
-        # service if it does not yet exist.  If you don't wish to use a file backed
-        # volume group, create your own volume group called ``stack-volumes`` before
-        # invoking ``stack.sh``.
-        #
-        # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
 
-        if ! sudo vgs $VOLUME_GROUP; then
-            VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
-            # Only create if the file doesn't already exists
-            [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
-            DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
-            # Only create if the loopback device doesn't contain $VOLUME_GROUP
-            if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
-        fi
-
-        mkdir -p $CINDER_STATE_PATH/volumes
+        create_cinder_volume_group
 
         if sudo vgs $VOLUME_GROUP; then
             if is_fedora || is_suse; then
@@ -299,10 +317,7 @@
         fi
     fi
 
-    # Create cache dir
-    sudo mkdir -p $CINDER_AUTH_CACHE_DIR
-    sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
-    rm -f $CINDER_AUTH_CACHE_DIR/*
+    create_cinder_cache_dir
 }
 
 # install_cinder() - Collect source and prepare
diff --git a/lib/glance b/lib/glance
index 5d48129..80d3902 100644
--- a/lib/glance
+++ b/lib/glance
@@ -141,6 +141,17 @@
     cp -p $GLANCE_DIR/etc/policy.json $GLANCE_POLICY_JSON
 }
 
+# create_glance_cache_dir() - Part of the init_glance() process
+function create_glance_cache_dir() {
+    # Create cache dir
+    sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/api
+    sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/api
+    rm -f $GLANCE_AUTH_CACHE_DIR/api/*
+    sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/registry
+    sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/registry
+    rm -f $GLANCE_AUTH_CACHE_DIR/registry/*
+}
+
 # init_glance() - Initialize databases, etc.
 function init_glance() {
     # Delete existing images
@@ -151,18 +162,13 @@
     rm -rf $GLANCE_CACHE_DIR
     mkdir -p $GLANCE_CACHE_DIR
 
-    # (re)create glance database
+    # (Re)create glance database
     recreate_database glance utf8
 
+    # Migrate glance database
     $GLANCE_BIN_DIR/glance-manage db_sync
 
-    # Create cache dir
-    sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/api
-    sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/api
-    rm -f $GLANCE_AUTH_CACHE_DIR/api/*
-    sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/registry
-    sudo chown $STACK_USER $GLANCE_AUTH_CACHE_DIR/registry
-    rm -f $GLANCE_AUTH_CACHE_DIR/registry/*
+    create_glance_cache_dir
 }
 
 # install_glanceclient() - Collect source and prepare
diff --git a/lib/nova b/lib/nova
index 1681af7..849ec57 100644
--- a/lib/nova
+++ b/lib/nova
@@ -166,20 +166,13 @@
         # Get the sample configuration file in place
         cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR
 
-        # Rewrite the authtoken configuration for our Keystone service.
-        # This is a bit defensive to allow the sample file some variance.
-        sed -e "
-            /^admin_token/i admin_tenant_name = $SERVICE_TENANT_NAME
-            /admin_tenant_name/s/^.*$/admin_tenant_name = $SERVICE_TENANT_NAME/;
-            /admin_user/s/^.*$/admin_user = nova/;
-            /admin_password/s/^.*$/admin_password = $SERVICE_PASSWORD/;
-            s,%SERVICE_TENANT_NAME%,$SERVICE_TENANT_NAME,g;
-            s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g;
-        " -i $NOVA_API_PASTE_INI
         iniset $NOVA_API_PASTE_INI filter:authtoken auth_host $SERVICE_HOST
         if is_service_enabled tls-proxy; then
             iniset $NOVA_API_PASTE_INI filter:authtoken auth_protocol $SERVICE_PROTOCOL
         fi
+        iniset $NOVA_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
+        iniset $NOVA_API_PASTE_INI filter:authtoken admin_user nova
+        iniset $NOVA_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
     fi
 
     iniset $NOVA_API_PASTE_INI filter:authtoken signing_dir $NOVA_AUTH_CACHE_DIR
@@ -453,6 +446,14 @@
     done
 }
 
+# create_nova_cache_dir() - Part of the init_nova() process
+function create_nova_cache_dir() {
+    # Create cache dir
+    sudo mkdir -p $NOVA_AUTH_CACHE_DIR
+    sudo chown $STACK_USER $NOVA_AUTH_CACHE_DIR
+    rm -f $NOVA_AUTH_CACHE_DIR/*
+}
+
 function create_nova_conf_nova_network() {
     iniset $NOVA_CONF DEFAULT network_manager "nova.network.manager.$NET_MAN"
     iniset $NOVA_CONF DEFAULT public_interface "$PUBLIC_INTERFACE"
@@ -463,14 +464,17 @@
     fi
 }
 
+# create_nova_keys_dir() - Part of the init_nova() process
+function create_nova_keys_dir() {
+    # Create keys dir
+    sudo mkdir -p ${NOVA_STATE_PATH}/keys
+    sudo chown -R $STACK_USER ${NOVA_STATE_PATH}
+}
+
 # init_nova() - Initialize databases, etc.
 function init_nova() {
-    # Nova Database
-    # -------------
-
-    # All nova components talk to a central database.  We will need to do this step
-    # only once for an entire cluster.
-
+    # All nova components talk to a central database.
+    # Only do this step once on the API node for an entire cluster.
     if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then
         # (Re)create nova database
         # Explicitly use latin1: to avoid lp#829209, nova expects the database to
@@ -478,7 +482,7 @@
         # 082_essex.py in nova)
         recreate_database nova latin1
 
-        # (Re)create nova database
+        # Migrate nova database
         $NOVA_BIN_DIR/nova-manage db sync
 
         # (Re)create nova baremetal database
@@ -488,15 +492,8 @@
         fi
     fi
 
-    # Create cache dir
-    sudo mkdir -p $NOVA_AUTH_CACHE_DIR
-    sudo chown $STACK_USER $NOVA_AUTH_CACHE_DIR
-    rm -f $NOVA_AUTH_CACHE_DIR/*
-
-    # Create the keys folder
-    sudo mkdir -p ${NOVA_STATE_PATH}/keys
-    # make sure we own NOVA_STATE_PATH and all subdirs
-    sudo chown -R $STACK_USER ${NOVA_STATE_PATH}
+    create_nova_cache_dir
+    create_nova_keys_dir
 }
 
 # install_novaclient() - Collect source and prepare
diff --git a/lib/quantum b/lib/quantum
index f3a3ec4..61a5218 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -297,7 +297,7 @@
         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)
-        EXT_GW_IP=$(quantum subnet-create --ip_version 4 $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
+        EXT_GW_IP=$(quantum subnet-create --ip_version 4 ${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
         quantum router-gateway-set $ROUTER_ID $EXT_NET_ID
 
         if is_quantum_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
diff --git a/lib/quantum_plugins/brocade b/lib/quantum_plugins/brocade
new file mode 100644
index 0000000..c372c19
--- /dev/null
+++ b/lib/quantum_plugins/brocade
@@ -0,0 +1,49 @@
+# Brocade Quantum Plugin
+# ----------------------
+
+# Save trace setting
+BRCD_XTRACE=$(set +o | grep xtrace)
+set +o xtrace
+
+function is_quantum_ovs_base_plugin() {
+    return 1
+}
+
+function quantum_plugin_create_nova_conf() {
+    NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver"}
+}
+
+function quantum_plugin_install_agent_packages() {
+    install_package bridge-utils
+}
+
+function quantum_plugin_configure_common() {
+    Q_PLUGIN_CONF_PATH=etc/quantum/plugins/brocade
+    Q_PLUGIN_CONF_FILENAME=brocade.ini
+    Q_DB_NAME="brcd_quantum"
+    Q_PLUGIN_CLASS="quantum.plugins.brocade.QuantumPlugin.BrocadePluginV2"
+}
+
+function quantum_plugin_configure_debug_command() {
+    :
+}
+
+function quantum_plugin_configure_dhcp_agent() {
+    :
+}
+
+function quantum_plugin_configure_l3_agent() {
+    :
+}
+
+function quantum_plugin_configure_plugin_agent() {
+    AGENT_BINARY="$QUANTUM_DIR/bin/quantum-linuxbridge-agent"
+}
+
+function quantum_plugin_setup_interface_driver() {
+    local conf_file=$1
+    iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.BridgeInterfaceDriver
+}
+
+# Restore xtrace
+$BRCD_XTRACE
diff --git a/lib/quantum_plugins/openvswitch b/lib/quantum_plugins/openvswitch
index 12bc244..181e7e7 100644
--- a/lib/quantum_plugins/openvswitch
+++ b/lib/quantum_plugins/openvswitch
@@ -75,7 +75,7 @@
         # Nova will always be installed along with quantum for a domU
         # devstack install, so it should be safe to rely on nova.conf
         # for xenapi configuration.
-        Q_RR_DOM0_COMMAND="$QUANTUM_DIR/bin/quantum-rootwrap-dom0 $NOVA_CONF"
+        Q_RR_DOM0_COMMAND="$QUANTUM_DIR/bin/quantum-rootwrap-xen-dom0 $NOVA_CONF"
         # Under XS/XCP, the ovs agent needs to target the dom0
         # integration bridge.  This is enabled by using a root wrapper
         # that executes commands on dom0 via a XenAPI plugin.
diff --git a/lib/tempest b/lib/tempest
index 49d0da7..e43f6d7 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -205,12 +205,7 @@
     iniset $TEMPEST_CONF identity admin_password "$password"
 
     # Compute
-    iniset $TEMPEST_CONF compute password "$password" # DEPRECATED
-    iniset $TEMPEST_CONF compute alt_username $ALT_USERNAME # DEPRECATED
-    iniset $TEMPEST_CONF compute alt_password "$password" # DEPRECATED
-    iniset $TEMPEST_CONF compute alt_tenant_name $ALT_TENANT_NAME # DEPRECATED
     iniset $TEMPEST_CONF compute change_password_available False
-    iniset $TEMPEST_CONF compute compute_log_level ERROR
     # Note(nati) current tempest don't create network for each tenant
     # so reuse same tenant for now
     if is_service_enabled quantum; then
@@ -231,10 +226,6 @@
     iniset $TEMPEST_CONF compute flavor_ref_alt $flavor_ref_alt
     iniset $TEMPEST_CONF compute live_migration_available ${LIVE_MIGRATION_AVAILABLE:-False}
     iniset $TEMPEST_CONF compute use_block_migration_for_live_migration ${USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION:-False}
-    iniset $TEMPEST_CONF compute source_dir $NOVA_SOURCE_DIR # DEPRECATED
-    iniset $TEMPEST_CONF compute bin_dir $NOVA_BIN_DIR # DEPRECATED
-    iniset $TEMPEST_CONF compute path_to_private_key $TEMPEST_DIR/id_rsa # DEPRECATED
-    iniset $TEMPEST_CONF compute db_uri $BASE_SQL_CONN/nova # DEPRECATED
 
     # Whitebox
     iniset $TEMPEST_CONF whitebox source_dir $NOVA_SOURCE_DIR
@@ -245,21 +236,11 @@
     iniset $TEMPEST_CONF whitebox db_uri $BASE_SQL_CONN/nova
 
 
-    # image
-    iniset $TEMPEST_CONF image password "$password" # DEPRECATED
-
-    # identity-admin
-    iniset $TEMPEST_CONF "identity-admin" password "$password" # DEPRECATED
-
     # compute admin
     iniset $TEMPEST_CONF "compute-admin" password "$password" # DEPRECATED
 
-    # network admin
-    iniset $TEMPEST_CONF "network-admin" password "$password" # DEPRECATED
-
     # network
     iniset $TEMPEST_CONF network api_version 2.0
-    iniset $TEMPEST_CONF network password "$password" # DEPRECATED
     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"
diff --git a/stack.sh b/stack.sh
index 0f009fc..331743f 100755
--- a/stack.sh
+++ b/stack.sh
@@ -1073,9 +1073,11 @@
         iniset $NOVA_CONF DEFAULT compute_driver nova.virt.baremetal.driver.BareMetalDriver
         iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
         iniset $NOVA_CONF DEFAULT scheduler_host_manager nova.scheduler.baremetal_host_manager.BaremetalHostManager
-        iniset $NOVA_CONF DEFAULT scheduler_default_filters AllHostsFilter
-        iniset $NOVA_CONF baremetal driver $BM_DRIVER
+        # NOTE(deva): ComputeCapabilitiesFilter does not currently work with Baremetal. See bug # 1129485
+        #             As a work around, we disable CCFilter by explicitly enabling all the other default filters.
+        iniset $NOVA_CONF DEFAULT scheduler_default_filters ComputeFilter,RetryFilter,AvailabilityZoneFilter,ImagePropertiesFilter
         iniset $NOVA_CONF baremetal instance_type_extra_specs cpu_arch:$BM_CPU_ARCH
+        iniset $NOVA_CONF baremetal driver $BM_DRIVER
         iniset $NOVA_CONF baremetal power_manager $BM_POWER_MANAGER
         iniset $NOVA_CONF baremetal tftp_root /tftpboot
 
@@ -1266,7 +1268,7 @@
     sudo dnsmasq --conf-file= --port=0 --enable-tftp --tftp-root=/tftpboot \
         --dhcp-boot=pxelinux.0 --bind-interfaces --pid-file=/var/run/dnsmasq.pid \
         --interface=$BM_DNSMASQ_IFACE --dhcp-range=$BM_DNSMASQ_RANGE \
-        ${$BM_DNSMASQ_DNS:+--dhcp-option=option:dns-server,$BM_DNSMASQ_DNS}
+        ${BM_DNSMASQ_DNS:+--dhcp-option=option:dns-server,$BM_DNSMASQ_DNS}
     # ensure callback daemon is running
     sudo pkill nova-baremetal-deploy-helper || true
     screen_it baremetal "nova-baremetal-deploy-helper"