Add regexp to recognize new error text.
[arvados-dev.git] / jenkins / run_upload_packages.py
index 83feaba04381b721545407c0d0d99bd6873829ac..871b80ee967ff75e7076984b9dda52bbcd359b4c 100755 (executable)
@@ -1,5 +1,9 @@
 #!/usr/bin/env python3
 
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 import argparse
 import functools
 import glob
@@ -13,8 +17,8 @@ import subprocess
 import sys
 import time
 
-def run_and_scan_output(cmd, read_output, *line_matchers,
-                        encoding=locale.getpreferredencoding(), **popen_kwargs):
+def run_and_grep(cmd, read_output, *regexps,
+                 encoding=locale.getpreferredencoding(), **popen_kwargs):
     """Run a subprocess and capture output lines matching regexps.
 
     Arguments:
@@ -29,13 +33,17 @@ def run_and_scan_output(cmd, read_output, *line_matchers,
 
     Returns 2-tuple (subprocess returncode, list of matched output lines).
     """
-    line_matchers = [matcher if hasattr(matcher, 'search') else re.compile(matcher)
-                     for matcher in line_matchers]
+    regexps = [regexp if hasattr(regexp, 'search') else re.compile(regexp)
+               for regexp in regexps]
     popen_kwargs[read_output] = subprocess.PIPE
     proc = subprocess.Popen(cmd, **popen_kwargs)
     with open(getattr(proc, read_output).fileno(), encoding=encoding) as output:
-        matched_lines = [line for line in output
-                         if any(regexp.search(line) for regexp in line_matchers)]
+        matched_lines = []
+        for line in output:
+            if any(regexp.search(line) for regexp in regexps):
+                matched_lines.append(line)
+            if read_output == 'stderr':
+                print(line, file=sys.stderr, end='')
     return proc.wait(), matched_lines
 
 
@@ -90,8 +98,14 @@ class PackageSuite:
 
 class PythonPackageSuite(PackageSuite):
     LOGGER_PART = 'python'
-    REUPLOAD_REGEXP = re.compile(
-        r'^error: Upload failed \(400\): A file named "[^"]+" already exists\b')
+    REUPLOAD_REGEXPS = [
+        re.compile(
+            r'^error: Upload failed \(400\): A file named "[^"]+" already exists\b'),
+        re.compile(
+            r'^error: Upload failed \(400\): File already exists\b'),
+        re.compile(
+            r'^error: Upload failed \(400\): Only one sdist may be uploaded per release\b'),
+    ]
 
     def __init__(self, glob_root, rel_globs):
         super().__init__(glob_root, rel_globs)
@@ -115,8 +129,8 @@ class PythonPackageSuite(PackageSuite):
         if not self.logger.isEnabledFor(logging.INFO):
             cmd.append('--quiet')
         cmd.extend(['sdist', '--dist-dir', '.upload_dist', 'upload'])
-        upload_returncode, repushed = run_and_scan_output(
-            cmd, 'stderr', self.REUPLOAD_REGEXP, cwd=src_dir)
+        upload_returncode, repushed = run_and_grep(
+            cmd, 'stderr', *self.REUPLOAD_REGEXPS, cwd=src_dir)
         if (upload_returncode != 0) and not repushed:
             raise subprocess.CalledProcessError(upload_returncode, cmd)
         shutil.rmtree(os.path.join(src_dir, '.upload_dist'))
@@ -128,8 +142,7 @@ class GemPackageSuite(PackageSuite):
 
     def upload_file(self, path):
         cmd = ['gem', 'push', path]
-        push_returncode, repushed = run_and_scan_output(
-            cmd, 'stdout', self.REUPLOAD_REGEXP)
+        push_returncode, repushed = run_and_grep(cmd, 'stdout', self.REUPLOAD_REGEXP)
         if (push_returncode != 0) and not repushed:
             raise subprocess.CalledProcessError(push_returncode, cmd)
 
@@ -165,8 +178,11 @@ class DistroPackageSuite(PackageSuite):
                 self.__class__.__name__, *(pipes.quote(s) for s in args)))
 
     def upload_files(self, paths):
+        dest_dir = os.path.join(self.REMOTE_DEST_DIR, self.target)
+        mkdir = self._build_cmd('ssh', self.ssh_host, 'install', '-d', dest_dir)
+        subprocess.check_call(mkdir)
         cmd = self._build_cmd('scp', *paths)
-        cmd.append('{self.ssh_host}:{self.REMOTE_DEST_DIR}/{self.target}'.format(self=self))
+        cmd.append('{}:{}'.format(self.ssh_host, dest_dir))
         subprocess.check_call(cmd)
 
 
@@ -179,10 +195,11 @@ freight cache "apt/$DISTNAME"
 rm "$@"
 """
     TARGET_DISTNAMES = {
-        'debian7': 'wheezy',
         'debian8': 'jessie',
+        'debian9': 'stretch',
         'ubuntu1204': 'precise',
         'ubuntu1404': 'trusty',
+        'ubuntu1604': 'xenial',
         }
 
     def post_uploads(self, paths):
@@ -201,7 +218,6 @@ createrepo "$REPODIR"
 """
     REPO_ROOT = '/var/www/rpm.arvados.org/'
     TARGET_REPODIRS = {
-        'centos6': 'CentOS/6/os/x86_64/',
         'centos7': 'CentOS/7/os/x86_64/',
         }
 
@@ -229,11 +245,11 @@ PACKAGE_SUITES = {
                           'services/login-sync/*.gem',
                       ),
     }
-for target in ['debian7', 'debian8', 'ubuntu1204', 'ubuntu1404']:
+for target in ['debian8', 'debian9', 'ubuntu1204', 'ubuntu1404', 'ubuntu1604']:
     PACKAGE_SUITES[target] = _define_suite(
         DebianPackageSuite, os.path.join('packages', target, '*.deb'),
         target=target)
-for target in ['centos6', 'centos7']:
+for target in ['centos7']:
     PACKAGE_SUITES[target] = _define_suite(
         RedHatPackageSuite, os.path.join('packages', target, '*.rpm'),
         target=target)