Add local upper constraints support

The issue is that we want to install os-brick from source, but if we
do this using upper-constraints on the install, it will fail.  This
patch modifies the tox install command used by appropriate testenvs
so it will create and use a local constraints file with os-brick
removed.

The local u-c file is named 'local-upper-constraints.txt'.  The
constraints file used can be overridden via the
CINDERLIB_CONSTRAINTS_FILE environment variable.

Change-Id: I8cb4085dd465043a783c974886f56e49820871a1
This commit is contained in:
Brian Rosmaita 2022-06-13 12:43:11 -04:00 committed by Rajat Dhasmana
parent 4d784d23a9
commit e4dd75a3b4
4 changed files with 152 additions and 6 deletions

1
.gitignore vendored
View File

@ -70,3 +70,4 @@ target/
temp/
cinder-lioadm
local-upper-constraints.txt

97
tools/generate_uc.sh Executable file
View File

@ -0,0 +1,97 @@
#!/bin/bash
UC_LOC='https://releases.openstack.org/constraints/upper'
RELEASE='master'
OUTNAME='local-upper-constraints.txt'
print_usage() {
cat <<EOF
usage: $(basename $0) [-o <outfile>] [<branch>]
Retrieve the upper-constraints for the specified release
and write them to the specified file.
positional arguments:
branch Release whose upper constraints you want.
Default is '$RELEASE'
optional arguments:
-d, --directory Directory to write the outfile to.
Default is the current directory
-n, --no-error Only warn if an error occurs when fetching updated
constraints. (This allows a script to continue and
use an existing constraints file.)
-o, --outfile The file to write the upper constraints to.
Default is '$OUTNAME'
-x, --exclude Remove os-brick from the generated constraints file
(for when we want to install os-brick from source)
-h, --help Show this message and exit
EOF
}
get_constraints_file() {
local C_FILE=$(mktemp)
# if we use OUTFILE here, wget will destroy its content when the GET fails
wget -q -O $C_FILE $UC_URL
WGET_EXIT=$?
if [[ "$WGET_EXIT" == "0" ]]; then
cp $C_FILE $OUTFILE
fi
rm -f $C_FILE
return $WGET_EXIT
}
# parse options
while [ "${1:0:1}" == "-" ] ; do
if [[ "${1}" == '--help' || "${1}" == '-h' ]] ; then
print_usage
exit 0
elif [[ "${1}" == '--directory' || "${1}" == '-d' ]] ; then
shift
OUTDIR="${1}"
elif [[ "${1}" == '--no-error' || "${1}" == '-n' ]] ; then
NO_ERROR=true
elif [[ "${1}" == '--outfile' || "${1}" == '-o' ]] ; then
shift
OUTNAME="${1}"
elif [[ "${1}" == '--exclude' || "${1}" == '-x' ]] ; then
DO_EDIT=true
else
echo "[warning] ignoring unknown option '$1'"
fi
shift
done
# check for positional arg
if [[ -n ${1} ]]; then
RELEASE="${1}"
fi
UC_URL="${UC_LOC}/${RELEASE}"
if [[ -n "${OUTDIR:-}" ]]; then
OUTFILE="$OUTDIR/$OUTNAME"
else
OUTFILE="$OUTNAME"
fi
get_constraints_file
RESULT=$?
if [[ "$RESULT" != "0" ]]; then
if ${NO_ERROR:-false} ; then
echo "[warning] wget error code $RESULT when getting new constraints"
else
echo "[error] could not get upper constraints file"
exit $RESULT
fi
fi
if ${DO_EDIT:-false}; then
unset DO_EDIT
sed -i -e '/^os-brick/d' $OUTFILE
fi

23
tools/special_install.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# special-purpose pip installer, intended for tox use only
INSTALL_CMD="$*"
# need to know the toxinidir
if [[ -z "${TOX_INI_DIR:-}" ]] ; then
echo "[error] This testenv must set the TOX_INI_DIR env var"
exit 1
fi
if [[ -z "${CINDERLIB_CONSTRAINTS_FILE:-}" ]] ; then
# generate the local constraints file without os_brick
$TOX_INI_DIR/tools/generate_uc.sh -d $TOX_INI_DIR -n -x $CINDERLIB_RELEASE
# use the absolute path to the generated file
CINDERLIB_CONSTRAINTS_FILE="${TOX_INI_DIR}/local-upper-constraints.txt"
fi
# need to specify that we want the python in this testenv, not
# the default python bash would use
$TOX_ENV_DIR/bin/python -m pip install -c$CINDERLIB_CONSTRAINTS_FILE $INSTALL_CMD

37
tox.ini
View File

