]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move DB TestModelsMigrations from unit to functional
authorHenry Gessau <gessau@cisco.com>
Sun, 5 Oct 2014 05:23:50 +0000 (01:23 -0400)
committerMark McClain <mark@mcclain.xyz>
Fri, 19 Dec 2014 03:41:05 +0000 (22:41 -0500)
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

doc/source/devref/db_layer.rst
neutron/tests/contrib/gate_hook.sh
neutron/tests/functional/db/test_migrations.py [moved from neutron/tests/unit/db/test_migration.py with 100% similarity]
neutron/tests/functional/requirements.txt [new file with mode: 0644]
test-requirements.txt
tox.ini

index bacd7731600c78cf1094550b326a80fc0ce0eeb6..d0d7bd52105585ce9e3d24e89a03a00c94789a9e 100644 (file)
@@ -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:
index 9b04233ac2520961eb2d2537018521495ec5c477..8409a3c3448bdd08f5f8b12098f0d3eeaa04895f 100644 (file)
@@ -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/functional/requirements.txt b/neutron/tests/functional/requirements.txt
new file mode 100644 (file)
index 0000000..0c5f221
--- /dev/null
@@ -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
index c46402904af12bc4bcfd25f335244531feed67f2..26cf54526a4e0661037ce1eb9f07444c8b5a4dac 100644 (file)
@@ -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 858999c09b84be3ec736b422496ce9e6439c835e..301d453d041a8d9d46893cd7ae114e28a6ddec65 100644 (file)
--- 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