Skip to content

Commit

Permalink
Add a release requirements CLI command
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <[email protected]>
  • Loading branch information
mattiaverga committed Nov 22, 2024
1 parent 2dc23f6 commit 7aa3e1b
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 5 deletions.
45 changes: 45 additions & 0 deletions bodhi-client/bodhi/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,12 @@ def edit_release(url: str, id_provider: str, client_id: str, debug: bool, **kwar

data = munch.unmunchify(res)

# These are just read-only and not editable
data.pop('critpath_mandatory_days_in_testing', None)
data.pop('mandatory_days_in_testing', None)
data.pop('critpath_min_karma', None)
data.pop('min_karma', None)

if 'errors' in data:
print_errors(data)

Expand Down Expand Up @@ -1306,6 +1312,45 @@ def info_release(name: str, url: str, id_provider: str, client_id: str, **kwargs
print_release(res)


@releases.command(name='requirements')
@handle_errors
@click.argument('name')
@url_option
@add_options(openid_options)
@debug_option
@staging_option
def requirements_release(name: str, url: str, id_provider: str, client_id: str, **kwargs):
"""Retrieve and print testing requirements for a release."""
def _bold(text: str, color: str = None):
"""Return a click bolded text."""
if color is not None:
return click.style(text, bold=True, fg=color)
else:
return click.style(text, bold=True)

client = bindings.BodhiClient(
base_url=url, client_id=client_id, id_provider=id_provider, staging=kwargs['staging']
)

res = client.send_request(f'releases/{name}', verb='GET', auth=False)

if 'errors' in res:
print_errors(res)
else:
status = f'{res['state']} {res['setting_status']}' if res['setting_status'] \
else res['state']

click.echo(f'Release {_bold(res["name"])} state is currently "{status}"\n')
click.echo(' - Requirements for critical path updates are:\n'
f' {_bold(res["critpath_mandatory_days_in_testing"], "white")} '
'days in testing OR '
f'{_bold("+" + str(res["critpath_min_karma"]), "white")} karma\n')
click.echo(' - Requirements for non-critical path updates are:\n'
f' {_bold(res["mandatory_days_in_testing"], "white")} '
'days in testing OR '
f'{_bold("+" + str(res["min_karma"]), "white")} karma\n')


@releases.command(name='list')
@handle_errors
@click.option('--display-archived', is_flag=True, default=False,
Expand Down
5 changes: 5 additions & 0 deletions bodhi-client/docs/man_pages/bodhi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ The ``releases`` command allows users to manage update releases.

Go to page number.

``bodhi releases requirements RELEASE_NAME``

The ``requirements`` command prints information about the status of the given release
and the requirements needed by its updates for being pushed to stable.


Examples
========
Expand Down
36 changes: 31 additions & 5 deletions bodhi-client/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@
'pending_testing_tag': 'f27-updates-testing-pending', 'stable_tag': 'f27-updates',
'candidate_tag': 'f27-updates-candidate', 'mail_template': 'fedora_errata_template',
'create_automatic_updates': False, 'package_manager': 'unspecified',
'testing_repository': None, 'released_on': None, 'eol': None, 'setting_status': None})
'testing_repository': None, 'released_on': None, 'eol': None,
'critpath_mandatory_days_in_testing': 0, 'mandatory_days_in_testing': 0,
'critpath_min_karma': 0, 'min_karma': 0, 'setting_status': None})


EXPECTED_RELEASE_OUTPUT = """Saved release:
Expand Down Expand Up @@ -943,6 +945,16 @@
End of Life: None
"""

EXPECTED_RELEASE_REQUIREMENTS_OUTPUT = """Release F27 state is currently "pending"
- Requirements for critical path updates are:
0 days in testing OR +0 karma
- Requirements for non-critical path updates are:
0 days in testing OR +0 karma
"""

EXAMPLE_ARCHIVED_RELEASE_MUNCH = Munch({
'composes': [], 'dist_tag': 'f26', 'name': 'F26',
'testing_tag': 'f26-updates-testing', 'pending_stable_tag': 'f26-updates-pending',
Expand All @@ -953,7 +965,8 @@
'candidate_tag': 'f26-updates-candidate', 'stable_tag': 'f26-updates',
'override_tag': 'f26-override', 'composed_by_bodhi': True,
'package_manager': 'unspecified', 'testing_repository': None, 'released_on': None,
'eol': None, 'setting_status': None,
'eol': None, 'critpath_mandatory_days_in_testing': 14, 'mandatory_days_in_testing': 7,
'critpath_min_karma': 2, 'min_karma': 1, 'setting_status': None,
})

