Allow testing of MySQL and PostgreSQL scenario locally

This leverage pifpaf to start MySQL or PostgreSQL temporarily and allow to test
provisioning directly without being on OpenStack CI by adding new tox
targets:

- py27-mysql
- py27-postgresql
- py34-mysql
- py34-postgresql
- py27-all
- py34-all

These targets will start MySQL or PostgreSQL before running the tests,
while exporting the connection string to $PIFPAF_URL. The `all' target
will start both MySQL and PostgreSQL and will run the tests against
these backends, plus SQLite.

Also, this patches add OS_TEST_DBAPI_ADMIN_CONNECTION to be allowed to
be passed through tox. This allows to run the opportunistic tests on a
more persistent pifpaf database, for example by running tox with:

$ eval `pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run postgresql`
$ echo $OS_TEST_DBAPI_ADMIN_CONNECTION
postgresql://localhost/postgres?host=/var/folders/7k/pwdhb_mj2cv4zyr0kyrlzjx40000gq/T/tmpMGqN8C&port=9824
$ tox -e py27
[…]
$ tox -e py34
[…]
$ kill $PIFPAF_PID

Change-Id: I1ee582e6f96e98378f02be79f4aaff0f447a062a
Depends-On: Id3e6b694bb186724517599cd9875ad80ceeee053
This commit is contained in:
Julien Danjou 2016-04-13 23:17:57 +02:00
parent 663092d675
commit 044cf85ef5
4 changed files with 61 additions and 1 deletions

View File

@ -59,4 +59,31 @@ For MySQL you can use the following commands::
mysql> GRANT ALL PRIVILEGES ON * . * TO 'openstack_citest'@'localhost'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'openstack_citest'@'localhost';
mysql> FLUSH PRIVILEGES; mysql> FLUSH PRIVILEGES;
Alternatively, you can use `pifpaf`_ to run the unit tests directly without
setting up the database yourself. You still need to have the database software
installed on your system. The following tox environments can be used::
tox -e py27-mysql
tox -e py27-postgresql
tox -e py34-mysql
tox -e py34-postgresql
tox -e py27-all
tox -e py34-all
The database will be set up for you locally and temporarily on each run.
Another way is to start `pifpaf` manually and use it to run the tests as you
wish::
$ eval `pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run postgresql`
$ echo $OS_TEST_DBAPI_ADMIN_CONNECTION
postgresql://localhost/postgres?host=/var/folders/7k/pwdhb_mj2cv4zyr0kyrlzjx40000gq/T/tmpMGqN8C&port=9824
$ tox -e py27
[…]
$ tox -e py34
[…]
# Kill pifpaf once you're done
$ kill $PIFPAF_PID
.. _wiki: https://wiki.openstack.org/wiki/Testing#Unit_Tests .. _wiki: https://wiki.openstack.org/wiki/Testing#Unit_Tests
.. _pifpaf: https://github.com/jd/pifpaf

View File

@ -48,6 +48,8 @@ test =
fixtures = fixtures =
testresources>=0.2.4 # Apache-2.0/BSD testresources>=0.2.4 # Apache-2.0/BSD
testscenarios>=0.4 # Apache-2.0/BSD testscenarios>=0.4 # Apache-2.0/BSD
pifpaf =
pifpaf>=0.1.0
[files] [files]
packages = packages =

7
tools/run-pifpaf-tests.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
# Replace mysql:// by mysql+pymysql:// and add sqlite
export OS_TEST_DBAPI_ADMIN_CONNECTION="${OS_TEST_DBAPI_ADMIN_CONNECTION/#mysql:/mysql+pymysql:};sqlite://"
echo $OS_TEST_DBAPI_ADMIN_CONNECTION
tools/pretty_tox.sh $*
TEST_EVENTLET=1 tools/pretty_tox.sh $*

26
tox.ini
View File

@ -1,5 +1,5 @@
[tox] [tox]
minversion = 1.6 minversion = 1.8
envlist = py34,py27,pep8,pip-missing-reqs envlist = py34,py27,pep8,pip-missing-reqs
[testenv] [testenv]
@ -8,7 +8,9 @@ whitelist_externals = bash
setenv = setenv =
VIRTUAL_ENV={envdir} VIRTUAL_ENV={envdir}
deps = .[test,fixtures,mysql,postgresql] deps = .[test,fixtures,mysql,postgresql]
py{27,34}-{postgresql,mysql,all}: .[pifpaf]
commands = bash tools/pretty_tox.sh '{posargs}' commands = bash tools/pretty_tox.sh '{posargs}'
passenv = OS_TEST_DBAPI_ADMIN_CONNECTION
[testenv:sqla_09] [testenv:sqla_09]
commands = pip install SQLAlchemy>=0.9.0,!=0.9.5,<1.0.0 commands = pip install SQLAlchemy>=0.9.0,!=0.9.5,<1.0.0
@ -19,6 +21,28 @@ commands =
env TEST_EVENTLET=0 bash tools/pretty_tox.sh '{posargs}' env TEST_EVENTLET=0 bash tools/pretty_tox.sh '{posargs}'
env TEST_EVENTLET=1 bash tools/pretty_tox.sh '{posargs}' env TEST_EVENTLET=1 bash tools/pretty_tox.sh '{posargs}'
[testenv:py27-all]
commands = pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run mysql -- pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run postgresql -- {toxinidir}/tools/run-pifpaf-tests.sh {posargs}
[testenv:py34-all]
commands = pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run mysql -- pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run postgresql -- {toxinidir}/tools/run-pifpaf-tests.sh {posargs}
[testenv:py27-mysql]
commands =
pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run mysql {toxinidir}/tools/run-pifpaf-tests.sh {posargs}
[testenv:py27-postgresql]
commands =
pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run postgresql {toxinidir}/tools/run-pifpaf-tests.sh {posargs}
[testenv:py34-mysql]
commands =
pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run mysql {toxinidir}/tools/run-pifpaf-tests.sh {posargs}
[testenv:py34-postgresql]
commands =
pifpaf -g OS_TEST_DBAPI_ADMIN_CONNECTION run postgresql {toxinidir}/tools/run-pifpaf-tests.sh {posargs}
[testenv:mysql-python] [testenv:mysql-python]
deps = .[mysql-c,postgresql,test,fixtures] deps = .[mysql-c,postgresql,test,fixtures]
setenv = setenv =