Ejemplo n.º 1
0
    def watch(self, build_number):
        jenkins = util.jenkins_connection()

        build_info = jenkins.get_build_info('build-package', build_number)

        job_url = posixpath.join(jenkins.url, 'job', 'build-package',
                                 str(build_number))
        log.info('Watching %s' % job_url)

        pkg_name = self.pkg_name(build_info)

        start_seconds = build_info['timestamp'] / 1000.0
        # rcm-jenkins is uses the America/New_York timezone:
        jenkins_tz = tz.gettz('America/New_York')
        start = datetime.fromtimestamp(start_seconds, jenkins_tz)
        # If you want to convert to local time:
        # start = start.astimezone(tz.tzlocal())
        log.info('Started %s' % start.strftime("%F %r %z"))

        was_building = build_info['building']
        while build_info['building']:
            try:
                elapsed = datetime.now(jenkins_tz) - start
                # TODO: Xenial has python-humanize (humanize.naturaldelta()
                # here)
                (minutes, seconds) = divmod(elapsed.total_seconds(), 60)
                # Clear the previous line:
                msg = '\r%s building for %02d:%02d' % \
                    (pkg_name, minutes, seconds)
                sys.stdout.write(msg)
                sys.stdout.flush()
                sleep(10)
                build_info = jenkins.get_build_info('build-package',
                                                    build_number)
            except requests.exceptions.ConnectionError as e:
                print('')
                log.error('connection error: %s' % e)
                log.info('Re-try watching with `rhcephpkg watch-build %s`' %
                         build_number)
            except KeyboardInterrupt:
                print('')
                log.info('continue watching with `rhcephpkg watch-build %s`' %
                         build_number)
                raise SystemExit(1)
        if was_building:
            # The above "while" loop will not print a final newline.
            print('')

        end_millis = build_info['timestamp'] + build_info['duration']
        end_seconds = end_millis / 1000.0
        end = datetime.fromtimestamp(end_seconds, jenkins_tz)
        log.info('Ended %s' % end.strftime("%F %r %z"))

        # Show the final build result.
        if build_info['result'] == 'SUCCESS':
            log.info('result is SUCCESS')
        else:
            log.error(build_info['result'])
            raise SystemExit(1)
Ejemplo n.º 2
0
 def main(self):
     self.parser = Transport(self.argv, options=self.options)
     self.parser.catch_help = self.help()
     self.parser.parse_args()
     force = False
     if self.parser.has(['--force', '--hard-reset']):
         force = True
     if self.parser.unknown_commands:
         log.error('unknown option %s',
                   ' '.join(self.parser.unknown_commands))
         return self.parser.print_help()
     self._run(force)
Ejemplo n.º 3
0
 def main(self):
     self.parser = Transport(self.argv, options=self.options)
     self.parser.catch_help = self.help()
     self.parser.parse_args()
     force = False
     if self.parser.has(['--force', '--hard-reset']):
         force = True
     if self.parser.unknown_commands:
         log.error('unknown option %s',
                   ' '.join(self.parser.unknown_commands))
         return self.parser.print_help()
     self._run(force)
Ejemplo n.º 4
0
    def main(self):
        self.parser = Transport(self.argv, options=self.options)
        self.parser.catch_help = self.help()
        self.parser.parse_args()

        # Allow user to override the distro.
        if self.parser.has('--dist'):
            if self.parser.get('--dist') is None:
                raise SystemExit('Specify a distro to --dist')
            distro = self.parser.get('--dist')
        else:
            distro = get_distro()

        if self.parser.unknown_commands:
            log.error('unknown option %s',
                      ' '.join(self.parser.unknown_commands))
            return self.parser.print_help()

        self._run(distro)
