def _run_setup(self): if self.setup: module, err = get_module(self.setup, self.service_parameters) if not err: if hasattr(module,'setup_deploy'): # call the setup_deloy fxn in the module err = module.setup_deploy(self.service_parameters) else: msg = ("setup module %s "%self.setup + " does not have a 'setup_deploy' function") if err: self.logger.error(msg)
def _run_setup(self, name, target, module_rel_path): err = "" servicefile_path = self.params.get("servicefile-path") module, err = get_module(module_rel_path, servicefile_path) if not err: if hasattr(module, 'test_setup'): # call the test_setup fxn in the module err = module.test_setup(target, self.params) else: err = ("setup module %s does not have a " + "'test_setup' function" % module_rel_path) return err
def run(self, params): err = "" self.params = params servicefile_path = self.params.get('servicefile-path') # process task inputs and load results into params self.inputs.load(self.params) task_module, err = get_module(self.module, servicefile_path) # run the handler method in the task module if not err: if hasattr(task_module, 'task_handler'): err = task_module.task_handler(self.params) else: err = ("task module %s does not have a " + "'test_setup' function" % self.module) return err
def get_engine(engine_type, engine_key, serialized_obj): engine_configs = get_engine_configs() instance = None err = "" if engine_type: module_path = search( "%s[?key=='%s'] | [0].module" % (engine_type, engine_key), engine_configs) class_name = search( "%s[?key=='%s'] | [0].class" % (engine_type, engine_key), engine_configs) provider_module, err = get_module(module_path) if not err and class_name: class_ = getattr(provider_module, class_name) instance = class_(serialized_obj) return instance, err
def register_engine(engine_type, engine_key, module_path, class_name, configs_path=""): configs = get_engine_configs(configs_path) err = "" provider_module, err = get_module(module_path) if not err and class_name: class_ = getattr(provider_module, class_name) instance = class_({}) # make sure engine does not already exist existing_module_path = search( "%s[?key=='%s'] | [0].module" % (engine_type, engine_key), configs) if existing_module_path: err = "'%s' engine with key %s already exists" % (engine_type, engine_key) if not err: configs[engine_type].append({ "key": engine_key, "module": module_path, "class": class_name }) # write the engine configs to disk write_engine_configs(configs, configs_path) return err
def run( self ): servicefile_path = self.params.get("servicefile-path") module, err = get_module(self.driver_path, servicefile_path) if not err: if hasattr(module,'test_driver'): # call the test driver fxn in the module return_val = module.test_driver( self.test_name, self.target, self.test_results, self.params, self.context) else: msg = ("custom test module %s does " + "not have a 'test_driver' function"%self.driver_path) if err: self.test_results.failing_test(self.test_name, err)
def do_calc(calc_arg, params): """ Generates a parameter via a calculation, either via a 'stock' calculator, or via a provided calculator module. stock calcs are describe in wiki on the 'yac calcs' page Args: calc_arg: argv-style list where: * first item is either stock_calc_fxn_map or a path to a custom calc module with a do_calc function * remaining items are arguments to be pass to the function params: a Params instance Returns: object: an object containing the calculated value err: a string containing an error code Raises: None """ stock_calc_fxn_map = { 'vpc-id': calc_vpc_id, 'subnet-ids': calc_subnet_ids, 'ec2-boot': calc_ec2_user_data, 'subnet-id': calc_subnet_id, 'vpc-cidr': calc_vpc_cidr, 'b64enc': calc_base64_encoding, 'to_int': calc_int, 'configmaps-hash': calc_configmaps_hash, 'secrets-hash': calc_secrets_hash } # initialize return values value = None err = "" calc_key = calc_arg[0] if calc_key in list(stock_calc_fxn_map.keys()): if len(calc_arg) > 1: value, err = stock_calc_fxn_map[calc_key](params, calc_arg[1:]) else: value, err = stock_calc_fxn_map[calc_key](params) else: localized_file_path = "" servicefile_path = params.get('servicefile-path', "") if os.path.exists(os.path.join(get_yac_path(), calc_key)): # calculator is part of yac (but renders intrinsics, so can't # be imported directly) localized_file_path = os.path.join(get_yac_path(), calc_key) else: # treat the argument as a custom calculator localized_file_path = localize_file(calc_key, servicefile_path) if localized_file_path: calc_module, err = get_module(localized_file_path, servicefile_path) if not err: argv = calc_arg[1:] if calc_arg[1:] else [] try: value, err = calc_module.do_calc(argv, params) except AttributeError as e: err = "calling do_calc() against %s failed with error: %s" % ( calc_key, e) else: err = "calc file %s does not exist" % calc_key return value, err