Пример #1
0
def test_slot_result():
    """
    Tests the result slots for correct number of similar jobs based on RAM
    :return:
    """
    mocked_content = mocked_collector().query()

    slots = collect.collect_slots(mocked_content)

    ram = 10.0
    result = examine.check_slots(
        examine.filter_slots(slots, "Static"),
        examine.filter_slots(slots, "Partitionable"),
        1, ram, 0.0, 0, 1, 0.0, 0, verbose=False
    )
    slots = result["slots"]
    previews = result["preview"]

    for preview in previews:
        if preview['fits'] != 'YES':
            # Ignore results that do not fit
            continue

        # Find the slot referenced in results (same node-name and RAM)
        for slot in slots:
            slot_name = slot['Machine']

            if slot_name == preview["Machine"] and \
                    slot["TotalSlotMemory"] == preview['TotalSlotMemory']:
                ram_ratio = int(float(slot["TotalSlotMemory"]) / ram)

                # Assume that number of similar jobs does not exceed RAM ratio
                assert preview['sim_jobs'] <= ram_ratio
Пример #2
0
def test_slot_checking():
    """
    Tests the slot checking method.
    :return:
    """
    mocked_content = mocked_collector().query()

    slots = collect.collect_slots(mocked_content)

    assert "preview" in examine.check_slots(
        examine.filter_slots(slots, "static"),
        examine.filter_slots(slots, "partitionable"),
        1, 10.0, 0.0, 0, 1, 0.0, 0, verbose=False
    )
    assert "slots" in examine.check_slots(
        examine.filter_slots(slots, "static"),
        examine.filter_slots(slots, "partitionable"),
        1, 10.0, 0.0, 0, 1, 0.0, 0, verbose=False
    )
    assert examine.check_slots(
        examine.filter_slots(slots, "static"),
        examine.filter_slots(slots, "partitionable"),
        0, 10.0, 0.0, 0, 1, 0.0, 0, verbose=False
    ) == {'slots': [], 'preview': []}
    assert examine.check_slots(
        examine.filter_slots(slots, "static"),
        examine.filter_slots(slots, "partitionable"),
        0, 10.0, 0.0, 0, 1, 0.0, 0, verbose=False
    ) == {'slots': [], 'preview': []}
Пример #3
0
def test_slot_config():
    """
    Tests the slot loading method.
    :return:
    """
    mocked_content = mocked_collector().query()

    slots = collect.collect_slots(mocked_content)

    assert "SlotType" in slots['cpu2'][0]

    assert "SlotType" in examine.filter_slots(slots, "Static")[0]
    assert examine.filter_slots(slots, "Static")[0]["SlotType"] == "Static"

    assert "SlotType" in examine.filter_slots(slots, "Partitionable")[0]
    assert examine.filter_slots(slots, "Partitionable")[0]["SlotType"] == "Partitionable"
Пример #4
0
def test_slot_result(root_dir):
    """
    Tests the result slots for correct number of similar jobs based on RAM
    :return:
    """
    config_file = path.join(root_dir, 'example_config.json')

    with open(config_file) as f:
        slots = json.load(f)['slots']

    ram = 10.0
    result = examine.check_slots(examine.filter_slots(slots, "static"),
                                 examine.filter_slots(slots, "dynamic"),
                                 examine.filter_slots(slots, "gpu"),
                                 1,
                                 ram,
                                 0.0,
                                 0,
                                 1,
                                 0.0,
                                 0,
                                 verbose=False)
    slots = result["slots"]
    previews = result["preview"]

    for preview in previews:
        if preview['fits'] != 'YES':
            # Ignore results that do not fit
            continue

        preview_name = preview["name"]
        preview_ram = preview['ram_usage']

        # Find the slot referenced in results (same node-name and RAM)
        for slot in slots:
            slot_name = slot['node']
            slot_ram = f'/{slot["ram"]}'

            if slot_name == preview_name and slot_ram in preview_ram:
                ram_ratio = int(float(slot['ram']) / ram)

                # Assume that number of similar jobs does not exceed RAM ratio
                assert preview['sim_jobs'] <= ram_ratio
Пример #5
0
def test_slot_config(root_dir):
    """
    Tests the slot loading method.
    :return:
    """
    config_file = path.join(root_dir, 'example_config.json')

    with open(config_file) as f:
        slots = json.load(f)['slots']

    assert "SlotType" in slots[0]["slot_size"][0]

    assert "SlotType" in examine.filter_slots(slots, "static")[0]
    assert examine.filter_slots(slots, "static")[0]["SlotType"] == "static"

    assert "SlotType" in examine.filter_slots(slots, "dynamic")[0]
    assert examine.filter_slots(slots, "dynamic")[0]["SlotType"] == "dynamic"

    if len(examine.filter_slots(slots, "gpu")) > 0:
        assert "SlotType" in examine.filter_slots(slots, "gpu")[0]
        assert examine.filter_slots(slots, "gpu")[0]["SlotType"] == "gpu"
Пример #6
0
def test_slot_checking(root_dir):
    """
    Tests the slot checking method.
    :return:
    """
    config_file = path.join(root_dir, 'example_config.json')

    with open(config_file) as f:
        slots = json.load(f)['slots']

    assert "preview" in examine.check_slots(
        examine.filter_slots(slots, "static"),
        examine.filter_slots(slots, "dynamic"),
        examine.filter_slots(slots, "gpu"),
        1,
        10.0,
        0.0,
        0,
        1,
        0.0,
        0,
        verbose=False)
    assert "slots" in examine.check_slots(
        examine.filter_slots(slots, "static"),
        examine.filter_slots(slots, "dynamic"),
        examine.filter_slots(slots, "gpu"),
        1,
        10.0,
        0.0,
        0,
        1,
        0.0,
        0,
        verbose=False)
    assert examine.check_slots(examine.filter_slots(slots, "static"),
                               examine.filter_slots(slots, "dynamic"),
                               examine.filter_slots(slots, "gpu"),
                               0,
                               10.0,
                               0.0,
                               0,
                               1,
                               0.0,
                               0,
                               verbose=False) == {}
    assert examine.check_slots(examine.filter_slots(slots, "static"),
                               examine.filter_slots(slots, "dynamic"),
                               examine.filter_slots(slots, "gpu"),
                               0,
                               10.0,
                               0.0,
                               0,
                               1,
                               0.0,
                               0,
                               verbose=False) == {}