From aae5e3f47fb4ac59c36b55b3d91da9bb5f747c22 Mon Sep 17 00:00:00 2001 From: Filip Tehlar Date: Wed, 7 Dec 2016 18:10:28 +0100 Subject: Add a test for mapping expiration Change-Id: I94004c1cf7651aef2bcfa408aafac6a9bec20b0b Signed-off-by: Filip Tehlar --- .../vpp_lite_topo/scripts/vat/mapping_exists.py | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 tests/data_plane/vpp_lite_topo/scripts/vat/mapping_exists.py (limited to 'tests/data_plane/vpp_lite_topo/scripts/vat/mapping_exists.py') diff --git a/tests/data_plane/vpp_lite_topo/scripts/vat/mapping_exists.py b/tests/data_plane/vpp_lite_topo/scripts/vat/mapping_exists.py new file mode 100755 index 0000000..2015b4a --- /dev/null +++ b/tests/data_plane/vpp_lite_topo/scripts/vat/mapping_exists.py @@ -0,0 +1,38 @@ +# Script for checking whether a mapping exists in the vpp's map-cache +# +# Params: +# vat_exec - VAT executable +# vpp_prefix - shared vpp memory prefix +# mapping - mapping to verify + +import sys +import subprocess +import json + +def has_mapping(json, mapping): + if len (json) == 0: + return False + + for obj in json: + if obj['eid'] == mapping: + return True; + + return False + +def verify_mapping(vat_exec, prefix, mapping, vat_path): + vat_file = vat_path + '/' + 'dump_remote_mappings.tpl' + out = subprocess.Popen([vat_exec, "chroot", "prefix", prefix, "json", "script", + "in", vat_file], stdout=subprocess.PIPE).communicate()[0] + + o = json.loads(out) + return has_mapping(o, mapping) + +if __name__ == "__main__": + if len(sys.argv) < 4: + raise Exception('expecteds 4 parameters: VAT executable, shared prefix ' + + ' name, mapping expected, path to vat templates!') + + if verify_mapping(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]): + sys.exit(0) + else: + sys.exit(1) -- cgit 1.2.3-korg