Commit Graph

25 Commits

Author SHA1 Message Date
Clark Boylan 13925d1965 Flip ensure-tox to tox v4 by default
The previous change added a bunch of tox v4 compatiblity, now we switch
to as our default. This should only happen after people have had
sufficient time to add tox v4 compatibility or manually pin back to <4
in their projects.

Change-Id: I16742fb933dba2162a73d532e1a9613af69021aa
2022-12-22 15:40:11 -08:00
Clark Boylan 41153f0653 Update zuul-jobs to handle tox3 and tox4
Tox 4 released today and is a complete rewrite with many backward
incompatible changes. We need to update a number of things to support
that in the zuul-jobs tox role and elsewhere. A possibly incomplete
list of what was changed in this commit to make this work:

  * Don't run tox --showconfig with {{ tox_extra_args }} as -vv is
    in tox_extra_args by default and results in interleaved debug
    output in the ini output making it invalid ini content.
  * Update the tox siblings tox config parser to look for renamed
    environment dir locations.
  * Stop using whitelist_externals and use allowlist_exteranls
    because whitelist_externals is removed and external commands that
    are not explicitly allowed produce errors.
  * Make the tox version configurable in ensure-tox as some users
    may not be able to easily upgrade to tox v4.
  * Escape literal # chars in tox.ini as they are treated as comments
    when in the command strings now.
    https://github.com/tox-dev/tox/issues/2617

