71 Commits

Author SHA1 Message Date
Dmitriy Rabotyagov
53db970168 Fix facts gathering when run with tags
Currently facts are not gathered when role is run with tags
This patch fixes that behaviour and prevents role failure.

Change-Id: If27a6e57c56a0b294442b71aa777d759bc401868
2021-04-23 10:48:25 +03:00
Jonathan Rosser
dcc4572be5 Use ansible_facts[] instead of fact variables
See https://github.com/ansible/ansible/issues/73654

Change-Id: I8e38b479c257e077c2f6cb982acf79f02f0e43a9
2021-03-16 10:49:29 +00:00
Dmitriy Rabotyagov
20f8ad42ce Slurp constraints for all hosts
This fixes bug when content slurp has been performed only for single
host. Others were having invalid contstraints file with single record
in it.

Change-Id: I7189e061f6c8ab3dfb69dda6a9e7f974f8bdc06b
2021-03-01 15:32:34 +02:00
Zuul
90f8fe6801 Merge "Gather facts for repo containers" 2021-03-01 10:37:57 +00:00
Dmitriy Rabotyagov
f487ab46ba Gather facts for repo containers
We can't evaluate `venv_wheel_build_enable` without gathered facts about
repo containers. And default facts cache is 1day. After that time role
will fail to evaluate the variable.

Change-Id: I79a10a3f774246ab9c57313f19f3804f9422e08c
2021-02-27 17:24:19 +00:00
Jonathan Rosser
2a533ed185 Use ansible_facts[] instead of fact variables
See https://github.com/ansible/ansible/issues/73654

Change-Id: Iec4a2a8c5251ddccedc4310c26c8fd2ca8bdc913
2021-02-25 12:24:01 +00:00
Jonathan Rosser
bd63b90aeb Factor out unnecessary set_fact
These varaibles are not required to be persisted as facts, so
convert them from facts to task vars to save a task execution.

Change-Id: Ibaae18199295761f8b52da31cccb9fa8ec40558b
2021-02-08 10:39:34 +00:00
Jonathan Rosser
a4d8d5fa3e Remove preflight checks
Other tasks in the role will fail with similar errors to these
preflight checks if virtualenv is missing or variables are undefined.

As these tasks are run many times we should drop them and rely
on regular ansible error messages.

Change-Id: Iabec3f88c02bf4d44c09735a314985366daddffb
2021-02-08 08:47:38 +00:00
Dmitriy Rabotyagov
ab68e94425 Import wheels build only when necessary
Skipping tasks take time. It's faster not to import things we don't need

We also move symlinking to the separate task that can be inlcuded.

Change-Id: I20a5cda421910df9aaca3aacb3f3e088a1fd2938
2021-02-05 13:29:16 +02:00
Dmitriy Rabotyagov
9e7877d55a Do not drop all wheels with venv_rebuild
Removal of venv_build_host_wheel_path leads to all wheels for all
services being dropped which results in other role brokeness
since we build wheels only when requirements or constraints
file is changed. Also we technically don't need to clean it up, since
removal of just rest of the files will lead to wheels being rebuild.

This change should make usage venv_rebuild safe and not breaking wheels
for all services rather then single one.

Change-Id: I6bbe66b699ce5ab245bb9779b61b5c4625eba927
Related-Bug: #1914301
2021-02-03 20:37:44 +02:00
Jonathan Rosser
d896c01c52 Replace pip requirement source specs with the package name for built wheels
When wheels are built from source, the repo server wheel build requirements
will have an input of the form git+https://example.com/foo.git@branch#egg=foo.
The wheel build will result in a wheel with a version like 1.2.3dev4.

When installing the built wheel into the venv we must switch the source
spec in the requirements from the original git repo to just the
package name 'foo', as the constraints file generated from the wheel
build will specify the exact version of the built wheel 'foo==1.2.3dev4'.

The new pip resolver will not accept there being a source spec in the
input requirements as well as a contradictory constraint from the wheel
build output, this results in an error from pip.

Change-Id: I9be6bbf4a29a4da2ddf96dc0336bc2a7d8ec9281
2021-01-18 12:36:23 +00:00
Dmitriy Rabotyagov
6b3d95e13b Drop empty pip packages from the list
This patch aims to remove empty records from venv_pip_packages list
to avoid pip error due to that.

