- return getattr(self, section)
- except:
- msg = 'Section {} not found in the configuration file'.\
- format(section)
- raise ValueError(msg)
-
-# ------------------------------------------------------
-# Manage files
-# ------------------------------------------------------
-
-
-def get_heat_template_params():
- """
- Returns the list of deployment parameters from the configuration file
- for the heat template
-
- :return: dict
- """
- heat_parameters_list = CONF_FILE.get_variable_list(
- files.DEPLOYMENT_PARAMETERS)
- testcase_parameters = dict()
- for param in heat_parameters_list:
- testcase_parameters[param] = CONF_FILE.get_variable(
- files.DEPLOYMENT_PARAMETERS, param)
- return testcase_parameters
-
-
-def get_testcase_params():
- """
- Returns the list of testcase parameters from the configuration file
-
- :return: dict
- """
- testcase_parameters = dict()
- parameters = CONF_FILE.get_variable_list(files.TESTCASE_PARAMETERS)
- for param in parameters:
- testcase_parameters[param] = CONF_FILE.get_variable(
- files.TESTCASE_PARAMETERS, param)
- return testcase_parameters
-
-
-def get_file_first_line(file_name):
- """
- Returns the first line of a file
-
- :param file_name: name of the file to be read (str)
- :return: str
- """
- message = "name of the file must be a string"
- InputValidation.validate_string(file_name, message)
- message = 'file {} does not exist'.format(file_name)
- InputValidation.validate_file_exist(file_name, message)
- res = open(file_name, 'r')
- return res.readline()
-
-
-def replace_in_file(file, text_to_search, text_to_replace):
- """
- Replaces a string within a file
-
- :param file: name of the file (str)
- :param text_to_search: text to be replaced
- :param text_to_replace: new text that will replace the previous
- :return: None
- """
- message = 'text to be replaced in the file must be a string'
- InputValidation.validate_string(text_to_search, message)
- message = 'text to replace in the file must be a string'
- InputValidation.validate_string(text_to_replace, message)
- message = "name of the file must be a string"
- InputValidation.validate_string(file, message)
- message = "The file does not exist"
- InputValidation.validate_file_exist(file, message)
- for line in fileinput.input(file, inplace=True):
- print(line.replace(text_to_search, text_to_replace).rstrip())
-
-# ------------------------------------------------------
-# Shell interaction
-# ------------------------------------------------------
-
-
-def run_command(command):
- LOG.info("Running command: {}".format(command))
- return os.system(command)
-
-# ------------------------------------------------------
-# Expose variables to other modules
-# ------------------------------------------------------
-
-
-def get_base_dir():
- return BASE_DIR
-
-
-def get_template_dir():
- return TEMPLATE_DIR
-
-# ------------------------------------------------------
-# Configuration Variables from Config File
-# ------------------------------------------------------
-
-
-def get_deployment_configuration_variables_from_conf_file():
- variables = dict()
- types = dict()
- all_variables = CONF_FILE.get_variable_list(files.EXPERIMENT_VNF)
- for var in all_variables:
- v = CONF_FILE.get_variable(files.EXPERIMENT_VNF, var)
- type = re.findall(r'@\w*', v)
- values = re.findall(r'\"(.+?)\"', v)
- variables[var] = values
- try:
- types[var] = type[0][1:]
- except IndexError:
- LOG.debug("No type has been specified for variable " + var)
- return variables
-
-# ------------------------------------------------------
-# benchmarks from Config File
-# ------------------------------------------------------
-
-
-def get_benchmarks_from_conf_file():
- requested_benchmarks = list()
- benchmarks = CONF_FILE.get_variable(
- files.GENERAL, files.BENCHMARKS).split(', ')
- for benchmark in benchmarks:
- requested_benchmarks.append(benchmark)
- return requested_benchmarks
-
-
-class InputValidation(object):
-
- @staticmethod
- def validate_string(param, message):
- if not isinstance(param, str):
- raise ValueError(message)
- return True
-
- @staticmethod
- def validate_integer(param, message):
- if not isinstance(param, int):
- raise ValueError(message)
- return True