Ejemplo n.º 1
0
def test_get_running_tasks_count_new_revision(client, service,
                                              task_definition_revision_2):
    client.describe_tasks.return_value = RESPONSE_DESCRIBE_TASKS
    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    service.set_task_definition(task_definition_revision_2)
    running_count = action.get_running_tasks_count(service,
                                                   [TASK_ARN_1, TASK_ARN_2])
    assert running_count == 0
Ejemplo n.º 2
0
def test_is_not_deployed_with_more_than_one_deployment(client, service):
    service['deployments'].append(service['deployments'][0])

    client.list_tasks.return_value = RESPONSE_LIST_TASKS_1
    client.describe_tasks.return_value = RESPONSE_DESCRIBE_TASKS

    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    is_deployed = action.is_deployed(service)

    assert is_deployed is False
Ejemplo n.º 3
0
def test_is_deployed(client, service):
    client.list_tasks.return_value = RESPONSE_LIST_TASKS_1
    client.describe_tasks.return_value = RESPONSE_DESCRIBE_TASKS

    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    is_deployed = action.is_deployed(service)

    assert is_deployed is True
    client.list_tasks.assert_called_once_with(cluster_name=service.cluster,
                                              service_name=service.name)
Ejemplo n.º 4
0
def test_update_service(client, service):
    client.update_service.return_value = RESPONSE_SERVICE

    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    new_service = action.update_service(service)

    assert isinstance(new_service, EcsService)
    client.update_service.assert_called_once_with(
        cluster=service.cluster,
        service=service.name,
        desired_count=None,
        task_definition=service.task_definition)
Ejemplo n.º 5
0
def test_ecs_action_get_current_task_definition(client, service):
    client.describe_task_definition.return_value = RESPONSE_TASK_DEFINITION

    action = EcsAction(client, u'test-cluster', u'test-service')
    task_definition = action.get_current_task_definition(service)

    client.describe_task_definition.assert_called_once_with(
        task_definition_arn=service.task_definition)

    assert isinstance(task_definition, EcsTaskDefinition)
    assert task_definition.family == u'test-task'
    assert task_definition.revision == 1
    assert task_definition.arn == u'arn:aws:ecs:eu-central-1:123456789012:task-definition/test-task:1'
Ejemplo n.º 6
0
def test_ecs_action_init_without_credentials():
    with pytest.raises(EcsConnectionError) as excinfo:
        client = EcsTestClient()
        EcsAction(client, u'test-cluster', u'invalid-service')
    assert str(
        excinfo.value
    ) == u'Unable to locate credentials. Configure credentials by running "aws configure".'
Ejemplo n.º 7
0
def test_ecs_action_init_with_invalid_service():
    with pytest.raises(EcsConnectionError) as excinfo:
        client = EcsTestClient(u'access_key', u'secret_key')
        EcsAction(client, u'test-cluster', u'invalid-service')
    assert str(
        excinfo.value
    ) == u'An error occurred when calling the DescribeServices operation: Service not found.'
Ejemplo n.º 8
0
def test_update_task_definition(client, task_definition):
    client.register_task_definition.return_value = RESPONSE_TASK_DEFINITION

    action = EcsAction(client, u'test-cluster', u'test-service')
    new_task_definition = action.update_task_definition(task_definition)

    assert isinstance(new_task_definition, EcsTaskDefinition)
    client.register_task_definition.assert_called_once_with(
        family=task_definition.family,
        containers=task_definition.containers,
        volumes=task_definition.volumes,
        role_arn=task_definition.role_arn,
        execution_role_arn=task_definition.execution_role_arn,
        tags=task_definition.tags,
        additional_properties={
            u'networkMode': u'host',
            u'placementConstraints': {},
            u'unknownProperty': u'lorem-ipsum'
        })
Ejemplo n.º 9
0
def test_get_running_tasks_count(client, service):
    client.describe_tasks.return_value = RESPONSE_DESCRIBE_TASKS
    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    running_count = action.get_running_tasks_count(service,
                                                   [TASK_ARN_1, TASK_ARN_2])
    assert running_count == 2
Ejemplo n.º 10
0
def test_is_not_deployed_if_no_tasks_running(client, service):
    client.list_tasks.return_value = RESPONSE_LIST_TASKS_0
    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    is_deployed = action.is_deployed(service)
    assert is_deployed is False
Ejemplo n.º 11
0
def test_is_deployed_if_no_tasks_should_be_running(client, service):
    client.list_tasks.return_value = RESPONSE_LIST_TASKS_0
    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    service[u'desiredCount'] = 0
    is_deployed = action.is_deployed(service)
    assert is_deployed is True
Ejemplo n.º 12
0
def test_deregister_task_definition(client, task_definition):
    action = EcsAction(client, u'test-cluster', u'test-service')
    action.deregister_task_definition(task_definition)

    client.deregister_task_definition.assert_called_once_with(
        task_definition.arn)
Ejemplo n.º 13
0
def test_ecs_action_get_service():
    client = EcsTestClient(u'access_key', u'secret_key')
    action = EcsAction(client, u'test-cluster', u'test-service')
    service = action.get_service()
    assert service.name == u'test-service'
    assert service.cluster == u'test-cluster'
Ejemplo n.º 14
0
def test_ecs_action_init(client):
    action = EcsAction(client, u'test-cluster', u'test-service')
    assert action.client == client
    assert action.cluster_name == u'test-cluster'
    assert action.service_name == u'test-service'
    assert isinstance(action.service, EcsService)