Ejemplo n.º 1
0
def test_invalid_plugin_ignored(observer: TestStateObserver):
    test_plugin.TestPlugin.error_on_new_job_instance = BaseException(
        'Must be captured')
    create_test_config({"plugins": ["test_plugin"]
                        })  # Use testing plugin in package 'test_plugin'
    run_app('exec --id run_with_failing_plugin echo')

    assert observer.exec_state(-1) == ExecutionState.COMPLETED
Ejemplo n.º 2
0
def test_exec_time_warning():
    observer = TestWarningObserver()
    runner.register_warning_observer(observer)
    try:
        run_app("exec -mc --warn-time=1s sleep 1.2")
    finally:
        runner.deregister_warning_observer(observer)

    assert observer.warnings['exec_time>1.0s']
Ejemplo n.º 3
0
def test_logging_stdout_level_cli_override():
    create_test_config(
        {"log": {
            "enabled": True,
            "stdout": {
                "level": "error"
            }
        }})
    run_app('exec --set log_stdout_level=warn echo')
    assert logging.WARN == log.get_console_level()
Ejemplo n.º 4
0
def test_logging_stdout_level_in_config():
    create_test_config(
        {"log": {
            "enabled": True,
            "stdout": {
                "level": "error"
            }
        }})
    run_app('exec echo')
    assert logging.ERROR == log.get_console_level()
Ejemplo n.º 5
0
def test_job_instance_filter_true(capsys):
    run_app_as_process_and_wait('exec -mc --id f_test_job1 sleep 1',
                                wait_for=ExecutionState.RUNNING,
                                daemon=True)

    run_app('ps f_test_job*')
    output = capsys.readouterr().out

    jobs = ps.parse_table(output, view_inst.DEFAULT_COLUMNS)
    assert len(jobs) == 1
Ejemplo n.º 6
0
def test_job_persisted():
    cfg.persistence_enabled = True
    cfg.persistence_type = 'sqlite'
    cfg.persistence_database = str(test_db_path())

    try:
        run_app('exec --id persisted_job echo')
        assert next(iter(
            persistence.read_jobs(asc=True))).job_id == 'persisted_job'
    finally:
        remove_test_db()
Ejemplo n.º 7
0
def test_stop(capsys):
    run_w = run_wait(ExecutionState.RUNNING, 2)
    stop_w = run_wait(ExecutionState.STOPPED)
    p1 = run_app_as_process('exec -mc --id to_stop sleep 5', daemon=True)
    p2 = run_app_as_process('exec -mc --id to_keep sleep 5', daemon=True)
    run_w.join()  # Wait for both exec to run

    run_app('stop to_stop')

    stop_w.join(1)
    assert not p1.is_alive()
    assert p2.is_alive()
Ejemplo n.º 8
0
def test_job_waiting(capsys):
    run_app_as_process_and_wait('exec -mc -p val sleep 1',
                                wait_for=ExecutionState.PENDING,
                                daemon=True)

    run_app('ps')
    output = capsys.readouterr().out

    jobs = ps.parse_table(output, view_inst.DEFAULT_COLUMNS)
    assert 'sleep 1' == jobs[0][view_inst.JOB_ID]
    assert ExecutionState.PENDING.name.casefold() == jobs[0][
        view_inst.STATE].casefold()
Ejemplo n.º 9
0
def test_more_jobs_require_all_flag(capsys):
    pw = run_wait(ExecutionState.RUNNING, 2)
    p1 = run_app_as_process('exec -mc --id j1 sleep 5', daemon=True)
    p2 = run_app_as_process('exec -mc --id j1 sleep 5', daemon=True)
    pw.join()  # Wait for both exec to run

    run_app('stop j1')

    output = capsys.readouterr().out
    assert 'No action performed' in output
    assert p1.is_alive()
    assert p2.is_alive()
