Exemplo n.º 1
0
    def _run(self, force=False):
        # Determine the names of the relevant branches
        current_branch = util.current_branch()
        debian_branch = util.current_debian_branch()
        patches_branch = util.current_patches_branch()
        rhel_patches_branch = self.get_rhel_patches_branch(debian_branch)

        # Do the merge
        if current_branch == patches_branch:
            # HEAD is our patch-queue branch. Use "git pull" directly.
            # For example: "git pull --ff-only patches/ceph-2-rhel-patches"
            cmd = ['git', 'pull', '--ff-only',
                   'patches/' + rhel_patches_branch]
            if force:
                # Do a hard reset on HEAD instead.
                cmd = ['git', 'reset', '--hard',
                       'patches/' + rhel_patches_branch]
        else:
            # HEAD is our debian branch. Use "git fetch" to update the
            # patch-queue ref. For example:
            # "git fetch . \
            #  patches/ceph-2-rhel-patches:patch-queue/ceph-2-ubuntu"
            cmd = ['git', 'fetch', '.',
                   'patches/%s:%s' % (rhel_patches_branch, patches_branch)]
            if force:
                # Do a hard push (with "+") instead.
                cmd = ['git', 'push', '.', '+patches/%s:%s' %
                       (rhel_patches_branch, patches_branch)]
        log.info(' '.join(cmd))
        subprocess.check_call(cmd)
Exemplo n.º 2
0
    def _run(self, force=False):
        # Determine the names of the relevant branches
        current_branch = util.current_branch()
        debian_branch = util.current_debian_branch()
        patch_queue_branch = util.current_patch_queue_branch()
        rhel_patches_branch = self.get_rhel_patches_branch(debian_branch)

        # Do the merge
        if current_branch == patch_queue_branch:
            # HEAD is our patch-queue branch. Use "git pull" directly.
            # For example: "git pull --ff-only patches/ceph-2-rhel-patches"
            cmd = ['git', 'pull', '--ff-only',
                   'patches/' + rhel_patches_branch]
            if force:
                # Do a hard reset on HEAD instead.
                cmd = ['git', 'reset', '--hard',
                       'patches/' + rhel_patches_branch]
        else:
            # HEAD is our debian branch. Use "git fetch" to update the
            # patch-queue ref. For example:
            # "git fetch . \
            #  patches/ceph-2-rhel-patches:patch-queue/ceph-2-ubuntu"
            util.ensure_patch_queue_branch()
            cmd = ['git', 'fetch', '.',
                   'patches/%s:%s' % (rhel_patches_branch, patch_queue_branch)]
            if force:
                # Do a hard push (with "+") instead.
                cmd = ['git', 'push', '.', '+patches/%s:%s' %
                       (rhel_patches_branch, patch_queue_branch)]
        log.info(' '.join(cmd))
        subprocess.check_call(cmd)
Exemplo n.º 3
0
 def _run(self):
     """ Build a source package on the local system. """
     util.setup_pristine_tar_branch()
     cmd = ['gbp', 'buildpackage', '--git-tag', '--git-retag', '-S',
            '-us', '-uc']
     log.info(' '.join(cmd))
     subprocess.check_call(cmd)
Exemplo n.º 4
0
 def _run(self):
     """ Build a source package on the local system. """
     util.setup_pristine_tar_branch()
     cmd = [
         'gbp', 'buildpackage', '--git-tag', '--git-retag', '-S', '-us',
         '-uc'
     ]
     log.info(' '.join(cmd))
     subprocess.check_call(cmd)
Exemplo n.º 5
0
    def _run(self, patches_branch):
        debian_branch = self.get_debian_branch(patches_branch)
        if not debian_branch:
            err = 'could not find debian branch for %s' % patches_branch
            raise SystemExit(err)

        cmd = ['git', 'checkout', debian_branch]
        log.info(' '.join(cmd))
        subprocess.check_call(cmd)
Exemplo n.º 6
0
 def import_orig(self, tarball=None):
     """ Import new upstream tarball, optionally with uscan. """
     cmd = ['gbp', 'import-orig', '--no-interactive']
     if tarball is None:
         cmd.append('--uscan')
     else:
         cmd.append(tarball)
     log.info(' '.join(cmd))
     subprocess.check_call(cmd)
