From 94f371d54372ff7bcb64c89e6634de379ba9f440 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Tue, 1 Jul 2014 23:05:15 +0400 Subject: [PATCH] Only the last CI result can be treated as merged CI may leave several comments for the same patch set. This can happen if tests are restarted by recheck command. For merged patchsets only the very last result can be treated as final. Change-Id: I5a0200089795cc132c083d9683ca4a4f70e37d5f --- stackalytics/processor/driverlog.py | 11 ++-- tests/unit/test_driverlog.py | 79 +++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 tests/unit/test_driverlog.py diff --git a/stackalytics/processor/driverlog.py b/stackalytics/processor/driverlog.py index e5459ff55..27d78639e 100644 --- a/stackalytics/processor/driverlog.py +++ b/stackalytics/processor/driverlog.py @@ -44,6 +44,7 @@ def find_ci_result(review, ci_map): review_id = review['id'] review_number = review['number'] + ci_already_seen = set() for comment in reversed(review.get('comments') or []): reviewer_id = comment['reviewer'].get('username') @@ -76,9 +77,13 @@ def find_ci_result(review, ci_map): result = _find_vote(review, ci['id'], patch_set_number) if result is not None: - is_merged = (review['status'] == 'MERGED' and - patch_set_number == review['patchSets'][-1] - ['number']) + is_merged = ( + review['status'] == 'MERGED' and + patch_set_number == review['patchSets'][-1]['number'] and + ci['id'] not in ci_already_seen) + + ci_already_seen.add(ci['id']) + yield { 'reviewer': comment['reviewer'], 'ci_result': result, diff --git a/tests/unit/test_driverlog.py b/tests/unit/test_driverlog.py new file mode 100644 index 000000000..b4483bbe4 --- /dev/null +++ b/tests/unit/test_driverlog.py @@ -0,0 +1,79 @@ +# Copyright (c) 2013 Mirantis Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import testtools + +from stackalytics.processor import driverlog + + +class TestDriverlog(testtools.TestCase): + def setUp(self): + super(TestDriverlog, self).setUp() + + def test_find_ci_result_voting_ci(self): + review = { + 'record_type': 'review', + 'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e', + 'module': 'nova', + 'branch': 'master', + 'status': 'NEW', + 'number': '97860', + 'patchSets': [ + {'number': '1', + 'approvals': [ + {'type': 'Verified', 'description': 'Verified', + 'value': '1', 'grantedOn': 1234567890 - 1, + 'by': { + 'name': 'Batman', + 'email': 'batman@openstack.org', + 'username': 'batman'}}, + {'type': 'Verified', 'description': 'Verified', + 'value': '-1', 'grantedOn': 1234567890, + 'by': { + 'name': 'Pikachu', + 'email': 'pikachu@openstack.org', + 'username': 'pikachu'}}, + ]}], + 'comments': [ + {'message': 'Patch Set 1: build successful', + 'reviewer': {'username': 'batman'}, + 'timestamp': 1234567890} + ]} + + ci_map = { + 'batman': { + 'name': 'Batman Driver', + 'vendor': 'Gotham Inc', + 'ci': { + 'id': 'batman' + } + } + } + + res = list(driverlog.find_ci_result(review, ci_map)) + + expected_result = { + 'reviewer': {'username': 'batman'}, + 'ci_result': True, + 'is_merged': False, + 'message': 'build successful', + 'date': 1234567890, + 'review_id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e', + 'review_number': '97860', + 'driver_name': 'Batman Driver', + 'driver_vendor': 'Gotham Inc', + } + self.assertEqual(1, len(res), 'One CI result is expected') + self.assertEqual(expected_result, res[0])