Update CI tools with an openstack wrapper

Change-Id: I786884c540962fd908b0d323938aa9733ead65ce
This commit is contained in:
Federico Ressi 2019-06-25 12:30:13 +02:00
parent c0d8e38d03
commit 27e46c8c39
5 changed files with 143 additions and 18 deletions

3
tools/ci/lib Normal file
View File

@ -0,0 +1,3 @@
CI_TOOLS_DIR=$(dirname "${BASH_SOURCE[0]}")
CI_TOOLS_DIR=$("${CI_TOOLS_DIR}/realpath" "${CI_TOOLS_DIR}")
PATH=${CI_TOOLS_DIR}:${PATH}

50
tools/ci/os Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
set -eu
source $(dirname "$0")/lib
OS_VIRTUAL_ENV=$(realpath "${OS_VIRTUAL_ENV:-.tox/scenario}")
function os {
os_setup
openstack "$@"
}
function os_setup {
if ! os_activate; then
# Cleanup and create virtualenv directory
tox -r -e venv --notest
os_activate
fi
}
function os_activate {
local venv_script=${OS_VIRTUAL_ENV}/bin/activate
if ! [ -r "${venv_script}" ]; then
return 1
fi
if ! os_is_active; then
# Activate only once
set +eu
source "${venv_script}"
set -eu
os_is_active
fi
}
function os_is_active {
[ "$(python_prefix)" == "${OS_VIRTUAL_ENV}" ]
}
if [ $(basename "$0") == os ]; then
os "$@"
fi

6
tools/ci/python_prefix Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python
import os
import sys
print(os.path.realpath(sys.prefix))

8
tools/ci/realpath Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env python
import os
import sys
args = sys.argv[1:] or ['.']
results = [os.path.realpath(a) for a in args]
print(' '.join(results))

View File

@ -1,23 +1,81 @@
#!/bin/bash
set -eux
set -eu
# Prefer python3 on python2
PYTHON=$(which python3 || which python)
source $(dirname "$0")/lib
# Create a virtualenv for executing Tox and activate it
BASE_VIRTUALENV_DIR=.tox/base
if ! [ -d "${BASE_VIRTUALENV_DIR}" ]; then
"${PYTHON}" -m virtualenv "${BASE_VIRTUALENV_DIR}"
set +eux
source "${BASE_VIRTUALENV_DIR}/bin/activate"
set -eux
curl https://bootstrap.pypa.io/get-pip.py | python
pip install --upgrade setuptools wheel virtualenv tox
else
set +eux
source "${BASE_VIRTUALENV_DIR}/bin/activate"
set -eux
# Prefer python 3 over python 2
TOX_BASE_PYTHON=${PYTHON:-$(which python3 || which python)}
TOX_VIRTUAL_ENV=$(realpath "${TOX_VIRTUAL_ENV:-.tox/tox}")
function tox {
tox_setup
"${TOX_VIRTUAL_ENV}/bin/tox" "$@"
}
function tox_python {
"${TOX_VIRTUAL_ENV}/bin/python" "$@"
}
function tox_pip {
"${TOX_VIRTUAL_ENV}/bin/pip" "$@"
}
function tox_setup {
if ! tox_activate; then
tox_install_deps
# Cleanup and create virtualenv directory
rm -fR "${TOX_VIRTUAL_ENV}"
mkdir -p $(dirname "${TOX_VIRTUAL_ENV}")
"${TOX_BASE_PYTHON}" -m virtualenv "${TOX_VIRTUAL_ENV}"
# Activate virtualenv
if tox_activate; then
# Install/upgrade the last Python packages into the new virutalenv
curl https://bootstrap.pypa.io/get-pip.py | tox_python
tox_pip install --upgrade setuptools wheel virtualenv tox
fi
fi
}
function tox_install_deps {
if ! "${TOX_BASE_PYTHON}" -m pip --version; then
curl https://bootstrap.pypa.io/get-pip.py --user | "${TOX_BASE_PYTHON}"
fi
if ! "${TOX_BASE_PYTHON}" -m virtualenv --version; then
"${TOX_BASE_PYTHON}" -m pip install --user virtualenv
fi
}
function tox_activate {
local venv_script=${TOX_VIRTUAL_ENV}/bin/activate
if ! [ -r "${venv_script}" ]; then
return 1
fi
if ! tox_is_active; then
# Activate only once
set +eu
source "${venv_script}"
set -eu
tox_is_active
fi
}
function tox_is_active {
[ "$(python_prefix)" == "${TOX_VIRTUAL_ENV}" ]
}
if [ $(basename "$0") == tox ]; then
tox "$@"
fi
tox "$*"