Exemplo n.º 1
0
def test_noderoledimension_construction_empty():
    """Check that we construct empty node role dimension properly."""
    empty = NodeRoleDimension("g1", roleDimensionMappings=[])

    assert NodeRoleDimension("g1") == empty
    assert NodeRoleDimension("g1", roles=None) == empty
    assert NodeRoleDimension("g1", roleDimensionMappings=None) == empty
Exemplo n.º 2
0
def test_noderoledimension_construction_item():
    """Check that we construct node role dimension when sub-props are not a list."""
    role = NodeRole("a", "b")
    dimension1 = NodeRoleDimension("g1", roles=[role])
    assert NodeRoleDimension("g1", roles=role) == dimension1

    rdMap = RoleDimensionMapping("a", [], {}, False)
    dimension2 = NodeRoleDimension("g1", roleDimensionMappings=[rdMap])
    assert NodeRoleDimension("g1", roleDimensionMappings=rdMap) == dimension2
Exemplo n.º 3
0
def test_noderoledimension_construction():
    """Check that we throw an error when node role dimension is built with wrong type."""
    with pytest.raises(ValueError):
        NodeRoleDimension("g1", roles="i1")
    with pytest.raises(ValueError):
        NodeRoleDimension("book1", roles=["ag", NodeRole("a", "b")])
    with pytest.raises(ValueError):
        NodeRoleDimension("g1", roleDimensionMappings="i1")
    with pytest.raises(ValueError):
        NodeRoleDimension(
            "book1",
            roleDimensionMappings=["ag",
                                   RoleDimensionMapping("a", "b", "c")])
Exemplo n.º 4
0
def test_get_snapshot_node_role_dimension(network, roles_snapshot):
    bf_set_network(network)
    bf_set_snapshot(roles_snapshot)
    node_roles = NodeRolesData([NodeRoleDimension('dim1')])
    bf_put_node_roles(node_roles)
    # should not crash
    bf_get_snapshot_node_role_dimension('dim1')
Exemplo n.º 5
0
def test_noderoledimension_construction_list():
    """Check that we construct interface groups where sub-props are lists."""
    role = NodeRole("a", "b")
    dimension1 = NodeRoleDimension("g1", roles=[role])
    assert dimension1.name == "g1"
    assert dimension1.roles == [role]

    rdMap = RoleDimensionMapping("a", [], {}, False)
    dimension2 = NodeRoleDimension("g1", roleDimensionMappings=[rdMap])
    assert dimension2.name == "g1"
    assert dimension2.roleDimensionMappings == [rdMap]

    dimension3 = NodeRoleDimension("g1",
                                   roles=[role],
                                   roleDimensionMappings=[rdMap])
    assert dimension3.name == "g1"
    assert dimension3.roles == [role]
    assert dimension3.roleDimensionMappings == [rdMap]
def test_put_node_roles():
    try:
        network_name = 'n1'
        bf_set_network(network_name)
        node_roles = NodeRolesData([NodeRoleDimension('dim1')])
        bf_put_node_roles(node_roles)
        assert bf_get_node_roles() == node_roles
    finally:
        bf_delete_network(network_name)
def test_add_node_role_dimension():
    try:
        network_name = 'n1'
        bf_set_network(network_name)
        dim_name = 'd1'
        dim = NodeRoleDimension(dim_name)
        bf_add_node_role_dimension(dim)
        assert bf_get_node_role_dimension(dim_name) == dim
    finally:
        bf_delete_network(network_name)
Exemplo n.º 8
0
def test_get_snapshot_node_roles(network, roles_snapshot):
    bf_set_network(network)
    bf_set_snapshot(roles_snapshot)
    dimension_name = 'dim1'
    node_roles = NodeRolesData([NodeRoleDimension(dimension_name)])
    bf_put_node_roles(node_roles)
    # there should be 1 role dimension
    snapshot_node_roles = bf_get_snapshot_node_roles()
    assert len(snapshot_node_roles.roleDimensions) == 1
    assert snapshot_node_roles.roleDimensions[0].name == dimension_name
Exemplo n.º 9
0
def test_add_node_role_dimension(session):
    try:
        network_name = "n1"
        bf_set_network(network_name)
        dim_name = "d1"
        rdMap = RoleDimensionMapping("a", [1], {})
        dim = NodeRoleDimension(dim_name, roleDimensionMappings=[rdMap])
        bf_add_node_role_dimension(dim)
        assert bf_get_node_role_dimension(dim_name) == dim
    finally:
        bf_delete_network(network_name)
Exemplo n.º 10
0
def test_add_node_role_dimension():
    try:
        network_name = 'n1'
        bf_set_network(network_name)
        dim_name = 'd1'
        rdMap = RoleDimensionMapping("a", [1], {}, False)
        dim = NodeRoleDimension(dim_name, roleDimensionMappings=[rdMap])
        bf_add_node_role_dimension(dim)
        assert bf_get_node_role_dimension(dim_name) == dim
    finally:
        bf_delete_network(network_name)
