summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2016-04-13 23:17:57 +0200
committerJulien Danjou <julien@danjou.info>2016-05-19 16:19:53 +0200
commit044cf85ef562da1cea696fc047277297c6ee7bf4 (patch)
tree9bcd716d6c606f321695433e61440bbade6abf37
parent663092d675bca7c2420665b820db9306e381d73f (diff)
downloadoslo-db-044cf85ef562da1cea696fc047277297c6ee7bf4.tar.gz
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
-rw-r--r--CONTRIBUTING.rst27
-rw-r--r--setup.cfg2
-rwxr-xr-xtools/run-pifpaf-tests.sh7
-rw-r--r--tox.ini26
4 files changed, 61 insertions, 1 deletions
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 019004c..aa704f9 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -59,4 +59,31 @@ For MySQL you can use the following commands::
mysql> GRANT ALL PRIVILEGES ON * . * TO 'openstack_citest'@'localhost';
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
+.. _pifpaf: https://github.com/jd/pifpaf
diff --git a/setup.cfg b/setup.cfg
index e3f1012..741413d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -48,6 +48,8 @@ test =
fixtures =
testresources>=0.2.4 # Apache-2.0/BSD
testscenarios>=0.4 # Apache-2.0/BSD
+pifpaf =
+ pifpaf>=0.1.0
[files]
packages =
diff --git a/tools/run-pifpaf-tests.sh b/tools/run-pifpaf-tests.sh
new file mode 100755
index 0000000..687b6bb
--- /dev/null
+++ b/tools/run-pifpaf-tests.sh
@@ -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 $*
diff --git a/tox.ini b/tox.ini
index a54730f..0e073f8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
[tox]
-minversion = 1.6
+minversion = 1.8
envlist = py34,py27,pep8,pip-missing-reqs
[testenv]
@@ -8,7 +8,9 @@ whitelist_externals = bash
setenv =
VIRTUAL_ENV={envdir}
deps = .[test,fixtures,mysql,postgresql]
+ py{27,34}-{postgresql,mysql,all}: .[pifpaf]
commands = bash tools/pretty_tox.sh '{posargs}'
+passenv = OS_TEST_DBAPI_ADMIN_CONNECTION
[testenv:sqla_09]
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=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]
deps = .[mysql-c,postgresql,test,fixtures]
setenv =