introduce pip_install_gr

This creates a new pip_install_gr that installs from global
requirements allowed versions. Now that stable branches are getting
capped all of devstack needs to be fixed to do things like this.

Change-Id: I8fd0ef2bfc544ca2576fab09d3018f760b8848fe
diff --git a/inc/python b/inc/python
index 39684b6..c7cbb52 100644
--- a/inc/python
+++ b/inc/python
@@ -52,6 +52,18 @@
     fi
 }
 
+# Wrapper for ``pip install`` that only installs versions of libraries
+# from the global-requirements specification.
+#
+# Uses globals ``REQUIREMENTS_DIR``
+#
+# pip_install_gr packagename
+function pip_install_gr {
+    local name=$1
+    local clean_name=$(get_from_global_requirements $name)
+    pip_install $clean_name
+}
+
 # Wrapper for ``pip install`` to set cache and proxy environment variables
 # Uses globals ``OFFLINE``, ``PIP_VIRTUAL_ENV``,
 # ``PIP_UPGRADE``, ``TRACK_DEPENDS``, ``*_proxy``
@@ -125,7 +137,7 @@
 # get_from_global_requirements <package>
 function get_from_global_requirements {
     local package=$1
-    local required_pkg=$(grep -h ${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
+    local required_pkg=$(grep -h ^${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
     if [[ $required_pkg == ""  ]]; then
         die $LINENO "Can't find package $package in requirements"
     fi
diff --git a/lib/ceilometer b/lib/ceilometer
index 8135309..dba92ba 100644
--- a/lib/ceilometer
+++ b/lib/ceilometer
@@ -315,6 +315,9 @@
         git_clone_by_name "ceilometermiddleware"
         setup_dev_lib "ceilometermiddleware"
     else
+        # BUG: this should be a pip_install_gr except it was never
+        # included in global-requirements. Needs to be fixed by
+        # https://bugs.launchpad.net/ceilometer/+bug/1441655
         pip_install ceilometermiddleware
     fi
 }
diff --git a/lib/databases/mysql b/lib/databases/mysql
index 310817b..1b9a081 100644
--- a/lib/databases/mysql
+++ b/lib/databases/mysql
@@ -155,7 +155,7 @@
 
 function install_database_python_mysql {
     # Install Python client module
-    pip_install MySQL-python
+    pip_install_gr MySQL-python
     ADDITIONAL_VENV_PACKAGES+=",MySQL-python"
 }
 
diff --git a/lib/databases/postgresql b/lib/databases/postgresql
index a6bcf8c..e087a1e 100644
--- a/lib/databases/postgresql
+++ b/lib/databases/postgresql
@@ -104,7 +104,7 @@
 
 function install_database_python_postgresql {
     # Install Python client module
-    pip_install psycopg2
+    pip_install_gr psycopg2
     ADDITIONAL_VENV_PACKAGES+=",psycopg2"
 }
 
diff --git a/lib/horizon b/lib/horizon
index 63a9d0f..f953f5c 100644
--- a/lib/horizon
+++ b/lib/horizon
@@ -183,7 +183,7 @@
 # NOTE: It can be moved to common functions, but it is only used by compilation
 # of django_openstack_auth catalogs at the moment.
 function _prepare_message_catalog_compilation {
-    pip_install $(get_from_global_requirements Babel)
+    pip_install_gr Babel
 }
 
 
diff --git a/lib/ironic b/lib/ironic
index c8481ab..7afed05 100644
--- a/lib/ironic
+++ b/lib/ironic
@@ -206,7 +206,7 @@
         sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-ironicclient"]}/tools/,/etc/bash_completion.d/}ironic.bash_completion
     else
         # nothing actually "requires" ironicclient, so force instally from pypi
-        pip_install python-ironicclient
+        pip_install_gr python-ironicclient
     fi
 }
 
@@ -729,7 +729,7 @@
 
     # install diskimage-builder
     if [[ $(type -P ramdisk-image-create) == "" ]]; then
-        pip_install diskimage_builder
+        pip_install_gr "diskimage-builder"
     fi
 
     if [ -z "$IRONIC_DEPLOY_KERNEL" -o -z "$IRONIC_DEPLOY_RAMDISK" ]; then
diff --git a/lib/keystone b/lib/keystone
index 7b41812..31659f4 100644
--- a/lib/keystone
+++ b/lib/keystone
@@ -524,7 +524,7 @@
         setup_dev_lib "keystonemiddleware"
     else
         # When not installing from repo, keystonemiddleware is still needed...
-        pip_install keystonemiddleware
+        pip_install_gr keystonemiddleware
     fi
 }
 
diff --git a/lib/ldap b/lib/ldap
index d69d3f8..d2dbc3b 100644
--- a/lib/ldap
+++ b/lib/ldap
@@ -142,7 +142,7 @@
         sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
     fi
 
-    pip_install ldappool
+    pip_install_gr ldappool
 
     rm -rf $tmp_ldap_dir
 }
diff --git a/lib/nova_plugins/functions-libvirt b/lib/nova_plugins/functions-libvirt
index d4a0768..04da5e2 100755
--- a/lib/nova_plugins/functions-libvirt
+++ b/lib/nova_plugins/functions-libvirt
@@ -31,12 +31,12 @@
             install_package python-guestfs
         fi
         install_package libvirt-bin libvirt-dev
-        pip_install libvirt-python
-        #pip_install <there-si-no-guestfs-in-pypi>
+        pip_install_gr libvirt-python
+        #pip_install_gr <there-si-no-guestfs-in-pypi>
     elif is_fedora || is_suse; then
         install_package kvm
         install_package libvirt libvirt-devel
-        pip_install libvirt-python
+        pip_install_gr libvirt-python
         install_package python-libguestfs
     fi
 
diff --git a/lib/nova_plugins/hypervisor-xenserver b/lib/nova_plugins/hypervisor-xenserver
index 4d0ec89..efce383 100644
--- a/lib/nova_plugins/hypervisor-xenserver
+++ b/lib/nova_plugins/hypervisor-xenserver
@@ -94,7 +94,7 @@
 
 # install_nova_hypervisor() - Install external components
 function install_nova_hypervisor {
-    pip_install xenapi
+    pip_install_gr xenapi
 }
 
 # start_nova_hypervisor - Start any required external services
diff --git a/lib/rpc_backend b/lib/rpc_backend
index cc083de..2b7c6cb 100644
--- a/lib/rpc_backend
+++ b/lib/rpc_backend
@@ -141,7 +141,7 @@
         # TODO(kgiusti) can remove once python qpid bindings are
         # available on all supported platforms _and_ pyngus is added
         # to the requirements.txt file in oslo.messaging
-        pip_install pyngus
+        pip_install_gr pyngus
     fi
 
     if is_service_enabled rabbit; then
diff --git a/lib/tempest b/lib/tempest
index e8e9e0b..cd8fbd7 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -103,7 +103,7 @@
         setup_develop $TEMPEST_DIR
     else
         # install testr since its used to process tempest logs
-        pip_install $(get_from_global_requirements testrepository)
+        pip_install_gr testrepository
     fi
 
     local image_lines
diff --git a/lib/zaqar b/lib/zaqar
index 34f1915..8d51910 100644
--- a/lib/zaqar
+++ b/lib/zaqar
@@ -140,10 +140,10 @@
 function configure_redis {
     if is_ubuntu; then
         install_package redis-server
-        pip_install redis
+        pip_install_gr redis
     elif is_fedora; then
         install_package redis
-        pip_install redis
+        pip_install_gr redis
     else
         exit_distro_not_supported "redis installation"
     fi
diff --git a/pkg/elasticsearch.sh b/pkg/elasticsearch.sh
index f53c7f2..29dc22f 100755
--- a/pkg/elasticsearch.sh
+++ b/pkg/elasticsearch.sh
@@ -77,7 +77,7 @@
 }
 
 function install_elasticsearch {
-    pip_install elasticsearch
+    pip_install_gr elasticsearch
     if is_package_installed elasticsearch; then
         echo "Note: elasticsearch was already installed."
         return
diff --git a/stack.sh b/stack.sh
index adcaa21..69b76a9 100755
--- a/stack.sh
+++ b/stack.sh
@@ -847,7 +847,7 @@
     git_clone_by_name "python-openstackclient"
     setup_dev_lib "python-openstackclient"
 else
-    pip_install 'python-openstackclient>=1.0.2'
+    pip_install_gr python-openstackclient
 fi
 
 if [[ $TRACK_DEPENDS = True ]]; then