Browse Source

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
changes/03/527203/3
Jeremy Stanley 1 year ago
parent
commit
9e2a5d4633
3 changed files with 17 additions and 7 deletions
  1. 15
    5
      manifests/init.pp
  2. 1
    1
      manifests/server.pp
  3. 1
    1
      manifests/worker.pp

+ 15
- 5
manifests/init.pp View File

@@ -37,10 +37,20 @@ class subunit2sql (
37 37
     require  => Class['pip'],
38 38
   }
39 39
 
40
-  package { 'subunit2sql':
41
-    ensure   => latest,
42
-    provider => openstack_pip,
43
-    require  => [
40
+  exec { 'install-subunit2sql-safely':
41
+    command => '/usr/bin/pip install --upgrade --upgrade-strategy=only-if-needed subunit2sql',
42
+    # This checks the current installed subunit2sql version with pip list and
43
+    # the latest version of subunit2sql on pypi with pip search and if they are
44
+    # different then we know we need to upgrade to reconcile the local version
45
+    # with the upstream version.
46
+    #
47
+    # We do this using this check here rather than a pip package resource so we
48
+    # can override pip's default upgrade strategy in order to avoid replacing
49
+    # deps we've preinstalled from system packages because they lack wheels on
50
+    # PyPI and must be otherwise rebuilt from sdist instead (specifically
51
+    # netifaces).
52
+    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\')"',
53
+    require => [
44 54
       Class['pip'],
45 55
       Package['python-mysqldb'],
46 56
       Package['python-psycopg2'],
@@ -107,7 +117,7 @@ class subunit2sql (
107 117
       Package['python-zmq'],
108 118
       Package['python-yaml'],
109 119
       Package['gear'],
110
-      Package['subunit2sql'],
120
+      Exec['install-subunit2sql-safely'],
111 121
       Package['python-subunit'],
112 122
       Package['testtools']
113 123
     ],

+ 1
- 1
manifests/server.pp View File

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

+ 1
- 1
manifests/worker.pp View File

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

Loading…
Cancel
Save