This also brings _venv_pip_packages variable, which optimize process by
doing union and sort only once.

Change-Id: Ic94f5a00346e47c394bd2cefc1cfca4ed8c3bdef
2020-08-10 20:12:54 +03:00
Jesse Pretorius (odyssey4me)
880ed4b185 Only create local facts folder when necessary
If we do not plan to set any local facts, we should
not be creating this folder. If we do need to set the
facts, then the tasks will need to be run via sudo to
ensure that they has the appropriate rights to create
the folder/files under /etc.

If this change is not implemented, and the playbook
running this role is not executed as root, then the
task fails because it does not have rights to create
the folder - even when there are no facts to set.

Change-Id: Idcb093775507728a7c68a877a05b8895d4c8c39f
2020-07-29 08:31:08 +00:00
Jonathan Rosser
aabd3c07c2 Remove the virtualenv version check
Simplify this code by making the assumption that we always have a
new enough version of virtualenv present. Centos-7 ships 15.1.0 so
it is now possible to remove some conditional logic as well.

This patch removes the version check and replaces it with a check
that the virtualenv command is present on the system patch and
is usable.

Change-Id: I1a8f4961358c9551c5493b332187b411177b2769
2020-07-06 12:44:21 +00:00
Jonathan Rosser
04c93bab7f Facts are strings so make this explicit
This patch fixes the following ansible warning:

[WARNING]: The value True (type bool) in a string field was converted to
u'True' (type string). If this does not look like what you expect, quote the
entire value to ensure it does not change.

Change-Id: I06cee8173aaf79c2a1bd288fa1a813117ab2b319
2020-05-12 09:57:45 +01:00
Jonathan Rosser
e059d96826 Verify version number for virtualenv>=20.0.0
Depends-On: https://review.opendev.org/711015
Change-Id: Ibc92a6126ff161e1f2edd5d831a1f832d328323e
2020-03-03 18:19:17 +00:00
Dmitriy Rabotyagov
7bde578d9b Use version test instead of version_compare
This test was changed to 'version' in ansible 2.5 [1].

[1] https://docs.ansible.com/ansible/2.8/user_guide/playbooks_tests.html#version-comparison

Change-Id: If6a4a14fe5bdda27a2d8e050fcac71337ea05d02
2019-09-10 13:43:36 +03:00
Jonathan Rosser
4d47c1ed04 Do not symlink the __pycache__ directory into the venv
If a service is already started it will create files in the venv
__pycache__ directory. This role will then try to symlink the non empty
directory to the host, which will fail.

"the directory /openstack/venvs/nova-19.1.0.dev272/lib/python3.6/
site-packages/__pycache__ is not empty, refusing to convert it"

This patch stops any __pycache__ files from being symlinked to the
venv, these appear to be present in suse packages [1].

[1] http://paste.openstack.org/show/773974/

Change-Id: Ib718f5de4e5ae5b401858dea6437e0039b7082e0
2019-09-09 11:55:42 +01:00
Jesse Pretorius
90fe547276 Name the venv install block/rescue tasks
Looking at the output of the tasks, or reviewing them with ARA,
is a bit confusing without the names explaining what they are
doing.

Change-Id: Idb940f011f3b83c222a5acfe6a9430027eb2a657
2019-04-17 15:25:11 +01:00
Jesse Pretorius
cce10ac38e Implement global constraints
In the previous repo build process, we had global constraints which
override upper constraints and anything set in the roles. This was
essential for two purposes:

1. To enable us to pin things that were not in upper constraints. eg: pip,
   setuptools, wheel
2. To enable us to pin things which were in upper constraints, but broken.
   This would usually be a temporary measure until upper constraints was
   fixed.

This patch implements a new variable 'venv_build_global_constraints' which
is a list of constraints to be applied globally for all venvs. This list
will be used to produce a file in the venv suffixed with
'-global-constraints.txt' and will be used on the pip command line when
building the wheels and when installing packages.

We also ensure that all constraints are used when both building and
installing pip, setuptools and wheel into the venv.

