Example #1
0
def test_num_nodes(scheduler_and_fs: Tuple[Scheduler, FileSystem]) -> None:
    sched, fs, _ = scheduler_and_fs

    if isinstance(sched, DirectGnuScheduler):
        # this scheduler runs everything on the same node
        # and ignores the num_nodes attribute
        return

    job_desc = JobDescription()
    job_desc.working_directory = '/home/cerulean'
    job_desc.num_nodes = 2

    if isinstance(sched, TorqueScheduler):
        job_desc.command = 'wc'
        job_desc.arguments = ['-l', '$PBS_NODEFILE']
    elif isinstance(sched, SlurmScheduler):
        job_desc.command = 'echo'
        job_desc.arguments = ['$SLURM_JOB_NUM_NODES']

    job_desc.queue_name = 'batch'
    job_desc.stdout_file = '/home/cerulean/test_num_nodes.out'
    job_id = sched.submit(job_desc)

    while sched.get_status(job_id) != JobStatus.DONE:
        time.sleep(10.0)

    outfile = fs / 'home/cerulean/test_num_nodes.out'
    num_nodes_output = outfile.read_text()
    assert '2' in outfile.read_text()
    outfile.unlink()
Example #2
0
def test_scheduler(scheduler_and_fs: Tuple[Scheduler, FileSystem],
                   caplog: Any) -> None:
    caplog.set_level(logging.DEBUG)
    sched, fs, _ = scheduler_and_fs

    job_desc = JobDescription()
    job_desc.working_directory = '/home'
    job_desc.command = 'ls'
    job_desc.arguments = ['-l']
    job_desc.stdout_file = '/home/cerulean/test_scheduler.out'
    job_id = sched.submit(job_desc)
    print('Job id: {}'.format(job_id))

    while sched.get_status(job_id) != JobStatus.DONE:
        time.sleep(10.0)

    retval = sched.get_exit_code(job_id)
    assert retval == 0

    try:
        output = (fs / 'home/cerulean/test_scheduler.out').read_text()
    except FileNotFoundError:
        msg = ''
        for path in (fs / 'home/cerulean').iterdir():
            msg += '{}\n'.format(path)
        pytest.xfail('Output file not found, to be investigated.'
                     ' Debug output: {}'.format(msg))
    assert 'cerulean' in output

    (fs / 'home/cerulean/test_scheduler.out').unlink()
Example #3
0
def test_queue_name(scheduler_and_fs: Tuple[Scheduler, FileSystem]) -> None:
    sched, fs, _ = scheduler_and_fs

    if isinstance(sched, DirectGnuScheduler):
        # this scheduler ignores queues
        return

    job_desc = JobDescription()
    job_desc.working_directory = '/home/cerulean'
    job_desc.command = 'echo'
    job_desc.arguments = ['$SLURM_JOB_PARTITION', '$PBS_QUEUE']
    job_desc.queue_name = 'batch'
    job_desc.stdout_file = '/home/cerulean/test_queue_name.out'
    job_id = sched.submit(job_desc)
    print('Job id: {}'.format(job_id))

    while sched.get_status(job_id) != JobStatus.DONE:
        time.sleep(10.0)

    retval = sched.get_exit_code(job_id)
    assert retval == 0

    outfile = fs / 'home/cerulean/test_queue_name.out'
    assert 'batch' in outfile.read_text()
    outfile.unlink()
Example #4
0
def test_job_script_command_args() -> None:
    # Note: doesn't test that it works, that's what test_scheduler is for
    job_desc = JobDescription()
    job_desc.command = 'echo'
    job_desc.arguments = ['-n', 'Hello world', 'testing']

    script = _job_desc_to_job_script(job_desc)

    assert "echo -n Hello world testing" in script
