Browse Source

tox: Integrate tox-docker

This allows us to start a zookeeper instance via docker as part of the
standard tox process, avoiding issues like those described in [1]. It's
exposed as a separate target, to ensure users can use local
installations if necessary. This requires bumping the minimum version of
tox to 3.2 so we can make use of the 'requires' config option [2].

[1] https://review.openstack.org/#/c/648399/
[2] https://tox.readthedocs.io/en/latest/config.html#conf-requires

Change-Id: Ie848d409533b2a53523cd930299acf21ac10e13c
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
tags/3.9.0
Stephen Finucane 5 months ago
parent
commit
390f071563
3 changed files with 26 additions and 6 deletions
  1. 5
    3
      TESTING.rst
  2. 14
    1
      tests/base.py
  3. 7
    2
      tox.ini

+ 5
- 3
TESTING.rst View File

@@ -14,11 +14,13 @@ Detailed information on testing can be found here: https://wiki.openstack.org/wi
14 14
 
15 15
 More information on pip here: http://www.pip-installer.org/en/latest/
16 16
 
17
-*Use pip to install tox*::
17
+*Use pip to install tox and tox-docker*::
18 18
 
19
-  pip install tox
19
+  pip install tox tox-docker
20 20
 
21
-As of zuul v3, a running zookeeper is required to execute tests.
21
+As of zuul v3, a running zookeeper is required to execute tests. Using the
22
+``-docker`` suffixed commands will ensure this is started automatically by tox,
23
+but if you do not wish to use this:
22 24
 
23 25
 *Install zookeeper*::
24 26
 

+ 14
- 1
tests/base.py View File

@@ -2047,7 +2047,20 @@ class ChrootedKazooFixture(fixtures.Fixture):
2047 2047
     def __init__(self, test_id):
2048 2048
         super(ChrootedKazooFixture, self).__init__()
2049 2049
 
2050
-        zk_host = os.environ.get('NODEPOOL_ZK_HOST', 'localhost')
2050
+        if 'ZOOKEEPER_2181_TCP' in os.environ:
2051
+            # prevent any nasty hobbits^H^H^H suprises
2052
+            if 'NODEPOOL_ZK_HOST' in os.environ:
2053
+                raise Exception(
2054
+                    'Looks like tox-docker is being used but you have also '
2055
+                    'configured NODEPOOL_ZK_HOST. Either avoid using the '
2056
+                    'docker environment or unset NODEPOOL_ZK_HOST.')
2057
+
2058
+            zk_host = 'localhost:' + os.environ['ZOOKEEPER_2181_TCP']
2059
+        elif 'NODEPOOL_ZK_HOST' in os.environ:
2060
+            zk_host = os.environ['NODEPOOL_ZK_HOST']
2061
+        else:
2062
+            zk_host = 'localhost'
2063
+
2051 2064
         if ':' in zk_host:
2052 2065
             host, port = zk_host.split(':')
2053 2066
         else:

+ 7
- 2
tox.ini View File

@@ -1,8 +1,11 @@
1 1
 [tox]
2
-minversion = 3.1
2
+minversion = 3.2
3 3
 skipsdist = True
4
-envlist = pep8,py35
4
+envlist = pep8,py35{-docker}
5 5
 ignore_basepython_conflict = True
6
+# TODO(stephenfin): It would be good to set 'requires = tox-docker', but doing
7
+# so borks the tools/pip.sh wrapper we're using here and probably isn't what
8
+# we want in the gate :(
6 9
 
7 10
 [testenv]
8 11
 basepython = python3
@@ -28,6 +31,8 @@ whitelist_externals = bash
28 31
 deps =
29 32
   -r{toxinidir}/requirements.txt
30 33
   -r{toxinidir}/test-requirements.txt
34
+docker =
35
+  docker: zookeeper:3.4
31 36
 commands =
32 37
   stestr run {posargs}
33 38
   stestr slowest

Loading…
Cancel
Save