Change-Id: I9ae3ef19c863b9237a51d2fcd6f4ebce1a9ebad7
2019-04-17 12:21:47 +01:00
Mohammed Naser
b2abfe4bad Delete constraints and requirements files on build fail
If the installation of Python packages fails for any reason, the
constraint and requirements file is already written and therefore
unless you delete the virtualenv, it would not rebuild things
again.

This patch will handle failure and delete those files, then provide
a warning for the user upon failing to inspect the needed file.

Closes-Bug: #1824189

Change-Id: I67db44ce10250908f23c26c90d271a780a875eb6
2019-04-10 12:21:07 -04:00
Zuul
d222c3f26d Merge "Revert "speedup: move when block to outside include"" 2019-03-31 16:25:40 +00:00
Mohammed Naser
0ae478ac78 Revert "speedup: move when block to outside include"
This meant that we can't actually run fact checks and the evaluation
of that bool fails again!

This reverts commit 092d874e6fe78937a308b686b56b835cc3bf23ea.

Change-Id: Iab9e396bef03417e2dda19efab7da7d2bf92ee8b
2019-03-30 21:56:48 +00:00
Zuul
82cc52b4a5 Merge "Add fact gathing for hardware when building venvs" 2019-03-30 11:10:39 +00:00
Mohammed Naser
092d874e6f speedup: move when block to outside include
Instead of including a file, then running a conditional in the block
which gets applied inside the task, which then results in every task
running, but getting skipped (especially in scenarios where the build
host is the same as the current one), we simply include if we have to.

This saves around 20 seconds in every iteration of python_venv_build
on metal.

Change-Id: I8afb2970ee696f0fe9a9e250f19f1db465d63511
2019-03-29 22:36:48 -04:00
Mohammed Naser
c94cd6c4b6 Add option to upgrade PyPI/etc without using site config
There are sometimes buggy releases of PyPI shipped by the
distributions which don't react well to pip.conf config
options such extra index URLs which make it impossible to
upgrade it.

This adds a a variable which allows working around this
issue by ignoring the site config to do the upgrade.

Change-Id: I5266d827f19e14c6313b11408913e2f754befaca
2019-03-29 17:25:34 +00:00
Kevin Carter
c5e0ed0751 Add fact gathing for hardware when building venvs
The python venv build process requires access to facts that from a
delegated host to build venvs. This change adds a fact gathering
loop to the group "repo_all" if it exists and defaults to the current
inventory hostname. This change will allow the build system to gather
all facts from all build targets as needed ensuring a successful
playbook run.

Change-Id: I8a6c60de99360570bd7ae1c1fd8055f99d770c9f
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2019-03-29 09:48:33 -05:00
Jesse Pretorius
ef7a991193 Close ternary filter properly
In I8b032f3b5d043e543c1d0fd0434d833385ceecc4 the ternary filter
for the distro package install was not closed properly.

Change-Id: Iae88db62aa3d1a1f955347f817b43a82e23789ac
2019-03-22 16:45:15 +00:00
Jesse Pretorius
eb167317c2 Use union for list combinations to ensure uniqueness
Rather than adding two lists together then passing them through
the 'unique' filter to remove duplicates, we combine the two
actions by using the union filter.

Change-Id: I8b032f3b5d043e543c1d0fd0434d833385ceecc4
2019-03-20 05:55:10 +00:00
Jesse Pretorius
b84199341f Add toggle for python wheel build process
If a package (like stackviz) should be installed using
a tarball, rather than from a git source, then it is
better to be able to disable the wheel build process,
constraints usage, etc and just install it from the
tarball.

Change-Id: Id1dc504586a3a1bbd7a161b7367606ced3789043
2019-03-19 10:09:46 +00:00
Jesse Pretorius
53dea0d306 Use the repo if available
Currently a configured pip.conf is required in order to make
use of the repo server in an OSA build. This ensures that it
is used, but not exclusively used, if it is available to source
python packages.

The implementation allows it to still respect any configured pip
configuration on the host, so we should be able to remove the OSA
pip.conf with this in place and still maintain the use of the local
repo.

Change-Id: Ia6f2cf86f77ee380fce2d1ecc89e1cb4341e39df
2019-03-19 10:09:46 +00:00
Jesse Pretorius
8f5ea40a5b Apply constraints when building the venv
Currently the role expects all constraints to be applied
in pip arguments provided to the role, which means that
there is some pre-processing required outside the role
for this to happen.

