Determine environment version based requirement files

It is painful to increment the venv version manually because
requirements.txt and test-requirements.txt are now updated by cron job.
This commit changes run_tests.sh to just store two requirements
files to .venv/environments file and check if it is up-to-date.
(Note that the environment cache file is moved to .venv directory
as there is no reason to store it in the top directory.)

Closes-Bug: #1376485
Change-Id: Ie44ccf6e2e65890baca3f316468254b600c518b1
This commit is contained in:
Akihiro Motoki 2014-09-09 02:32:15 +09:00
parent 2aa0315e8b
commit 0da0ea1438
2 changed files with 18 additions and 27 deletions

View File

@ -253,9 +253,9 @@ The environment backup is stored in ``/tmp/.horizon_environment/``.
Environment Versioning
======================
Horizon keeps track of changes to the environment by incrementing an
``environment_version`` integer at the top of ``run_tests.sh``.
If you do anything which changes the environment (adding new dependencies
or renaming directories are both great examples) be sure to increment the
``environment_version`` counter as well.
Horizon keeps track of changes to the environment by comparing the
current requirements files (``requirements.txt`` and
``test-requirements.txt``) and the files last time the virtual
environment was created or updated. If there is any difference,
the virtual environment will be update automatically when you run
``run_tests.sh``.

View File

@ -2,13 +2,6 @@
set -o errexit
# ---------------UPDATE ME-------------------------------#
# Increment me any time the environment should be rebuilt.
# This includes dependency changes, directory renames, etc.
# Simple integer sequence: 1, 2, 3...
environment_version=47
#--------------------------------------------------------#
function usage {
echo "Usage: $0 [OPTION]..."
echo "Run Horizon's test suite(s)"
@ -60,6 +53,7 @@ function usage {
#
root=`pwd -P`
venv=$root/.venv
venv_env_version=$venv/environments
with_venv=tools/with_venv.sh
included_dirs="openstack_dashboard horizon"
@ -221,21 +215,20 @@ function destroy_venv {
echo "Removing virtualenv..."
rm -rf $venv
echo "Virtualenv removed."
rm -f .environment_version
echo "Environment cleaned."
}
function environment_check {
echo "Checking environment."
if [ -f .environment_version ]; then
ENV_VERS=`cat .environment_version`
if [ $ENV_VERS -eq $environment_version ]; then
if [ -e ${venv} ]; then
# If the environment exists and is up-to-date then set our variables
command_wrapper="${root}/${with_venv}"
echo "Environment is up to date."
return 0
fi
if [ -f $venv_env_version ]; then
set +o errexit
cat requirements.txt test-requirements.txt | cmp $venv_env_version - > /dev/null
local env_check_result=$?
set -o errexit
if [ $env_check_result -eq 0 ]; then
# If the environment exists and is up-to-date then set our variables
command_wrapper="${root}/${with_venv}"
echo "Environment is up to date."
return 0
fi
fi
@ -284,7 +277,6 @@ function backup_environment {
fi
mkdir -p /tmp/.horizon_environment/$JOB_NAME
cp -r $venv /tmp/.horizon_environment/$JOB_NAME/
cp .environment_version /tmp/.horizon_environment/$JOB_NAME/
# Remove the backup now that we've completed successfully
rm -rf /tmp/.horizon_environment/$JOB_NAME.old
echo "Backup completed"
@ -300,7 +292,6 @@ function restore_environment {
fi
cp -r /tmp/.horizon_environment/$JOB_NAME/.venv ./ || true
cp -r /tmp/.horizon_environment/$JOB_NAME/.environment_version ./ || true
echo "Environment restored successfully."
fi
@ -320,7 +311,7 @@ function install_venv {
# Make sure it worked and record the environment version
sanity_check
chmod -R 754 $venv
echo $environment_version > .environment_version
cat requirements.txt test-requirements.txt > $venv_env_version
}
function run_tests {