From a211f19382a75d4322f7dd6f74ee694222735ff9 Mon Sep 17 00:00:00 2001 From: Julien Date: Thu, 15 Jun 2017 11:24:57 +0800 Subject: seperate exception rules for releng project add optional project exception configuration file. for one project: configuration in project exception file and in gatechecks.yaml will be merged together for one project JIRA:RELENG-234 Change-Id: I7fff3082e837a478f155769fadd75533583543cd Signed-off-by: Julien --- anteater/src/get_lists.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'anteater') diff --git a/anteater/src/get_lists.py b/anteater/src/get_lists.py index 8941510..7d6d3f1 100644 --- a/anteater/src/get_lists.py +++ b/anteater/src/get_lists.py @@ -16,6 +16,8 @@ import anteater.utils.anteater_logger as antlog import ConfigParser +import copy +import os import yaml import re @@ -27,14 +29,45 @@ gate_checks = config.get('config', 'gate_checks') with open(gate_checks, 'r') as f: yl = yaml.safe_load(f) +def _remove_nullvalue(contents): + if contents and len(contents) > 2 and 'nullvalue' in contents: + contents.remove('nullvalue') + +def _merge(org, ded): + ret = copy.deepcopy(org) + for key in list(set([k for k in org] + [k for k in ded])): + if key in org and key in ded: + ret[key] = list(set(ret[key] + ded[key])) + _remove_nullvalue(ret[key]) + elif key in ded: + ret[key] = ded[key] + return ret class GetLists(object): def __init__(self, *args): # Placeholder for future args if more filters are needed self.args = args + self.loaded = False + + def load_project_exception_file(self, project_config, project): + if self.loaded: + return + exception_file = None + for item in project_config: + if project in item: + exception_file = item.get(project) + if exception_file is not None: + with open(exception_file, 'r') as f: + ex = yaml.safe_load(f) + for key in ex: + if key in yl: + yl[key][project] = _merge(yl[key][project], ex.get(key, None)) \ + if project in yl[key] else ex.get(key, None) + self.loaded = True def binary_list(self, project): project_list = False + self.load_project_exception_file(yl.get('project_config'), project) try: default_list = (yl['binaries']['binary_ignore']) except KeyError: @@ -58,6 +91,7 @@ class GetLists(object): def file_audit_list(self, project): project_list = False + self.load_project_exception_file(yl.get('project_config'), project) try: default_list = set((yl['file_audits']['file_names'])) except KeyError: @@ -83,6 +117,7 @@ class GetLists(object): def file_content_list(self, project): project_list = False + self.load_project_exception_file(yl.get('project_config'), project) try: default_list = set((yl['file_audits']['file_contents'])) except KeyError: -- cgit 1.2.3-korg