Beispiel #1
0
def test_instance_manager_cpu_reservation(client, core_api):  # NOQA
    """
    Test if the CPU requests of instance manager pods are controlled by
    the settings and the node specs correctly.

    1. Try to change the deprecated setting `Guaranteed Engine CPU`.
       --> The setting update should fail.
    2. Pick up node 1, set `node.engineManagerCPURequest` and
       `node.replicaManagerCPURequest` to 150 and 250, respectively.
       --> The IM pods on this node will be restarted. And the CPU requests
       of these IM pods matches the above milli value.
    3. Change the new settings `Guaranteed Engine Manager CPU` and
       `Guaranteed Replica Manager CPU` to 10 and 20, respectively.
       Then wait for all IM pods except for the pods on node 1 restarting.
       --> The CPU requests of the restarted IM pods equals to
           the new setting value multiply the kube node allocatable CPU.
    4. Set the both new settings to 0.
       --> All IM pods except for the pod on node 1 will be restarted without
        CPU requests.
    5. Set the fields on node 1 to 0.
       --> The IM pods on node 1 will be restarted without CPU requests.
    6. Set the both new settings to 2 random values,
       and the sum of the 2 values is small than 40.
       Then wait for all IM pods restarting.
       --> The CPU requests of all IM pods equals to
           the new setting value multiply the kube node allocatable CPU.
    7. Set the both new settings to 2 random values,
       and the single value or the sum of the 2 values is greater than 40.
       --> The setting update should fail.
    8. Create a volume, verify everything works as normal

    Note: use fixture to restore the setting into the original state
    """

    instance_managers = client.list_instance_manager()
    deprecated_setting = client.by_id_setting(SETTING_GUARANTEED_ENGINE_CPU)
    with pytest.raises(Exception) as e:
        client.update(deprecated_setting, value="0.1")

    host_node_name = get_self_host_id()
    host_node = client.by_id_node(host_node_name)
    other_ems, other_rms = [], []
    for im in instance_managers:
        if im.managerType == "engine":
            if im.nodeID == host_node_name:
                em_on_host = im
            else:
                other_ems.append(im)
        else:
            if im.nodeID == host_node_name:
                rm_on_host = im
            else:
                other_rms.append(im)
    assert em_on_host and rm_on_host
    host_kb_node = core_api.read_node(host_node_name)
    if host_kb_node.status.allocatable["cpu"].endswith('m'):
        allocatable_millicpu = int(host_kb_node.status.allocatable["cpu"][:-1])
    else:
        allocatable_millicpu = int(
            host_kb_node.status.allocatable["cpu"]) * 1000

    client.update(host_node,
                  allowScheduling=True,
                  engineManagerCPURequest=150,
                  replicaManagerCPURequest=250)
    time.sleep(5)
    guaranteed_engine_cpu_setting_check(client, core_api, [em_on_host],
                                        "Running", True, "150m")
    guaranteed_engine_cpu_setting_check(client, core_api, [rm_on_host],
                                        "Running", True, "250m")

    em_setting = client.by_id_setting(SETTING_GUARANTEED_ENGINE_MANAGER_CPU)
    client.update(em_setting, value="10")
    rm_setting = client.by_id_setting(SETTING_GUARANTEED_REPLICA_MANAGER_CPU)
    client.update(rm_setting, value="20")
    time.sleep(5)
    guaranteed_engine_cpu_setting_check(
        client, core_api, other_ems, "Running", True,
        str(int(allocatable_millicpu * 10 / 100)) + "m")
    guaranteed_engine_cpu_setting_check(
        client, core_api, other_rms, "Running", True,
        str(int(allocatable_millicpu * 20 / 100)) + "m")

    em_setting = client.by_id_setting(SETTING_GUARANTEED_ENGINE_MANAGER_CPU)
    client.update(em_setting, value="0")
    rm_setting = client.by_id_setting(SETTING_GUARANTEED_REPLICA_MANAGER_CPU)
    client.update(rm_setting, value="0")
    time.sleep(5)
    guaranteed_engine_cpu_setting_check(client, core_api, other_ems, "Running",
                                        True, "")
    guaranteed_engine_cpu_setting_check(client, core_api, other_rms, "Running",
                                        True, "")

    ems, rms = other_ems, other_rms
    ems.append(em_on_host)
    rms.append(rm_on_host)

    host_node = client.by_id_node(host_node_name)
    client.update(host_node,
                  allowScheduling=True,
                  engineManagerCPURequest=0,
                  replicaManagerCPURequest=0)
    time.sleep(5)
    guaranteed_engine_cpu_setting_check(client, core_api, ems, "Running", True,
                                        "")
    guaranteed_engine_cpu_setting_check(client, core_api, rms, "Running", True,
                                        "")

    client.update(em_setting, value="20")
    rm_setting = client.by_id_setting(SETTING_GUARANTEED_REPLICA_MANAGER_CPU)
    client.update(rm_setting, value="15")
    time.sleep(5)
    guaranteed_engine_cpu_setting_check(
        client, core_api, ems, "Running", True,
        str(int(allocatable_millicpu * 20 / 100)) + "m")
    guaranteed_engine_cpu_setting_check(
        client, core_api, rms, "Running", True,
        str(int(allocatable_millicpu * 15 / 100)) + "m")

    with pytest.raises(Exception) as e:
        client.update(em_setting, value="41")
    assert "should be between 0 to 40" in \
           str(e.value)

    em_setting = client.by_id_setting(SETTING_GUARANTEED_ENGINE_MANAGER_CPU)
    with pytest.raises(Exception) as e:
        client.update(em_setting, value="35")
    assert "The sum should not be smaller than 0% or greater than 40%" in \
           str(e.value)

    # Create a volume to test
    vol_name = generate_volume_name()
    volume = create_and_check_volume(client, vol_name)
    volume.attach(hostId=get_self_host_id())
    volume = wait_for_volume_healthy(client, vol_name)
    assert len(volume.replicas) == 3
    data = write_volume_random_data(volume)
    check_volume_data(volume, data)
    cleanup_volume(client, volume)
