Esempio n. 1
0
def test_JelasticEnvironment_node_fetcher():
    """
    Test the convennience node fetcher
    """
    nodes = []
    for i in range(2):
        node = get_standard_node()
        node["id"] = i
        nodes.append(node)

    nodes[0]["nodeGroup"] = "cp"
    nodes[1]["nodeGroup"] = "sqldb"

    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(get_standard_env())
    jelenv.update_node_groups_from_info(get_standard_node_groups())
    jelenv.update_nodes_from_info(nodes)

    from jelapi.classes import JelasticNodeGroup

    # Do not look by full NodeGroup object
    with pytest.raises(JelasticObjectException):
        jelenv.node_by_node_group(JelasticNodeGroup.NodeGroupType.CACHE)

    # If the node's not around, exception
    with pytest.raises(JelasticObjectException):
        jelenv.node_by_node_group("nosqldb")

    assert isinstance(jelenv.node_by_node_group("cp"), JelasticNode)
Esempio n. 2
0
def test_JelasticEnvironment_nodes():
    """
    JelasticEnvironment can be instantiated with nodes
    """
    nodes = []
    for i in range(3):
        node = get_standard_node()
        node["id"] = i
        nodes.append(node)

    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(get_standard_env())
    jelenv.update_node_groups_from_info(get_standard_node_groups())
    jelenv.update_nodes_from_info(nodes)

    assert not jelenv.differs_from_api()
    jelenv.nodeGroups["cp"].nodes[0].fixedCloudlets = 8
    assert jelenv.differs_from_api()

    jelapic()._ = Mock(return_value={
        "env": get_standard_env(),
        "envGroups": [],
        "nodes": [get_standard_node()],
    }, )
    jelenv.save()
    assert not jelenv.differs_from_api()
Esempio n. 3
0
def test_JelasticEnvironment_ordering():
    """
    JelasticEnvironment can be instantiated, but the updates cannot be called in any order
    """
    j = JelasticEnvironment()
    with pytest.raises(JelasticObjectException):
        j.update_node_groups_from_info([])

    with pytest.raises(JelasticObjectException):
        j.update_nodes_from_info([])

    # Calling the update_from_env_dict first solves this
    j.update_from_env_dict(get_standard_env())
    j.update_node_groups_from_info([])
    j.update_nodes_from_info([])
Esempio n. 4
0
def test_JelasticEnvironment_stranger_nodes():
    """
    JelasticEnvironment cannot be instantiated with nodes outside of the nodeGroups
    """
    nodes = [
        get_standard_node(),
    ]

    #  Get a node groups' list without above nodes' nodegroup
    node_groups = [
        ngdict for ngdict in get_standard_node_groups()
        if ngdict["name"] != nodes[0]["nodeGroup"]
    ]

    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(get_standard_env())
    jelenv.update_node_groups_from_info(node_groups)

    with pytest.raises(JelasticObjectException):
        jelenv.update_nodes_from_info(nodes)