From 6a012a68dcd31afadccc8d2595ef9fc5275a86e2 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Feb 14 2020 15:33:17 +0000 Subject: Remove unneeded code for filtering latest results Filtering by system_architecture and system_variant field is done for all subject types, not only composes ("productmd.compose.id"). I.e. all latest test results with unique pair of system_architecture and system_variant are considered. Signed-off-by: Lukas Holecek --- diff --git a/conf/subject_types/compose.yaml b/conf/subject_types/compose.yaml index 272c12f..2ea31a3 100644 --- a/conf/subject_types/compose.yaml +++ b/conf/subject_types/compose.yaml @@ -4,6 +4,3 @@ item_key: "productmd.compose.id" item_dict: # {"productmd.compose.id": ITEM} item_key: "productmd.compose.id" -latest_result_unique_keys: - - system_variant - - system_architecture diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index e0c90af..9a064b4 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -1086,6 +1086,35 @@ def test_make_a_decision_about_compose_all_variants_architectures( }] +def test_make_a_decision_about_compose_latest_variants_architectures( + requests_session, greenwave_server, testdatabuilder): + compose_id = testdatabuilder.unique_compose_id() + + testdatabuilder.create_rtt_compose_result( + compose_id=compose_id, + outcome='FAILED', + variant='BaseOS', + architecture='ppc64') + + testdatabuilder.create_rtt_compose_result( + compose_id=compose_id, + outcome='PASSED', + variant='BaseOS', + architecture='ppc64') + + data = { + 'decision_context': 'rtt_compose_gate', + 'product_version': 'rhel-something', + 'subject_type': 'compose', + 'subject_identifier': compose_id, + } + r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) + assert r.status_code == 200 + res_data = r.json() + assert res_data['policies_satisfied'] + assert len(res_data['satisfied_requirements']) == 1 + + def test_make_a_decision_about_compose_new_variants_architectures( requests_session, greenwave_server, testdatabuilder): compose_id = testdatabuilder.unique_compose_id() diff --git a/greenwave/policies.py b/greenwave/policies.py index 3285934..5a85421 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -577,7 +577,7 @@ class PassingTestCaseRule(Rule): # results ordered by `submit_time` descending. return [ self._answer_for_result(result, subject) - for result in subject.get_latest_results(matching_results) + for result in matching_results ] def matches(self, policy, **attributes): diff --git a/greenwave/subjects/subject.py b/greenwave/subjects/subject.py index 1e3d535..e6cf893 100644 --- a/greenwave/subjects/subject.py +++ b/greenwave/subjects/subject.py @@ -1,29 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ -def _get_latest_results(results, unique_keys): - """ - Yields only the latest results for unique architecture and variant pairs. - - The input results are sorted from latest to oldest. - """ - visited_arch_variants = set() - for result in results: - result_data = result["data"] - - # Items under test result "data" are lists which are unhashable - # types in Python. This converts anything that is stored there - # to a string so we don't have to care about the stored value. - arch_variant = tuple( - str(result_data.get(key)) - for key in unique_keys - ) - - if arch_variant not in visited_arch_variants: - visited_arch_variants.add(arch_variant) - yield result - - def _to_dict(format_dict, item): result = {} @@ -117,16 +94,6 @@ class Subject: else: yield self.to_dict() - def get_latest_results(self, results): - """ - Filters out results to get only the latest relevant ones. - - The input results are sorted from latest to oldest. - """ - if self._type.latest_result_unique_keys: - return list(_get_latest_results(results, self._type.latest_result_unique_keys)) - return results - def __str__(self): return "subject_type {!r}, subject_identifier {!r}".format( self.type, self.item diff --git a/greenwave/subjects/subject_type.py b/greenwave/subjects/subject_type.py index 463d796..916e978 100644 --- a/greenwave/subjects/subject_type.py +++ b/greenwave/subjects/subject_type.py @@ -48,11 +48,6 @@ class SubjectType(SafeYAMLObject): # List of serialization dicts for ResultsDB requests. # If not defined, defaults to single request with item_dict value. 'result_queries': SafeYAMLList(item_type=dict, optional=True), - - # List of keys in ResultsDB data for checking obsolete items. - # E.g. [a, b] means that only the first item with unique values of keys - # 'a', 'b' in 'data' of each result is valid. - 'latest_result_unique_keys': SafeYAMLList(item_type=str, optional=True), } def matches(self, id_): diff --git a/greenwave/tests/test_subjects.py b/greenwave/tests/test_subjects.py index 18ade3c..cbedac1 100644 --- a/greenwave/tests/test_subjects.py +++ b/greenwave/tests/test_subjects.py @@ -52,48 +52,6 @@ def test_subject_ignore_missing_policy(app): assert subject.ignore_missing_policy -def test_subject_get_latest_results(app): - compose_id = 'some_compose' - variant_arch_outcome = ( - ('BaseOS', 'ppc64', 'PASSED'), - ('BaseOS', 'ppc64', 'FAILED'), - ('BaseOS', 'x86_64', 'PASSED'), - ('BaseOS', 'ppc64', 'FAILED'), - ('BaseOS', 'x86_64', 'FAILED'), - ) - - results = [ - { - 'testcase': {'name': 'rtt.acceptance.validation'}, - 'outcome': outcome, - 'data': { - 'productmd.compose.id': [compose_id], - 'system_variant': [variant], - 'system_architecture': [arch], - } - } - for variant, arch, outcome in variant_arch_outcome - ] - - subject = create_subject('compose', compose_id) - - assert len(subject.get_latest_results(results)) == 2 - - assert subject.get_latest_results(results)[0]['data'] == { - 'productmd.compose.id': [compose_id], - 'system_variant': ['BaseOS'], - 'system_architecture': ['ppc64'], - } - assert subject.get_latest_results(results)[0]['outcome'] == 'PASSED' - - assert subject.get_latest_results(results)[1]['data'] == { - 'productmd.compose.id': [compose_id], - 'system_variant': ['BaseOS'], - 'system_architecture': ['x86_64'], - } - assert subject.get_latest_results(results)[1]['outcome'] == 'PASSED' - - def test_subject_to_str(app): subject = create_subject('koji_build', 'some_nvr') assert str(subject) == "subject_type 'koji_build', subject_identifier 'some_nvr'"