Ejemplo n.º 1
0
    def test_list_overrides_by_multiple_usernames(self):
        release = Release.get('F17')

        package = RpmPackage(name='just-testing')
        self.db.add(package)
        build = RpmBuild(nvr='just-testing-1.0-2.fc17', package=package, release=release)
        self.db.add(build)
        another_user = User(name='aUser')
        self.db.add(another_user)

        expiration_date = datetime.utcnow() + timedelta(days=1)

        override = BuildrootOverride(build=build, submitter=another_user,
                                     notes='Crazy! 😱',
                                     expiration_date=expiration_date)
        self.db.add(override)
        self.db.flush()

        res = self.app.get('/overrides/', {"user": "******"})
        body = res.json_body
        self.assertEqual(len(body['overrides']), 2)

        override_fake = body['overrides'][0]
        self.assertEqual(override_fake['build']['nvr'], 'just-testing-1.0-2.fc17')
        self.assertEqual(override_fake['submitter']['name'], 'aUser')
        self.assertEqual(override_fake['notes'], 'Crazy! 😱')

        override_orig = body['overrides'][1]
        self.assertEqual(override_orig['build']['nvr'], 'bodhi-2.0-1.fc17')
        self.assertEqual(override_orig['submitter']['name'], 'guest')
        self.assertEqual(override_orig['notes'], 'blah blah blah')
Ejemplo n.º 2
0
def create_update(session, build_nvrs, release_name='F17'):
    """
    Use the given session to create and return an Update with the given iterable of build_nvrs.

    Each build_nvr should be a string describing the name, version, and release for the build
    separated by dashes. For example, build_nvrs might look like this:

    ('bodhi-2.3.3-1.fc24', 'python-fedora-atomic-composer-2016.3-1.fc24')

    You can optionally pass a release_name to select a different release than the default F17, but
    the release must already exist in the database.

    Args:
        build_nvrs (iterable): An iterable of strings of NVRs to put into the update.
        release_name (str): The name of the release to associate with the update.
    Returns:
        bodhi.server.models.Update: The generated update.
    """
    release = session.query(Release).filter_by(name=release_name).one()
    user = session.query(User).filter_by(name='guest').one()

    builds = []
    for nvr in build_nvrs:
        name, version, rel = nvr.rsplit('-', 2)
        try:
            package = session.query(RpmPackage).filter_by(name=name).one()
        except sqlalchemy.orm.exc.NoResultFound:
            package = RpmPackage(name=name)
            session.add(package)
            testcase = TestCase(name='Wat')
            session.add(testcase)
            package.test_cases.append(testcase)

        builds.append(
            RpmBuild(nvr=nvr, release=release, package=package, signed=True))
        session.add(builds[-1])

        # Add a buildroot override for this build
        expiration_date = datetime.utcnow()
        expiration_date = expiration_date + timedelta(days=1)
        override = BuildrootOverride(build=builds[-1],
                                     submitter=user,
                                     notes='blah blah blah',
                                     expiration_date=expiration_date)
        session.add(override)

    update = Update(builds=builds,
                    user=user,
                    request=UpdateRequest.testing,
                    notes='Useful details!',
                    type=UpdateType.bugfix,
                    date_submitted=datetime(1984, 11, 2),
                    requirements='rpmlint',
                    stable_karma=3,
                    unstable_karma=-3,
                    release=release)
    session.add(update)
    return update
Ejemplo n.º 3
0
def save_override(request):
    """
    Create or edit a buildroot override.

    This entails either creating a new buildroot override, or editing an
    existing one. To edit an existing buildroot override, the buildroot
    override's original id needs to be specified in the ``edited`` parameter.

    Args:
        request (pyramid.request): The current web request.
    Returns:
        dict: The new or edited override.
    """
    data = request.validated

    edited = data.pop("edited")

    caveats = []
    try:
        submitter = User.get(request.user.name)
        if edited is None:
            builds = data['builds']
            overrides = []
            if len(builds) > 1:
                caveats.append({
                    'name':
                    'nvrs',
                    'description':
                    'Your override submission was '
                    'split into %i.' % len(builds)
                })
            for build in builds:
                log.info("Creating a new buildroot override: %s" % build.nvr)
                existing_override = BuildrootOverride.get(build.id)
                if existing_override:
                    if not existing_override.expired_date:
                        data['expiration_date'] = max(
                            existing_override.expiration_date,
                            data['expiration_date'])

                    new_notes = f"""{data['notes']}
_____________
_@{existing_override.submitter.name} ({existing_override.submission_date.strftime('%b %d, %Y')})_
{existing_override.notes}"""
                    # Truncate notes at 2000 chars
                    if len(new_notes) > 2000:
                        new_notes = new_notes[:1972] + '(...)\n___Notes truncated___'

                    overrides.append(
                        BuildrootOverride.edit(
                            request,
                            edited=build,
                            submitter=submitter,
                            submission_date=datetime.now(),
                            notes=new_notes,
                            expiration_date=data['expiration_date'],
                            expired=None,
                        ))
                else:
                    overrides.append(
                        BuildrootOverride.new(
                            request,
                            build=build,
                            submitter=submitter,
                            notes=data['notes'],
                            expiration_date=data['expiration_date'],
                        ))

            if len(builds) > 1:
                result = dict(overrides=overrides)
            else:
                result = overrides[0]
        else:
            log.info("Editing buildroot override: %s" % edited)

            edited = Build.get(edited)

            if edited is None:
                request.errors.add('body', 'edited', 'No such build')
                return

            result = BuildrootOverride.edit(
                request,
                edited=edited,
                submitter=submitter,
                notes=data["notes"],
                expired=data["expired"],
                expiration_date=data["expiration_date"])

            if not result:
                # Some error inside .edit(...)
                return

    except Exception as e:
        log.exception(e)
        request.errors.add('body', 'override',
                           'Unable to save buildroot override: %s' % e)
        return

    if not isinstance(result, dict):
        result = result.__json__()

    result['caveats'] = caveats

    return result
Ejemplo n.º 4
0
def save_override(request):
    """
    Create or edit a buildroot override.

    This entails either creating a new buildroot override, or editing an
    existing one. To edit an existing buildroot override, the buildroot
    override's original id needs to be specified in the ``edited`` parameter.

    Args:
        request (pyramid.request): The current web request.
    Returns:
        dict: The new or edited override.
    """
    data = request.validated

    edited = data.pop("edited")

    caveats = []
    try:
        submitter = User.get(request.user.name)
        if edited is None:
            builds = data['builds']
            overrides = []
            if len(builds) > 1:
                caveats.append({
                    'name': 'nvrs',
                    'description': 'Your override submission was '
                    'split into %i.' % len(builds)
                })
            for build in builds:
                log.info("Creating a new buildroot override: %s" % build.nvr)
                if BuildrootOverride.get(build.id):
                    request.errors.add('body', 'builds',
                                       'Buildroot override for %s already exists' % build.nvr)
                    return
                else:
                    overrides.append(BuildrootOverride.new(
                        request,
                        build=build,
                        submitter=submitter,
                        notes=data['notes'],
                        expiration_date=data['expiration_date'],
                    ))

            if len(builds) > 1:
                result = dict(overrides=overrides)
            else:
                result = overrides[0]
        else:
            log.info("Editing buildroot override: %s" % edited)

            edited = Build.get(edited)

            if edited is None:
                request.errors.add('body', 'edited', 'No such build')
                return

            result = BuildrootOverride.edit(
                request, edited=edited, submitter=submitter,
                notes=data["notes"], expired=data["expired"],
                expiration_date=data["expiration_date"])

            if not result:
                # Some error inside .edit(...)
                return

    except Exception as e:
        log.exception(e)
        request.errors.add('body', 'override',
                           'Unable to save buildroot override: %s' % e)
        return

    if not isinstance(result, dict):
        result = result.__json__()

    result['caveats'] = caveats

    return result