Skip to content

Commit

Permalink
Allow restricting check tools according to resource classification
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Büchse <matthias.buechse@cloudandheat.com>
  • Loading branch information
mbuechse committed Nov 7, 2023
1 parent ad3cd0b commit 890aee7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Tests/scs-compliance-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@ def search_version(layerdict, checkdate, forceversion=None):


def optparse(argv):
"Parse options. Return (args, verbose, quiet, checkdate, version, output)."
"Parse options. Return (args, verbose, quiet, checkdate, version, output, classes)."
verbose = False
quiet = False
checkdate = datetime.date.today()
version = None
output = None
classes = ["light", "medium", "heavy"]
try:
opts, args = getopt.gnu_getopt(argv, "hvqd:V:sc:o:",
("help", "verbose", "quiet", "date=", "version=",
"os-cloud=", "output="))
opts, args = getopt.gnu_getopt(argv, "hvqd:V:sc:o:r:", (
"help", "verbose", "quiet", "date=", "version=",
"os-cloud=", "output=", "resource-usage=",
))
except getopt.GetoptError as exc:
print(f"Option error: {exc}", file=sys.stderr)
usage()
Expand All @@ -171,12 +173,14 @@ def optparse(argv):
os.environ["OS_CLOUD"] = opt[1]
elif opt[0] == "-o" or opt[0] == "--output":
output = opt[1]
elif opt[0] == "-r" or opt[0] == "--resource-usage":
classes = [x.strip() for x in opt[1].split(",")]
else:
print(f"Error: Unknown argument {opt[0]}", file=sys.stderr)
if len(args) < 1:
usage()
sys.exit(1)
return (args, verbose, quiet, checkdate, version, output)
return (args, verbose, quiet, checkdate, version, output, classes)


def condition_optional(cond, default=False):
Expand Down Expand Up @@ -205,7 +209,7 @@ def optstr(optional):

def main(argv):
"""Entry point for the checker"""
args, verbose, quiet, checkdate, version, output = optparse(argv)
args, verbose, quiet, checkdate, version, output, classes = optparse(argv)
with open(args[0], "r", encoding="UTF-8") as specfile:
specdict = yaml.load(specfile, Loader=yaml.SafeLoader)
allerrors = 0
Expand Down Expand Up @@ -242,6 +246,9 @@ def main(argv):
else:
chkidx = 0
for check in standard["check_tools"]:
if check.get("classification", "light") not in classes:
print(f"skipping check tool '{check['executable']}' because of resource classification")
continue
args = dictval(check, 'args')
error = run_check_tool(check["executable"], args, verbose, quiet)
if output:
Expand Down

0 comments on commit 890aee7

Please sign in to comment.