def start_work_service(self): """Start service by running the ExecStart script.""" env = os.environ.copy() env.update(self._config.env) env.update(self._master_env) rank = self.svc.rank self.log.info('Starting %s service on rank %s: "%s"', self._config.name, rank, self._config.start_script) self.log.info("Env for %s service on rank %s: %s", self._config.name, rank, env2str(env)) command = Command(self._config.start_script, env=env, timeout=self._config.timeout) output = command.run() self.log.info('Ran %s service on rank %s start script. Output: "%s"', self._config.name, rank, output)
def test_ConfigOpts_runs_on_MASTER(self): config = StringIO(""" [Unit] Name=testconfig RunsOn=master [Service] ExecStart=starter ExecStop=stopper [Environment] SOME_ENV=123""") cfg = hcc.ConfigOpts.from_file(config, hct.TemplateResolver(workdir='')) self.assertEqual(cfg.name, 'testconfig') self.assertEqual(cfg._runs_on, hcc.RUNS_ON_MASTER) self.assertEqual(cfg.runs_on(0, [0, 1, 2, 3]), [0]) self.assertEqual(cfg.start_script, 'starter') self.assertEqual(cfg.stop_script, 'stopper') self.assertTrue('SOME_ENV' in cfg.env) self.assertEqual(cfg.env['SOME_ENV'], '123') self.assertTrue(isinstance(cfg.env['SOME_ENV'], basestring)) self.assertEqual(hcc.env2str(cfg.env), 'SOME_ENV="123" ')
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))
def test_env2str(self): env = dict(PATH="/usr/bin", LD_LIBRARY_PATH="something with spaces") self.assertEqual(hcc.env2str(env), 'LD_LIBRARY_PATH="something with spaces" PATH="/usr/bin" ')