Merge "xenapi: Setup and Rotate text console logs"
diff --git a/README.md b/README.md
index 5fd4291..fbf7b4a 100644
--- a/README.md
+++ b/README.md
@@ -85,30 +85,42 @@
 
 # Swift
 
-Swift is enabled by default configured with only one replica to avoid being IO/memory intensive on a small vm. When running with only one replica the account, container and object services will run directly in screen. The others services like replicator, updaters or auditor runs in background.
+Swift is disabled by default.  When enabled, it is configured with
+only one replica to avoid being IO/memory intensive on a small
+vm. When running with only one replica the account, container and
+object services will run directly in screen. The others services like
+replicator, updaters or auditor runs in background.
 
-If you would like to disable Swift you can add this to your `localrc` :
+If you would like to enable Swift you can add this to your `localrc` :
 
-    disable_service s-proxy s-object s-container s-account
+    enable_service s-proxy s-object s-container s-account
 
-If you want a minimal Swift install with only Swift and Keystone you can have this instead in your `localrc`:
+If you want a minimal Swift install with only Swift and Keystone you
+can have this instead in your `localrc`:
 
     disable_all_services
     enable_service key mysql s-proxy s-object s-container s-account
 
-If you only want to do some testing of a real normal swift cluster with multiple replicas you can do so by customizing the variable `SWIFT_REPLICAS` in your `localrc` (usually to 3).
+If you only want to do some testing of a real normal swift cluster
+with multiple replicas you can do so by customizing the variable
+`SWIFT_REPLICAS` in your `localrc` (usually to 3).
 
 # Swift S3
 
-If you are enabling `swift3` in `ENABLED_SERVICES` devstack will install the swift3 middleware emulation. Swift will be configured to act as a S3 endpoint for Keystone so effectively replacing the `nova-objectstore`.
+If you are enabling `swift3` in `ENABLED_SERVICES` devstack will
+install the swift3 middleware emulation. Swift will be configured to
+act as a S3 endpoint for Keystone so effectively replacing the
+`nova-objectstore`.
 
-Only Swift proxy server is launched in the screen session all other services are started in background and managed by `swift-init` tool.
+Only Swift proxy server is launched in the screen session all other
+services are started in background and managed by `swift-init` tool.
 
 # Neutron
 
 Basic Setup
 
-In order to enable Neutron a single node setup, you'll need the following settings in your `localrc` :
+In order to enable Neutron a single node setup, you'll need the
+following settings in your `localrc` :
 
     disable_service n-net
     enable_service q-svc
diff --git a/functions b/functions
index f4a3da1..eb83dfb 100644
--- a/functions
+++ b/functions
@@ -18,15 +18,38 @@
 set +o xtrace
 
 