@ -6,6 +6,7 @@ skipsdist = True
# setting ignore_basepython_conflict allows tox to infer the base python
# from the environment name and override any basepython configured in this file
ignore_basepython_conflict=true
[testenv]
basepython=python3
setenv = OS_STDOUT_CAPTURE=1
@ -13,8 +14,15 @@ setenv = OS_STDOUT_CAPTURE=1
OS_TEST_TIMEOUT=60
OS_TEST_PATH=./cinderlib/tests/unit
VIRTUAL_ENV={envdir}
TOX_INI_DIR={toxinidir}
# make sure this is accurate for current development, both here
# and in [testenv:functional]
CINDERLIB_RELEASE=yoga
usedevelop=True
install_command = python -m pip install {env:PIP_OPTIONS:} {opts} {packages}
# note: cannot set the special local install command here because it is also
# applied if tox has to update itself to meet the minversion specified above
# Use cinder and os-brick from the appropriate development branch instead of
# from PyPi. Defining the egg name we won't overwrite the package installed
# by Zuul on jobs supporting cross-project dependencies (include Cinder in
@ -34,14 +42,21 @@ commands =
allowlist_externals =
bash
find
passenv = *_proxy *_PROXY
passenv = *_proxy *_PROXY CINDERLIB_CONSTRAINTS_FILE
[testenv:py{3,36,38,39}]
install_command = {toxinidir}/tools/special_install.sh {env:PIP_OPTIONS:} {opts} {packages}
[testenv:functional]
install_command = {[testenv:py3]install_command}
usedevelop=True
passenv = CL_FTEST_POOL_NAME CL_FTEST_LOGGING CL_FTEST_DEBUG
passenv = CL_FTEST_POOL_NAME CL_FTEST_LOGGING CL_FTEST_DEBUG CINDERLIB_CONSTRAINTS_FILE
setenv = OS_TEST_PATH=./cinderlib/tests/functional
CL_FTEST_CFG={env:CL_FTEST_CFG:{toxinidir}/cinderlib/tests/functional/lvm.yaml}
CL_FTEST_ROOT_HELPER={env:CL_FTEST_ROOT_HELPER:{toxinidir}/tools/virtualenv-sudo.sh}
TOX_INI_DIR={toxinidir}
# make sure this is accurate for current development
CINDERLIB_RELEASE=yoga
sitepackages = True
# Not reusing py37's env due to https://github.com/tox-dev/tox/issues/477
@ -57,10 +72,11 @@ commands =
python -m stestr slowest
allowlist_externals =
find
{[testenv]allowlist_externals}
stestr
[testenv:functional-py36]
install_command = {[testenv:functional]install_command}
usedevelop=True
passenv =
{[testenv:functional]passenv}
@ -74,6 +90,7 @@ commands = {[testenv:functional]commands}
allowlist_externals = {[testenv:functional]allowlist_externals}
[testenv:functional-py39]
install_command = {[testenv:functional]install_command}
usedevelop=True
passenv =
{[testenv:functional]passenv}
@ -89,14 +106,17 @@ allowlist_externals = {[testenv:functional]allowlist_externals}
[testenv:releasenotes]
# Not reusing doc's env due to https://github.com/tox-dev/tox/issues/477
# envdir = {toxworkdir}/docs
install_command = {[testenv:docs]install_command}
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/yoga}
-r{toxinidir}/doc/requirements.txt
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
[testenv:docs]
# yes, we want the constraint in the install_command, not deps, so that
# https://review.opendev.org/c/openstack/glance/+/839786 does not happen
# to us
install_command = python -m pip install -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/yoga} {opts} {packages}
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/yoga}
-r{toxinidir}/doc/requirements.txt
commands =
doc8 --ignore D001 --ignore-path .tox --ignore-path *.egg-info --ignore-path doc/build --ignore-path .eggs/*/EGG-INFO/*.txt -e txt -e rst
@ -106,6 +126,7 @@ commands =
allowlist_externals = rm
[testenv:pdf-docs]
install_command = {[testenv:docs]install_command}
deps =
{[testenv:docs]deps}
commands =
@ -125,11 +146,13 @@ allowlist_externals =
# separately, outside of the requirements files, and develop mode disabled
# explicitly to avoid unnecessarily installing the checked-out repo too (this
# further relies on "tox.skipsdist = True" above).
install_command = python -m pip install {opts} {packages}
deps = bindep
commands = bindep {posargs}
usedevelop = False
[testenv:pylint]
install_command = {[testenv:docs]install_command}
deps = -r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
pylint==2.1.1
@ -156,6 +179,7 @@ per-file-ignores =
cinderlib/cmd/cinder_to_yaml.py:E402
[testenv:pep8]
install_command = {[testenv:docs]install_command}
commands=flake8 {posargs} .
deps=
-r{toxinidir}/test-requirements.txt
@ -163,5 +187,6 @@ deps=
[testenv:fast8]
# Not reusing Flake8's env due to https://github.com/tox-dev/tox/issues/477
# envdir = {toxworkdir}/flake8
install_command = {[testenv:docs]install_command}
commands={toxinidir}/tools/fast8.sh
passenv = FAST8_NUM_COMMITS