From c8e3cc4347e1e35e6900acfed1c6be489420ae70 Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Dec 08 2020 13:09:32 +0000 Subject: Add a --scenario argument to CLI JIRA: RHELWF-1882 --- diff --git a/docs/waiverdb-cli.rst b/docs/waiverdb-cli.rst index a228869..e160ac2 100644 --- a/docs/waiverdb-cli.rst +++ b/docs/waiverdb-cli.rst @@ -43,6 +43,10 @@ Options Specify a testcase for the subject. +.. option:: -S, --scenario SCENARIO + + Specify a scenario for a result to waive. + .. option:: -p, --product-version TEXT Specify one of PDC's product version identifiers. @@ -86,3 +90,10 @@ Waive test results with specific subject and product version:: waiverdb-cli -t dist.rpmdeplint \ -s '{"item": "qclib-1.3.1-3.fc28", "type": "koji_build"}' \ -p "fedora-28" -c "This is expected for non-x86 packages" + +Waive test results with a specific subject and scenario:: + + waiverdb-cli -t update.install_default_update_live \ + -i FEDORA-2020-a70501de3d -T koji_build \ + -S "fedora.updates-everything-boot-iso.x86_64.uefi" \ + -c "This is ok" diff --git a/requirements.txt b/requirements.txt index 3691d97..de5c8ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,8 @@ flask-cors SQLAlchemy gssapi flask-oidc +Flask-Migrate +stomp.py # Documentation requirements sphinx diff --git a/tests/test_cli.py b/tests/test_cli.py index 9b29249..80a0b9a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,6 +2,7 @@ import pytest import json from mock import Mock, patch +from textwrap import dedent from click.testing import CliRunner from waiverdb import __version__ from waiverdb.cli import cli as waiverdb_cli @@ -313,6 +314,19 @@ api_url=http://localhost:5004/api/v1.0 assert result.output == 'Error: Please specify result_id or subject/testcase. Not both\n' +def test_malformed_submission_with_id_and_scenario(tmpdir): + runner = CliRunner() + p = tmpdir.join('client.conf') + p.write(dedent(""" + [waiverdb] + auth_method=dummy + api_url=http://localhost:5004/api/v1.0 + """)) + args = ['-C', p.strpath, '-p', 'Parrot', '-r', '123', '-S', 'somescenario', '-c', "This is OK"] + result = runner.invoke(waiverdb_cli, args, catch_exceptions=False) + assert result.output == 'Error: Please specify result_id or scenario. Not both\n' + + def test_submit_waiver_for_original_spec_nvr_result(tmpdir): with patch('requests.request') as mock_request: mock_rv = Mock() @@ -389,6 +403,42 @@ koji_base_url=https://koji.fedoraproject.org/kojihub ) +def test_create_waiver_product_version_from_koji_build_scenario(tmpdir): + with patch('requests.request') as mock_request: + mock_rv = Mock() + mock_rv.json.return_value = [{ + "comment": "This is fine", + "id": 15, + "subject_type": "koji_build", + "subject_identifier": "setup-2.8.71-7.el7_4", + "scenario": "somescenario", + "testcase": "test.testcase", + "timestamp": "2017-010-16T17:42:04.209638", + "username": "foo", + "waived": True + }] + mock_request.return_value = mock_rv + p = tmpdir.join('client.conf') + p.write(dedent(""" + [waiverdb] + auth_method=dummy + api_url=http://localhost:5004/api/v1.0 + koji_base_url=https://koji.fedoraproject.org/kojihub + """)) + runner = CliRunner() + args = [ + '-C', p.strpath, '-s', '{"type": "koji_build", "item": "setup-2.8.71-7.el7_4"}', + '-S', 'somescenario', '-t', 'test.testcase', '-c', "This is fine" + ] + result = runner.invoke(waiverdb_cli, args, catch_exceptions=False) + mock_request.assert_called() + assert result.output == ( + 'Created waiver 15 for result with ' + 'subject type koji_build, identifier setup-2.8.71-7.el7_4 ' + 'and testcase test.testcase, scenario is somescenario\n' + ) + + def test_create_waiver_product_version_from_compose(tmpdir): with patch('requests.request') as mock_request: mock_rv = Mock() diff --git a/waiverdb/cli.py b/waiverdb/cli.py index 3612d61..d17a8cb 100644 --- a/waiverdb/cli.py +++ b/waiverdb/cli.py @@ -86,6 +86,8 @@ def check_response(resp, result_ids): waiver_id = data['id'] msg = 'subject type {0}, identifier {1} and testcase {2}'.format( data['subject_type'], data['subject_identifier'], data['testcase']) + if data.get('scenario'): + msg += f", scenario is {data['scenario']}" print_result(waiver_id, msg) @@ -122,6 +124,8 @@ def guess_product_version(toparse, koji_build=False): help='Specify a config file to use') @click.option('--result-id', '-r', multiple=True, type=int, help='Specify one or more results to be waived') +@click.option('--scenario', '-S', + help='Specify a scenario for a result to waive') @click.option('--subject', '-s', type=OldJSONSubject(), help=('Deprecated. Use --subject-identifier and --subject-type instead. ' 'Subject for a result to waive.')) @@ -139,8 +143,8 @@ def guess_product_version(toparse, koji_build=False): help='A comment explaining why the result is waived') @click.option('--username', '-u', default=None, help='Username on whose behalf the caller is proxying.') -def cli(username, comment, waived, product_version, testcase, subject, subject_identifier, - subject_type, result_id, config_file): +def cli(username, comment, waived, product_version, testcase, scenario, subject, + subject_identifier, subject_type, result_id, config_file): """ Creates new waiver against test results. @@ -150,8 +154,12 @@ def cli(username, comment, waived, product_version, testcase, subject, subject_i waiverdb-cli -r 47 -r 48 -p "fedora-28" -c "This is fine" \b - waiverdb-cli -t dist.rpmdeplint -i qclib-1.3.1-3.fc28 -T koji_build \\ + waiverdb-cli -t dist.rpmdeplint -i qclib-1.3.1-3.fc28 -T bodhi_update \\ -p "fedora-28" -c "This is expected for non-x86 packages" + + \b + waiverdb-cli -t update.install_default_update_live -i FEDORA-2020-a70501de3d \\ + -T koji_build -S "fedora.updates-everything-boot-iso.x86_64.uefi" -c "This is ok" """ config = configparser.ConfigParser() @@ -179,6 +187,8 @@ def cli(username, comment, waived, product_version, testcase, subject, subject_i raise click.ClickException('Please specify comment') if result_ids and (testcase or subject_identifier): raise click.ClickException('Please specify result_id or id/type/testcase. Not both') + if result_ids and scenario: + raise click.ClickException('Please specify result_id or scenario. Not both') if not result_ids and not subject_identifier: raise click.ClickException('Please specify subject-identifier') if not result_ids and not testcase: @@ -223,6 +233,7 @@ def cli(username, comment, waived, product_version, testcase, subject, subject_i 'subject_type': subject_type, 'testcase': testcase, 'waived': waived, + 'scenario': scenario, 'product_version': product_version, 'comment': comment, 'username': username