Merge "Add stack phases to extras.d handling"
diff --git a/functions b/functions
index 9e99cb2..d969677 100644
--- a/functions
+++ b/functions
@@ -264,7 +264,7 @@
 # - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
 #   of the package to the distros listed.  The distro names are case insensitive.
 function get_packages() {
-    local services=$1
+    local services=$@
     local package_dir=$(_get_package_dir)
     local file_to_parse
     local service
@@ -276,7 +276,7 @@
     if [[ -z "$DISTRO" ]]; then
         GetDistro
     fi
-    for service in general ${services//,/ }; do
+    for service in ${services//,/ }; do
         # Allow individual services to specify dependencies
         if [[ -e ${package_dir}/${service} ]]; then
             file_to_parse="${file_to_parse} $service"
diff --git a/run_tests.sh b/run_tests.sh
new file mode 100755
index 0000000..9d9d186
--- /dev/null
+++ b/run_tests.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+#
+# this runs a series of unit tests for devstack to ensure it's functioning
+
+if [[ -n $@ ]]; then
+    FILES=$@
+else
+    LIBS=`find lib -type f | grep -v \.md`
+    SCRIPTS=`find . -type f -name \*\.sh`
+    EXTRA="functions"
+    FILES="$SCRIPTS $LIBS $EXTRA"
+fi
+
+echo "Running bash8..."
+
+./tools/bash8.py $FILES
diff --git a/tools/bash8.py b/tools/bash8.py
new file mode 100755
index 0000000..82a1010
--- /dev/null
+++ b/tools/bash8.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# bash8 - a pep8 equivalent for bash scripts
+#
+# this program attempts to be an automated style checker for bash scripts
+# to fill the same part of code review that pep8 does in most OpenStack
+# projects. It starts from humble beginnings, and will evolve over time.
+#
+# Currently Supported checks
+#
+# Errors
+# - E001: check that lines do not end with trailing whitespace
+# - E002: ensure that indents are only spaces, and not hard tabs
+# - E003: ensure all indents are a multiple of 4 spaces
+
+import argparse
+import fileinput
+import re
+import sys
+
+
+ERRORS = 0
+
+
+def print_error(error, line):
+    global ERRORS
+    ERRORS = ERRORS + 1
+    print("%s: '%s'" % (error, line.rstrip('\n')))
+    print(" - %s: L%s" % (fileinput.filename(), fileinput.filelineno()))
+
+
+def check_no_trailing_whitespace(line):
+    if re.search('[ \t]+$', line):
+        print_error('E001: Trailing Whitespace', line)
+
+
+def check_indents(line):
+    m = re.search('^(?P<indent>[ \t]+)', line)
+    if m:
+        if re.search('\t', m.group('indent')):
+            print_error('E002: Tab indents', line)
+        if (len(m.group('indent')) % 4) != 0:
+            print_error('E003: Indent not multiple of 4', line)
+
+
+def check_files(files):
+    for line in fileinput.input(files):
+        check_no_trailing_whitespace(line)
+        check_indents(line)
+
+
+def get_options():
+    parser = argparse.ArgumentParser(
+        description='A bash script style checker')
+    parser.add_argument('files', metavar='file', nargs='+',
+                        help='files to scan for errors')
+    return parser.parse_args()
+
+
+def main():
+    opts = get_options()
+    check_files(opts.files)
+
+    if ERRORS > 0:
+        print("%d bash8 error(s) found" % ERRORS)
+        return 1
+    else:
+        return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/tools/fixup_stuff.sh b/tools/fixup_stuff.sh
index f3c0f98..9e65b7c 100755
--- a/tools/fixup_stuff.sh
+++ b/tools/fixup_stuff.sh
@@ -35,25 +35,35 @@
 # Python Packages
 # ---------------
 
+# get_package_path python-package    # in import notation
+function get_package_path() {
+    local package=$1
+    echo $(python -c "import os; import $package; print(os.path.split(os.path.realpath($package.__file__))[0])")
+}
+
+
 # Pre-install affected packages so we can fix the permissions
+# These can go away once we are confident that pip 1.4.1+ is available everywhere
+
+# Fix prettytable 0.7.2 permissions
+# Don't specify --upgrade so we use the existing package if present
 pip_install prettytable
+PACKAGE_DIR=$(get_package_path prettytable)
+# Only fix version 0.7.2
+dir=$(echo $PACKAGE_DIR/prettytable-0.7.2*)
+if [[ -d $dir ]]; then
+    sudo chmod +r $dir/*
+fi
+
+# Fix httplib2 0.8 permissions
+# Don't specify --upgrade so we use the existing package if present
 pip_install httplib2
-
-SITE_DIRS=$(python -c "import site; import os; print os.linesep.join(site.getsitepackages())")
-for dir in $SITE_DIRS; do
-
-    # Fix prettytable 0.7.2 permissions
-    if [[ -r $dir/prettytable.py ]]; then
-        sudo chmod +r $dir/prettytable-0.7.2*/*
-    fi
-
-    # Fix httplib2 0.8 permissions
-    httplib_dir=httplib2-0.8.egg-info
-    if [[ -d $dir/$httplib_dir ]]; then
-        sudo chmod +r $dir/$httplib_dir/*
-    fi
-
-done
+PACKAGE_DIR=$(get_package_path httplib2)
+# Only fix version 0.8
+dir=$(echo $PACKAGE_DIR-0.8*)
+if [[ -d $dir ]]; then
+    sudo chmod +r $dir/*
+fi
 
 
 # RHEL6
diff --git a/tools/install_prereqs.sh b/tools/install_prereqs.sh
index 68f11ce..0c65fd9 100755
--- a/tools/install_prereqs.sh
+++ b/tools/install_prereqs.sh
@@ -55,7 +55,7 @@
 # ================
 
 # Install package requirements
-install_package $(get_packages $ENABLED_SERVICES)
+install_package $(get_packages general $ENABLED_SERVICES)
 
 if [[ -n "$SYSLOG" && "$SYSLOG" != "False" ]]; then
     if is_ubuntu || is_fedora; then