Change-Id: I38e13b4f13bb1b2d6fb7e5c70b708e9bb016a455
2022-12-07 15:14:16 -08:00
Clark Boylan cf678365af Pin tox to <4 in ensure-tox installation
Tox v4 just released and has a number of breaking changes. One of which
(yet to be properly identified) has completely broken Zuul's tox
siblings processing and produces errors like:

  Traceback (most recent call last):
    File "<stdin>", line 107, in <module>
    File "<stdin>", line 99, in _ansiballz_main
    File "<stdin>", line 47, in invoke_module
    File "/usr/lib/python3.10/runpy.py", line 224, in run_module
      return _run_module_code(code, init_globals, run_name, mod_spec)
    File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
      _run_code(code, mod_globals, init_globals,
    File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
      exec(code, run_globals)
    File "/tmp/ansible_tox_install_sibling_packages_payload_0af4x4lc/ansible_tox_install_sibling_packages_payload.zip/ansible/modules/tox_install_sibling_packages.py", line 397, in <module>
    File "/tmp/ansible_tox_install_sibling_packages_payload_0af4x4lc/ansible_tox_install_sibling_packages_payload.zip/ansible/modules/tox_install_sibling_packages.py", line 328, in main
    File "/usr/lib/python3.10/configparser.py", line 724, in read_string
      self.read_file(sfile, source)
    File "/usr/lib/python3.10/configparser.py", line 719, in read_file
      self._read(f, source)
    File "/usr/lib/python3.10/configparser.py", line 1097, in _read
      raise DuplicateOptionError(sectname, optname,
  configparser.DuplicateOptionError: While reading from '<string>' [line 45]: option 'root' in section 'testenv:docs' already exists

Let's pin tox for now and a change that removes the pin can also fix tox
siblings (the change to remove the pin should be self testing
thankfully).

Also we make the zuul-tox-docs job temporarily non voting as it runs
ensure-tox non speculatively out of the opendev/base-jobs repo. We have
plenty of tox jobs runing against this changeto show it should work
fine.

Change-Id: Idcebd397f47cfef718721d2576cb43dbdb70801d
2022-12-07 11:31:44 -08:00
Zuul ec6b89b0d4 Merge "ensure-tox: Avoid Reinstalling tox venv if present" 2021-10-04 20:48:06 +00:00
Monty Taylor 06ad3eef8a Add option to install tox into a path location
We can't do this all the time, because of rootless environments.
But sometimes people have root and want to be able to use something
from scripts from normal path.

Change-Id: I3f57a6108f8f53ebfdd12f04ecb3d8c68c5b4a60
2020-06-17 16:31:07 -05:00
Guillaume Chauvel 0b152244e4 ensure-tox: Avoid Reinstalling tox venv if present
On a static node where tox isn't present in the PATH, tox would be always
reinstalled even if already present in venv because it's not checked.

This patch adds tox_venv check, the first matching line is used to get
executable path

Change-Id: Ia27af308cd3b5e2ce5efe36508fe82468e88cbc7
2020-06-12 15:57:38 +02:00
Guillaume Chauvel 54645685a8 ensure-tox: fix tox_executable fact when tox is preinstalled
While making test with a node:
- with tox installed using "pip install --user" as a non-root user
- PATH modified using ~/.ssh/environment
- declared in nodepool to run as this non-root user

tox checks produce an error:
"Check if tox is installed" evalues correctly (shell, bash)
"Output tox version" cannot find tox (command, no sh, no etc ...)

This change sets fact using the output of the first install check

Change-Id: I5886858bcd57afc8ea5fd121ad44bd82afb1a671
2020-05-30 00:26:30 +02:00
Ian Wienand 9c04709719 Revert "Revert "ensure-tox: use venv to install""
This reverts commit bac2bf6c45.

The problem was really that ensure-pip was giving us a
"ensure_pip_virtualenv_command" that didn't work on some systems.
Iaa3ecd05b64af6dd9b2ee17a39bcbe6cde8686ba fixes this underlying issue,
so we can revert to the original change that uses that to install the
tox environment.

Change-Id: I8ce9dceb721474d3220f6e72409481dc89875ee0
2020-05-11 11:10:09 +10:00
James E. Blair bac2bf6c45 Revert "ensure-tox: use venv to install"
This reverts commit 6d78fc4f90.

In some environments, this error is being seen:

2020-05-07 18:36:02.139422 | debian-buster |   "msg": "stdout: The virtual environment was not created successfully because ensurepip is not\navailable.  On Debian/Ubuntu systems, you need to install the python3-venv\npackage using the following command.\n\n    apt-get install python3-venv\n\nYou may need to use sudo with that command.  After installing the python3-venv\npackage, recreate your virtual environment.\n\nFailing command: ['/home/zuul/.local/tox/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']\n\n"

Change-Id: I6d38bf16cc38020c53815dfa6ab94f8cab4de0a2
2020-05-08 07:36:40 -07:00
Ian Wienand 6d78fc4f90 ensure-tox: use venv to install
This currently installs with pip --user which cases problems if you
try to run this version of tox as another user.  This is done in
system-config, for example, where we run tox with "become: yes" to run
testinfra.

By installing tox into a venv, we can call it as another user and it
just works because it's all encapsulated in the venv.  We use the
virtualenv commands exported by ensure-pip to create this.

I think the original motivation for installing tox like this was to
ensure it is done without sudo permissions.  This also doesn't require
permissions, but ensures the resulting tox_executable is able to be
executed in more contexts.

Needed-By: https://review.opendev.org/712819
Change-Id: Iebee8cb72cce7944c537fdb91b6c98ed51878661
2020-05-06 13:01:03 +10:00
Andreas Jaeger 2026f1825b Use main.yaml, not .yml
There are over 490 .yaml files but only a few .yml, let's rename to be
consistent.

Add a test to block .yml files.

Change-Id: I2f1354de82f231154d926b51d9812b1e9c1a6202
2020-04-20 17:44:49 +02:00
Ian Wienand 2f7ff89384 Python roles: misc doc updates
Some minor formatting things I noticed when reading through the page
of role documentation.

Change-Id: I2f94102badd83d82073df2dfb1e36a524c7b0686
2020-04-17 10:45:26 +02:00
Ian Wienand 9e92459592 Document output variables
Several roles are setting facts that are expected to be consumed by
roles following them; generally things like the path to installed
tools, etc.

Add a section to policy about this behaviour in general, noting it
should use the cachable flags to persist the values.

Add specific documentation notes in an "Output Variable" section for
roles currently implementing this behaviour.

Change-Id: I05657fec198176c7d7345e84293f4902c81fa30c
2020-04-17 10:45:15 +02:00
Ian Wienand 8f06e1a536 ensure-tox: use ensure-pip role
Use the ensure-pip role to ensure that `pip` is available.  If the
existing flag `tox_prefer_python2` is set, we pass along the flag to
ensure-pip to install Python 2 pip as well.

Story: #2007386
Task: #39308
Change-Id: I5053e315df8d2ea9892911800c88afcbe31cc05b
2020-04-15 15:34:21 -07:00
Ian Wienand b2d27969a9 ensure-tox: make idempotent and update testing
This role currently does

 which tox || pip install --user tox

and then sets "tox_exectuable" iff it has installed tox into the
user's pip environment.

This isn't idempotent -- if you run ensure-tox again, it will again
run "which tox" and miss that it already installed tox in the private
pip environment.  Instead, make it look for
"which {{ tox_executable }}" ... this way it will find the install it
just did if it runs again.

There seems to be no reason to only set "tox_exectuable" in the case
this role had to install tox.  Make this *always* set tox_exectuable
so that you can run ensure-tox and then be sure tox_exectuable is
something sane.

The current testing assumes that tox is installed in the base image.
We are working to remove this assumption; remove this part of the
test.

Rework the testing to first clear out any existing tox, which is
present on most images but will have no effect on the -plain images.
Then test when we install fresh it goes into the user pip install
area, and then test if we explicitly set tox_exectuable it overrides.

Change-Id: I36cfb62f2a2e2b9c2bbe92b46ed0b8098a873732
2020-04-08 11:18:34 +10:00
Ian Wienand 82b466aa68 ensure-tox: update Python version documentation
Change bed3643b28 modified the
tox_prefer_python2 default to false; update the README.rst.

Change-Id: Ie8f9ecbb2da06f1e3a3602a4cc0975ea21c2f822
2020-04-06 17:04:00 +10:00
Mohammed Naser bed3643b28 ensure-tox: use python3 by default
The role currently defaults to installing tox with python2 in order
to maintain compatibility with existing jobs.  This change makes the
default behaviour use python3 as python2 is EOL.

Change-Id: Ic41b8fee7ae8a8f5df6c1107c6ed812c14b8c8be
2020-03-12 17:49:45 -04:00
Mohammed Naser 9254fbb5ff ensure-tox: add prefer_python2
This patch enables the ability to set a value which prefers the
installation of tox within python2 over python3.

Change-Id: I29c9585aa9048c0e2855ec1eaf1f48041cfe46e2
2020-03-04 07:21:20 +00:00
Mohammed Naser 45a3790d85 ensure-tox: save tox_executable fact
If we install our own local version of tox, we should set a fact
with the tox_executable so other tasks can leverage it.

Change-Id: If6895bbb898261e88c0e3083d21210209f79995f
2020-02-04 20:46:07 +01:00
Zuul b37367637e Merge "ensure-tox: Output tox version" 2020-01-21 21:32:25 +00:00
Ian Wienand 9e5907f4cc ensure-tox: fix pipe race
The

 command -v pip pip3 | head -n1

introduced with Ie50928c9b782ea84db916bb1441567e1206ff466 has a very
subtle race; if "pip" and "pip3" exists and there are two lines
output, the "head -n1" will exit and depending on scheduling the
"command" might write to a broken pipe (this manifests as exit code
141).

Move this to a more explicit if statement.

Co-Authored-By: Jens Harbott <j.harbott@x-ion.de>
Change-Id: I80823a7bc6351925d6f0b20bdebca3eafef0b27d
2020-01-22 07:49:35 +11:00
David Shrewsbury 4538583b1a ensure-tox: Output tox version
This can be useful for debugging.

Change-Id: Ic5ffb46cf2f583cd6dd04289e55f40f8acd3d9bf
2020-01-21 15:00:05 -05:00
Sorin Sbarnea 2410119ac9 ensure-tox: improve pip detection
Fixed issues failing to install tox on python3 only systems which have
only pip3 executable and not the pip one.

Needed-By: https://review.rdoproject.org/r/#/c/24584/
Change-Id: Ie50928c9b782ea84db916bb1441567e1206ff466
2020-01-16 21:06:07 +00:00
James E. Blair 69b7492af9 Add README to ensure-tox role
Change-Id: I1efdcb8eff522cd58e94d9465d093bbc851aa496
2018-04-05 11:07:42 -07:00
Monty Taylor dafe1bfcb4
Split ensuring tox is installed into a role
We do this in a few places, make it reusable.

Change-Id: Ied118508dc4b8e4cbfca88b5636730664dbe10b4
2017-08-22 15:19:33 -04:00