Esempio n. 1
0
def test_host_passes_whitelist():
    fake_slave_attributes = {
        'location_type': 'fake_location',
        'fake_location_type': 'fake_location',
    }
    fake_whitelist_allow = ['fake_location_type', ['fake_location']]
    fake_whitelist_deny = ['anoterfake_location_type', ['anotherfake_location']]

    slave_passes = long_running_service_tools.host_passes_whitelist(fake_slave_attributes, fake_whitelist_deny)
    assert not slave_passes
    slave_passes = long_running_service_tools.host_passes_whitelist(fake_slave_attributes, fake_whitelist_allow)
    assert slave_passes
    slave_passes = long_running_service_tools.host_passes_whitelist(fake_slave_attributes, None)
    assert slave_passes
Esempio n. 2
0
def filter_nodes_by_blacklist(
    nodes: Sequence[V1Node],
    blacklist: DeployBlacklist,
    whitelist: DeployWhitelist,
) -> Sequence[V1Node]:
    """Takes an input list of nodes and filters them based on the given blacklist.
    The blacklist is in the form of:

        [["location_type", "location]]

    Where the list inside is something like ["region", "uswest1-prod"]

    :returns: The list of nodes after the filter
    """
    if whitelist:
        whitelist = (maybe_add_yelp_prefix(whitelist[0]), whitelist[1])
    blacklist = [(maybe_add_yelp_prefix(entry[0]), entry[1])
                 for entry in blacklist]
    return [
        node for node in nodes if host_passes_whitelist(
            node.metadata.labels,
            whitelist,
        ) and host_passes_blacklist(
            node.metadata.labels,
            blacklist,
        )
    ]
Esempio n. 3
0
def test_host_passes_whitelist():
    fake_slave_attributes = {
        "location_type": "fake_location",
        "fake_location_type": "fake_location",
    }
    fake_whitelist_allow = ("fake_location_type", ["fake_location"])
    fake_whitelist_deny = ("anoterfake_location_type",
                           ["anotherfake_location"])

    slave_passes = long_running_service_tools.host_passes_whitelist(
        fake_slave_attributes, fake_whitelist_deny)
    assert not slave_passes
    slave_passes = long_running_service_tools.host_passes_whitelist(
        fake_slave_attributes, fake_whitelist_allow)
    assert slave_passes
    slave_passes = long_running_service_tools.host_passes_whitelist(
        fake_slave_attributes, None)
    assert slave_passes
Esempio n. 4
0
def filter_mesos_slaves_by_blacklist(slaves, blacklist: DeployBlacklist,
                                     whitelist: DeployWhitelist):
    """Takes an input list of slaves and filters them based on the given blacklist.
    The blacklist is in the form of:

        [["location_type", "location]]

    Where the list inside is something like ["region", "uswest1-prod"]

    :returns: The list of mesos slaves after the filter
    """
    filtered_slaves = []
    for slave in slaves:
        if host_passes_blacklist(slave["attributes"],
                                 blacklist) and host_passes_whitelist(
                                     slave["attributes"], whitelist):
            filtered_slaves.append(slave)
    return filtered_slaves