Beispiel #2
0
def test_setting_guaranteed_engine_cpu(client, core_api):  # NOQA
    """
    Test setting Guaranteed Engine CPU

    Notice any change of the setting will result in all the instance manager
    recreated, no matter if there is any volume attached or not.

    1. Change the setting to `xxx`. Update setting should fail.
    2. Change the setting to `0.1`
    3. Wait for all the IM pods to recreated and become running
    4. Verify every IM pod has guaranteed CPU set correctly to 100m
    5. Change the setting to `0`
    6. Wait for all the IM pods to recreated and become running
    7. Verify every IM pod no longer has guaranteed CPU set
    8. Change the setting to `200m`
    9. Wait for all the IM pods to recreated and become running
    10. Verify every IM pod has guaranteed CPU set to 200m
    11. Change the setting to `10`, means 10 vcpus
    12. Wait for all the IM pods to recreated but unable to run
    13. Verify no IM pod can become running, with guaranteed CPU set to 10
    14. Change the setting to `0.25`
    15. Wait for all the IM pods to recreated and become running
    16. Verify every IM pod has guaranteed CPU set to 250m
    17. Create a volume, verify everything works as normal

    Note: use fixture to restore the setting into the original state
    """
    # Get current guaranteed engine cpu setting and save it to org_setting
    setting = client.by_id_setting(SETTING_GUARANTEED_ENGINE_CPU)

    # Get current running instance managers
    instance_managers = client.list_instance_manager()

    # Set an invalid value, and it should return error
    with pytest.raises(Exception) as e:
        client.update(setting, value="xxx")
    assert "with invalid " + SETTING_GUARANTEED_ENGINE_CPU in \
           str(e.value)

    # Update guaranteed engine cpu setting to 0.1
    guaranteed_engine_cpu_setting_check(client, core_api, setting, "0.1",
                                        "100m", instance_managers,
                                        "Running", True)

    # Update guaranteed engine cpu setting to 0
    guaranteed_engine_cpu_setting_check(client, core_api, setting, "0",
                                        None, instance_managers,
                                        "Running", True)

    # Update guaranteed engine cpu setting to 200m
    guaranteed_engine_cpu_setting_check(client, core_api, setting, "200m",
                                        "200m", instance_managers,
                                        "Running", True)

    # Update guaranteed engine cpu setting to 10
    guaranteed_engine_cpu_setting_check(client, core_api, setting, "10",
                                        None, instance_managers,
                                        "Running", False)

    # Update guaranteed engine cpu setting to 0.25
    guaranteed_engine_cpu_setting_check(client, core_api, setting, "0.25",
                                        "250m", instance_managers,
                                        "Running", True)

    # Create a volume to test
    vol_name = generate_volume_name()
    volume = create_and_check_volume(client, vol_name)
    volume.attach(hostId=get_self_host_id())
    volume = wait_for_volume_healthy(client, vol_name)
    assert len(volume.replicas) == 3

    data = write_volume_random_data(volume)
    check_volume_data(volume, data)