Skip to content

Commit

Permalink
Add critical path support to bodhi cli.
Browse files Browse the repository at this point in the history
This commit allow the use of bodhi cli to access the critical path
API. This add 2 command critpah list and critpath set.

Co-authored-by: Vismay Golwala [email protected]
Co-authored-by: Clement Verna [email protected]
Signed-off-by: Clement Verna <[email protected]>
  • Loading branch information
cverna committed Mar 14, 2019
1 parent febef27 commit 5e29c36
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 51 deletions.
84 changes: 84 additions & 0 deletions bodhi/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,90 @@ def print_release(release):
click.echo(" Composed by Bodhi: %s" % release['composed_by_bodhi'])


def print_critpath_packages(packages):
"""
Print critical path packages of a release.
Args:
packages (list): list of Package objects that are in critical path for this Release.
"""

if packages:
package_names = sorted([pkg['name'] for pkg in packages])
click.echo("Critical path packages:")
for pkg_name in package_names:
click.echo(" - {}".format(pkg_name))
else:
click.echo("No critical path packages for this release.")


@releases.group(name='critpath')
def critpath_pkgs():
"""Manage critical path packages."""
pass # pragma: no cover


@critpath_pkgs.command(name='list')
@handle_errors
@click.argument('release')
@url_option
@staging_option
def list_critpath_packages(release, url, staging, **kwargs):
# User Docs that show in the --help
"""
List critical path packages of a release.
RELEASE: Release name (e.g. F27)
"""
# Developer Docs
"""
Args:
release (unicode): The release name to query.
url (unicode): The URL of a Bodhi server to query on. Ignored if staging is
True.
staging (bool): Whether to use the staging server or not.
kwargs (dict): Other keyword arguments passed to us by click.
"""
client = bindings.BodhiClient(base_url=url, staging=staging)
res = client.get_critpath_packages(release=release)

print_critpath_packages(res.get("packages"))


@critpath_pkgs.command(name='set')
@handle_errors
@click.option('--user')
@click.option('--password', hide_input=True)
@click.argument('release')
@click.argument('packages')
@url_option
@staging_option
def set_critpath_packages(user, password, release, packages, url, staging, **kwargs):
# User Docs that show in the --help
"""
Set a list of critical path packages to a release.
RELEASE: Release name (e.g. F27)
[PACKAGES]: comma separated list of packages to add (e.g. firefox,vim,python)
"""
# Developer Docs
"""
Args:
release (unicode): The release name to add critpath packages to.
packages (str): A string of comma separated package names to add.
url (unicode): The URL of a Bodhi server to query on. Ignored if staging is
True.
staging (bool): Whether to use the staging server or not.
kwargs (dict): Other keyword arguments passed to us by click.
"""
client = bindings.BodhiClient(base_url=url, username=user, password=password, staging=staging)

res = client.set_critpath_packages(release=release, packages=packages)

print_critpath_packages(res.get("packages"))


def print_errors(data):
"""
Print errors to the terminal and exit with code 1.
Expand Down
58 changes: 58 additions & 0 deletions bodhi/client/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,64 @@ def get_releases(self, **kwargs):
"""
return self.send_request('releases/', verb='GET', params=kwargs)

@errorhandled
def get_critpath_packages(self, release: str) -> dict:
"""
Get a list of critical path packages for a release.
Args:
release: The release name to query for.
Returns:
A dictionary returned by critpath_package_requests() method.
"""
return self.critpath_package_request(release=release, verb='GET', auth=False, data=None)

@errorhandled
def set_critpath_packages(self, release, packages):
"""
Add a list of critical path packages to a release.
Args:
release (unicode): The release name to add packages to.
packages (list): List of critpath package names to add.
Returns:
dict: A dictionary returned by critpath_package_requests() method.
"""
return self.critpath_package_request(
release=release, verb='POST', auth=True, data={'packages': packages}
)

@errorhandled
def critpath_package_request(self, release, verb, auth, data):
"""
Return a list of critical path packages for a release after request.
Request can be for set critpath packages,or get critpath packages
for the release.
This method returns a dictionary in the following format::
{"packages": [
{"type": "rpm", "requirements": null,
"name": "python", "stack": null}]}
Args:
release (unicode): The release name to interact with.
verb (unicode): Type of request to make.
'GET': list packages
'POST': set packages
auth (bool): Whether to authenticate for send_request.
data (dict or unicode): data to be sent along the request.
Returns:
dict: A dictionary with a single key, packages, mapping to a list of Package
objects that are in critical path for this Release.
"""
if verb not in ('GET', 'POST'):
raise ValueError("Unsupported request type.")
return self.send_request(
f'releases/{release}/critpath', verb=verb, auth=auth, data=data
)

