示例#1
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()
示例#2
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()
示例#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()
示例#4
0
def test_job_script_stdout_file() -> None:
    # Note: doesn't test that it works, that's what test_scheduler is for
    job_desc = JobDescription()
    job_desc.stdout_file = '/home/user/test.out'

    script = _job_desc_to_job_script(job_desc)

    assert '/home/user/test.out' in script
示例#5
0
def test_system_out_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 = 'ls'
    job_desc.time_reserved = 1
    job_desc.stdout_file = '/dev/null'
    job_desc.system_out_file = '/home/cerulean/test_sys_redirect.out'

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

    sysout = (fs / 'home/cerulean/test_sys_redirect.out').read_text()

    retval = sched.get_exit_code(job_id)
    assert retval == 0
    assert sysout == ''
示例#6
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()