Esempio n. 1
0
def test_custom_node_attrs_and_node_config() -> None:
    b = MockClusterBinding()
    b.add_nodearray("htc", {},
                    software_configuration={"myscheduler": {
                        "A": 1
                    }})
    b.add_bucket("htc", "Standard_F2", 10, 10)
    b.add_node("htc-1", "htc")
    node_mgr = new_node_manager({"_mock_bindings": b})
    (existing_node, ) = node_mgr.get_nodes()

    try:
        existing_node.node_attribute_overrides["willfail"] = 123
        assert False
    except TypeError:
        pass

    result = node_mgr.allocate({"exclusive": True}, node_count=2)
    assert result
    (node, ) = [n for n in result.nodes if not n.exists]

    assert node.software_configuration.get("test_thing") is None
    node.node_attribute_overrides["Configuration"] = {"test_thing": "is set"}
    assert node.software_configuration.get("test_thing") == "is set"
    try:
        node.software_configuration["willfail"] = 123
        assert not node.software_configuration.get("willfail")
    except TypeError:
        pass

    # we won't handle dict merges here.
    assert node.software_configuration.get("myscheduler") == {"A": 1}

    node.node_attribute_overrides["Configuration"] = {"myscheduler": {"B": 2}}
    assert node.software_configuration.get("myscheduler") == {"B": 2}

    # if you want to add to the existing software_configuration, use
    # the node.software_configuration
    node.node_attribute_overrides["Configuration"][
        "myscsheduler"] = node.software_configuration.get("myscheduler", {})
    node.node_attribute_overrides["Configuration"]["myscheduler"]["B"] = 2

    node.node_attribute_overrides["Configuration"] = {
        "myscheduler": {
            "A": 1,
            "B": 2
        }
    }

    node.software_configuration["willsucceed"] = 123
    node.exists = True
    try:
        node.software_configuration["willfail"] = 123
        assert False
    except TypeError:
        pass
Esempio n. 2
0
def test_delete_internally(bindings: MockClusterBinding) -> None:
    bindings.add_node("htc-1", "htc")
    node_mgr = _node_mgr(bindings)
    assert len(node_mgr.get_nodes()) == 1
    node = node_mgr.get_nodes()[0]
    assert node.name == "htc-1"
    result = node_mgr.delete([node])
    assert result

    assert len(result.nodes) == 1
    assert result.nodes[0].name == "htc-1"
    assert result.nodes[0].state == "Terminating"

    assert len(node_mgr.get_nodes()) == 0
Esempio n. 3
0
def test_mock_bindings(bindings: MockClusterBinding) -> None:
    ctx = register_result_handler(DefaultContextHandler("[test]"))
    hpc, htc = _node_mgr(bindings).get_buckets()
    if hpc.nodearray != "hpc":
        hpc, htc = htc, hpc
    assert hpc.nodearray == "hpc"
    assert htc.nodearray == "htc"

    assert hpc.family_available_count == 10
    assert hpc.available_count == 10

    assert hpc.family_available_count == 10
    assert htc.family_available_count == 20

    hpc.decrement(1)
    assert hpc.family_available_count == 9
    assert htc.family_available_count == 20
    hpc.commit()
    assert hpc.family_available_count == 9
    assert htc.family_available_count == 18

    hpc.increment(1)
    hpc.commit()
    assert hpc.family_available_count == 10
    assert htc.family_available_count == 20

    ctx.set_context("[failure]")
    nm = _node_mgr(bindings)

    b = MockClusterBinding()
    b.add_nodearray("haspgs", {}, max_placement_group_size=20)
    b.add_bucket(
        "haspgs",
        "Standard_F4",
        100,
        100,
        placement_groups=["pg0", "pg1"],
    )
    # make sure we take the max_placement_group_size (20) into account
    # and that we have the non-pg and 2 pg buckets.
    nm = _node_mgr(b)
    no_pg, pg0, pg1 = sorted(nm.get_buckets(),
                             key=lambda b: b.placement_group or "")
    assert no_pg.available_count == 100
    assert pg0.available_count == 20
    assert pg1.available_count == 20

    # let's add a node to pg0 (100 - 1, 20 - 1, 20)
    b.add_node("haspgs-pg0-1", "haspgs", "Standard_F4", placement_group="pg0")

    nm = _node_mgr(b)
    no_pg, pg0, pg1 = sorted(nm.get_buckets(),
                             key=lambda b: b.placement_group or "")
    assert no_pg.available_count == 99
    assert pg0.available_count == 19
    assert pg1.available_count == 20

    # let's add a node to pg1 (100 - 2, 20 - 1, 20 - 1)
    b.add_node("haspgs-pg1-1", "haspgs", "Standard_F4", placement_group="pg1")

    nm = _node_mgr(b)
    no_pg, pg0, pg1 = sorted(nm.get_buckets(),
                             key=lambda b: b.placement_group or "")
    assert no_pg.available_count == 98
    assert pg0.available_count == 19
    assert pg1.available_count == 19

    # let's add 90 htc nodes so that our pg available counts are floored
    # by the overall available_count
    for i in range(90):
        b.add_node("haspgs-{}".format(i + 1), "haspgs", "Standard_F4")

    nm = _node_mgr(b)
    no_pg, pg0, pg1 = sorted(nm.get_buckets(),
                             key=lambda b: b.placement_group or "")
    assert no_pg.available_count == 8
    assert pg0.available_count == 8
    assert pg1.available_count == 8

    # lastly, add a nother node to a pg and see that all of avail go down
    b.add_node("haspgs-pg1-2", "haspgs", "Standard_F4", placement_group="pg1")
    nm = _node_mgr(b)
    no_pg, pg0, pg1 = sorted(nm.get_buckets(),
                             key=lambda b: b.placement_group or "")
    assert no_pg.available_count == 7
    assert pg0.available_count == 7
    assert pg1.available_count == 7