Exemplo n.º 7
0
 def run_dch(self, version, bugstr):
     """ Edit debian/changelog for a new upstream release """
     version_release = version + '-2redhat1'
     text = 'Imported Upstream version %s' % version
     if bugstr:
         text = '%s (%s)' % (text, bugstr)
     dist = changelog.distribution()  # reuse previous distribution
     cmd = ['dch', '-D', dist, '-v', version_release, text]
     log.info(' '.join(cmd))
     subprocess.check_call(cmd)
Exemplo n.º 8
0
def find_patches_url(configp, user, pkg):
    """ Return a verified Git URL for this package's RHEL patches. """
    try:
        patchesbaseurl = configp.get('rhcephpkg', 'patchesbaseurl')
    except configparser.Error:
        log.info('no patchesbaseurl configured, skipping patches remote')
        return None
    # Ubuntu python packages are named eg. "execnet", whereas the RPM name is
    # "python-execnet".
    for module in [pkg, 'python-%s' % pkg]:
        patches_url = patchesbaseurl % {'user': user, 'module': module}
        if check_git_url(patches_url):
            return patches_url
Exemplo n.º 9
0
def setup_pbuilder_cache(pbuilder_cache, distro):
    # Delete existing cache file if it is bogus (zero-length).
    if os.path.isfile(pbuilder_cache):
        if os.stat(pbuilder_cache).st_size == 0:
            log.info('deleting 0 length %s', pbuilder_cache)
            cmd = ['sudo', 'rm', pbuilder_cache]
            subprocess.check_call(cmd)
    # Set up the cache if it does not exist.
    if not os.path.isfile(pbuilder_cache):
        log.info('initializing pbuilder cache %s', pbuilder_cache)
        cmd = [
            'sudo', 'pbuilder', 'create', '--debootstrapopts',
            '--variant=buildd', '--basetgz', pbuilder_cache, '--distribution',
            distro
        ]
        subprocess.check_call(cmd)
Exemplo 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 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)
Exemplo n.º 11
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)
Exemplo n.º 12
0
    def _run(self, distro):
        """ Build a package on the local system, using pbuilder. """
        pkg_name = util.package_name()

        os.environ['BUILDER'] = 'pbuilder'
        j_arg = self._get_j_arg(cpu_count())
        pbuilder_cache = '/var/cache/pbuilder/base-%s-amd64.tgz' % distro
        if not os.path.isfile(pbuilder_cache):
            cmd = ['sudo', 'pbuilder', 'create', '--debootstrapopts',
                   '--variant=buildd', '--basetgz', pbuilder_cache,
                   '--distribution', distro]
            log.info('initializing pbuilder cache %s', pbuilder_cache)
            subprocess.check_call(cmd)
        # TODO: we should also probably check parent dir for leftovers and warn
        # the user to delete them (or delete them ourselves?)
        cmd = ['gbp', 'buildpackage', '--git-dist=%s' % distro,
               '--git-arch=amd64', '--git-verbose', '--git-pbuilder', j_arg,
               '-us', '-uc']

        log.info('building %s with pbuilder', pkg_name)
        subprocess.check_call(cmd)
Exemplo n.º 13
0
    def _run(self, distro):
        """ Build a package on the local system, using pbuilder. """
        pkg_name = util.package_name()

        os.environ['BUILDER'] = 'pbuilder'
        j_arg = self._get_j_arg(cpu_count())
        pbuilder_cache = '/var/cache/pbuilder/base-%s-amd64.tgz' % distro

        setup_pbuilder_cache(pbuilder_cache, distro)

        util.setup_pristine_tar_branch()

        # TODO: we should also probably check parent dir for leftovers and warn
        # the user to delete them (or delete them ourselves?)
        cmd = [
            'gbp', 'buildpackage',
            '--git-dist=%s' % distro, '--git-arch=amd64', '--git-verbose',
            '--git-pbuilder', j_arg, '-us', '-uc'
        ]

        log.info('building %s with pbuilder', pkg_name)
        subprocess.check_call(cmd)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
0
 def _run(self):
     """ Build a source package on the local system. """
     cmd = ['gbp', 'buildpackage', '--git-tag', '--git-retag', '-S',
            '-us', '-uc']
     log.info(' '.join(cmd))
     subprocess.check_call(cmd)
Exemplo n.º 18
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)