In order to pave the way to replace repo_build with this
role, we need to be able to apply constraints and maintain
idempotency even when building from a git source.

To achieve this we ensure that we build the wheels in a
temporary location, then use the resulting wheels for the
specific service to build a service-specific set of
requirements and constraints. To enable idempotency, we
only rebuild the wheels if the requirements/constraints
change.

We use slurp to collect the constraints and re-implement
them when installing the venv on the target hosts. This
prevents us having to inform the venv build role about
the repo server URL. We may change this at a later date
in order to facilitate a centralised repo server for
multiple regions.

Change-Id: I7c467e3a9e6627b75664b94f6b8e3232975171a7
2019-03-19 10:09:46 +00:00
Chandan Kumar
44c421b5af Create venv_install_destination_path parent directory
Before creating the venv, it is necessary to make sure that the
parent directory exists otherwise venv creation will fail.

Change-Id: I241e249c919bc52fcc0220737b9d96d9608afebf
2019-01-08 18:25:17 +05:30
Jesse Pretorius
5a31e77fb4 Add ability to symlink host python packages into venv
Some python packages have C bindings which tend to be very
particular about the version of their underlying shared libraries.
To ensure things run smoothly for stable releases, we opt to
use the distro packages for these python packages and symlink the
appropriate python library files and their bindings into the venv.

This functionality is required for libvirt and ceph and is used
across multiple roles.

Change-Id: Ib5b7fa1d06abe1e1bb4f14aea7de4207b61aca88
2018-12-11 10:28:24 +00:00
Jesse Pretorius
c54aa8117e Add default distro packages for wheel builds
There are some packages which absolutely must be there
for all wheel builds, or for installing without wheels.
Without them, pip is totally unable to compile the
package due to missing headers or tooling.

This patch adds a default, minimal, set of compilers
and python headers.

Rather than use include_vars, with_first_found as we
do in most other roles, we use vars/main and a dict
based on ansible_os_family. The role is often included
by other roles, and we'd rather not risk the search
path being incorrect (there are constant bugs related
to this in ansible). Using this mechanism takes away
the need for an include_vars task and avoids any pathing
issues.

Change-Id: I4ef11e47e4d3fe5adc65e9888e660a5a121d205b
2018-10-31 10:35:20 +00:00
Zuul
d515b0d7ff Merge "Only install the appropriate distro packages" 2018-10-25 16:38:34 +00:00
Jesse Pretorius
70525a7fbb Only install the appropriate distro packages
Currently all packages provided to the role (build and install)
are installed on both the build host and the install host. This
was done as a temporary measure to allow us time to ensure that
each role seperates these, but now that there are some
installations using this it's causing conflicts in services and
packages.

We should rather do the right thing, and fix the roles which need
the packages separated.

If there is no wheel build host, the venv_build_distro_package_list
packages will need to be installed on the target host, otherwise
the sdist install will not work, so we cater for that in this patch
too.

Depends-On: https://review.openstack.org/612704
Depends-On: https://review.openstack.org/613256
Change-Id: I04100a1073dddb06775d8583104bfd6ef4b3213a
2018-10-25 12:29:22 +01:00
Jimmy McCrory
609ea84d1b Mark build task changed only when wheels are built
Only set the 'Build wheels for the packages to be installed into the
venv' task to changed when new wheels are built or saved.

Change-Id: Iec1818c54f4a40791cbb69d9cc726960c905c069
2018-10-21 17:07:37 -07:00
Kevin Carter
5818696cf6 Add option for default pip package install
Add an option to define a default set of python packages to install
within a virtual environment. This can be used to install a package
wihin a virtual environment that may be outside of a normal package
list but for a given service.

Change-Id: Ic2dc024049062ad9be396a1f71435f661576e91b
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-09-09 18:35:15 +01:00
Jesse Pretorius
2e3af35ee6 Use updated syntax for task changed result
Change-Id: I0148e342074993c62b41cca84616875b084da8ab
2018-09-02 15:40:43 +01:00
Jesse Pretorius
288faa80e9 Add retries to wheel build task
Given that the wheel build process uses remote resources,
we should retry the task if it fails.

