def test_no_state_files_from_previous_driver(mocker, tmpdir):
    rewrite_state_file_mock = setup_mocks(
        mocker, state_files={}, process_name_output=PROCESS_NAME_OUTPUT)

    watchdog.clean_up_previous_stunnel_pids(tmpdir)

    utils.assert_not_called(rewrite_state_file_mock)
def test_clean_up_active_stunnel_from_previous_watchdog(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir)

    rewrite_state_file_mock = setup_mocks(
        mocker,
        state_files={"mnt": state_file},
        process_name_output=PROCESS_NAME_OUTPUT)

    watchdog.clean_up_previous_stunnel_pids(state_file_dir)

    utils.assert_not_called(rewrite_state_file_mock)
예제 #3
0
def test_clean_up_stunnel_pid_from_previous_driver(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir)

    rewrite_state_file_mock = setup_mocks(
        mocker,
        state_files={'mnt': state_file},
        process_name_output=PROCESS_NAME_OUTPUT_ERR)

    watchdog.clean_up_previous_stunnel_pids(state_file_dir)

    utils.assert_called_once(rewrite_state_file_mock)
예제 #4
0
def test_malformed_state_file(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir, 'not-json')

    rewrite_state_file_mock = setup_mocks(
        mocker,
        state_files={'mnt': state_file},
        process_name_output=PROCESS_NAME_OUTPUT)

    watchdog.clean_up_previous_stunnel_pids(state_file_dir)

    utils.assert_not_called(rewrite_state_file_mock)
예제 #5
0
def test_clean_up_stunnel_no_pid(mocker, tmpdir):
    state = dict(STATE)
    state.pop('pid')

    state_file_dir, state_file = create_state_file(tmpdir,
                                                   content=json.dumps(state))

    rewrite_state_file_mock = setup_mocks(
        mocker,
        state_files={'mnt': state_file},
        process_name_output=PROCESS_NAME_OUTPUT_LWP)

    watchdog.clean_up_previous_stunnel_pids(state_file_dir)

    utils.assert_not_called(rewrite_state_file_mock)
예제 #6
0
def test_clean_up_multiple_stunnel_pids(mocker, tmpdir):
    state_file_dir, state_file_1 = create_state_file(tmpdir)

    state = dict(STATE)
    state['pid'] = 5678
    state_file_dir, state_file_2 = create_state_file(tmpdir,
                                                     content=json.dumps(state))

    rewrite_state_file_mock = setup_mocks(
        mocker,
        state_files={
            'mnt/a1': state_file_1,
            'mnt/a2': state_file_2
        },
        process_name_output=PROCESS_NAME_OUTPUT_ERR)

    watchdog.clean_up_previous_stunnel_pids(state_file_dir)

    utils.assert_called(rewrite_state_file_mock)