From 2680de40cc22f2ab9e9f547cff71a889ea4ecb2f Mon Sep 17 00:00:00 2001 From: PJ Richardson Date: Tue, 19 May 2020 14:58:10 -0400 Subject: [PATCH 1/8] Updated bz coveraage utility to not update flags for bugs in coverage= and replaced log msg with exception when no bz creds --- cfme/fixtures/bzs.py | 6 +----- cfme/utils/bz.py | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cfme/fixtures/bzs.py b/cfme/fixtures/bzs.py index c0cda9cd3d..bfda308caf 100644 --- a/cfme/fixtures/bzs.py +++ b/cfme/fixtures/bzs.py @@ -23,16 +23,12 @@ def pytest_addoption(parser): def pytest_collection_modifyitems(session, config, items): if not config.getvalue("generate_bz_report"): return - store.terminalreporter.write("Loading automated/covered BZs ...\n", bold=True) + store.terminalreporter.write("Loading automated BZs ...\n", bold=True) bz_list = [] for item in items: - if "automates" not in item._metadata and "coverage" not in item._metadata: - continue # get list of bzs with coverage if "automates" in item._metadata: bz_list.extend(item._metadata["automates"]) - if "coverage" in item._metadata: - bz_list.extend(item._metadata["coverage"]) if bz_list: # remove duplicate BZs diff --git a/cfme/utils/bz.py b/cfme/utils/bz.py index a64b383f25..306fd890fa 100644 --- a/cfme/utils/bz.py +++ b/cfme/utils/bz.py @@ -106,9 +106,9 @@ def from_config(cls): logger.info('Using api key for Bugzilla authentication') bz_kwargs.update(dict(api_key=bz_creds.get('api_key'))) else: - logger.error('Credentials key for bugzilla does not have username or api key') + raise Exception('Credentials key for bugzilla does not have username or api key') else: - logger.warn('No credentials found for bugzilla') + raise Exception('No credentials found for bugzilla') # where should I catch these???^ return cls(**bz_kwargs) From 4b8d802d75316ff2b1df46ff0ec571646d437683 Mon Sep 17 00:00:00 2001 From: PJ Richardson Date: Tue, 19 May 2020 15:24:34 -0400 Subject: [PATCH 2/8] Remove remaining coverage references --- cfme/fixtures/bzs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfme/fixtures/bzs.py b/cfme/fixtures/bzs.py index bfda308caf..5ea8f57a74 100644 --- a/cfme/fixtures/bzs.py +++ b/cfme/fixtures/bzs.py @@ -16,7 +16,7 @@ def pytest_addoption(parser): action='store_true', default=False, dest='generate_bz_report', - help='Generate a BZ report based on the automates/coverage metadata of test cases.' + help='Generate a BZ report based on the automates metadata of test cases.' ) @@ -42,6 +42,6 @@ def pytest_collection_modifyitems(session, config, items): yaml.dump(info, outfile, default_flow_style=False) else: store.terminalreporter.write( - "ERROR: No BZs marked with 'automates'/'coverage' in that test module. A report will " + "ERROR: No BZs marked with 'automates' in that test module. A report will " "not be generated.\n", bold=True ) From e474c6a98289aa27f004248301e374de0cc567e8 Mon Sep 17 00:00:00 2001 From: PJ Richardson Date: Tue, 19 May 2020 16:36:18 -0400 Subject: [PATCH 3/8] Remove changes to bz.py --- cfme/utils/bz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfme/utils/bz.py b/cfme/utils/bz.py index 306fd890fa..a64b383f25 100644 --- a/cfme/utils/bz.py +++ b/cfme/utils/bz.py @@ -106,9 +106,9 @@ def from_config(cls): logger.info('Using api key for Bugzilla authentication') bz_kwargs.update(dict(api_key=bz_creds.get('api_key'))) else: - raise Exception('Credentials key for bugzilla does not have username or api key') + logger.error('Credentials key for bugzilla does not have username or api key') else: - raise Exception('No credentials found for bugzilla') # where should I catch these???^ + logger.warn('No credentials found for bugzilla') return cls(**bz_kwargs) From ff1bac01ff37062e681e05cd4b3b49182f1ddf04 Mon Sep 17 00:00:00 2001 From: PJ Richardson Date: Tue, 19 May 2020 17:30:52 -0400 Subject: [PATCH 4/8] Remove changes to bzs.py --- cfme/fixtures/bzs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cfme/fixtures/bzs.py b/cfme/fixtures/bzs.py index 5ea8f57a74..c0cda9cd3d 100644 --- a/cfme/fixtures/bzs.py +++ b/cfme/fixtures/bzs.py @@ -16,19 +16,23 @@ def pytest_addoption(parser): action='store_true', default=False, dest='generate_bz_report', - help='Generate a BZ report based on the automates metadata of test cases.' + help='Generate a BZ report based on the automates/coverage metadata of test cases.' ) def pytest_collection_modifyitems(session, config, items): if not config.getvalue("generate_bz_report"): return - store.terminalreporter.write("Loading automated BZs ...\n", bold=True) + store.terminalreporter.write("Loading automated/covered BZs ...\n", bold=True) bz_list = [] for item in items: + if "automates" not in item._metadata and "coverage" not in item._metadata: + continue # get list of bzs with coverage if "automates" in item._metadata: bz_list.extend(item._metadata["automates"]) + if "coverage" in item._metadata: + bz_list.extend(item._metadata["coverage"]) if bz_list: # remove duplicate BZs @@ -42,6 +46,6 @@ def pytest_collection_modifyitems(session, config, items): yaml.dump(info, outfile, default_flow_style=False) else: store.terminalreporter.write( - "ERROR: No BZs marked with 'automates' in that test module. A report will " + "ERROR: No BZs marked with 'automates'/'coverage' in that test module. A report will " "not be generated.\n", bold=True ) From f3ff4591e62848c21b823d62eada7bf404ff534a Mon Sep 17 00:00:00 2001 From: PJ Richardson Date: Tue, 19 May 2020 17:34:40 -0400 Subject: [PATCH 5/8] Add option --inc_man to coverage() and set option to false by default --- cfme/scripting/bz.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/cfme/scripting/bz.py b/cfme/scripting/bz.py index c08c9234b2..35a9b3bddf 100644 --- a/cfme/scripting/bz.py +++ b/cfme/scripting/bz.py @@ -44,18 +44,19 @@ BZ_URL = conf.env.bugzilla.url -def get_report(directory): +def get_report(directory, inc_manual=True): click.echo("Generating a BZ report in bz-report.yaml") - pytest.main([ - "--use-provider", "complete", + options = ["--use-provider", "complete", "--long-running", "--use-template-cache", "--collect-only", "--dummy-appliance", - "--include-manual", "-q", - "--generate-bz-report", directory - ]) + "--generate-bz-report" + ] + if inc_manual: + options.append("--include-manual") + pytest.main(options.append(directory)) # read the generated yaml try: with open("bz-report.yaml") as stream: @@ -224,6 +225,15 @@ def list(directory, bz_status): @main.command(help="Set QE test coverage flag based on automates/coverage metadata") @click.argument("directory", default="cfme/tests") +@click.option( + "-m", + "--inc_man", + "inc_manual", + is_flag=True, + help="Include BZs that are marked in coverage test metadata for manual tests", + default=False, + show_default=True +) @click.option( "-s", "--set", @@ -263,8 +273,8 @@ def list(directory, bz_status): show_default=True, flag_value="closed_bzs" ) -def coverage(directory, set_bzs, bz_status): - info = get_report(directory) +def coverage(directory, inc_manual, set_bzs, bz_status): + info = get_report(directory, inc_manual=inc_manual) # get list of bzs that should have test coverage set bz_list = get_qe_test_coverage(info, bz_status) From 3f57a09e32e63a8722347ed664028b7f2b956db0 Mon Sep 17 00:00:00 2001 From: PJ Richardson Date: Wed, 20 May 2020 12:16:18 -0400 Subject: [PATCH 6/8] Add check for user or key attributes and error out if both are missing --- cfme/scripting/bz.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cfme/scripting/bz.py b/cfme/scripting/bz.py index 35a9b3bddf..046df2d324 100644 --- a/cfme/scripting/bz.py +++ b/cfme/scripting/bz.py @@ -30,6 +30,7 @@ from cfme.utils import conf from cfme.utils.blockers import BZ +from cfme.utils.bz import Bugzilla from cfme.utils.log import logger from cfme.utils.path import data_path from cfme.utils.version import current_version @@ -45,6 +46,11 @@ def get_report(directory, inc_manual=True): + bz_instance = Bugzilla.from_config() + if not (bz_instance.user or bz_instance.key): + msg = ("ERROR: Credentials key for bugzilla does not have username or api key.") + click.secho(msg, err=True, bold=True, fg="red") + sys.exit(0) click.echo("Generating a BZ report in bz-report.yaml") options = ["--use-provider", "complete", "--long-running", @@ -227,7 +233,7 @@ def list(directory, bz_status): @click.argument("directory", default="cfme/tests") @click.option( "-m", - "--inc_man", + "--inc_manual", "inc_manual", is_flag=True, help="Include BZs that are marked in coverage test metadata for manual tests", From e6426838846f67f3565de790a1313c96b6281014 Mon Sep 17 00:00:00 2001 From: Mike Shriver Date: Thu, 21 May 2020 07:36:04 -0400 Subject: [PATCH 7/8] Apply suggestions from code review Updating arg to include_manual Co-authored-by: john-dupuy <44065123+john-dupuy@users.noreply.github.com> --- cfme/scripting/bz.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cfme/scripting/bz.py b/cfme/scripting/bz.py index 046df2d324..ddf702a546 100644 --- a/cfme/scripting/bz.py +++ b/cfme/scripting/bz.py @@ -45,7 +45,7 @@ BZ_URL = conf.env.bugzilla.url -def get_report(directory, inc_manual=True): +def get_report(directory, include_manual=True): bz_instance = Bugzilla.from_config() if not (bz_instance.user or bz_instance.key): msg = ("ERROR: Credentials key for bugzilla does not have username or api key.") @@ -60,7 +60,7 @@ def get_report(directory, inc_manual=True): "-q", "--generate-bz-report" ] - if inc_manual: + if include_manual: options.append("--include-manual") pytest.main(options.append(directory)) # read the generated yaml @@ -233,7 +233,7 @@ def list(directory, bz_status): @click.argument("directory", default="cfme/tests") @click.option( "-m", - "--inc_manual", + "--include-manual", "inc_manual", is_flag=True, help="Include BZs that are marked in coverage test metadata for manual tests", @@ -279,8 +279,8 @@ def list(directory, bz_status): show_default=True, flag_value="closed_bzs" ) -def coverage(directory, inc_manual, set_bzs, bz_status): - info = get_report(directory, inc_manual=inc_manual) +def coverage(directory, include_manual, set_bzs, bz_status): + info = get_report(directory, include_manual=include_manual) # get list of bzs that should have test coverage set bz_list = get_qe_test_coverage(info, bz_status) From 4a5ce0fc6ff2aa8d9905bc5e9b6ad6362cd25289 Mon Sep 17 00:00:00 2001 From: Mike Shriver Date: Thu, 21 May 2020 07:36:40 -0400 Subject: [PATCH 8/8] Update cfme/scripting/bz.py missed one of the include_manual changes --- cfme/scripting/bz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfme/scripting/bz.py b/cfme/scripting/bz.py index ddf702a546..146cb8209c 100644 --- a/cfme/scripting/bz.py +++ b/cfme/scripting/bz.py @@ -234,7 +234,7 @@ def list(directory, bz_status): @click.option( "-m", "--include-manual", - "inc_manual", + "include_manual", is_flag=True, help="Include BZs that are marked in coverage test metadata for manual tests", default=False,