From 5f29b1457782fa1568d9aa0d40dd008c22e09b35 Mon Sep 17 00:00:00 2001 From: Jacky Hu Date: Mon, 3 Jul 2017 23:10:18 +0800 Subject: [PATCH] Make it work with devstack To avoid the "installation from path or url cannot be constrained to a version" issue. Change-Id: Ia602a6509780c394b30c2f663fe1207e69706e32 --- test-requirements.txt | 1 - tools/tox_install.sh | 73 ++++++++++++++++++++++++++++++++++++++++++- tox.ini | 2 +- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index f769edfc..bca631c5 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,7 +3,6 @@ # process, which may cause wedges in the gate later. hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 -http://tarballs.openstack.org/horizon/horizon-master.tar.gz#egg=horizon coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT django-nose>=1.4.4 # BSD diff --git a/tools/tox_install.sh b/tools/tox_install.sh index e61b63a8..6cb6e159 100755 --- a/tools/tox_install.sh +++ b/tools/tox_install.sh @@ -1,5 +1,71 @@ #!/usr/bin/env bash +# Many of horizon's repos suffer from the problem of depending on horizon, +# but it not existing on pypi. + +# This wrapper for tox's package installer will use the existing package +# if it exists, else use zuul-cloner if that program exists, else grab it +# from horizon master via a hard-coded URL. That last case should only +# happen with devs running unit tests locally. + +# From the tox.ini config page: +# install_command=ARGV +# default: +# pip install {opts} {packages} + +ZUUL_CLONER=/usr/zuul-env/bin/zuul-cloner +BRANCH_NAME=master + +install_project() { + local project=$1 + local branch=${2:-$BRANCH_NAME} + local PROJECT_DIR=$HOME/$project + + set +e + project_installed=$(echo "import $project" | python 2>/dev/null ; echo $?) + set -e + + # The devstack based functional tests have project checked out in + # $PROJECT_DIR on the test systems - with the change to test in it. + # Use this directory if it exists, so that this script installs the + # project version to test here. + # Note that the functional tests use sudo to run tox and thus + # variables used for zuul-cloner to check out the correct version are + # lost. + if [ -d "$PROJECT_DIR" ]; then + echo "FOUND $project code at $PROJECT_DIR - using" + $install_cmd -U $PROJECT_DIR + elif [ $project_installed -eq 0 ]; then + echo "ALREADY INSTALLED" > /tmp/tox_install.txt + location=$(python -c "import $project; print($project.__file__)") + echo "ALREADY INSTALLED at $location" + + echo "$project already installed; using existing package" + elif [ -x "$ZUUL_CLONER" ]; then + echo "ZUUL CLONER" > /tmp/tox_install.txt + # Make this relative to current working directory so that + # git clean can remove it. We cannot remove the directory directly + # since it is referenced after $install_cmd + mkdir -p .tmp + PROJECT_DIR=$(/bin/mktemp -d -p $(pwd)/.tmp) + pushd $PROJECT_DIR + $ZUUL_CLONER --cache-dir \ + /opt/git \ + --branch $branch \ + http://git.openstack.org \ + openstack/$project + cd openstack/$project + $install_cmd . + popd + else + echo "PIP HARDCODE" > /tmp/tox_install.txt + if [ -z "$PIP_LOCATION" ]; then + PIP_LOCATION="git+https://git.openstack.org/openstack/$project@$branch#egg=$project" + fi + $install_cmd -U ${PIP_LOCATION} + fi +} + # Client constraint file contains this client version pin that is in conflict # with installing the client from source. We should remove the version pin in # the constraints file before applying it for from-source installation. @@ -8,6 +74,7 @@ CONSTRAINTS_FILE="$1" shift 1 set -e +set -x # NOTE(tonyb): Place this in the tox enviroment's log dir so it will get # published to logs.openstack.org for easy debugging. @@ -26,5 +93,9 @@ pip install -c"$localfile" openstack-requirements # install will be constrained and we need to unconstrain it. edit-constraints "$localfile" -- "$CLIENT_NAME" -pip install -c"$localfile" -U "$@" +install_cmd="pip install -c$localfile" + +install_project horizon + +$install_cmd -U $* exit $? diff --git a/tox.ini b/tox.ini index 1b2c9557..f99e77a6 100644 --- a/tox.ini +++ b/tox.ini @@ -63,4 +63,4 @@ commands = npm install show-source = True ignore = E123,E125 builtins = _ -exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,node_modules +exclude=.venv,.git,.tox,.tmp,dist,doc,*lib/python*,*egg,build,node_modules