def test_etcd_key_size_check_calculates_correct_size(ansible_mounts, tree, root_path, expected_size, extra_words):
    def execute_module(module_name, module_args, *_):
        if module_name != "etcdkeysize":
            return {
                "changed": False,
            }

        client = fake_etcd_client(tree)
        size, limit_exceeded = check_etcd_key_size(client, root_path, module_args["size_limit_bytes"])

        assert size == expected_size
        return {
            "size_limit_exceeded": limit_exceeded,
        }

    task_vars = dict(
        ansible_mounts=ansible_mounts,
        openshift=dict(
            master=dict(etcd_hosts=["localhost"]),
            common=dict(config_base="/var/lib/origin")
        )
    )

    check = EtcdImageDataSize(execute_module, task_vars).run()
    assert not check.get("failed", False)
def test_etcd_key_size_check_calculates_correct_size(ansible_mounts, tree,
                                                     root_path, expected_size,
                                                     extra_words):
    def execute_module(module_name, args, tmp=None, task_vars=None):
        if module_name != "etcdkeysize":
            return {
                "changed": False,
            }

        client = fake_etcd_client(tree)
        size, limit_exceeded = check_etcd_key_size(client, root_path,
                                                   args["size_limit_bytes"])

        assert size == expected_size
        return {
            "size_limit_exceeded": limit_exceeded,
        }

    task_vars = dict(ansible_mounts=ansible_mounts,
                     openshift=dict(
                         master=dict(etcd_hosts=["localhost"]),
                         common=dict(config_base="/var/lib/origin")))

    check = EtcdImageDataSize(execute_module=execute_module).run(
        tmp=None, task_vars=task_vars)
    assert not check.get("failed", False)
def test_check_etcd_key_size_calculates_correct_limit(ansible_mounts, tree, size_limit, should_fail, extra_words):
    def execute_module(module_name, module_args, *_):
        if module_name != "etcdkeysize":
            return {
                "changed": False,
            }

        client = fake_etcd_client(tree)
        s, limit_exceeded = check_etcd_key_size(client, tree["key"], module_args["size_limit_bytes"])

        return {"size_limit_exceeded": limit_exceeded}

    task_vars = dict(
        etcd_max_image_data_size_bytes=size_limit,
        ansible_mounts=ansible_mounts,
        openshift=dict(
            master=dict(etcd_hosts=["localhost"]),
            common=dict(config_base="/var/lib/origin")
        )
    )
    if size_limit is None:
        task_vars.pop("etcd_max_image_data_size_bytes")

    check = EtcdImageDataSize(execute_module, task_vars).run()

    if should_fail:
        assert check["failed"]

        for word in extra_words:
            assert word in check["msg"]
    else:
        assert not check.get("failed", False)
def test_check_etcd_key_size_calculates_correct_limit(ansible_mounts, tree,
                                                      size_limit, should_fail,
                                                      extra_words):
    def execute_module(module_name, args, tmp=None, task_vars=None):
        if module_name != "etcdkeysize":
            return {
                "changed": False,
            }

        client = fake_etcd_client(tree)
        s, limit_exceeded = check_etcd_key_size(client, tree["key"],
                                                args["size_limit_bytes"])

        return {"size_limit_exceeded": limit_exceeded}

    task_vars = dict(etcd_max_image_data_size_bytes=size_limit,
                     ansible_mounts=ansible_mounts,
                     openshift=dict(
                         master=dict(etcd_hosts=["localhost"]),
                         common=dict(config_base="/var/lib/origin")))
    if size_limit is None:
        task_vars.pop("etcd_max_image_data_size_bytes")

    check = EtcdImageDataSize(execute_module=execute_module).run(
        tmp=None, task_vars=task_vars)

    if should_fail:
        assert check["failed"]

        for word in extra_words:
            assert word in check["msg"]
    else:
        assert not check.get("failed", False)
def test_cannot_determine_available_mountpath(ansible_mounts, extra_words):
    task_vars = dict(ansible_mounts=ansible_mounts, )
    check = EtcdImageDataSize(execute_module=fake_execute_module)

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.run(tmp=None, task_vars=task_vars)

    for word in 'determine valid etcd mountpath'.split() + extra_words:
        assert word in str(excinfo.value)
示例#6
0
def test_cannot_determine_available_mountpath(ansible_mounts, extra_words):
    task_vars = dict(ansible_mounts=ansible_mounts, )
    check = EtcdImageDataSize(fake_execute_module, task_vars)

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.run()

    for word in ['Unable to determine mount point'] + extra_words:
        assert word in str(excinfo.value)
def test_cannot_determine_available_mountpath(ansible_mounts, extra_words):
    task_vars = dict(
        ansible_mounts=ansible_mounts,
    )
    check = EtcdImageDataSize(fake_execute_module, task_vars)

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.run()

    for word in ['Unable to determine mount point'] + extra_words:
        assert word in str(excinfo.value)
def test_cannot_determine_available_mountpath(ansible_mounts, extra_words):
    task_vars = dict(
        ansible_mounts=ansible_mounts,
    )
    check = EtcdImageDataSize(execute_module=fake_execute_module)

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.run(tmp=None, task_vars=task_vars)

    for word in 'determine valid etcd mountpath'.split() + extra_words:
        assert word in str(excinfo.value)
def test_etcdkeysize_module_failure():
    def execute_module(module_name, tmp=None, task_vars=None):
        if module_name != "etcdkeysize":
            return {
                "changed": False,
            }

        return {
            "rc": 1,
            "module_stderr": "failure",
        }

    task_vars = dict(ansible_mounts=[{
        'mount': '/',
        'size_available': 40 * 10**9,
        'size_total': 80 * 10**9,
    }],
                     openshift=dict(
                         master=dict(etcd_hosts=["localhost"]),
                         common=dict(config_base="/var/lib/origin")))

    check = EtcdImageDataSize(execute_module=execute_module).run(
        tmp=None, task_vars=task_vars)

    assert check["failed"]
    for word in "Failed to retrieve stats":
        assert word in check["msg"]