From: Cristina Pauna Date: Tue, 21 Apr 2020 13:48:30 +0000 (+0000) Subject: Merge "docker: kube-conformance: Enforce upstream tag" X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=validation.git;a=commitdiff_plain;h=ac71d4b4f4818831ffbbbab620002034f876ddb5;hp=058638cc69d8195dfa5d5c182a976b875988df96 Merge "docker: kube-conformance: Enforce upstream tag" --- diff --git a/bluval/blucon.py b/bluval/blucon.py index 0d5d7ca..ee7f706 100644 --- a/bluval/blucon.py +++ b/bluval/blucon.py @@ -53,27 +53,27 @@ def get_volumes(layer): return volume_list -def invoke_docker(bluprint, layer): +def invoke_docker(bluprint, layer, tag): """Start docker container for given layer """ volume_list = get_volumes('common') + get_volumes(layer) cmd = ("docker run --rm" + volume_list + _SUBNET + - " akraino/validation:{0}-latest" + " akraino/validation:{0}-{3}" " /bin/sh -c" " 'cd /opt/akraino/validation " "&& python -B bluval/bluval.py -l {0} {1} {2}'" - .format(layer, ("-o" if _OPTIONAL_ALSO else ""), bluprint)) + .format(layer, ("-o" if _OPTIONAL_ALSO else ""), bluprint, tag)) args = [cmd] try: - print('\nInvoking {}'.format(args)) + print('\nInvoking {}'.format(args), flush=True) subprocess.call(args, shell=True) except OSError: #print('Error while executing {}'.format(args)) raise BluvalError(OSError) -def invoke_dockers(yaml_loc, layer, blueprint_name): +def invoke_dockers(yaml_loc, layer, blueprint_name, tag): """Parses yaml file and starts docker container for one/all layers """ with open(str(yaml_loc)) as yaml_file: @@ -81,19 +81,20 @@ def invoke_dockers(yaml_loc, layer, blueprint_name): blueprint = yamldoc['blueprint'] if layer is None or layer == "all": for each_layer in blueprint['layers']: - invoke_docker(blueprint_name, each_layer) + invoke_docker(blueprint_name, each_layer, tag) else: - invoke_docker(blueprint_name, layer) + invoke_docker(blueprint_name, layer, tag) @click.command() @click.argument('blueprint') @click.option('--layer', '-l') @click.option('--network', '-n') +@click.option('--tag', '-t') @click.option('--optional_also', '-o', is_flag=True) -def main(blueprint, layer, network, optional_also): +def main(blueprint, layer, network, tag, optional_also): """Takes blueprint name and optional layer. Validates inputs and derives - yaml location from blueprint name. Invokes validate on blue print. + yaml location from blueprint name. Invokes validate on blueprint. """ global _OPTIONAL_ALSO # pylint: disable=global-statement global _SUBNET # pylint: disable=global-statement @@ -107,8 +108,11 @@ def main(blueprint, layer, network, optional_also): if network is not None: _SUBNET = " --net=" + network print("Using", _SUBNET) + if tag is None: + tag = 'latest' + print("Using tag {}".format(tag)) try: - invoke_dockers(yaml_loc, layer, blueprint) + invoke_dockers(yaml_loc, layer, blueprint, tag) except ShowStopperError as err: print('ShowStopperError:', err) except BluvalError as err: diff --git a/bluval/blucon.sh b/bluval/blucon.sh index afe54db..b882f92 100755 --- a/bluval/blucon.sh +++ b/bluval/blucon.sh @@ -18,14 +18,17 @@ if [ -z "$AKRAINO_HOME" ] then - echo "AKRAINO_HOME not available. Setting..." - this_file="$(readlink -f $0)" - bluval_dir="$(dirname $this_file)" - validation_dir="$(dirname $bluval_dir)" - parent_dir="$(dirname $validation_dir)" - export AKRAINO_HOME="$parent_dir" + echo "AKRAINO_HOME not available. Setting ..." + AKRAINO_HOME="$(readlink -f "$(dirname "$0")/../..")" fi + +# Allow overriding VALIDATION_DIR and/or RESULTS_DIR via env vars +VALIDATION_DIR=${VALIDATION_DIR:-"${AKRAINO_HOME}/validation"} +RESULTS_DIR=${RESULTS_DIR:-"${AKRAINO_HOME}/results"} + echo "AKRAINO_HOME=$AKRAINO_HOME" +echo "VALIDATION_DIR=$VALIDATION_DIR" +echo "RESULTS_DIR=$RESULTS_DIR" if [ "$#" -eq 0 ] then @@ -38,6 +41,7 @@ then Options: -l, --layer TEXT -n, --network TEXT + -t, --tag TEXT -o, --optional_also --help Show this message and exit.' @@ -45,13 +49,13 @@ then fi echo "Building docker image" -image_tag=$( (git branch || echo "* local") | grep "^\*" | awk '{print $2}') -docker build -t akraino/validation:blucon-$image_tag $AKRAINO_HOME/validation/bluval +img="akraino/validation:blucon-$(git rev-parse --abbrev-ref HEAD || echo local)" +docker build -t "$img" "$VALIDATION_DIR/bluval" set -x docker run --rm \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v $AKRAINO_HOME/results:/opt/akraino/results \ - -v $AKRAINO_HOME/validation:/opt/akraino/validation \ - akraino/validation:blucon-$image_tag "$@" + -v "$RESULTS_DIR":/opt/akraino/results \ + -v "$VALIDATION_DIR":/opt/akraino/validation \ + "$img" "$@" diff --git a/bluval/bluval.py b/bluval/bluval.py index 63b301f..73cc68a 100644 --- a/bluval/bluval.py +++ b/bluval/bluval.py @@ -68,7 +68,7 @@ def run_testcase(testcase): print('Executing testcase {}'.format(name)) print('show_stopper {}'.format(show_stopper)) - print('Invoking {}'.format(args)) + print('Invoking {}'.format(args), flush=True) try: status = subprocess.call(args, shell=False) if status != 0 and show_stopper.lower() == "true": diff --git a/bluval/rules.txt b/bluval/rules.txt new file mode 100644 index 0000000..f2273ff --- /dev/null +++ b/bluval/rules.txt @@ -0,0 +1,10 @@ +# Separate results based on suite (group the messages by suite) +start /(?:Executing testcase ).*$/ + +# Only fail if some critical tests failed +debug /critical test.*passed, 0 failed/ +error /critical test.*passed/ + +# Suite/subsuite test results will be marked as info/warn +info /PASS/ +warn /FAIL/