def get_koji_session(self):
"""
Return an authenticated koji session.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) YEAR AUTHOR
#
# This file is part of Bodhi.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Add critical path Packages
Revision ID: a429f263fc3f
Revises: 58b7919b942c
Create Date: 2019-03-14 09:31:38.169232
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'a429f263fc3f'
down_revision = '58b7919b942c'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('critical_path_packages_table',
sa.Column('package_id', sa.Integer(), nullable=False),
sa.Column('release_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['package_id'], ['packages.id'], ),
sa.ForeignKeyConstraint(['release_id'], ['releases.id'], ))
op.create_index(
op.f('ix_critical_path_packages_table_package_id'),
'critical_path_packages_table',
['package_id'],
unique=False
)
op.create_index(
op.f('ix_critical_path_packages_table_release_id'),
'critical_path_packages_table',
['release_id'],
unique=False
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f('ix_critical_path_packages_table_release_id'),
table_name='critical_path_packages_table'
)
op.drop_index(
op.f('ix_critical_path_packages_table_package_id'),
table_name='critical_path_packages_table'
)
op.drop_table('critical_path_packages_table')
# ### end Alembic commands ###

This file was deleted.

4 changes: 2 additions & 2 deletions bodhi/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ class ComposeState(DeclEnum):

critical_path_packages_table = Table(
'critical_path_packages_table', Base.metadata,
Column('package_id', Integer, ForeignKey('packages.id'), nullable=False),
Column('release_id', Integer, ForeignKey('releases.id'), nullable=False)
Column('package_id', Integer, ForeignKey('packages.id'), nullable=False, index=True),
Column('release_id', Integer, ForeignKey('releases.id'), nullable=False, index=True)
)


Expand Down
4 changes: 2 additions & 2 deletions bodhi/server/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,11 @@ def validate_packages(request, **kwargs):
koji_session.listPackages(pkgID=p)
package = Package(name=p)
validated_packages.append(package)
except Exception:
except koji.GenericError:
request.errors.add(
'querystring',
'packages',
"Invalid packages specified: {}".format(", ".join(bad_packages))
f'Invalid packages specified: {", ".join(bad_packages)}'
)
return

Expand Down
39 changes: 39 additions & 0 deletions bodhi/tests/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,5 +991,44 @@
Name: F28
"""

EXAMPLE_INFO_RELEASE_MUNCH = Munch({
u'dist_tag': u'f27', u'name': u'F27', u'testing_tag': u'f27-updates-testing',
u'pending_stable_tag': u'f27-updates-pending', u'pending_signing_tag': u'f27-signing-pending',
u'long_name': u'Fedora 27', u'state': u'pending', u'version': u'27',
u'override_tag': u'f27-override', u'branch': u'f27', u'id_prefix': u'FEDORA',
u'pending_testing_tag': u'f27-updates-testing-pending', u'stable_tag': u'f27-updates',
u'candidate_tag': u'f27-updates-candidate', u'critpath_pkgs': [
Munch({'type': 'rpm', 'requirements': None,
'name': 'python', 'stack': None}),
Munch({'type': 'rpm', 'requirements': None,
'name': 'kernel', 'stack': None})]})

EXPECTED_INFO_RELEASE_OUTPUT = """Release:
Name: F27
Long Name: Fedora 27
Version: 27
Branch: f27
ID Prefix: FEDORA
Dist Tag: f27
Stable Tag: f27-updates
Testing Tag: f27-updates-testing
Candidate Tag: f27-updates-candidate
Pending Signing Tag: f27-signing-pending
Pending Testing Tag: f27-updates-testing-pending
Pending Stable Tag: f27-updates-pending
Override Tag: f27-override
State: pending
"""

EXAMPLE_CRITPATH_PACKAGES_MUNCH = Munch({
'packages': [
Munch({'type': 'rpm', 'requirements': None, 'name': 'python', 'stack': None}),
Munch({'type': 'rpm', 'requirements': None, 'name': 'kernel', 'stack': None})]
})

EXPECTED_CRITPATH_PACKAGES_OUTPUT = """Critical path packages:
- kernel
- python
"""

UNMATCHED_RESP = {"pants": "pants"}
Loading

0 comments on commit 5e29c36

Please sign in to comment.