def test_get_submit_cmd(self): scheduler = EmopSLURM(self.settings) expected_cmd = [ "sbatch", "--parsable", "-p", "stakeholder,stakeholder-4g", "-J", "emop-controller", "-o", "/dne/emop-controller-%j.out", "--mem-per-cpu", "4000", "--cpus-per-task", "1", os.path.join(self.settings.emop_home, "batch_scripts/emop.slrm") ] actual_cmd = scheduler.get_submit_cmd('1') self.assertEqual(expected_cmd, actual_cmd)
def test_current_job_count(self): scheduler = EmopSLURM(self.settings) expected_cmd = [ "squeue", "-r", "--noheader", "-p", "stakeholder,stakeholder-4g", "-n", "emop-controller" ] mock_stdout = (" 0001 idhmc emop-controller treydock R 0:01:00 1 c0101\n" " 0002 idhmc emop-controller treydock R 0:01:00 1 c0102\n") self.mock_rv.communicate.return_value[0] = mock_stdout retval = scheduler.current_job_count() args, kwargs = self.mock_popen.call_args self.assertTrue(self.mock_popen.called) self.assertEqual(expected_cmd, args[0]) self.assertEqual(retval, 2)
def test_submit_job(self): scheduler = EmopSLURM(self.settings) expected_cmd = [ "sbatch", "--parsable", "-p", "stakeholder,stakeholder-4g", "-J", "emop-controller", "-o", "/dne/emop-controller-%j.out", "--mem-per-cpu", "4000", "--cpus-per-task", "1", os.path.join(self.settings.emop_home, "batch_scripts/emop.slrm") ] self.mock_rv.communicate.return_value[0] = "1" retval = scheduler.submit_job('0001', '1') args, kwargs = self.mock_popen.call_args PROC_ID = os.environ.get('PROC_ID') EMOP_CONFIG_PATH = os.environ.get('EMOP_CONFIG_PATH') self.assertTrue(self.mock_popen.called) self.assertEqual(expected_cmd, args[0]) self.assertEqual(PROC_ID, '0001') self.assertEqual(EMOP_CONFIG_PATH, self.settings.config_path) self.assertTrue(retval)
def test_submit_job_failed(self): scheduler = EmopSLURM(self.settings) self.mock_rv.communicate.return_value[0] = "1" self.mock_rv.returncode = 1 retval = scheduler.submit_job('0001', '1') self.assertFalse(retval)
def test_get_job_id(self): scheduler = EmopSLURM(self.settings) os.environ["SLURM_JOB_ID"] = '0001' actual = scheduler.get_job_id() self.assertEqual('0001', actual)
def test_get_name(self): scheduler = EmopSLURM(self.settings) self.assertEqual("SLURM", scheduler.get_name())
def test_get_job_id_not_set(self): scheduler = EmopSLURM(self.settings) self.clear_job_id_env() actual = scheduler.get_job_id() self.assertEqual(None, actual)
def test_is_job_environment_true(self): scheduler = EmopSLURM(self.settings) os.environ["SLURM_JOB_ID"] = '0001' retval = scheduler.is_job_environment() self.assertTrue(retval)
def test_is_job_environment_false(self): scheduler = EmopSLURM(self.settings) self.clear_job_id_env() retval = scheduler.is_job_environment() self.assertFalse(retval)
def test_walltime_150pct_2(self): scheduler = EmopSLURM(self.settings) walltime = scheduler.walltime(39) self.assertEqual(walltime, 3510)
def test_walltime_150pct_1(self): scheduler = EmopSLURM(self.settings) walltime = scheduler.walltime(40) self.assertEqual(walltime, 3600)
def test_walltime_200pct_2(self): scheduler = EmopSLURM(self.settings) walltime = scheduler.walltime(29) self.assertEqual(walltime, 3480)
def test_walltime_400pct_2(self): scheduler = EmopSLURM(self.settings) walltime = scheduler.walltime(14) self.assertEqual(walltime, 3360)
def test_walltime_max_runtime(self): scheduler = EmopSLURM(self.settings) walltime = scheduler.walltime(61) self.assertEqual(walltime, 3600)