Ejemplo n.º 10
0
def test_job_status(capsys):
    # Shell to use '&&' to combine commands
    run_app_as_process_and_wait(
        'exec -mc --id p_test echo progress1 && sleep 1',
        wait_for=ExecutionState.RUNNING,
        daemon=True,
        shell=True)

    run_app('ps')
    output = capsys.readouterr().out

    jobs = ps.parse_table(output, view_inst.DEFAULT_COLUMNS)
    assert 'progress1' == jobs[0][view_inst.STATUS]
Ejemplo n.º 11
0
def test_disable_job(observer: TestStateObserver):
    create_test_config({
        "persistence": {
            "enabled": True,
            "type": "sqlite",
            "database": str(test_db_path())
        }
    })
    run_app('disable job_to_disable')
    run_app('exec --id job_to_disable echo')

    assert observer.last_job().job_id == 'job_to_disable'
    assert observer.exec_state(-1) == ExecutionState.DISABLED
Ejemplo n.º 12
0
def test_more_jobs_require_all_flag(capsys):
    p1 = run_app_as_process_and_wait('exec -mc --id j1 sleep 5',
                                     wait_for=ExecutionState.RUNNING,
                                     daemon=True)
    p2 = run_app_as_process_and_wait('exec -mc --id j1 sleep 5',
                                     wait_for=ExecutionState.RUNNING,
                                     daemon=True)

    run_app('stop j1')

    output = capsys.readouterr().out
    assert 'No action performed' in output
    assert p1.is_alive()
    assert p2.is_alive()
Ejemplo n.º 13
0
def test_stop():
    p1 = run_app_as_process_and_wait('exec -mc --id to_stop sleep 5',
                                     wait_for=ExecutionState.RUNNING,
                                     daemon=True)
    p2 = run_app_as_process_and_wait('exec -mc --id to_keep sleep 5',
                                     wait_for=ExecutionState.RUNNING,
                                     daemon=True)

    run_app('stop to_stop --force')

    p1.join(
        timeout=1
    )  # Timeout (1 sec) must be x times smaller than sleeping interval (5 sec)
    assert not p1.is_alive()
    assert p2.is_alive()
Ejemplo n.º 14
0
def test_logging_file_path_cli_override():
    create_test_config({
        "log": {
            "mode": True,
            "file": {
                "level": "error",
                "path": "to_liberation.log"
            }
        }
    })
    try:
        run_app('exec --set log_file_path=to_nowhere.log echo')
        assert log.get_file_path().endswith('to_nowhere.log')
    finally:
        log_file = Path('to_nowhere.log')
        if log_file.exists():
            log_file.unlink()
Ejemplo n.º 15
0
def test_logging_file_path_in_config():
    create_test_config({
        "log": {
            "enabled": True,
            "file": {
                "level": "error",
                "path": "to_liberation.log"
            }
        }
    })
    try:
        run_app('exec echo')
        assert log.get_file_path().endswith('to_liberation.log')
    finally:
        log_file = Path('to_liberation.log')
        if log_file.exists():
            log_file.unlink()
Ejemplo n.º 16
0
def test_disable_jobs_by_regex(observer: TestStateObserver):
    create_test_config({
        "persistence": {
            "enabled": True,
            "type": "sqlite",
            "database": str(test_db_path())
        }
    })
    run_app('disable -regex disabled.*')

    run_app('exec --id disable echo')
    run_app('exec --id disabled echo')
    run_app('exec --id disabled1 echo')

    assert observer.last_state('disable') == ExecutionState.COMPLETED
    assert observer.last_state('disabled') == ExecutionState.DISABLED
    assert observer.last_state('disabled1') == ExecutionState.DISABLED
