Пример #1
0
def test_deployment_check_with_deployment_in_progress(mock_get_deployment):
    """ Test that deployment.check() returns False when the app has a deployment in progress.
    """
    deploy_in_progress = {
        "id":
        "97c136bf-5a28-4821-9d94-480d9fbb01c8",
        "version":
        "2015-09-30T09:09:17.614Z",
        "affectedApps": ["/foo"],
        "steps": [[{
            "action": "StartApplication",
            "app": "/foo"
        }], [{
            "action": "ScaleApplication",
            "app": "/foo"
        }]],
        "currentActions": [{
            "action": "ScaleApplication",
            "app": "/foo"
        }],
        "currentStep":
        2,
        "totalSteps":
        2
    }
    mock_get_deployment.return_value = deploy_in_progress

    client = MarathonClient("http://marathon.somedomian.com:8080")
    deployment = MarathonDeployment(client,
                                    "97c136bf-5a28-4821-9d94-480d9fbb01c8")
    assert not deployment.check()
Пример #2
0
def test_deployment_check(mock_get_deployment):
    """ Test that deployment.check() returns True when the app has deployed successfully.
    """
    mock_get_deployment.side_effect = DeploymentNotFound("1234")

    client = MarathonClient("http://marathon.somedomian.com:8080")
    deployment = MarathonDeployment(client, '1234')
    assert deployment.check()
Пример #3
0
def test_get_application_not_found():
    responses.add(responses.GET,
                  'http://marathon.somedomain.com:8080/v2/apps/test-app',
                  status=404,
                  json={"message": "App '/test-app' does not exist"})

    client = MarathonClient("http://marathon.somedomain.com:8080")
    with pytest.raises(ClientError):
        client.get_application('test-app')
Пример #4
0
def test_get_application_internal_server_error():
    responses.add(responses.GET,
                  'http://marathon.somedomain.com:8080/v2/apps/test-app',
                  status=500,
                  body="Internal Server Error")

    client = MarathonClient("http://marathon.somedomain.com:8080")
    with pytest.raises(ClientError):
        client.get_application('test-app')
Пример #5
0
def test_get_deployment_not_found():
    responses.add(responses.GET,
                  'http://marathon.somedomain.com:8080/v2/deployments',
                  status=200,
                  json=_load_json_fixture("deployments"))

    client = MarathonClient("http://marathon.somedomain.com:8080")
    with pytest.raises(DeploymentNotFound):
        client.get_deployment("1234")
Пример #6
0
def test_deploy_unprocessable_entity():
    responses.add(responses.PUT,
                  'http://marathon.somedomain.com:8080/v2/apps/test-app',
                  status=422,
                  json=_load_json_fixture("validation_errors"))

    client = MarathonClient("http://marathon.somedomain.com:8080")
    with pytest.raises(ClientError):
        client.deploy({"id": "test-app"})
Пример #7
0
def test_deploy_conflict():
    responses.add(responses.PUT,
                  'http://marathon.somedomain.com:8080/v2/apps/test-app',
                  status=409,
                  json=_load_json_fixture("deployment_in_progress"))

    client = MarathonClient("http://marathon.somedomain.com:8080")
    with pytest.raises(ClientError):
        client.deploy({"id": "test-app"})
Пример #8
0
def test_deployment_wait_with_timeout(mock_deployment_check):
    """ Test that deployment.wait() spins until a deployment succeeds.
    """
    mock_deployment_check.side_effect = [False, False, False]

    client = MarathonClient("http://marathon.somedomain.com:8080")
    deployment = MarathonDeployment(client, '1234')
    with pytest.raises(DeploymentFailed):
        deployment.wait(timeout=1, check_interval_secs=0.5)
    assert mock_deployment_check.call_count == 2
Пример #9
0
def _validate_marathon_client(ctx, _, __):
    """Validates that all options required to initialise a marathon client have
    been set properly and securely.

    A client is then initialised and returned to the command function.
    """
    _c = ctx.params
    _validate_authentication(ctx, _c["marathon_url"], "Marathon")
    return MarathonClient(_c["marathon_url"], _c["username"], _c["password"],
                          _c["dry_run"])
Пример #10
0
def test_deploy_single_app_list(mock_deployment_check):
    responses.add(responses.PUT,
                  'http://marathon.somedomain.com:8080/v2/apps/test-app',
                  status=201,
                  json=_load_json_fixture("deployment"))
    mock_deployment_check.return_value = True

    client = MarathonClient("http://marathon.somedomain.com:8080")
    deployment = client.deploy([{"id": "test-app"}])
    assert deployment.wait(check_interval_secs=0.1)
Пример #11
0
def test_get_application():
    responses.add(responses.GET,
                  'http://marathon.somedomain.com:8080/v2/apps/test-app',
                  status=200,
                  json=_load_json_fixture("valid_app"))

    client = MarathonClient("http://marathon.somedomain.com:8080")
    application = client.get_application('test-app')
    assert application['id'] == "/test-app"
    assert application['cmd'] is None
Пример #12
0
def test_basic_auth_headers_not_present():
    responses.add(responses.GET,
                  'http://marathon.somedomain.com:8080/v2/apps/test-app',
                  status=200,
                  json=_load_json_fixture("valid_app"))

    client = MarathonClient("http://marathon.somedomain.com:8080")
    client.get_application('test-app')

    assert "Authorization" not in responses.calls[0].request.headers
Пример #13
0
def test_get_deployment():
    responses.add(responses.GET,
                  'http://marathon.somedomain.com:8080/v2/deployments',
                  status=200,
                  json=_load_json_fixture("deployments"))

    client = MarathonClient("http://marathon.somedomain.com:8080")
    deployment = client.get_deployment("97c136bf-5a28-4821-9d94-480d9fbb01c8")
    assert deployment is not None
    assert deployment['id'] == "97c136bf-5a28-4821-9d94-480d9fbb01c8"
Пример #14
0
def test_deployment_wait(mock_deployment_check):
    """ Test that deployment.wait() spins until a deployment succeeds.
    """
    mock_deployment_check.side_effect = [
        False, False, False, False, False, False, False, False, False, False,
        False, False, False, False, False, False, False, False, False, True
    ]

    client = MarathonClient("http://marathon.somedomain.com:8080")
    deployment = MarathonDeployment(client, '1234')
    deployment.wait(check_interval_secs=0.01)
    assert mock_deployment_check.call_count == 20
Пример #15
0
def test_deploy_dry_run():
    client = MarathonClient("http://marathon.somedomain.com:8080",
                            dry_run=True)
    with pytest.raises(DryRun):
        client.deploy({"id": "test-app"})