Example #5
0
def test_scheduler_exit_code(scheduler_and_fs: Tuple[Scheduler, FileSystem],
                             caplog: Any) -> None:
    caplog.set_level(logging.DEBUG)
    sched, fs, _ = scheduler_and_fs

    job_desc = JobDescription()
    job_desc.working_directory = '/home/cerulean'
    job_desc.command = 'exit'
    job_desc.arguments = ['5']
    job_id = sched.submit(job_desc)

    while sched.get_status(job_id) != JobStatus.DONE:
        time.sleep(10.0)

    retval = sched.get_exit_code(job_id)
    assert retval == 5
Example #6
0
def test_system_err_redirect(
        scheduler_and_fs: Tuple[Scheduler, FileSystem]) -> None:
    sched, fs, _ = scheduler_and_fs

    job_desc = JobDescription()
    job_desc.working_directory = '/home/cerulean'
    job_desc.command = 'bash'
    job_desc.arguments = ['-c', 'for i in x ; do something invalid']
    job_desc.time_reserved = 1
    job_desc.stderr_file = '/dev/null'
    job_desc.system_err_file = '/home/cerulean/test_sys_redirect.err'

    job_id = sched.submit(job_desc)
    sched.wait(job_id)

    syserr = (fs / 'home/cerulean/test_sys_redirect.err').read_text()

    retval = sched.get_exit_code(job_id)
    assert retval != 0
    assert 'syntax error' in syserr
Example #7
0
def test_stderr_redirect(
        scheduler_and_fs: Tuple[Scheduler, FileSystem]) -> None:
    sched, fs, _ = scheduler_and_fs

    job_desc = JobDescription()
    job_desc.working_directory = '/home'
    job_desc.command = 'ls'
    job_desc.arguments = ['--non-existing-option']
    job_desc.stderr_file = '/home/cerulean/test_stderr_redirect.out'
    job_id = sched.submit(job_desc)
    print('Job id: {}'.format(job_id))

    while sched.get_status(job_id) != JobStatus.DONE:
        time.sleep(10.0)

    retval = sched.get_exit_code(job_id)
    assert retval == 2

    outfile = fs / 'home/cerulean/test_stderr_redirect.out'
    assert 'unrecognized option' in outfile.read_text()
    outfile.unlink()
Example #8
0
def test_scheduler_cancel(scheduler_and_fs: Tuple[Scheduler, FileSystem],
                          caplog: Any) -> None:
    caplog.set_level(logging.DEBUG)
    sched, fs, _ = scheduler_and_fs

    job_desc = JobDescription()
    job_desc.working_directory = '/home/cerulean'
    job_desc.command = 'sleep'
    job_desc.arguments = ['15']
    job_id = sched.submit(job_desc)
    print('Job id: {}'.format(job_id))

    while sched.get_status(job_id) != JobStatus.RUNNING:
        time.sleep(1.0)

    sched.cancel(job_id)

    t = 0.0
    while sched.get_status(job_id) != JobStatus.DONE:
        time.sleep(1.0)
        t += 1.0
        assert t < 10.0
Example #9
0
def test_environment(scheduler_and_fs: Tuple[Scheduler, FileSystem]) -> None:
    sched, fs, _ = scheduler_and_fs

    job_desc = JobDescription()
    job_desc.environment['ENVIRONMENT_TEST1'] = 'test_environment_value1'
    job_desc.environment['ENVIRONMENT_TEST2'] = 'test_environment_value2'
    job_desc.command = 'echo'
    job_desc.arguments = ['$ENVIRONMENT_TEST1', '$ENVIRONMENT_TEST2']
    job_desc.stdout_file = '/home/cerulean/test_environment.out'

    job_id = sched.submit(job_desc)
    print('Job id: {}'.format(job_id))

    while sched.get_status(job_id) != JobStatus.DONE:
        time.sleep(10.0)

    retval = sched.get_exit_code(job_id)
    assert retval == 0

    outfile = fs / 'home/cerulean/test_environment.out'
    assert 'test_environment_value1' in outfile.read_text()
    assert 'test_environment_value2' in outfile.read_text()
    outfile.unlink()