Example #1
0
def test_JelasticEnvironment_sleep_via_method():
    """
    JelasticEnvironment can be started if stopped or sleeping, with the start() method
    """
    jelapic()._ = Mock(
        return_value={
            "env":
            get_standard_env(
                status=JelasticEnvironment.Status.SLEEPING.value
            ),  # After the stop, the API returns that it was stopped
            "envGroups": [],
        })

    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(
        get_standard_env(JelasticEnvironment.Status.RUNNING))

    jelenv.sleep()
    assert jelenv.status == JelasticEnvironment.Status.SLEEPING
    jelapic()._.assert_called()

    # A second save should not call the API
    jelapic()._.reset_mock()
    jelenv.save()
    jelapic()._.assert_not_called()
Example #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()
Example #3
0
def test_JelasticEnvironment_sleep_via_status():
    """
    JelasticEnvironment can be put to sleep if running, by setting the status to SLEEPING, and saving
    """
    jelapic()._ = Mock(
        return_value={
            "env":
            get_standard_env(
                status=JelasticEnvironment.Status.SLEEPING.value
            ),  # After the sleep, the API returns that it was sleeping
            "envGroups": [],
        })

    # Test these two starting statuses
    for status in [
            JelasticEnvironment.Status.STOPPED,
            JelasticEnvironment.Status.SLEEPING,
    ]:
        jelapic()._.reset_mock()
        jelenv = JelasticEnvironment()
        jelenv.update_from_env_dict(get_standard_env(status.value))

        jelenv.status = JelasticEnvironment.Status.RUNNING
        jelenv.save()
        assert jelenv.status == JelasticEnvironment.Status.SLEEPING
        jelapic()._.assert_called()

        # A second save should not call the API
        jelapic()._.reset_mock()
        jelenv.save()
        jelapic()._.assert_not_called()
Example #4
0
def test_JelasticEnvironment_stop_via_status():
    """
    JelasticEnvironment can be started if started, by setting the status to STOPPED, and saving
    """
    jelapic()._ = Mock(
        return_value={
            "env":
            get_standard_env(
                status=JelasticEnvironment.Status.STOPPED.value
            ),  # After the stop, the API returns that it was stopped
            "envGroups": [],
        })

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

    jelenv.status = JelasticEnvironment.Status.STOPPED
    jelenv.save()
    assert jelenv.status == JelasticEnvironment.Status.STOPPED
    jelapic()._.assert_called()

    # A second save should not call the API
    jelapic()._.reset_mock()
    jelenv.save()
    jelapic()._.assert_not_called()
Example #5
0
def test_JelasticEnvironment_unsupported_statuses():
    """
    JelasticEnvironment cannot (yet) be put to certain states
    """
    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(get_standard_env())

    JelStatus = JelasticEnvironment.Status
    for status in [
            JelStatus.UNKNOWN,
            JelStatus.LAUNCHING,
            JelStatus.SUSPENDED,
            JelStatus.CREATING,
            JelStatus.CLONING,
            JelStatus.UPDATING,
    ]:
        jelenv.status = status
        with pytest.raises(JelasticObjectException):
            jelenv.save()
Example #6
0
def test_JelasticEnvironment_extdomains_change_and_save_will_talk_to_API():
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """
    twodomains = ["test.example.com", "test.example.org"]
    jelapic()._ = Mock(return_value={
        "env": get_standard_env(extdomains=twodomains),
        "envGroups": []
    }, )

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

    jelenv.extdomains = twodomains
    jelenv.save()
    jelapic()._.assert_called()

    jelapic()._.reset_mock()

    #  Removing a domain also calls
    jelenv.extdomains.remove("test.example.com")
    jelenv.save()
    jelapic()._.assert_called()

    jelapic()._.reset_mock()

    # A second save should not call the API
    jelenv.save()
    jelapic()._.assert_not_called()
Example #7
0
def test_JelasticEnvironment_envGroups_change_and_save_will_talk_to_API():
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """
    jelapic()._ = Mock(return_value={
        "env": get_standard_env(),
        "envGroups": []
    }, )

    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(get_standard_env())
    jelenv.update_env_groups_from_info(["A", "B"])

    jelenv.envGroups.append("C")
    jelenv.save()
    jelapic()._.assert_called()

    jelapic()._.reset_mock()

    # A second save should not call the API
    jelenv.save()
    jelapic()._.assert_not_called()