Ejemplo n.º 5
0
    def _run(self, tarball, bugstr):
        # Ensure we're on the right branch.
        current_branch = util.current_branch()
        debian_branch = util.current_debian_branch()
        if current_branch != debian_branch:
            log.error('current branch is "%s"' % current_branch)
            log.error('debian branch is "%s"' % debian_branch)
            raise RuntimeError('Must run `new-version` on debian branch')

        util.setup_pristine_tar_branch()
        self.ensure_gbp_settings()

        self.setup_upstream_branch()
        self.import_orig(tarball)
        version = self.upstream_version()
        self.run_dch(version, bugstr)

        self.commit()
        self.show()
Ejemplo n.º 6
0
    def watch(self, build_number):
        jenkins = util.jenkins_connection()

        build_info = jenkins.get_build_info('build-package', build_number)

        job_url = posixpath.join(jenkins.url, 'job', 'build-package',
                                 str(build_number))
        log.info('Watching %s' % job_url)

        pkg_name = self.pkg_name(build_info)

        start_seconds = build_info['timestamp'] / 1000.0
        # rcm-jenkins is uses the America/New_York timezone:
        jenkins_tz = tz.gettz('America/New_York')
        start = datetime.fromtimestamp(start_seconds, jenkins_tz)
        # If you want to convert to local time:
        # start = start.astimezone(tz.tzlocal())
        log.info('Started %s' % start.strftime("%F %r %z"))

        while build_info['building']:
            elapsed = datetime.now(jenkins_tz) - start
            # TODO: Xenial has python-humanize (humanize.naturaldelta() here)
            # Backport the python-humanize package for Trusty? Or drop Trusty?
            (minutes, seconds) = divmod(elapsed.total_seconds(), 60)
            # Clear the previous line:
            msg = '\r%s building for %02d:%02d' % (pkg_name, minutes, seconds)
            sys.stdout.write(msg)
            sys.stdout.flush()
            sleep(10)
            build_info = jenkins.get_build_info('build-package', build_number)

        end_millis = build_info['timestamp'] + build_info['duration']
        end_seconds = end_millis / 1000.0
        end = datetime.fromtimestamp(end_seconds, jenkins_tz)
        log.info('Ended %s' % end.strftime("%F %r %z"))

        # Show the final build result.
        if build_info['result'] == 'SUCCESS':
            log.info('result is SUCCESS')
        else:
            log.error(build_info['result'])
            raise SystemExit(1)
Ejemplo n.º 7
0
    def _run(self):
        """ Build a package in Jenkins. """
        pkg_name = util.package_name()
        branch_name = util.current_branch()
        jenkins = util.jenkins_connection()

        if branch_name.startswith('patch-queue/'):
            log.error('%s a patch-queue branch' % branch_name)
            msg = 'You can switch to the debian branch with "gbp pq switch"'
            raise SystemExit(msg)

        log.info('building %s branch %s at %s', pkg_name, branch_name,
                 posixpath.join(jenkins.url, 'job', 'build-package'))
        job_params = {'PKG_NAME': pkg_name, 'BRANCH': branch_name}

        if self._has_broken_build_job():
            jenkins.build_job = types.MethodType(_build_job_fixed, jenkins)

        jenkins.build_job('build-package', parameters=job_params,
                          token=jenkins.password)
Ejemplo n.º 8
0
    def _run(self):
        """ Build a package in Jenkins. """
        pkg_name = util.package_name()
        branch_name = util.current_branch()
        jenkins = util.jenkins_connection()

        if branch_name.startswith("patch-queue/"):
            log.error("%s a patch-queue branch" % branch_name)
            msg = 'You can switch to the debian branch with "gbp pq switch"'
            raise SystemExit(msg)

        log.info(
            "building %s branch %s at %s", pkg_name, branch_name, posixpath.join(jenkins.url, "job", "build-package")
        )
        job_params = {"PKG_NAME": pkg_name, "BRANCH": branch_name}

        if self._has_broken_build_job():
            jenkins.build_job = types.MethodType(_build_job_fixed, jenkins)

        jenkins.build_job("build-package", parameters=job_params, token=jenkins.password)
