Beispiel #1
0
def test_no_mount_for_state_file_mark_as_unmounted(mocker, tmpdir):
    state = dict(STATE)
    state["unmount_count"] = UNMOUNT_COUNT + 1

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

    (
        clean_up_mock,
        restart_tls_mock,
        check_certificate_call,
        _,
        mark_as_unmounted_mock,
    ) = setup_mocks(mocker, mounts={}, state_files={"mnt": state_file})

    watchdog.check_efs_mounts(
        _get_config(),
        [],
        GRACE_PERIOD,
        UNMOUNT_COUNT,
        state_file_dir=state_file_dir,
    )

    utils.assert_called_once(mark_as_unmounted_mock)
    utils.assert_not_called(restart_tls_mock)
    utils.assert_not_called(check_certificate_call)
Beispiel #2
0
def test_tls_not_running_due_to_pid_clean_up(mocker, tmpdir):
    state = dict(STATE)
    state.pop("pid")

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

    clean_up_mock, restart_tls_mock, _, _, _ = setup_mocks(
        mocker,
        mounts={
            "mnt": watchdog.Mount("127.0.0.1", "/mnt", "nfs4", "", "0", "0")
        },
        state_files={"mnt": state_file},
        is_pid_running=True,
    )

    watchdog.check_efs_mounts(
        _get_config(),
        [],
        GRACE_PERIOD,
        UNMOUNT_COUNT,
        state_file_dir=state_file_dir,
    )

    utils.assert_not_called(clean_up_mock)
    utils.assert_called_once(restart_tls_mock)
Beispiel #3
0
def test_malformed_state_file(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir, 'not-json')

    clean_up_mock, restart_tls_mock, _ = setup_mocks(
        mocker, mounts={}, state_files={'mnt': state_file})

    watchdog.check_efs_mounts(_get_config(), [], GRACE_PERIOD, state_file_dir)

    utils.assert_not_called(clean_up_mock)
    utils.assert_not_called(restart_tls_mock)
Beispiel #4
0
def test_no_state_files(mocker):
    clean_up_mock, restart_tls_mock, _ = setup_mocks(
        mocker,
        mounts={
            'mnt': watchdog.Mount('127.0.0.1', '/mnt', 'nfs4', '', '0', '0')
        },
        state_files={})

    watchdog.check_efs_mounts(_get_config(), [], GRACE_PERIOD)

    utils.assert_not_called(clean_up_mock)
    utils.assert_not_called(restart_tls_mock)
Beispiel #5
0
def test_no_mount_for_state_file(mocker, tmpdir):
    state = dict(STATE)

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

    clean_up_mock, restart_tls_mock, _ = setup_mocks(
        mocker, mounts={}, state_files={'mnt': state_file})

    watchdog.check_efs_mounts(_get_config(), [], GRACE_PERIOD, state_file_dir)

    utils.assert_not_called(clean_up_mock)
    utils.assert_not_called(restart_tls_mock)
Beispiel #6
0
def test_no_state_files(mocker):
    clean_up_mock, restart_tls_mock, _, _, _ = setup_mocks(
        mocker,
        mounts={
            "mnt": watchdog.Mount("127.0.0.1", "/mnt", "nfs4", "", "0", "0")
        },
        state_files={},
    )

    watchdog.check_efs_mounts(_get_config(), [], GRACE_PERIOD, UNMOUNT_COUNT)

    utils.assert_not_called(clean_up_mock)
    utils.assert_not_called(restart_tls_mock)
def test_no_mount_for_state_file_out_of_grace_period(mocker, tmpdir):
    state = dict(STATE)
    state['unmount_time'] = TIME - GRACE_PERIOD

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

    clean_up_mock, restart_tls_mock = setup_mocks(
        mocker, mounts={}, state_files={'mnt': state_file})

    watchdog.check_efs_mounts([], GRACE_PERIOD, state_file_dir)

    clean_up_mock.assert_called_once()
    restart_tls_mock.assert_not_called()
def test_no_state_files(mocker):
    clean_up_mock, restart_tls_mock = setup_mocks(mocker,
                                                  mounts={
                                                      'mnt':
                                                      watchdog.Mount(
                                                          '127.0.0.1', '/mnt',
                                                          'nfs4', '', '0', '0')
                                                  },
                                                  state_files={})

    watchdog.check_efs_mounts([], GRACE_PERIOD)

    clean_up_mock.assert_not_called()
    restart_tls_mock.assert_not_called()