Ejemplo n.º 17
0
def test_disable_jobs(observer: TestStateObserver):
    create_test_config({
        "persistence": {
            "enabled": True,
            "type": "sqlite",
            "database": str(test_db_path())
        }
    })
    run_app('disable job1 job3 j.*'
            )  # 'j.*' not a regular expression here as -regex opt not used

    run_app('exec --id job1 echo')
    run_app('exec --id j2 echo')
    run_app('exec --id job3 echo')

    assert observer.last_state('job1') == ExecutionState.DISABLED
    assert observer.last_state('j2') == ExecutionState.COMPLETED
    assert observer.last_state('job3') == ExecutionState.DISABLED
Ejemplo n.º 18
0
def test_disable_jobs(capsys):
    run_app('disable j1 j2')
    run_app('disable -regex j3')
    output = capsys.readouterr().out
    assert 'j1' in output
    assert 'j2' in output
    assert 'j3' in output

    run_app('list-disabled')
    output = capsys.readouterr().out
    disabled = ps.parse_table(output, view_dis.DEFAULT_COLUMNS)

    assert 'j1' in disabled[0][view_dis.JOB_ID]
    assert 'no' in disabled[0][view_dis.REGEX]

    assert 'j2' in disabled[1][view_dis.JOB_ID]
    assert 'no' in disabled[1][view_dis.REGEX]

    assert 'j3' in disabled[2][view_dis.JOB_ID]
    assert 'yes' in disabled[2][view_dis.REGEX]
Ejemplo n.º 19
0
def test_plugin_executed():
    create_test_config({"plugins": ["test_plugin"]})  # Use testing plugin in package 'test_plugin'
    run_app('exec --id run_with_test_plugin echo')

    assert test_plugin.TestPlugin.instance_ref().job_instances[-1].job_id == 'run_with_test_plugin'
Ejemplo n.º 20
0
def test_explicit_job_id(observer: TestStateObserver):
    run_app('exec -mc --id this_is_an_id echo not an id')
    assert observer.last_job().job_id == 'this_is_an_id'
Ejemplo n.º 21
0
def test_default_job_id(observer: TestStateObserver):
    run_app('exec -mc echo life is dukkha')
    assert observer.last_job().job_id == 'echo life is dukkha'
Ejemplo n.º 22
0
def test_invalid_command_print_to_stderr(capsys):
    run_app('exec -mc non_existing_command')
    assert 'No such file' in capsys.readouterr().err
Ejemplo n.º 23
0
def test_failed_command(observer: TestStateObserver):
    run_app('exec -mc ls --no-such-option')
    assert observer.exec_state(-1) == ExecutionState.FAILED
Ejemplo n.º 24
0
def test_invalid_command(observer: TestStateObserver):
    run_app('exec -mc non_existing_command')
    assert observer.exec_state(-1) == ExecutionState.FAILED
Ejemplo n.º 25
0
def test_successful(observer: TestStateObserver):
    dir_name = util.unique_timestamp_hex()
    run_app('exec -mc mkdir ' + dir_name)

    assert observer.exec_state(-1) == ExecutionState.COMPLETED
    os.rmdir(dir_name)  # Exc if not existed
Ejemplo n.º 26
0
def test_logging_disabled():
    run_app('exec -mc --set log_mode=off echo')
    assert log.is_disabled()
Ejemplo n.º 27
0
def test_config_file_empty():
    create_test_config(None)
    try:
        run_app('exec echo alles gute')
    finally:
        remove_test_config()
Ejemplo n.º 28
0
def test_output_observer(observer: TestJobOutputObserver):
    run_app('exec -mc echo future sound of london')
    assert observer.last_output() == 'future sound of london'
Ejemplo n.º 29
0
def test_logging_file_level_in_config():
    create_test_config({"log": {"mode": True, "file": {"level": "error"}}})
    run_app('exec echo')
    assert logging.ERROR == log.get_file_level()
Ejemplo n.º 30
0
def test_logging_file_level_cli_override():
    create_test_config({"log": {"mode": True, "file": {"level": "error"}}})
    run_app('exec --set log_file_level=warn echo')
    assert logging.WARN == log.get_file_level()