summaryrefslogtreecommitdiffstats
path: root/tests/data_plane/vpp_lite_topo/scripts/generate_config.py
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2016-09-07 15:47:47 +0200
committerFilip Tehlar <ftehlar@cisco.com>2016-09-12 14:41:10 +0200
commitbf231ba795387064e7c4f1781240619429a4ef29 (patch)
tree86da34369910ca1c85672ed30d4374d4ecda9ac3 /tests/data_plane/vpp_lite_topo/scripts/generate_config.py
parent1df1d674eaace35d52973786403eb1dbe3c0d5eb (diff)
Introduce an option for testing binary API
This patch introduces an option for choosing a configuration method in tests. Supported methods are VAT and vpp's debug CLI. * Added new aprameter to run.sh to define method (--cfg-method [vat|cli]). Defaults to vat. * When running a test separately the method can be set as follows: $ sudo CFG_METHOD=cli ./tests/<test_case>.sh Again, it defaults to 'vat' if not provided. * Increased readability in test driver scripts when checking test status * When debugging you can stop test execution by running the test with WAIT=1: $ sudo WAIT=1 tests/<test_case>.sh Change-Id: If851139cff072ba2e3b3594a3345763d360f3b59 Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Diffstat (limited to 'tests/data_plane/vpp_lite_topo/scripts/generate_config.py')
-rwxr-xr-xtests/data_plane/vpp_lite_topo/scripts/generate_config.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/data_plane/vpp_lite_topo/scripts/generate_config.py b/tests/data_plane/vpp_lite_topo/scripts/generate_config.py
new file mode 100755
index 0000000..87204a6
--- /dev/null
+++ b/tests/data_plane/vpp_lite_topo/scripts/generate_config.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+
+"""
+generate_config.py - Generate specific configuration file for VPP from
+ generic config file
+
+Usage:
+ ./generate_config.py <directory> <output-file-type>
+
+where <directory> is a system directory containing generic config file(s)
+ (suffixed with *.config)
+ <output-file-type> is one of 'vat' or 'cli'
+
+This script looks for *.config files in provided directory and for each
+generates a specific configuration file based on output file type in form
+'<filename>.cli' or '<filename>.vat' respectively.
+"""
+
+import sys
+import glob
+import cmd_mappings
+
+
+def generate_config(file_name, mode):
+ """
+ param file_name:
+ param mode: one of 'vat' or 'cli'
+ """
+ s = ''
+ f = open(file_name, 'r')
+ line_num = 0
+
+ for line in f:
+ line_num += 1
+ line = line.strip()
+ if line == '' or line[0] == '#':
+ continue
+
+ kw = line[: line.index(' ')]
+ args = line[ line.index(' ') + 1:]
+
+ if kw not in cmd_mappings.mappings:
+ raise Exception('Conversion error at {}:{}:\n > {}\nKeyword not found:'
+ ' {}'.format(file_name, line_num, line, kw))
+
+ mapping = cmd_mappings.mappings[kw]
+ try:
+ s = s + mapping.generate(mode, args) + '\n'
+ except Exception as e:
+ raise Exception('Conversion error at {}:{}:\n > {}'
+ .format(file_name, line_num, line))
+
+ return s
+
+
+def main():
+ if len(sys.argv) != 3:
+ print('Error: expected 2 arguments!')
+ sys.exit(1)
+
+ dir_name = sys.argv[1]
+ config_type = sys.argv[2]
+
+ if config_type != 'vat' and config_type != 'cli':
+ print('Error: expected second parameter one of "vat" or "cli"!')
+ sys.exit(1)
+
+ for f in glob.glob(dir_name + "/*.config"):
+ config = generate_config(f, config_type)
+
+ output_fname = f.replace('.config', '.' + config_type)
+ print('\n* Generated config from {}:'.format(f))
+ print(config)
+ print ('* Saving to {}'.format(output_fname))
+
+ fout = open(output_fname, 'w')
+ fout.write(config);
+
+
+main()