-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This test ensures that any assigned CCE isn't in the respective avail file.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#! /usr/bin/python3 | ||
|
||
import argparse | ||
import json | ||
import os | ||
from typing import Set | ||
import sys | ||
|
||
SSG_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | ||
JSON_PATH = os.path.join(SSG_ROOT, "build", "rule_dirs.json") | ||
|
||
|
||
def _parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser( | ||
description="Given a list of products and CCE available list error and output if an " | ||
"assigned CCE is in the available list. This scripts needs rule_dirs.json to " | ||
"run.") | ||
parser.add_argument('-p', '--products', required=True, | ||
help='Comma separated list (no spaces) of products to check') | ||
parser.add_argument('-l', '--cee-list', type=str, required=True, | ||
help='Path to cce avail list') | ||
parser.add_argument('-j', '--json', type=str, default=JSON_PATH, | ||
help='Path to rule_dirs.json file') | ||
parser.add_argument('-r', '--root', type=str, default=SSG_ROOT, | ||
help='Path to the root of the content repo') | ||
return parser.parse_args() | ||
|
||
|
||
def _get_cces_in_use(data, products) -> Set[str]: | ||
cces_in_use: Set[str] = set() | ||
for rule_id, rule_obj in data.items(): | ||
for identifier_key, identifier_value in rule_obj['identifiers'].items(): | ||
for product in products.split(","): | ||
if identifier_key.endswith(product): | ||
cces_in_use.add(identifier_value) | ||
return cces_in_use | ||
|
||
|
||
def _get_avail_cces(args) -> Set[str]: | ||
avail_cces: Set[str] = set() | ||
with open(args.cee_list) as f: | ||
for line in f.readlines(): | ||
avail_cces.add(line.strip()) | ||
return avail_cces | ||
|
||
|
||
def main(): | ||
args = _parse_args() | ||
products = args.products | ||
with open(args.json) as f: | ||
data = json.load(f) | ||
cces_in_use = _get_cces_in_use(data, products) | ||
|
||
if len(cces_in_use) == 0: | ||
print(f"Test is useless, no CCEs were found for products in {','.join(products)}") | ||
exit(2) | ||
|
||
avail_cces = _get_avail_cces(args) | ||
|
||
not_removed = avail_cces.intersection(cces_in_use) | ||
if len(not_removed) != 0: | ||
for cce in not_removed: | ||
print(f"CCE {cce} not removed from {args.cee_list}.", file=sys.stderr) | ||
exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |