def _mkconfigopts(cfg_opts): reg = TemplateRegistry() register_templates(reg, cfg_opts) for ct in cfg_opts.master_template_kwargs: reg.register(ct) resolver = TemplateResolver(**reg.to_kwargs()) return ConfigOpts.from_params(cfg_opts, resolver)
def distribution(self, *master_template_args, **kwargs): """Master makes the distribution""" self.tasks = [] config_path = resolve_config_paths(self.options.hodconf, self.options.dist) m_config = load_hod_config(config_path, self.options.workdir, self.options.modulepaths, self.options.modules) m_config.autogen_configs() resolver = _setup_template_resolver(m_config, master_template_args) _setup_config_paths(m_config, resolver) master_env = dict([(v, os.getenv(v)) for v in m_config.master_env]) # There may be scripts in the hod.conf dir so add it to the PATH master_env['PATH'] = master_env.get('PATH', os.getenv('PATH')) + os.pathsep + m_config.hodconfdir self.log.debug('MasterEnv is: %s', env2str(master_env)) svc_cfgs = m_config.service_files self.log.info('Loading %d service configs.', len(svc_cfgs)) for config_filename in svc_cfgs: self.log.info('Loading "%s" service config', config_filename) config = ConfigOpts.from_file(open(config_filename, 'r'), resolver) ranks_to_run = config.runs_on(MASTERRANK, range(self.size)) self.log.debug('Adding ConfiguredService Task to work with config: %s', str(config)) cfg_opts = config.to_params(m_config.workdir, m_config.modulepaths, m_config.modules, master_template_args) self.tasks.append(Task(ConfiguredService, config.name, ranks_to_run, cfg_opts, master_env)) if hasattr(self.options, 'script') and self.options.script is not None: label = self.options.label env_script = 'source ' + hc.cluster_env_file(label) script = self.options.script script_stdout, script_stderr = _script_output_paths(script, label) redirection = ' > %s 2> %s' % (script_stdout, script_stderr) start_script = env_script + ' && ' + script + redirection + '; qdel $PBS_JOBID' self.log.debug('Adding script Task: %s', start_script) # TODO: How can we test this? config = ConfigOpts(script, RUNS_ON_MASTER, '', start_script, '', master_env, resolver, timeout=NO_TIMEOUT) ranks_to_run = config.runs_on(MASTERRANK, range(self.size)) cfg_opts = config.to_params(m_config.workdir, m_config.modulepaths, m_config.modules, master_template_args) self.tasks.append(Task(ConfiguredService, config.name, ranks_to_run, cfg_opts, master_env))