Install/upgrade subunit2sql safely

When installing or upgrading subunit2sql, override pip's default
upgrade strategy to avoid updating preinstalled dependencies if they
already satisfy the requirements. This in particular avoids
attempting to replace the distro package of python-netifaces by
rebuilding a newer sdist (it is not distributed as a wheel on PyPI
and needs C extensions compiled, which in turn have a lot of
build-time deps).

This implementation is copied from the puppet-zuul module.

Change-Id: I885a61527ca9938200fb965ea97ff957fed3c480
This commit is contained in:
Jeremy Stanley 2017-12-11 18:16:28 +00:00
parent 69150752a0
commit 9e2a5d4633
3 changed files with 17 additions and 7 deletions

View File

@ -37,10 +37,20 @@ class subunit2sql (
require => Class['pip'], require => Class['pip'],
} }
package { 'subunit2sql': exec { 'install-subunit2sql-safely':
ensure => latest, command => '/usr/bin/pip install --upgrade --upgrade-strategy=only-if-needed subunit2sql',
provider => openstack_pip, # This checks the current installed subunit2sql version with pip list and
require => [ # the latest version of subunit2sql on pypi with pip search and if they are
# different then we know we need to upgrade to reconcile the local version
# with the upstream version.
#
# We do this using this check here rather than a pip package resource so we
# can override pip's default upgrade strategy in order to avoid replacing
# deps we've preinstalled from system packages because they lack wheels on
# PyPI and must be otherwise rebuilt from sdist instead (specifically
# netifaces).
onlyif => '/bin/bash -c "test $(/usr/bin/pip list --format columns | sed -ne \'s/^subunit2sql\s\+\(.*\)$/\1/p\') != $(/usr/bin/pip search \'subunit2sql$\' | sed -ne \'s/^subunit2sql (\(.*\)).*$/\1/p\')"',
require => [
Class['pip'], Class['pip'],
Package['python-mysqldb'], Package['python-mysqldb'],
Package['python-psycopg2'], Package['python-psycopg2'],
@ -107,7 +117,7 @@ class subunit2sql (
Package['python-zmq'], Package['python-zmq'],
Package['python-yaml'], Package['python-yaml'],
Package['gear'], Package['gear'],
Package['subunit2sql'], Exec['install-subunit2sql-safely'],
Package['python-subunit'], Package['python-subunit'],
Package['testtools'] Package['testtools']
], ],

View File

@ -56,7 +56,7 @@ class subunit2sql::server (
exec { 'upgrade_subunit2sql_db': exec { 'upgrade_subunit2sql_db':
command => '/usr/local/bin/run_migrations.sh', command => '/usr/local/bin/run_migrations.sh',
require => File['/usr/local/bin/run_migrations.sh'], require => File['/usr/local/bin/run_migrations.sh'],
subscribe => Package['subunit2sql'], subscribe => Exec['install-subunit2sql-safely'],
refreshonly => true, refreshonly => true,
timeout => 0, timeout => 0,
} }

View File

@ -101,7 +101,7 @@ if ! defined(File['/var/log/subunit2sql']) {
hasrestart => true, hasrestart => true,
subscribe => [ subscribe => [
File["/etc/subunit2sql/jenkins-subunit-worker${suffix}.yaml"], File["/etc/subunit2sql/jenkins-subunit-worker${suffix}.yaml"],
Package['subunit2sql'], Exec['install-subunit2sql-safely'],
], ],
require => [ require => [
File['/etc/subunit2sql'], File['/etc/subunit2sql'],