Example #1
0
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        pkg_branch=acl.collection.branchname,
                        status='Retired',
                        user=flask.g.fas_user
                    )
                    flask.flash(
                        'This package has been retired on branch: %s'
                        % collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(str(err), 'error')
                    SESSION.rollback()
                break
            else:
                flask.flash(
                    'This package has not been orphaned on '
                    'branch: %s' % collection)
Example #2
0
def package_retire(package, full=True):
    ''' Gives the possibility to orphan or take a package. '''

    if not bool(full) or str(full) in ['0', 'False']:
        full = False

    try:
        package_acl = pkgdblib.get_acl_package(SESSION, package)
        package = pkgdblib.search_package(SESSION, package, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    if not is_pkgdb_admin(flask.g.fas_user):
        flask.flash(
            'Only Admins are allowed to retire package here, '
            'you should use `fedpkg retire`.', 'errors')
        return flask.redirect(
            flask.url_for('.package_info', package=package.name))

    collections = [
        acl.collection.branchname for acl in package_acl
        if acl.collection.status in ['Active', 'Under Development']
        and acl.status == 'Orphaned'
    ]

    form = pkgdb2.forms.BranchForm(collections=collections)

    if form.validate_on_submit():
        for acl in package_acl:
            if acl.collection.branchname in form.branches.data:
                if acl.point_of_contact == 'orphan':
                    try:
                        pkgdblib.update_pkg_status(
                            session=SESSION,
                            pkg_name=package.name,
                            pkg_branch=acl.collection.branchname,
                            status='Retired',
                            user=flask.g.fas_user)
                        flask.flash(
                            'This package has been retired on branch: %s' %
                            acl.collection.branchname)
                    except pkgdblib.PkgdbException, err:  # pragma: no cover
                        # We should never hit this
                        flask.flash(str(err), 'error')
                        SESSION.rollback()
                        APP.logger.exception(err)
                else:  # pragma: no cover
                    flask.flash('This package has not been orphaned on '
                                'branch: %s' % acl.collection.branchname)

        try:
            SESSION.commit()
        # Keep it in, but normally we shouldn't hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            # We should never hit this
            SESSION.rollback()
            APP.logger.exception(err)
            flask.flash(str(err), 'error')
Example #3
0
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, packagename)
        package = pkgdblib.search_package(SESSION, packagename, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        pkg_branch=acl.collection.branchname,
                        status='Retired',
                        user=flask.g.fas_user)
                    flask.flash('This package has been retired on branch: %s' %
                                collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(str(err), 'error')
                    SESSION.rollback()
                break
            else:
                flask.flash('This package has not been orphaned on '
                            'branch: %s' % collection)
Example #4
0
def api_package_unretire():
    '''
    Unretire packages
    -----------------
    Un-retire one or more packages.

    ::

        /api/package/unretire/

    Accepts POST queries only.

    :arg pkgnames: Comma separated list of the packages names.
    :arg branches: Comma separated list of string of the branches names in
        which these packages will be un-deprecated.


    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to update the status of "
                    "the package: $PACKAGE on branch $BRANCH to $STATUS."]
        }

    '''
    httpcode = 200
    output = {}

    pkgnames = flask.request.form.getlist('pkgnames', None)
    branches = flask.request.form.getlist('branches', None)

    if pkgnames and branches:
        try:
            messages = []
            for pkg_name, pkg_branch in itertools.product(pkgnames, branches):
                message = pkgdblib.update_pkg_status(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=pkg_branch,
                    status='Approved',
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = str(err)
            httpcode = 500
Example #5
0
def api_package_retire():
    '''
Retire packages
---------------
    Retire one or more packages.

    ::

        /api/package/retire/

    Accept POST queries only.

    :arg pkgnames: Comma separated list of string of the packages name.
    :arg branches: Comma separated list of string of the branches name in
        which these packages will be retire.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to retire the package: $PACKAGE "
                    "on branch $BRANCH."]
        }

    '''
    httpcode = 200
    output = {}

    pkgnames = flask.request.form.getlist('pkgnames', None)
    branches = flask.request.form.getlist('branches', None)

    if pkgnames and branches:
        try:
            messages = []
            for pkg_name, pkg_branch in itertools.product(
                    pkgnames, branches):
                message = pkgdblib.update_pkg_status(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=pkg_branch,
                    status='Retired',
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = str(err)
            httpcode = 500
Example #6
0
def api_package_unretire():
    """
    Unretire packages
    -----------------
    Un-retire one or more packages.

    ::

        /api/package/unretire/

    Accepts POST queries only.

    :arg pkgnames: Comma separated list of the packages names.
    :arg branches: Comma separated list of string of the branches names in
        which these packages will be un-deprecated.


    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to update the status of "
                    "the package: $PACKAGE on branch $BRANCH to $STATUS."]
        }

    """
    httpcode = 200
    output = {}

    pkgnames = flask.request.form.getlist("pkgnames", None)
    branches = flask.request.form.getlist("branches", None)

    if pkgnames and branches:
        try:
            messages = []
            for pkg_name, pkg_branch in itertools.product(pkgnames, branches):
                message = pkgdblib.update_pkg_status(
                    SESSION, pkg_name=pkg_name, pkg_branch=pkg_branch, status="Approved", user=flask.g.fas_user
                )
                messages.append(message)
            SESSION.commit()
            output["output"] = "ok"
            output["messages"] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output["output"] = "notok"
            output["error"] = str(err)
            httpcode = 500
Example #7
0
def api_package_retire():
    '''
Retire packages
---------------
    Retire one or more packages.

    ::

        /api/package/retire/

    Accept POST queries only.

    :arg pkgnames: Comma separated list of string of the packages name.
    :arg branches: Comma separated list of string of the branches name in
        which these packages will be retire.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to retire the package: $PACKAGE "
                    "on branch $BRANCH."]
        }

    '''
    httpcode = 200
    output = {}

    pkgnames = flask.request.form.getlist('pkgnames', None)
    branches = flask.request.form.getlist('branches', None)

    if pkgnames and branches:
        try:
            messages = []
            errors = set()
            for pkg_name, pkg_branch in itertools.product(
                    pkgnames, branches):
                message = pkgdblib.update_pkg_status(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=pkg_branch,
                    status='Retired',
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            errors.add(str(err))

        if messages:
            output['messages'] = messages
            output['output'] = 'ok'
        else:
            # If messages is empty that means that we failed all the
            # retire so output is `notok`, otherwise it means that we
            # succeeded at least once and thus output will be `ok` to keep
            # backward compatibility.
            httpcode = 500
            output['output'] = 'notok'

        if errors:
            errors = list(errors)
            output['error'] = errors
            if len(errors) == 1:
                output['error'] = errors.pop()
Example #8
0
def api_package_retire():
    '''
    Retire packages
    ---------------
    Retire one or more packages.

    ::

        /api/package/retire/

    Accepts POST queries only.

    :arg pkgnames: Comma separated list of string of the packages name.
    :arg branches: Comma separated list of string of the branches name in
        which these packages will be retire.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to retire the package: $PACKAGE "
                    "on branch $BRANCH."]
        }

    '''
    httpcode = 200
    output = {}

    pkgnames = flask.request.form.getlist('pkgnames', None)
    branches = flask.request.form.getlist('branches', None)

    if pkgnames and branches:
        try:
            messages = []
            errors = set()
            for pkg_name, pkg_branch in itertools.product(pkgnames, branches):
                message = pkgdblib.update_pkg_status(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=pkg_branch,
                    status='Retired',
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            errors.add(str(err))

        if messages:
            output['messages'] = messages
            output['output'] = 'ok'
        else:
            # If messages is empty that means that we failed all the
            # retire so output is `notok`, otherwise it means that we
            # succeeded at least once and thus output will be `ok` to keep
            # backward compatibility.
            httpcode = 500
            output['output'] = 'notok'

        if errors:
            errors = list(errors)
            output['error'] = errors
            if len(errors) == 1:
                output['error'] = errors.pop()
Example #9
0
def api_package_unretire():
    '''
Unretire packages
-----------------
    Un-retire one or more packages.

    ::

        /api/package/unretire/

    Accept POST queries only.

    :arg pkg_name: Comma separated list of the packages names.
    :arg clt_name: Comma separated list of string of the branches names in
        which these packages will be un-deprecated.


    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to update the status of "
                    "the package: $PACKAGE on branch $BRANCH to $STATUS."]
        }

    '''
    httpcode = 200
    output = {}

    form = forms.DeprecatePackageForm(csrf_enabled=False)
    if form.validate_on_submit():
        pkg_names = form.pkg_name.data.split(',')
        pkg_branchs = form.clt_name.data.split(',')

        try:
            messages = []
            for pkg_name, pkg_branch in itertools.product(
                    pkg_names, pkg_branchs):
                message = pkgdblib.update_pkg_status(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=pkg_branch,
                    status='Approved',
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = str(err)
            httpcode = 500
Example #10
0
def api_package_unretire():
    '''
    Unretire packages
    -----------------
    Un-retire one or more packages.

    ::

        /api/package/unretire/

    Accepts POST queries only.

    :arg pkgnames: Comma separated list of the packages names.
    :arg branches: Comma separated list of string of the branches names in
        which these packages will be un-deprecated.
    :kwarg namespace: The namespace of the package to unretire (can only
        process one namespace at a time), defaults to ``rpms``.


    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to update the status of "
                    "the package: $PACKAGE on branch $BRANCH to $STATUS."]
        }

    '''
    httpcode = 200
    output = {}

    pkgnames = flask.request.form.getlist('pkgnames', None)
    branches = flask.request.form.getlist('branches', None)
    namespace = flask.request.form.get('namespace', 'rpms')

    if pkgnames and branches:
        try:
            messages = []
            for pkg_name, pkg_branch in itertools.product(
                    pkgnames, branches):
                message = pkgdblib.update_pkg_status(
                    SESSION,
                    namespace=namespace,
                    pkg_name=pkg_name,
                    pkg_branch=pkg_branch,
                    status='Approved',
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = str(err)
            httpcode = 500
Example #11
0
def package_retire(namespace, package, full=True):
    ''' Gives the possibility to orphan or take a package. '''

    if not bool(full) or str(full) in ['0', 'False']:
        full = False

    try:
        package_acl = pkgdblib.get_acl_package(
            SESSION, namespace, package)
        package = pkgdblib.search_package(
            SESSION, namespace, package, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    if not is_pkgdb_admin(flask.g.fas_user):
        flask.flash(
            'Only Admins are allowed to retire package here, '
            'you should use `fedpkg retire`.', 'errors')
        return flask.redirect(flask.url_for(
            '.package_info',
            namespace=package.namespace,
            package=package.name)
        )

    collections = [
        acl.collection.branchname
        for acl in package_acl
        if acl.collection.status in ['Active', 'Under Development']
        and acl.status == 'Orphaned'
    ]

    form = pkgdb2.forms.BranchForm(collections=collections)

    if form.validate_on_submit():
        for acl in package_acl:
            if acl.collection.branchname in form.branches.data:
                if acl.point_of_contact == 'orphan':
                    try:
                        pkgdblib.update_pkg_status(
                            session=SESSION,
                            namespace=namespace,
                            pkg_name=package.name,
                            pkg_branch=acl.collection.branchname,
                            status='Retired',
                            user=flask.g.fas_user
                        )
                        flask.flash(
                            'This package has been retired on branch: %s'
                            % acl.collection.branchname)
                    except PkgdbException as err:  # pragma: no cover
                        # We should never hit this
                        flask.flash(str(err), 'error')
                        SESSION.rollback()
                        APP.logger.exception(err)
                else:  # pragma: no cover
                    flask.flash(
                        'This package has not been orphaned on '
                        'branch: %s' % acl.collection.branchname)

        try:
            SESSION.commit()
        # Keep it in, but normally we shouldn't hit this
        except PkgdbException as err:  # pragma: no cover
            # We should never hit this
            SESSION.rollback()
            APP.logger.exception(err)
            flask.flash(str(err), 'error')

        return flask.redirect(flask.url_for(
            '.package_info',
            namespace=package.namespace,
            package=package.name)
        )

    return flask.render_template(
        'branch_selection.html',
        full=full,
        package=package,
        form=form,
        action='retire',
    )
Example #12
0
    def test_orphan_group_package(self, bz_owner):
        """ Test the is_pkgdb_admin function of pkgdb2. """
        bz_owner.return_value = None

        create_collection(self.session)
        create_package(self.session)

        guake_pkg = model.Package.by_name(self.session, 'guake')
        fedocal_pkg = model.Package.by_name(self.session, 'fedocal')

        f18_collec = model.Collection.by_name(self.session, 'f18')
        devel_collec = model.Collection.by_name(self.session, 'master')

        # Pkg: guake - Collection: master - Approved
        pkgltg = model.PackageListing(
            point_of_contact='group::infra-sig',
            status='Approved',
            package_id=guake_pkg.id,
            collection_id=devel_collec.id,
        )
        self.session.add(pkgltg)

        # Pkg: guake - Collection: f18 - Approved
        pkgltg = model.PackageListing(
            point_of_contact='pingou',
            status='Approved',
            package_id=guake_pkg.id,
            collection_id=f18_collec.id,
        )
        self.session.add(pkgltg)

        # Pkg: fedocal - Collection: master - Approved
        pkgltg = model.PackageListing(
            point_of_contact='group::infra-sig',
            status='Approved',
            package_id=fedocal_pkg.id,
            collection_id=devel_collec.id,
        )
        self.session.add(pkgltg)

        user = FakeFasUser()

        # Orphan allowed (?)
        msg = pkgdblib.update_pkg_status(
            self.session, pkg_name='fedocal', pkg_branch='master',
            status='Orphaned', user=user, poc='orphan')

        self.assertEqual(
            msg,
            'user: pingou updated package: fedocal status from: Approved to '
            'Orphaned on branch: master')

        # Retired blocked
        msg = pkgdblib.update_pkg_status(
            self.session, pkg_name='guake', pkg_branch='master',
            status='Retired', user=user, poc='orphan')

        self.assertEqual(
            msg,
            'user: pingou updated package: guake status from: Approved to '
            'Retired on branch: master')
Example #13
0
def api_package_retire():
    '''
Retire packages
---------------
    Retire one or more packages.

    ::

        /api/package/retire/

    Accept POST queries only.

    :arg pkg_name: Comma separated list of string of the packages name.
    :arg clt_name: Comma separated list of string of the branches name in
        which these packages will be retire.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER updated package: $PACKAGE status from: "
                       "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to retire the package: $PACKAGE "
                    "on branch $BRANCH."]
        }

    '''
    httpcode = 200
    output = {}

    form = forms.DeprecatePackageForm(csrf_enabled=False)
    if form.validate_on_submit():
        pkg_names = form.pkg_name.data.split(',')
        pkg_branchs = form.clt_name.data.split(',')

        try:
            messages = []
            for pkg_name, pkg_branch in itertools.product(
                    pkg_names, pkg_branchs):
                message = pkgdblib.update_pkg_status(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=pkg_branch,
                    status='Retired',
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = str(err)
            httpcode = 500