-# Exit 0 if address is in network or 1 if address is not in
-# network or netaddr library is not installed.
+# Convert CIDR notation to a IPv4 netmask
+# cidr2netmask cidr-bits
+function cidr2netmask() {
+    local maskpat="255 255 255 255"
+    local maskdgt="254 252 248 240 224 192 128"
+    set -- ${maskpat:0:$(( ($1 / 8) * 4 ))}${maskdgt:$(( (7 - ($1 % 8)) * 4 )):3}
+    echo ${1-0}.${2-0}.${3-0}.${4-0}
+}
+
+
+# Return the network portion of the given IP address using netmask
+# netmask is in the traditional dotted-quad format
+# maskip ip-address netmask
+function maskip() {
+    local ip=$1
+    local mask=$2
+    local l="${ip%.*}"; local r="${ip#*.}"; local n="${mask%.*}"; local m="${mask#*.}"
+    local subnet=$((${ip%%.*}&${mask%%.*})).$((${r%%.*}&${m%%.*})).$((${l##*.}&${n##*.})).$((${ip##*.}&${mask##*.}))
+    echo $subnet
+}
+
+
+# Exit 0 if address is in network or 1 if address is not in network
+# ip-range is in CIDR notation: 1.2.3.4/20
 # address_in_net ip-address ip-range
 function address_in_net() {
-    python -c "
-import netaddr
-import sys
-sys.exit(netaddr.IPAddress('$1') not in netaddr.IPNetwork('$2'))
-"
+    local ip=$1
+    local range=$2
+    local masklen=${range#*/}
+    local network=$(maskip ${range%/*} $(cidr2netmask $masklen))
+    local subnet=$(maskip $ip $(cidr2netmask $masklen))
+    [[ $network == $subnet ]]
 }
 
 
diff --git a/lib/heat b/lib/heat
index 13bf130..8517773 100644
--- a/lib/heat
+++ b/lib/heat
@@ -41,11 +41,6 @@
     sudo rm -rf $HEAT_AUTH_CACHE_DIR
 }
 
-# configure_heatclient() - Set config files, create data dirs, etc
-function configure_heatclient() {
-    setup_develop $HEATCLIENT_DIR
-}
-
 # configure_heat() - Set config files, create data dirs, etc
 function configure_heat() {
     setup_develop $HEAT_DIR
@@ -176,6 +171,7 @@
 # install_heatclient() - Collect source and prepare
 function install_heatclient() {
     git_clone $HEATCLIENT_REPO $HEATCLIENT_DIR $HEATCLIENT_BRANCH
+    setup_develop $HEATCLIENT_DIR
 }
 
 # install_heat() - Collect source and prepare
diff --git a/lib/neutron_plugins/services/loadbalancer b/lib/neutron_plugins/services/loadbalancer
index 49e286a..c38f904 100644
--- a/lib/neutron_plugins/services/loadbalancer
+++ b/lib/neutron_plugins/services/loadbalancer
@@ -34,7 +34,6 @@
 
     cp $NEUTRON_DIR/etc/lbaas_agent.ini $LBAAS_AGENT_CONF_FILENAME
 
-    iniset $LBAAS_AGENT_CONF_FILENAME DEFAULT use_namespaces $Q_USE_NAMESPACE
     # ovs_use_veth needs to be set before the plugin configuration
     # occurs to allow plugins to override the setting.
     iniset $LBAAS_AGENT_CONF_FILENAME DEFAULT ovs_use_veth $Q_OVS_USE_VETH
diff --git a/lib/tempest b/lib/tempest
index b4a579b..3831c28 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -251,10 +251,6 @@
     # Compute admin
     iniset $TEMPEST_CONF "compute-admin" password "$password" # DEPRECATED
 
-    # Network
-    if is_service_enabled neutron; then
-        iniset $TEMPEST_CONF service_available neutron "True"
-    fi
     iniset $TEMPEST_CONF network api_version 2.0
     iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable"
     iniset $TEMPEST_CONF network public_network_id "$public_network_id"
@@ -268,11 +264,6 @@
     iniset $TEMPEST_CONF boto http_socket_timeout 30
     iniset $TEMPEST_CONF boto ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
 
-    # Orchestration
-    if is_service_enabled heat; then
-        iniset $TEMPEST_CONF orchestration heat_available "True"
-    fi
-
     # Scenario
     iniset $TEMPEST_CONF scenario img_dir "$FILES/images/cirros-0.3.1-x86_64-uec"
 
@@ -287,6 +278,15 @@
     # cli
     iniset $TEMPEST_CONF cli cli_dir $NOVA_BIN_DIR
 
+    # service_available
+    for service in nova cinder glance neutron swift heat ; do
+        if is_service_enabled $service ; then
+            iniset $TEMPEST_CONF service_available $service "True"
+        else
+            iniset $TEMPEST_CONF service_available $service "False"
+        fi
+    done
+
     echo "Created tempest configuration file:"
     cat $TEMPEST_CONF
 
diff --git a/stack.sh b/stack.sh
index 3fa025f..4e23505 100755
--- a/stack.sh
+++ b/stack.sh
@@ -666,12 +666,15 @@
 install_glanceclient
 install_cinderclient
 install_novaclient
-if is_service_enabled swift glance; then
+if is_service_enabled swift glance horizon; then
     install_swiftclient
 fi
-if is_service_enabled neutron nova; then
+if is_service_enabled neutron nova horizon; then
     install_neutronclient
 fi
+if is_service_enabled heat horizon; then
+    install_heatclient
+fi
 
 git_clone $OPENSTACKCLIENT_REPO $OPENSTACKCLIENT_DIR $OPENSTACKCLIENT_BRANCH
 setup_develop $OPENSTACKCLIENT_DIR
@@ -736,14 +739,15 @@
 if is_service_enabled ceilometer; then
     install_ceilometerclient
     install_ceilometer
+    echo_summary "Configuring Ceilometer"
+    configure_ceilometer
+    configure_ceilometerclient
 fi
 
 if is_service_enabled heat; then
     install_heat
-    install_heatclient
     cleanup_heat
     configure_heat
-    configure_heatclient
 fi
 
 if is_service_enabled tls-proxy; then
@@ -1080,10 +1084,10 @@
         echo_summary "Using VMware vCenter driver"
         iniset $NOVA_CONF DEFAULT compute_driver "vmwareapi.VMwareVCDriver"
         VMWAREAPI_USER=${VMWAREAPI_USER:-"root"}
-        iniset $NOVA_CONF DEFAULT vmwareapi_host_ip "$VMWAREAPI_IP"
-        iniset $NOVA_CONF DEFAULT vmwareapi_host_username "$VMWAREAPI_USER"
-        iniset $NOVA_CONF DEFAULT vmwareapi_host_password "$VMWAREAPI_PASSWORD"
-        iniset $NOVA_CONF DEFAULT vmwareapi_cluster_name "$VMWAREAPI_CLUSTER"
+        iniset $NOVA_CONF vmware host_ip "$VMWAREAPI_IP"
+        iniset $NOVA_CONF vmware host_username "$VMWAREAPI_USER"
+        iniset $NOVA_CONF vmware host_password "$VMWAREAPI_PASSWORD"
+        iniset $NOVA_CONF vmware cluster_name "$VMWAREAPI_CLUSTER"
         if is_service_enabled neutron; then
             iniset $NOVA_CONF vmware integration_bridge $OVS_BRIDGE
         fi
@@ -1211,9 +1215,6 @@
     start_cinder
 fi
 if is_service_enabled ceilometer; then
-    echo_summary "Configuring Ceilometer"
-    configure_ceilometer
-    configure_ceilometerclient
     echo_summary "Starting Ceilometer"
     init_ceilometer
     start_ceilometer
diff --git a/tests/test_ip.sh b/tests/test_ip.sh
new file mode 100755
index 0000000..e9cbcca
--- /dev/null
+++ b/tests/test_ip.sh
@@ -0,0 +1,118 @@
+#!/usr/bin/env bash
+
+# Tests for DevStack functions
+# address_in_net()
+
+TOP=$(cd $(dirname "$0")/.. && pwd)
+
+# Import common functions
+source $TOP/functions
+
+# Import configuration
+source $TOP/openrc
+
+
+echo "Testing IP addr functions"
+
+if [[ $(cidr2netmask 4) == 240.0.0.0 ]]; then
+    echo "cidr2netmask(): /4...OK"
+else
+    echo "cidr2netmask(): /4...failed"
+fi
+if [[ $(cidr2netmask 8) == 255.0.0.0 ]]; then
+    echo "cidr2netmask(): /8...OK"
+else
+    echo "cidr2netmask(): /8...failed"
+fi
+if [[ $(cidr2netmask 12) == 255.240.0.0 ]]; then
+    echo "cidr2netmask(): /12...OK"
+else
+    echo "cidr2netmask(): /12...failed"
+fi
+if [[ $(cidr2netmask 16) == 255.255.0.0 ]]; then
+    echo "cidr2netmask(): /16...OK"
+else
+    echo "cidr2netmask(): /16...failed"
+fi
+if [[ $(cidr2netmask 20) == 255.255.240.0 ]]; then
+    echo "cidr2netmask(): /20...OK"
+else
+    echo "cidr2netmask(): /20...failed"
+fi
+if [[ $(cidr2netmask 24) == 255.255.255.0 ]]; then
+    echo "cidr2netmask(): /24...OK"
+else
+    echo "cidr2netmask(): /24...failed"
+fi
+if [[ $(cidr2netmask 28) == 255.255.255.240 ]]; then
+    echo "cidr2netmask(): /28...OK"
+else
+    echo "cidr2netmask(): /28...failed"
+fi
+if [[ $(cidr2netmask 30) == 255.255.255.252 ]]; then
+    echo "cidr2netmask(): /30...OK"
+else
+    echo "cidr2netmask(): /30...failed"
+fi
+if [[ $(cidr2netmask 32) == 255.255.255.255 ]]; then
+    echo "cidr2netmask(): /32...OK"
+else
+    echo "cidr2netmask(): /32...failed"
+fi
+
+if [[ $(maskip 169.254.169.254 240.0.0.0) == 160.0.0.0 ]]; then
+    echo "maskip(): /4...OK"
+else
+    echo "maskip(): /4...failed"
+fi
+if [[ $(maskip 169.254.169.254 255.0.0.0) == 169.0.0.0 ]]; then
+    echo "maskip(): /8...OK"
+else
+    echo "maskip(): /8...failed"
+fi
+if [[ $(maskip 169.254.169.254 255.240.0.0) == 169.240.0.0 ]]; then
+    echo "maskip(): /12...OK"
+else
+    echo "maskip(): /12...failed"
+fi
+if [[ $(maskip 169.254.169.254 255.255.0.0) == 169.254.0.0 ]]; then
+    echo "maskip(): /16...OK"
+else
+    echo "maskip(): /16...failed"
+fi
+if [[ $(maskip 169.254.169.254 255.255.240.0) == 169.254.160.0 ]]; then
+    echo "maskip(): /20...OK"
+else
+    echo "maskip(): /20...failed"
+fi
+if [[ $(maskip 169.254.169.254 255.255.255.0) == 169.254.169.0 ]]; then
+    echo "maskip(): /24...OK"
+else
+    echo "maskip(): /24...failed"
+fi
+if [[ $(maskip 169.254.169.254 255.255.255.240) == 169.254.169.240 ]]; then
+    echo "maskip(): /28...OK"
+else
+    echo "maskip(): /28...failed"
+fi
+if [[ $(maskip 169.254.169.254 255.255.255.255) == 169.254.169.254 ]]; then
+    echo "maskip(): /32...OK"
+else
+    echo "maskip(): /32...failed"
+fi
+
+for mask in 8 12 16 20 24 26 28; do
+    echo -n "address_in_net(): in /$mask..."
+    if address_in_net 10.10.10.1 10.10.10.0/$mask; then
+        echo "OK"
+    else
+        echo "address_in_net() failed on /$mask"
+    fi
+
+    echo -n "address_in_net(): not in /$mask..."
+    if ! address_in_net 10.10.10.1 11.11.11.0/$mask; then
+        echo "OK"
+    else
+        echo "address_in_net() failed on /$mask"
+    fi
+done