Change-Id: Ida4b18182a863c3108887e6a7edd136381c31bb8
2018-09-02 15:38:51 +01:00
Jesse Pretorius
b93f331aa2 Consider pre-release wheels for installation
When building from git sources or from master, pre-release
wheels may be built. We need to ensure that they are used
if they are present. For stable branches, we are still
protected by the use of the constraints to ensure that we
only get the packages we expect.

Change-Id: I68e6d29cfb6a144d119eabdeb7e23bff73c51555
2018-09-02 14:53:33 +01:00
Jesse Pretorius
ac5e5e9283 Simplify builds/installs by eliminating venv packaging
Python venvs are not particularly portable. To overcome this
problem we have a bunch of stuff implemented to fix them
after we unpack them. This ranges from relatively simple
things like re-implementing python in the venv and changing
the shebangs for everything in it, to more complex things
like having to package a venv per distro/architecture.

All of this can be eliminated by simplifying the mechanism
into just creating the venv on the target host, and installing
the python packages into it. To help speed up the build, we
can simply build wheels before hand and store them on a web
server somewhere.

This patch implements the changes to:

1. Do away with packaging the venv.
2. Keep it simple. We install into the venv, and that's that.
3. Add a toggle to rebuild the venv if you'd like to.
4. Use import_tasks with tags for each stage so that it's
   easy to skip a portion of what executes.

Change-Id: I708b5cf32e5cce6a18624d0b3be0cd4c828ad389
2018-09-01 16:38:42 +00:00
Jesse Pretorius
94c6e3ff99 Only add --no-site-packages when necessary
The --no-site-packages option is deprecated, and is only
necessary for virtualenv versions below 1.7.0. This patch
checks the version and adds it only when necessary.

Change-Id: I19b4acf148c28c96f58bcbda4b19153d56206008
2018-08-27 22:58:46 +00:00
Jesse Pretorius
c4d466ad40 Add --always-copy when building the venv
As we do in the repo_build, so shall we do here.

Change-Id: I9c3f7fbc772614b49dfefedc67d27c14240f80ef
2018-08-27 23:23:51 +01:00
Jesse Pretorius
279ddb56da Create the venv with the right python version
to ensure that the venv is created with the right python
version, we pass the right parameter when creating it.
We remove it in the later task as the argument only
applies when actually creating it.

Change-Id: Ief645ad97a249fcb8545cd2d11edac6984d0014d
2018-08-27 23:02:51 +01:00
Jesse Pretorius
2820d9ec0b Correct cache_valid_time variable name
The variable name is venv_distro_cache_valid_time
rather than distro_cache_valid_time. Also, this
variable is only used by apt, not zypper.

Change-Id: I71682b7d6bf183967d06f485772760876e2c8df6
2018-08-27 20:06:18 +01:00
Jesse Pretorius
8f1129e989 Upgrade pip/setuptools/wheel in the venv
To ensure a uniform experience across distributions
and from build to build, we need to ensure that the
venv has a consistent version of pip, setuptools and
wheel. This patch ensures that these packages are
upgraded to the latest version allowed by the args
provided.

This prevents issues as discovered and solved by
https://review.openstack.org/596553

We also remove the virtualenv_site_packages argument
from the pip tasks as they are unnecessary given that
the virtualenv is created in an earlier task.

Change-Id: Ia9e2f695212b01a54f8e73fbd03faa8e9b492f93
2018-08-25 21:43:33 +01:00
Jesse Pretorius
eea695ecaa Use the virtualenv's pip to build the wheels
Instead of requiring pip installed on the host, we can
use the pip in the virtualenv instead. This keeps the
host cleaner.

Change-Id: I8d6c77e2cfa2cbcd81df21c7ed22a0a344d3b55c
2018-08-19 20:15:37 +01:00
Jean-Philippe Evrard
7f58c50bf3 Fix usage of "|" for tests
With the more recent versions of ansible, we should now use
"is" instead of the "|" sign for the tests.

This should fix it.

Change-Id: If684a4bf85249a4eb5372cb69365fb79423326db
2018-07-30 08:41:04 +00:00