From: Henry Gessau Date: Sun, 5 Oct 2014 05:23:50 +0000 (-0400) Subject: Move DB TestModelsMigrations from unit to functional X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3e0745827f414ecc39a0b0a40349e3646a8e2db9;p=openstack-build%2Fneutron-build.git Move DB TestModelsMigrations from unit to functional The tests to check that DB migrations and models are in sync depends on the mysql and postgresql backends being available with a specific DB user and database created. This violates the principles for unit tests and therefore these tests should be moved to functional tests. For these tests to work in the functional job in the gate, the backends must be installed and the DB user and database created. We do this via the functional gate hook. Closes-bug: #1372981 Change-Id: I7b89feef3f19ca07dbfb05acfaa30529a5bf683d --- diff --git a/doc/source/devref/db_layer.rst b/doc/source/devref/db_layer.rst index bacd77316..d0d7bd521 100644 --- a/doc/source/devref/db_layer.rst +++ b/doc/source/devref/db_layer.rst @@ -2,10 +2,10 @@ Neutron Database Layer ====================== -Testing database and models sync --------------------------------- +Tests to verify that database migrations and models are in sync +--------------------------------------------------------------- -.. automodule:: neutron.tests.unit.db.test_migration +.. automodule:: neutron.tests.functional.db.test_migration .. autoclass:: _TestModelsMigrations :members: diff --git a/neutron/tests/contrib/gate_hook.sh b/neutron/tests/contrib/gate_hook.sh index 9b04233ac..8409a3c34 100644 --- a/neutron/tests/contrib/gate_hook.sh +++ b/neutron/tests/contrib/gate_hook.sh @@ -10,3 +10,42 @@ $BASE/new/devstack-gate/devstack-vm-gate.sh FUNC_FILTER=$BASE/new/neutron/neutron/tests/functional/contrib/filters.template sed -e "s+\$BASE_PATH+$BASE/new/neutron/.tox/dsvm-functional+" \ $FUNC_FILTER | sudo tee /etc/neutron/rootwrap.d/functional.filters > /dev/null + +# Use devstack functions to install mysql and psql servers +TOP_DIR=$BASE/new/devstack +source $TOP_DIR/functions +source $TOP_DIR/lib/config +source $TOP_DIR/stackrc +source $TOP_DIR/lib/database +source $TOP_DIR/localrc + +disable_service postgresql +enable_service mysql +initialize_database_backends +install_database + +disable_service mysql +enable_service postgresql +initialize_database_backends +install_database + +# Set up the 'openstack_citest' user and database in each backend +tmp_dir=`mktemp -d` + +cat << EOF > $tmp_dir/mysql.sql +CREATE DATABASE openstack_citest; +CREATE USER 'openstack_citest'@'localhost' IDENTIFIED BY 'openstack_citest'; +CREATE USER 'openstack_citest' IDENTIFIED BY 'openstack_citest'; +GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'@'localhost'; +GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'; +FLUSH PRIVILEGES; +EOF +/usr/bin/mysql -u root < $tmp_dir/mysql.sql + +cat << EOF > $tmp_dir/postgresql.sql +CREATE USER openstack_citest WITH CREATEDB LOGIN PASSWORD 'openstack_citest'; +CREATE DATABASE openstack_citest WITH OWNER openstack_citest; +EOF +# User/group postgres needs to be given access to tmp_dir +setfacl -m g:postgres:rwx $tmp_dir +sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql diff --git a/neutron/tests/unit/db/test_migration.py b/neutron/tests/functional/db/test_migrations.py similarity index 100% rename from neutron/tests/unit/db/test_migration.py rename to neutron/tests/functional/db/test_migrations.py diff --git a/neutron/tests/functional/requirements.txt b/neutron/tests/functional/requirements.txt new file mode 100644 index 000000000..0c5f2215b --- /dev/null +++ b/neutron/tests/functional/requirements.txt @@ -0,0 +1,8 @@ +# Additional requirements for functional tests + +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +psycopg2 +MySQL-python diff --git a/test-requirements.txt b/test-requirements.txt index c46402904..26cf54526 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -17,6 +17,4 @@ testtools>=0.9.36,!=1.2.0 testscenarios>=0.4 WebTest>=2.0 oslotest>=1.2.0 # Apache-2.0 -psycopg2 -MySQL-python tempest-lib diff --git a/tox.ini b/tox.ini index 858999c09..301d453d0 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,9 @@ setenv = VIRTUAL_ENV={envdir} [testenv:functional] setenv = OS_TEST_PATH=./neutron/tests/functional OS_TEST_TIMEOUT=90 +deps = + {[testenv]deps} + -r{toxinidir}/neutron/tests/functional/requirements.txt [testenv:dsvm-functional] setenv = OS_TEST_PATH=./neutron/tests/functional @@ -35,6 +38,8 @@ setenv = OS_TEST_PATH=./neutron/tests/functional OS_FAIL_ON_MISSING_DEPS=1 OS_TEST_TIMEOUT=90 sitepackages=True +deps = + {[testenv:functional]deps} [tox:jenkins] sitepackages = True