Ejemplo n.º 9
0
def get_distro():
    """
    Automatically determine the distro to use, based on the dist-git branch
    name.
    """
    branch = util.current_branch()
    branch = re.sub('^private-[^-]+-', '', branch)
    parts = branch.split('-')  # ['ceph', '3.0', 'ubuntu']
    try:
        distro = parts[2]
    except IndexError:
        log.error('could not parse dist-git branch name "%s" distro' % branch)
        log.error('try explicitly specifying a distro with --dist')
        raise
    if distro != 'ubuntu':
        return distro
    if branch.startswith('ceph-1.3'):
        return 'trusty'
    if branch.startswith('ceph-2'):
        return 'xenial'
    if branch.startswith('ceph-3'):
        return 'xenial'
    # TODO: add Ubuntu 18.04 codename here for ceph-4 when available.
    log.error('unknown default distro for dist-git branch name "%s"' % branch)
    raise NotImplementedError('specify --dist')
Ejemplo n.º 10
0
    def _run(self):
        """ Build a package in Jenkins. """
        pkg_name = util.package_name()
        branch_name = util.current_branch()
        jenkins = util.jenkins_connection()

        if branch_name.startswith('patch-queue/'):
            log.error('%s is a patch-queue branch' % branch_name)
            msg = 'You can switch to the debian branch with "gbp pq switch"'
            raise SystemExit(msg)

        log.info('building %s branch %s at %s', pkg_name, branch_name,
                 posixpath.join(jenkins.url, 'job', 'build-package'))
        job_params = {'PKG_NAME': pkg_name, 'BRANCH': branch_name}

        queue_number = jenkins.build_job('build-package',
                                         parameters=job_params,
                                         token=jenkins.password)

        # Job is now queued, not yet running.
        log.info('Waiting for build queue #%d' % queue_number)
        log.info('This may be safely interrupted...')
        queue_item = jenkins.get_queue_item(queue_number)
        while 'executable' not in queue_item:
            try:
                log.info('queue state: %s' % queue_item['why'])
                sleep(2)
                queue_item = jenkins.get_queue_item(queue_number)
            except KeyboardInterrupt:
                # We have no build_number, so just print a general message with
                # a basic URL for the user to check.
                print('')
                print('Build is queued for starting at %s' % jenkins.url)
                raise SystemExit(1)

        # Job is now running.
        build_number = queue_item['executable']['number']
        # Pass the rest over to the "watch-build" command.
        watcher = WatchBuild(['watch'])
        watcher.watch(build_number)
Ejemplo n.º 11
0
 def _run(self, build):
     configp = util.config()
     try:
         base_url = configp.get('rhcephpkg.chacra', 'url')
     except configparser.Error as err:
         raise SystemExit('Problem parsing .rhcephpkg.conf: %s',
                          err.message)
     try:
         (pkg, version) = build.split('_')
     except ValueError:
         log.error('%s is not a valid package build N-V-R' % build)
         return self.parser.print_help()
     build_url = posixpath.join(base_url, 'binaries/', pkg, version,
                                'ubuntu', 'all')
     log.info('searching %s for builds' % build_url)
     build_response = urlopen(Request(build_url))
     headers = build_response.headers
     if six.PY2:
         encoding = headers.getparam('charset') or 'utf-8'
         # if encoding is None:
         #    encoding = 'utf-8'
     else:
         encoding = headers.get_content_charset(failobj='utf-8')
     payload = json.loads(build_response.read().decode(encoding))
     for arch, binaries in six.iteritems(payload):
         for binary in binaries:
             if os.path.isfile(binary):
                 # TODO: check the sha256sum of the already-downloaded file
                 # here?
                 log.info('skipping %s' % binary)
                 continue
             log.info('downloading %s' % binary)
             binary_url = posixpath.join(build_url, arch, binary) + '/'
             response = urlopen(Request(binary_url))
             with open(binary, 'wb') as fp:
                 shutil.copyfileobj(response, fp)