Merge "Add basic uec image preparation to tempest"
diff --git a/lib/quantum b/lib/quantum
index 7c2df91..788db53 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -212,6 +212,10 @@
 
     if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
         NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"}
+        if [ "$VIRT_DRIVER" = 'xenserver' ]; then
+            add_nova_opt "xenapi_vif_driver=nova.virt.xenapi.vif.XenAPIOpenVswitchDriver"
+            add_nova_opt "xenapi_ovs_integration_bridge=$FLAT_NETWORK_BRIDGE"
+        fi
     elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
         NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver"}
     elif [[ "$Q_PLUGIN" = "ryu" ]]; then
@@ -536,6 +540,11 @@
 # _configure_quantum_plugin_agent() - Set config files for quantum plugin agent
 # It is called when q-agt is enabled.
 function _configure_quantum_plugin_agent() {
+
+    # Specify the default root helper prior to agent configuration to
+    # ensure that an agent's configuration can override the default.
+    iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
+
     # Configure agent for plugin
     if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
         _configure_quantum_plugin_agent_openvswitch
@@ -544,8 +553,6 @@
     elif [[ "$Q_PLUGIN" = "ryu" ]]; then
         _configure_quantum_plugin_agent_ryu
     fi
-
-    iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
 }
 
 function _configure_quantum_plugin_agent_linuxbridge() {
@@ -593,6 +600,41 @@
         iniset /$Q_PLUGIN_CONF_FILE OVS bridge_mappings $OVS_BRIDGE_MAPPINGS
     fi
     AGENT_BINARY="$QUANTUM_DIR/bin/quantum-openvswitch-agent"
+
+    if [ "$VIRT_DRIVER" = 'xenserver' ]; then
+        # 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"
+        # 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.
+        iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_DOM0_COMMAND"
+
+        # FLAT_NETWORK_BRIDGE is the dom0 integration bridge.  To
+        # ensure the bridge lacks direct connectivity, set
+        # VM_VLAN=-1;VM_DEV=invalid in localrc
+        iniset /$Q_PLUGIN_CONF_FILE OVS integration_bridge $FLAT_NETWORK_BRIDGE
+
+        # The ovs agent needs to ensure that the ports associated with
+        # a given network share the same local vlan tag.  On
+        # single-node XS/XCP, this requires monitoring both the dom0
+        # bridge, where VM's are attached, and the domU bridge, where
+        # dhcp servers are attached.
+        if is_service_enabled q-dhcp; then
+            iniset /$Q_PLUGIN_CONF_FILE OVS domu_integration_bridge $OVS_BRIDGE
+            # DomU will use the regular rootwrap
+            iniset /$Q_PLUGIN_CONF_FILE AGENT domu_root_helper "$Q_RR_COMMAND"
+            # Plug the vm interface into the domU integration bridge.
+            sudo ip addr flush dev $GUEST_INTERFACE_DEFAULT
+            sudo ip link set $OVS_BRIDGE up
+            # Assign the VM IP only if it has been set explicitly
+            if [[ "$VM_IP" != "" ]]; then
+                sudo ip addr add $VM_IP dev $OVS_BRIDGE
+            fi
+            sudo ovs-vsctl add-port $OVS_BRIDGE $GUEST_INTERFACE_DEFAULT
+        fi
+    fi
 }
 
 function _configure_quantum_plugin_agent_ryu() {
diff --git a/lib/swift b/lib/swift
index 46c6eb2..a4faf03 100644
--- a/lib/swift
+++ b/lib/swift
@@ -108,16 +108,17 @@
     if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
         if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
             sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
+            sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img
         fi
-    else
-        mkdir -p  ${SWIFT_DATA_DIR}/drives/images
-        sudo touch  ${SWIFT_DATA_DIR}/drives/images/swift.img
-        sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
-
-        dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
-            bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
     fi
 
+    mkdir -p  ${SWIFT_DATA_DIR}/drives/images
+    sudo touch  ${SWIFT_DATA_DIR}/drives/images/swift.img
+    sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
+
+    dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
+        bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
+
     # Make a fresh XFS filesystem
     mkfs.xfs -f -i size=1024  ${SWIFT_DATA_DIR}/drives/images/swift.img
 
diff --git a/tools/xen/install_os_domU.sh b/tools/xen/install_os_domU.sh
index e270e59..b4fbb69 100755
--- a/tools/xen/install_os_domU.sh
+++ b/tools/xen/install_os_domU.sh
@@ -68,6 +68,19 @@
     XAPI_PLUGIN_DIR=/usr/lib/xcp/plugins/
 fi
 cp -pr ./nova/*/plugins/xenserver/xenapi/etc/xapi.d/plugins/* $XAPI_PLUGIN_DIR
+
+# Install the netwrap xapi plugin to support agent control of dom0 networking
+if [[ "$ENABLED_SERVICES" =~ "q-agt" && "$Q_PLUGIN" = "openvswitch" ]]; then
+    if [ -f ./quantum ]; then
+        rm -rf ./quantum
+    fi
+    # get quantum
+    QUANTUM_ZIPBALL_URL=${QUANTUM_ZIPBALL_URL:-$(echo $QUANTUM_REPO | sed "s:\.git$::;s:$:/zipball/$QUANTUM_BRANCH:g")}
+    wget $QUANTUM_ZIPBALL_URL -O quantum-zipball --no-check-certificate
+    unzip -o quantum-zipball  -d ./quantum
+    cp -pr ./quantum/*/quantum/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/* $XAPI_PLUGIN_DIR
+fi
+
 chmod a+x ${XAPI_PLUGIN_DIR}*
 
 mkdir -p /boot/guest
diff --git a/unstack.sh b/unstack.sh
index 1d4bfd5..a086d5c 100755
--- a/unstack.sh
+++ b/unstack.sh
@@ -65,6 +65,7 @@
 # Swift runs daemons
 if is_service_enabled swift; then
     stop_swift
+    cleanup_swift
 fi
 
 # Apache has the WSGI processes