EXAMPLE_CURRENT_RELEASE_MUNCH = Munch({
Expand All @@ -966,7 +979,8 @@
'candidate_tag': 'f28-updates-candidate', 'stable_tag': 'f28-updates',
'override_tag': 'f28-override', 'composed_by_bodhi': True,
'package_manager': 'unspecified', 'testing_repository': None, 'released_on': None,
'eol': None, 'setting_status': None,
'eol': None, 'critpath_mandatory_days_in_testing': 14, 'mandatory_days_in_testing': 7,
'critpath_min_karma': 2, 'min_karma': 1, 'setting_status': None,
})

EXAMPLE_PENDING_RELEASE_MUNCH = Munch({
Expand All @@ -979,9 +993,20 @@
'candidate_tag': 'f29-updates-candidate', 'stable_tag': 'f29-updates',
'override_tag': 'f29-override', 'composed_by_bodhi': True,
'package_manager': 'unspecified', 'testing_repository': None, 'released_on': None,
'eol': None, 'setting_status': None,
'eol': None, 'critpath_mandatory_days_in_testing': 3, 'mandatory_days_in_testing': 3,
'critpath_min_karma': 2, 'min_karma': 1, 'setting_status': 'prebeta',
})

EXPECTED_PENDING_RELEASE_REQUIREMENTS_OUTPUT = """Release F29 state is currently "pending prebeta"
- Requirements for critical path updates are:
3 days in testing OR +2 karma
- Requirements for non-critical path updates are:
3 days in testing OR +1 karma
"""

EXAMPLE_FROZEN_RELEASE_MUNCH = Munch({
'composes': [], 'dist_tag': 'f30', 'name': 'F30',
'testing_tag': 'f30-updates-testing', 'pending_stable_tag': 'f30-updates-pending',
Expand All @@ -992,7 +1017,8 @@
'candidate_tag': 'f30-updates-candidate', 'stable_tag': 'f30-updates',
'override_tag': 'f30-override', 'composed_by_bodhi': True,
'package_manager': 'unspecified', 'testing_repository': None, 'released_on': None,
'eol': None, 'setting_status': None,
'eol': None, 'critpath_mandatory_days_in_testing': 3, 'mandatory_days_in_testing': 3,
'critpath_min_karma': 2, 'min_karma': 1, 'setting_status': None,
})

EXAMPLE_RELEASE_MUNCH_NO_ARCHIVED = Munch({
Expand Down
52 changes: 52 additions & 0 deletions bodhi-client/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,58 @@ def test_info_with_errors(self, mocked_client_class):
assert result.output == "ERROR: an error was encountered... :(\n"


class TestRequirements:
"""
Test the requirements() function.
"""
def test_url_flag(self, mocked_client_class):
"""
Assert correct behavior with the --url flag.
"""
mocked_client_class.send_request.return_value = \
client_test_data.EXAMPLE_RELEASE_MUNCH
runner = testing.CliRunner()

result = runner.invoke(cli.requirements_release, ['--url', 'http://localhost:6543', 'F27'])

assert result.exit_code == 0
assert result.output == \
client_test_data.EXPECTED_RELEASE_REQUIREMENTS_OUTPUT.replace('Saved r', 'R')
mocked_client_class.send_request.assert_called_once_with(
'releases/F27', verb='GET', auth=False)

def test_pending_release(self, mocked_client_class):
"""
Assert correct output with a pensing prebeta release.
"""
mocked_client_class.send_request.return_value = \
client_test_data.EXAMPLE_PENDING_RELEASE_MUNCH
runner = testing.CliRunner()

result = runner.invoke(cli.requirements_release, ['--url', 'http://localhost:6543', 'F29'])

assert result.exit_code == 0
assert result.output == \
client_test_data.EXPECTED_PENDING_RELEASE_REQUIREMENTS_OUTPUT.replace('Saved r', 'R')
mocked_client_class.send_request.assert_called_once_with(
'releases/F29', verb='GET', auth=False)

def test_requirements_with_errors(self, mocked_client_class):
"""
Assert errors are printed if returned back in the request
"""
mocked_client_class.send_request.return_value = {
"errors": [{"description": "an error was encountered... :("}]
}

runner = testing.CliRunner()

result = runner.invoke(cli.requirements_release, ['--url', 'http://localhost:6543', 'F27'])

assert result.exit_code == 1
assert result.output == "ERROR: an error was encountered... :(\n"


class TestListReleases:
"""
Test the list_releases() function.
Expand Down
1 change: 1 addition & 0 deletions news/PR5807.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Release properties `min_karma`, `critpath_min_karma`, `mandatory_days_in_testing` and `critpath_mandatory_days_in_testing` are now expossed in JSON replies from bodhi-server and can be viewed in bodhi-client through the `release requirements` command

0 comments on commit 7aa3e1b

Please sign in to comment.