Beispiel #1
0
def check_users_presence(username: str) -> UserState:
    """
    Checks whether a user with a given name exists. It searches also for a namespace
    with a name equal to the given username

    :param username: username
    :return: returns a current state of user - as an item for UserState enum
    In case of problems during gathering user's data - it raises an exception.
    """
    namespace = find_namespace(username)

    if namespace != NamespaceStatus.NOT_EXISTS:
        logger.debug("Namespace {} already exists.".format(username))
        return UserState(namespace.value)

    try:
        user_data = User.get(username)

        if user_data and user_data.name == username:
            return UserState.ACTIVE
        else:
            return UserState.NOT_EXISTS

    except Exception as exe:
        error_message = Texts.USER_PRESENCE_CHECK_ERROR_MSG
        logger.error(error_message)
        raise KubernetesError(error_message) from exe
Beispiel #2
0
def test_find_namespace_failure(mocker, mocked_k8s_CoreV1Api,
                                mocked_kubeconfig):
    assert find_namespace(test_namespace +
                          '_wrong') == NamespaceStatus.NOT_EXISTS
Beispiel #3
0
def test_find_namespace_terminating(mocker, mocked_k8s_CoreV1Api,
                                    mocked_kubeconfig):
    mocked_k8s_CoreV1Api.read_namespace.return_value.status = V1NamespaceStatus(
        phase=NamespaceStatus.TERMINATING.value)
    assert find_namespace(test_namespace) == NamespaceStatus.TERMINATING
Beispiel #4
0
def test_find_namespace_success(mocker, mocked_k8s_CoreV1Api,
                                mocked_kubeconfig):
    assert find_namespace(test_namespace) == NamespaceStatus.ACTIVE