Fixing a simple issue in results count to fix exit code
This commit fixes a simple mistake in the baseline code that was causing a baseline run with no new issues to return a fail. Basically we were deleting all objects from the baseline list, and then using the length of the baseline list to check if we were in baseline mode. Since the length was now 0, we decided we weren't running baseline. Now we make a copy of the list and delete issues from the copy to leave the original list alone. Also we make the code more clear by doing an explicit list of get_issue_list instead of length of filter(). Change-Id: I32af0a1291cb94a527f31f4fcfe8faa7be302095
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
from collections import OrderedDict
|
||||
import copy
|
||||
import fnmatch
|
||||
import json
|
||||
import logging
|
||||
@@ -141,9 +142,7 @@ class BanditManager():
|
||||
:param conf_filter: Confidence level to filter
|
||||
:return: Number of results in the set
|
||||
'''
|
||||
res = self.filter_results(sev_filter=sev_filter,
|
||||
conf_filter=conf_filter)
|
||||
return len(res)
|
||||
return len(self.get_issue_list(sev_filter, conf_filter))
|
||||
|
||||
def output_results(self, lines, sev_level, conf_level, output_filename,
|
||||
output_format):
|
||||
@@ -376,6 +375,9 @@ def _compare_baseline_results(baseline, results):
|
||||
"""
|
||||
unmatched_issues = []
|
||||
|
||||
# make a copy so we don't mess with the original baseline list
|
||||
baseline_copy = copy.deepcopy(baseline)
|
||||
|
||||
# approach here: go through each issue in current results, check if it was
|
||||
# present in the baseline. If it was, remove it from the baseline (so we
|
||||
# don't count it twice). If it wasn't then we have an unmatched issue, so
|
||||
@@ -383,16 +385,16 @@ def _compare_baseline_results(baseline, results):
|
||||
for new_issue in results:
|
||||
# keep track of index in the baseline where the issue was so we can
|
||||
# remove it from the list
|
||||
for found_index, baseline_issue in enumerate(baseline):
|
||||
for found_index, baseline_issue in enumerate(baseline_copy):
|
||||
if new_issue.matches_issue(baseline_issue):
|
||||
break
|
||||
|
||||
# we went through all the results and didn't find it, add to unmatched
|
||||
if found_index == len(baseline):
|
||||
if found_index == len(baseline_copy):
|
||||
unmatched_issues.append(new_issue)
|
||||
# we found it, remove from the baseline
|
||||
else:
|
||||
del baseline[found_index]
|
||||
del baseline_copy[found_index]
|
||||
|
||||
return unmatched_issues
|
||||
|
||||
|
||||
Reference in New Issue
Block a user