|
| 1 | +What is Tox? |
| 2 | +=============== |
| 3 | +tox is a generic virtualenv management and test command line tool you can use for: |
| 4 | + |
| 5 | +- checking your package installs correctly with different Python versions and interpreters |
| 6 | +- running your tests in each of the environments, configuring your test tool of choice |
| 7 | +- acting as a frontend to Continuous Integration servers, greatly reducing boilerplate and merging CI and shell-based testing. |
| 8 | + |
| 9 | + |
| 10 | +taken from `tox.readthedocs.io <https://tox.readthedocs.io/en/latest/>`__. |
| 11 | + |
| 12 | +Basic example. |
| 13 | +---------------------------------------------------------------- |
| 14 | +First, install tox with pip install tox. Then put basic information about your project and the test |
| 15 | +environments you want your project to run in into a tox.ini file residing right next to your setup.py file: |
| 16 | + |
| 17 | +:: |
| 18 | + |
| 19 | + # content of: tox.ini , put in same dir as setup.py |
| 20 | + [tox] |
| 21 | + envlist = py27,py36 |
| 22 | + |
| 23 | + [testenv] |
| 24 | + deps = pytest # install pytest in the virtualenv where commands will be executed |
| 25 | + commands = |
| 26 | + # whatever extra steps before testing might be necessary |
| 27 | + pytest # or any other test runner that you might use |
| 28 | + |
| 29 | +.. note:: |
| 30 | + |
| 31 | +Note: |
| 32 | + |
| 33 | +You can also try generating a tox.ini file automatically, by running tox-quickstart |
| 34 | +and then answering a few simple questions. |
| 35 | + |
| 36 | +To sdist-package, install and test your project against Python2.7 and Python3.6, just type: |
| 37 | + |
| 38 | +:: |
| 39 | + |
| 40 | + tox |
| 41 | + |
| 42 | +and watch things happening (you must have python2.7 and python3.6 installed in your environment |
| 43 | +otherwise you will see errors). When you run tox a second time you’ll note that it runs much faster |
| 44 | +because it keeps track of virtualenv details and will not recreate or re-install dependencies. |
| 45 | +You also might want to checkout tox configuration and usage examples to get some more ideas. |
| 46 | + |
| 47 | +Environment variables |
| 48 | +--------------------- |
| 49 | + |
| 50 | +When running ``tox`` we've allowed for the usage of environment variables to tweak certain settings |
| 51 | +of the playbook run using Ansible's ``--extra-vars``. It's helpful in Jenkins jobs or for manual test |
| 52 | +runs of ``ceph-ansible``. |
| 53 | + |
| 54 | +The following environent variables are available for use: |
| 55 | + |
| 56 | +* ``FETCH_DIRECTORY`` : (default: ``changedir``) This would configure the ``ceph-ansible`` variable ``fetch_directory``. This defaults to |
| 57 | + the ``changedir`` of the given scenario and should not need to be changed. |
| 58 | + |
| 59 | +* ``CEPH_STABLE_RELEASE``: (default: ``jewel``) This would configure the ``ceph-ansible`` variable ``ceph_stable_relese``. This is set |
| 60 | + automatically when using the ``jewel-*`` or ``kraken-*`` testing scenarios. |
| 61 | + |
| 62 | +* ``UPDATE_CEPH_STABLE_RELEASE``: (default: ``kraken``) This would configure the ``ceph-ansible`` variable ``ceph_stable_relese`` during an ``update`` |
| 63 | + scenario. This is set automatically when using the ``jewel-*`` or ``kraken-*`` testing scenarios. |
| 64 | + |
| 65 | +* ``CEPH_DOCKER_REGISTRY``: (default: ``docker.io``) This would configure the ``ceph-ansible`` variable ``ceph_docker_registry``. |
| 66 | + |
| 67 | +* ``CEPH_DOCKER_IMAGE``: (default: ``ceph/daemon``) This would configure the ``ceph-ansible`` variable ``ceph_docker_image``. |
| 68 | + |
| 69 | +* ``CEPH_DOCKER_IMAGE_TAG``: (default: ``latest``) This would configure the ``ceph-ansible`` variable ``ceph_docker_image_name``. |
| 70 | + |
| 71 | +* ``CEPH_DEV_BRANCH``: (default: ``master``) This would configure the ``ceph-ansible`` variable ``ceph_dev_branch`` which defines which branch we'd |
| 72 | + like to install from shaman.ceph.com. |
| 73 | + |
| 74 | +* ``CEPH_DEV_SHA1``: (default: ``latest``) This would configure the ``ceph-ansible`` variable ``ceph_dev_sha1`` which defines which sha1 we'd like |
| 75 | + to install from shaman.ceph.com. |
| 76 | + |
| 77 | +* ``UPDATE_CEPH_DEV_BRANCH``: (default: ``master``) This would configure the ``ceph-ansible`` variable ``ceph_dev_branch`` which defines which branch we'd |
| 78 | + like to update to from shaman.ceph.com. |
| 79 | + |
| 80 | +* ``UPDATE_CEPH_DEV_SHA1``: (default: ``latest``) This would configure the ``ceph-ansible`` variable ``ceph_dev_sha1`` which defines which sha1 we'd like |
| 81 | + to update to from shaman.ceph.com. |
| 82 | + |
| 83 | + |
| 84 | +.. _tox_sections: |
| 85 | + |
| 86 | +Sections |
| 87 | +-------- |
| 88 | + |
| 89 | +The ``tox.ini`` file has a number of top level sections defined by ``[ ]`` and subsections within those. For complete documentation |
| 90 | +on all subsections inside of a tox section please refer to the tox documentation. |
| 91 | + |
| 92 | +* ``tox`` : This section contains the ``envlist`` which is used to create our dynamic matrix. Refer to the `section here <http://tox.readthedocs.io/en/latest/config.html#generating-environments-conditional-settings>`_ for more information on how the ``envlist`` works. |
| 93 | + |
| 94 | +* ``purge`` : This section contains commands that only run for scenarios that purge the cluster and redeploy. You'll see this section being reused in ``testenv`` |
| 95 | + with the following syntax: ``{[purge]commands}`` |
| 96 | + |
| 97 | +* ``update`` : This section contains commands taht only run for scenarios that deploy a cluster and then upgrade it to another Ceph version. |
| 98 | + |
| 99 | +* ``testenv`` : This is the main section of the ``tox.ini`` file and is run on every scenario. This section contains many *factors* that define conditional |
| 100 | + settings depending on the scenarios defined in the ``envlist``. For example, the factor ``centos7_cluster`` in the ``changedir`` subsection of ``testenv`` sets |
| 101 | + the directory that tox will change do when that factor is selected. This is an important behavior that allows us to use the same ``tox.ini`` and reuse commands while |
| 102 | + tweaking certain sections per testing scenario. |
| 103 | + |
| 104 | + |
| 105 | +.. _tox_environments: |
| 106 | + |
| 107 | +Modifying or Adding environments |
| 108 | +-------------------------------- |
| 109 | + |
| 110 | +The tox environments are controlled by the ``envlist`` subsection of the ``[tox]`` section. Anything inside of ``{}`` is considered a *factor* and will be included |
| 111 | +in the dynamic matrix that tox creates. Inside of ``{}`` you can include a comma separated list of the *factors*. Do not use a hyphen (``-``) as part |
| 112 | +of the *factor* name as those are used by tox as the separator between different factor sets. |
| 113 | + |
| 114 | +For example, if wanted to add a new test *factor* for the next Ceph release of luminious this is how you'd accomplish that. Currently, the first factor set in our ``envlist`` |
| 115 | +is used to define the Ceph release (``{jewel,kraken,rhcs}-...``). To add luminous you'd change that to look like ``{luminous,kraken,rhcs}-...``. In the ``testenv`` section |
| 116 | +this is a subsection called ``setenv`` which allows you to provide environment variables to the tox environment and we support an environment variable called ``CEPH_STABLE_RELEASE``. |
| 117 | +To ensure that all the new tests that are created by adding the luminous *factor* you'd do this in that section: ``luminous: CEPH_STABLE_RELEASE=luminous``. |
| 118 | + |
| 119 | +Note |
| 120 | + |
| 121 | + |
| 122 | +For more information about Tox configuration, consult the `official documentation <https://tox.readthedocs.io/en/latest/>`__. |
0 commit comments