Ejemplo n.º 1
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.º 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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.º 5
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.º 6
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.º 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 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.º 8
0
 def test_current_branch(self, testpkg):
     assert util.current_branch() == 'ceph-2-ubuntu'
Ejemplo n.º 9
0
    def _run(self):
        """ Generate quilt patch series with gbp pq, and update d/rules """

        # Determine the names of the patch-queue branch and debian branch
        current_branch = util.current_branch()
        patch_queue_branch = util.current_patch_queue_branch()
        debian_branch = util.current_debian_branch()

        # TODO: default to fetching from upstream, the way rdopkg patch does.

        # Get the new sha1 to insert into the $COMMIT variable in d/rules
        cmd = ['git', 'rev-parse', patch_queue_branch]
        output = subprocess.check_output(cmd)
        patch_queue_sha1 = output.rstrip()
        if six.PY3:
            patch_queue_sha1 = output.decode('utf-8').rstrip()

        # Switch to "debian" branch if necessary
        if current_branch != debian_branch:
            cmd = ['git', 'checkout', debian_branch]
            subprocess.check_call(cmd)

        # Get the original (old) patch series
        old_series = self.read_series_file('debian/patches/series')
        old_subjects = [patch.subject for patch in old_series]

        # Git-buildpackage pq operation
        cmd = ['gbp', 'pq', 'export']
        subprocess.check_call(cmd)

        # Add all patch files to Git's index
        cmd = ['git', 'add', '--all', 'debian/patches']
        subprocess.check_call(cmd)

        # Bail early if gbp pq did nothing.
        if not self.read_git_debian_patches_status():
            print('No new patches, quitting.')
            raise SystemExit(1)

        # Replace $COMMIT sha1 in d/rules
        old_sha1 = read_commit()
        if old_sha1:
            rules = read_rules_file()
            with open('debian/rules', 'w') as fileh:
                fileh.write(rules.replace(old_sha1, patch_queue_sha1))

        # Get the new patch series
        new_series = self.read_series_file('debian/patches/series')
        # Select only the ones that are new (according to commit subjects)
        new_series = [p for p in new_series if p.subject not in old_subjects]

        if not new_series:
            # Maybe we rewrote some patch files in place?
            # Check Git itself for changed files:
            new_series = self.read_git_debian_patches()

        # Add patch entries to d/changelog
        changelog = self.generate_changelog(new_series)
        try:
            ensure_bzs(changelog)
        except BzNotFound:
            if not self.parser.has('--nobz'):
                raise
        util.bump_changelog(changelog)

        # Assemble a standard commit message string "clog".
        clog = "debian: %s\n" % util.get_deb_version()
        clog += "\n"
        clog += "Add patches from %s\n" % patch_queue_branch
        clog += "\n"
        clog += util.format_changelog(changelog)

        # Commit everything with the standard commit message.
        with tempfile.NamedTemporaryFile(mode='w+') as temp:
            temp.write(clog)
            temp.flush()
            cmd = [
                'git', 'commit', 'debian/changelog', 'debian/patches',
                'debian/rules', '-F', temp.name
            ]
            subprocess.check_call(cmd)

        # Summarize this commit on STDOUT for the developer.
        # (This matches the behavior of "rdopkg patch".)
        cmd = ['git', '--no-pager', 'log', '--name-status', 'HEAD~..HEAD']
        subprocess.check_call(cmd)
Ejemplo n.º 10
0
    def _run(self):
        """ Generate quilt patch series with gbp pq, and update d/rules """

        # Determine the names of the patch-queue branch and debian branch
        current_branch = util.current_branch()
        patches_branch = util.current_patches_branch()
        debian_branch = util.current_debian_branch()

        # TODO: default to fetching from upstream, the way rdopkg patch does.

        # Get the new sha1 to insert into the $COMMIT variable in d/rules
        cmd = ['git', 'rev-parse', patches_branch]
        patches_sha1 = subprocess.check_output(cmd).rstrip()

        # Switch to "debian" branch if necessary
        if current_branch != debian_branch:
            cmd = ['git', 'checkout', debian_branch]
            subprocess.check_call(cmd)

        # Get the original (old) patch series
        old_series = self.read_series_file('debian/patches/series')
        old_subjects = map(lambda x: x.subject, old_series)

        # Git-buildpackage pq operation
        cmd = ['gbp', 'pq', 'export']
        subprocess.check_call(cmd)

        # Add all patch files to Git's index
        cmd = ['git', 'add', '--all', 'debian/patches']
        subprocess.check_call(cmd)

        # Replace $COMMIT sha1 in d/rules
        with open('debian/rules') as rules:
            rules_file = rules.read()
        old = r'export COMMIT=[0-9a-f]{40}'
        new = 'export COMMIT=%s' % patches_sha1
        with open('debian/rules', 'w') as fileh:
            fileh.write(re.sub(old, new, rules_file))

        # Get the new patch series
        new_series = self.read_series_file('debian/patches/series')

        # Add patch entries to d/changelog
        changelog = []
        for p in new_series:
            if p.subject in old_subjects:
                continue
            change = p.subject
            bzs = self.get_rhbzs(p)
            bzstr = ' '.join(map(lambda x: 'rhbz#%s' % x, bzs))
            if bzstr != '':
                change += ' (%s)' % bzstr
            changelog.append(change)
        util.bump_changelog(changelog)

        # Assemble a standard commit message string "clog".
        clog = "debian: %s\n" % util.get_deb_version()
        clog += "\n"
        clog += "Add patches from %s\n" % patches_branch
        clog += "\n"
        clog += util.format_changelog(changelog)

        # Commit everything with the standard commit message.
        with tempfile.NamedTemporaryFile() as temp:
            temp.write(clog)
            temp.flush()
            cmd = [
                'git', 'commit', 'debian/changelog', 'debian/patches',
                'debian/rules', '-F', temp.name
            ]
            subprocess.check_call(cmd)

        # Summarize this commit on STDOUT for the developer.
        # (This matches the behavior of "rdopkg patch".)
        cmd = ['git', '--no-pager', 'log', '--name-status', 'HEAD~..HEAD']
        subprocess.check_call(cmd)
Ejemplo n.º 11
0
 def test_current_branch(self, monkeypatch):
     monkeypatch.setattr('subprocess.check_output', self.fake_check_output)
     branch = util.current_branch()
     assert self.last_cmd == ['git', 'rev-parse', '--abbrev-ref', 'HEAD']
     assert branch == 'fake-branch'
Ejemplo n.º 12
0
 def test_current_branch(self, testpkg, monkeypatch):
     assert util.current_branch() == 'ceph-2-ubuntu'
Ejemplo n.º 13
0
 def test_current_branch(self, testpkg, monkeypatch):
     assert util.current_branch() == 'ceph-2-ubuntu'