Example #1
0
def k8s_node_zone_tags(client, core_api):  # NOQA

    k8s_zone_label = get_k8s_zone_label()
    lh_nodes = client.list_node()

    node_index = 0
    for node in lh_nodes:
        node_name = node.name

        if node_index % 2 == 0:
            zone = ZONE1
        else:
            zone = ZONE2

        payload = {"metadata": {"labels": {k8s_zone_label: zone}}}

        core_api.patch_node(node_name, body=payload)
        node_index += 1

    yield

    lh_nodes = client.list_node()

    node_index = 0
    for node in lh_nodes:
        node_name = node.name

        payload = {"metadata": {"labels": {k8s_zone_label: None}}}

        core_api.patch_node(node_name, body=payload)
Example #2
0
def test_node_default_disk_labeled(
        client,
        core_api,
        random_disk_path,
        reset_default_disk_label,  # NOQA
        reset_disk_settings):  # NOQA
    """
    Test that only Nodes with the proper label applied get a default Disk
    created on them when one doesn't already exist. Makes sure the created
    Disk matches the Default Data Path Setting.
    """
    # Set up cases.
    cases = {"disk_exists": None, "labeled": None, "unlabeled": None}
    nodes = client.list_node()
    assert len(nodes) >= 3

    node = nodes[0]
    cases["disk_exists"] = node["id"]
    core_api.patch_node(
        node["id"],
        {"metadata": {
            "labels": {
                CREATE_DEFAULT_DISK_LABEL: "true"
            }
        }})

    node = nodes[1]
    cases["labeled"] = node["id"]
    core_api.patch_node(
        node["id"],
        {"metadata": {
            "labels": {
                CREATE_DEFAULT_DISK_LABEL: "true"
            }
        }})
    disks = node["disks"]
    for _, disk in disks.iteritems():
        disk["allowScheduling"] = False
    update_disks = get_update_disks(disks)
    node = node.diskUpdate(disks=update_disks)
    node = node.diskUpdate(disks=[])
    wait_for_disk_update(client, node["id"], 0)

    node = nodes[2]
    cases["unlabeled"] = node["id"]
    disks = node["disks"]
    for _, disk in disks.iteritems():
        disk["allowScheduling"] = False
    update_disks = get_update_disks(disks)
    node = node.diskUpdate(disks=update_disks)
    node = node.diskUpdate(disks=[])
    wait_for_disk_update(client, node["id"], 0)

    # Set disk creation and path Settings.
    setting = client.by_id_setting(DEFAULT_DATA_PATH_SETTING)
    client.update(setting, value=random_disk_path)
    setting = client.by_id_setting(CREATE_DEFAULT_DISK_SETTING)
    client.update(setting, value="true")
    wait_for_disk_update(client, cases["labeled"], 1)

    # Check each case.
    node = client.by_id_node(cases["disk_exists"])
    assert len(node["disks"]) == 1
    assert get_update_disks(node["disks"])[0]["path"] == \
        DEFAULT_DISK_PATH

    node = client.by_id_node(cases["labeled"])
    assert len(node["disks"]) == 1
    assert get_update_disks(node["disks"])[0]["path"] == \
        random_disk_path

    node = client.by_id_node(cases["unlabeled"])
    assert len(node["disks"]) == 0
Example #3
0
def set_k8s_node_zone_label(core_api, node_name, zone_name):  # NOQA
    k8s_zone_label = get_k8s_zone_label()

    payload = {"metadata": {"labels": {k8s_zone_label: zone_name}}}

    core_api.patch_node(node_name, body=payload)