From 3f87674ad4c3ac35ebe1f831a6c2161fedfbd7b6 Mon Sep 17 00:00:00 2001 From: Dan Callaghan Date: Sep 29 2017 08:27:40 +0000 Subject: ResultsDB data is actually key -> list of values I noticed something amiss in the waiverdb consumer test. It was passing the subject with lists of values: 'subject': [{'item': [nvr], 'type': ['koji_build']}] which is contrary to how all our other tests and examples work. And contrary to how Bodhi will query the API. This unusual value for 'subject' is not an error, and the test passes as is, because Greenwave treats the subjects as opaque values. But when I changed the test case to match the others, it revealed a problem. In ResultsDB the 'data' dict is actually multi-valued: "data": { "item": [ "python-sphinxcontrib-httpdomain-1.5.0-4.fc26" ], "type": [ "koji_build" ] }, In theory there could be multiple values in those lists. And there could be other, unrelated keys present too. So I'm not sure if we can reliably map 'data' back to a 'subject' for Greenwave. For now, let's assume there is always one value and no extra keys. This should always be true for the test cases we know about, at least. --- diff --git a/functional-tests/consumers/test_waiverdb.py b/functional-tests/consumers/test_waiverdb.py index f1cc935..e49c517 100644 --- a/functional-tests/consumers/test_waiverdb.py +++ b/functional-tests/consumers/test_waiverdb.py @@ -51,7 +51,7 @@ def test_consume_new_waiver( data = { 'decision_context': 'bodhi_update_push_stable', 'product_version': 'fedora-26', - 'subject': [{'item': [nvr], 'type': ['koji_build']}], + 'subject': [{'item': nvr, 'type': 'koji_build'}], 'ignore_waiver': [waiver['id']] } r = requests_session.post(greenwave_server.url + 'api/v1.0/decision', @@ -59,6 +59,7 @@ def test_consume_new_waiver( data=json.dumps(data)) assert r.status_code == 200 old_decision = r.json() + assert old_decision['summary'] == '1 of 3 required tests failed' msg = { 'policies_satisified': True, @@ -68,8 +69,8 @@ def test_consume_new_waiver( 'product_version': 'fedora-26', 'subject': [ { - 'item': [nvr], - 'type': ['koji_build'] + 'item': nvr, + 'type': 'koji_build' } ], 'applicable_policies': ['taskotron_release_critical_tasks'], diff --git a/greenwave/consumers/waiverdb.py b/greenwave/consumers/waiverdb.py index e31a0ad..0cba417 100644 --- a/greenwave/consumers/waiverdb.py +++ b/greenwave/consumers/waiverdb.py @@ -70,7 +70,10 @@ class WaiverDBHandler(fedmsg.consumers.FedmsgConsumer): timeout=timeout) response.raise_for_status() testcase = response.json()['testcase']['name'] - item = response.json()['data'] + # In ResultsDB, 'data' is key -> list of strings. + # But in Greenwave, we only deal in key -> string. + # This is... iffy and might need cleaning up? + item = {k: v[0] for k, v in response.json()['data'].items()} for policy in config['policies']: for rule in policy.rules: if rule.test_case_name == testcase: