1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Can be used to generate VAT scripts from VAT template files."""
16 from robot.api import logger
19 class VatConfigGenerator(object):
20 """Generates VAT configuration scripts from VAT script template files.
26 def generate_vat_config_file(template_file, env_var_dict, out_file):
27 """ Write VAT configuration script to out file.
29 Generates VAT configuration script from template using
30 dictionary containing environment variables
31 :param template_file: file that contains the VAT script template
32 :param env_var_dict: python dictionary that maps test
36 template_data = open(template_file).read()
37 logger.trace("Loaded template file: \n '{0}'".format(template_data))
38 generated_config = template_data.format(**env_var_dict)
39 logger.trace("Generated script file: \n '{0}'".format(generated_config))
40 with open(out_file, 'w') as work_file:
41 work_file.write(generated_config)
44 def generate_vat_config_string(template_file, env_var_dict):
45 """ Return wat config string generated from template.
47 Generates VAT configuration script from template using
48 dictionary containing environment variables
49 :param template_file: file that contains the VAT script template
50 :param env_var_dict: python dictionary that maps test
54 template_data = open(template_file).read()
55 logger.trace("Loaded template file: \n '{0}'".format(template_data))
56 generated_config = template_data.format(**env_var_dict)
57 logger.trace("Generated script file: \n '{0}'".format(generated_config))
58 return generated_config