Beispiel #9
0
def test_tls_not_running(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir)

    clean_up_mock, restart_tls_mock, _ = setup_mocks(
        mocker,
        mounts={
            'mnt': watchdog.Mount('127.0.0.1', '/mnt', 'nfs4', '', '0', '0')
        },
        state_files={'mnt': state_file},
        is_pid_running=False)

    watchdog.check_efs_mounts(_get_config(), [], GRACE_PERIOD, state_file_dir)

    utils.assert_not_called(clean_up_mock)
    utils.assert_called_once(restart_tls_mock)
def test_extra_mount(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir)

    clean_up_mock, restart_tls_mock = setup_mocks(
        mocker,
        mounts={
            'mnt': watchdog.Mount('127.0.0.1', '/mnt', 'nfs4', '', '0', '0'),
            'mnt2': watchdog.Mount('192.168.1.1', '/mnt2', 'nfs4', '', '0',
                                   '0'),
        },
        state_files={'mnt': state_file})

    watchdog.check_efs_mounts([], GRACE_PERIOD, state_file_dir)

    clean_up_mock.assert_not_called()
    restart_tls_mock.assert_not_called()
Beispiel #11
0
def test_ap_mount_with_extra_mount(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir)

    clean_up_mock, restart_tls_mock, check_certificate_call = setup_mocks(
        mocker,
        mounts={
            'mnt': watchdog.Mount('127.0.0.1', '/mnt', 'nfs4', '', '0', '0'),
            'mnt2': watchdog.Mount('192.168.1.1', '/mnt2', 'nfs4', '', '0',
                                   '0'),
        },
        state_files={'mnt': state_file})

    watchdog.check_efs_mounts(_get_config(), [], GRACE_PERIOD, state_file_dir)

    utils.assert_not_called(clean_up_mock)
    utils.assert_not_called(restart_tls_mock)
    utils.assert_called_once(check_certificate_call)
Beispiel #12
0
def test_tls_not_running_due_to_pid_clean_up(mocker, tmpdir):
    state = dict(STATE)
    state.pop('pid')

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

    clean_up_mock, restart_tls_mock, _ = setup_mocks(
        mocker,
        mounts={
            'mnt': watchdog.Mount('127.0.0.1', '/mnt', 'nfs4', '', '0', '0')
        },
        state_files={'mnt': state_file},
        is_pid_running=True)

    watchdog.check_efs_mounts(_get_config(), [], GRACE_PERIOD, state_file_dir)

    utils.assert_not_called(clean_up_mock)
    utils.assert_called_once(restart_tls_mock)
Beispiel #13
0
def test_no_mount_for_state_file_in_grace_period(mocker, tmpdir):
    state = dict(STATE)
    state["unmount_time"] = TIME + GRACE_PERIOD

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

    clean_up_mock, restart_tls_mock, _, _, _ = setup_mocks(
        mocker, mounts={}, state_files={"mnt": state_file})

    watchdog.check_efs_mounts(
        _get_config(),
        [],
        GRACE_PERIOD,
        UNMOUNT_COUNT,
        state_file_dir=state_file_dir,
    )

    utils.assert_not_called(clean_up_mock)
    utils.assert_not_called(restart_tls_mock)
Beispiel #14
0
def test_tls_not_running(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir)

    clean_up_mock, restart_tls_mock, _, _, _ = setup_mocks(
        mocker,
        mounts={
            "mnt": watchdog.Mount("127.0.0.1", "/mnt", "nfs4", "", "0", "0")
        },
        state_files={"mnt": state_file},
        is_pid_running=False,
    )

    watchdog.check_efs_mounts(
        _get_config(),
        [],
        GRACE_PERIOD,
        UNMOUNT_COUNT,
        state_file_dir=state_file_dir,
    )

    utils.assert_not_called(clean_up_mock)
    utils.assert_called_once(restart_tls_mock)
Beispiel #15
0
def test_ap_mount_with_extra_mount(mocker, tmpdir):
    state_file_dir, state_file = create_state_file(tmpdir)

    clean_up_mock, restart_tls_mock, check_certificate_call, _, _ = setup_mocks(
        mocker,
        mounts={
            "mnt": watchdog.Mount("127.0.0.1", "/mnt", "nfs4", "", "0", "0"),
            "mnt2": watchdog.Mount("192.168.1.1", "/mnt2", "nfs4", "", "0",
                                   "0"),
        },
        state_files={"mnt": state_file},
    )

    watchdog.check_efs_mounts(
        _get_config(),
        [],
        GRACE_PERIOD,
        UNMOUNT_COUNT,
        state_file_dir=state_file_dir,
    )

    utils.assert_not_called(clean_up_mock)
    utils.assert_not_called(restart_tls_mock)
    utils.assert_called_once(check_certificate_call)