Exemplo n.º 11
0
def test_put_node_role_dimension():
    try:
        network_name = 'n1'
        bf_set_network(network_name)
        dim_name = 'd1'
        dim = NodeRoleDimension(dim_name)
        bf_put_node_role_dimension(dim)
        assert bf_get_node_role_dimension(dim_name) == dim
        # put again to check for idempotence
        bf_put_node_role_dimension(dim)
        assert bf_get_node_role_dimension(dim_name) == dim
    finally:
        bf_delete_network(network_name)
Exemplo n.º 12
0
def test_put_node_role_dimension(session):
    try:
        network_name = "n1"
        bf_set_network(network_name)
        dim_name = "d1"
        mapping = RoleDimensionMapping(regex="(regex)")
        dim = NodeRoleDimension(dim_name, roleDimensionMappings=[mapping])
        bf_put_node_role_dimension(dim)
        assert bf_get_node_role_dimension(dim_name) == dim
        # put again to check for idempotence
        bf_put_node_role_dimension(dim)
        assert bf_get_node_role_dimension(dim_name) == dim
    finally:
        bf_delete_network(network_name)
Exemplo n.º 13
0
def test_delete_node_role_dimension():
    try:
        network_name = 'n1'
        bf_set_network(network_name)
        dim_name = 'd1'
        dim = NodeRoleDimension(dim_name)
        bf_add_node_role_dimension(dim)
        # should not crash
        bf_get_node_role_dimension(dim_name)
        bf_delete_node_role_dimension(dim_name)
        # dimension should no longer exist
        with raises(HTTPError, match='404'):
            bf_get_node_role_dimension(dim_name)
        # second delete should fail
        with raises(HTTPError, match='404'):
            bf_delete_node_role_dimension(dim_name)

    finally:
        bf_delete_network(network_name)
Exemplo n.º 14
0
def test_delete_node_role_dimension(session):
    try:
        network_name = "n1"
        bf_set_network(network_name)
        dim_name = "d1"
        mapping = RoleDimensionMapping(regex="(regex)")
        dim = NodeRoleDimension(name=dim_name, roleDimensionMappings=[mapping])
        bf_add_node_role_dimension(dim)
        # should not crash
        bf_get_node_role_dimension(dim_name)
        bf_delete_node_role_dimension(dim_name)
        # dimension should no longer exist
        with raises(HTTPError, match="404"):
            bf_get_node_role_dimension(dim_name)
        # second delete should fail
        with raises(HTTPError, match="404"):
            bf_delete_node_role_dimension(dim_name)

    finally:
        bf_delete_network(network_name)
Exemplo n.º 15
0
def test_noderolesdata_construction_badtype():
    """Check that we throw an error when node role data is built with wrong type."""
    with pytest.raises(ValueError):
        NodeRolesData(roleDimensions="i1")
    with pytest.raises(ValueError):
        NodeRolesData(roleDimensions=["ag", NodeRoleDimension("a")])
Exemplo n.º 16
0
def bf_get_snapshot_node_role_dimension(dimension):
    # type: (str) -> NodeRoleDimension
    """Returns the defintion and assignments of node roles for the given dimension for the active network and snapshot."""
    return NodeRoleDimension.from_dict(
        restv2helper.get_snapshot_node_role_dimension(bf_session, dimension))
Exemplo n.º 17
0
def bf_get_node_role_dimension(dimension):
    # type: (str) -> NodeRoleDimension
    """Returns the set of node roles for the active network."""
    return NodeRoleDimension(
        **restv2helper.get_node_role_dimension(bf_session, dimension))
Exemplo n.º 18
0
def bf_get_snapshot_inferred_node_role_dimension(dimension):
    # type: (str) -> NodeRoleDimension
    """Gets the suggested definition and hypothetical assignments of node roles for the given inferred dimension for the active network and snapshot."""
    return NodeRoleDimension.from_dict(
        restv2helper.get_snapshot_inferred_node_role_dimension(
            bf_session, dimension))
Exemplo n.º 19
0
def bf_get_node_role_dimension(dimension):
    # type: (str) -> NodeRoleDimension
    """Returns the definition of the given node role dimension for the active network."""
    return NodeRoleDimension.from_dict(
        restv2helper.get_node_role_dimension(bf_session, dimension))
Exemplo n.º 20
0
def test_noderolesdata_construction_list():
    """Check that we construct node role data where sub-props are lists."""
    dimension = NodeRoleDimension("a", "b")
    data = NodeRolesData(roleDimensions=[dimension])

    assert data.roleDimensions == [dimension]
Exemplo n.º 21
0
def test_noderolesdata_construction_item():
    """Check that we construct node role data when sub-props are not a list."""
    dimension = NodeRoleDimension("a", "b")
    data = NodeRolesData(roleDimensions=[dimension])
    assert NodeRolesData(roleDimensions=dimension) == data