def main(args): """Run HOD cluster.""" optparser = LocalOptions(go_args=args) if MPI.COMM_WORLD.rank == MASTERRANK: label = optparser.options.label if label is None: # if no label is specified, use job ID; # if $PBS_JOBID is not set, generate a random string (10 chars) label = os.getenv('PBS_JOBID', ''.join(random.choice(string.letters + string.digits) for _ in range(10))) optparser.options.label = label _log.debug("Creating cluster info using label '%s'", label) cluster_info = gen_cluster_info(label, optparser.options) try: save_cluster_info(cluster_info) except (IOError, OSError) as e: _log.error("Failed to save cluster info files: %s", e) sys.exit(1) _log.debug("Starting master process") svc = ConfiguredMaster(optparser.options) else: _log.debug("Starting slave process") svc = ConfiguredSlave(optparser.options) try: setup_tasks(svc) run_tasks(svc) svc.stop_service() return 0 except Exception as err: _log.error(str(err)) _log.exception("HanythingOnDemand failed") sys.exit(1)
def test_save_cluster_info(self): env_file = StringIO() with patch('hod.cluster.cluster_jobid', side_effect=lambda lbl: dict(banana='123', apple='abc')[lbl]): with patch('hod.cluster.cluster_info_exists', return_value=True): with patch('hod.cluster.generate_cluster_env_script', return_value='my script'): with patch('__builtin__.open', side_effect=_mock_open(env=env_file)): hc.save_cluster_info(dict(label='banana', hadoop_conf_dir='hadoop', hod_localworkdir='localworkdir', modules='', workdir='')) self.assertTrue(env_file.getvalue(), 'my script')