2015b4a70642a902292d5bfd564e4a64d7f97804
[one.git] / tests / data_plane / vpp_lite_topo / scripts / vat / mapping_exists.py
1 # Script for checking whether a mapping exists in the vpp's map-cache
2 #
3 # Params:
4 #   vat_exec - VAT executable
5 #   vpp_prefix - shared vpp memory prefix
6 #   mapping - mapping to verify
7
8 import sys
9 import subprocess
10 import json
11
12 def has_mapping(json, mapping):
13   if len (json) == 0:
14     return False
15
16   for obj in json:
17     if obj['eid'] == mapping:
18       return True;
19
20   return False
21
22 def verify_mapping(vat_exec, prefix, mapping, vat_path):
23   vat_file = vat_path + '/' + 'dump_remote_mappings.tpl'
24   out = subprocess.Popen([vat_exec, "chroot", "prefix", prefix, "json", "script",
25       "in", vat_file], stdout=subprocess.PIPE).communicate()[0]
26
27   o = json.loads(out)
28   return has_mapping(o, mapping)
29
30 if __name__ == "__main__":
31   if len(sys.argv) < 4:
32     raise Exception('expecteds 4 parameters: VAT executable, shared prefix '
33         + ' name, mapping expected, path to vat templates!')
34
35   if verify_mapping(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]):
36     sys.exit(0)
37   else:
38     sys.exit(1)