Exemplo n.º 1
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
    )
Exemplo n.º 2
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
Exemplo n.º 3
0
def test_is_deployed_with_more_than_100_tasks(client, service):
    client.list_tasks.side_effect = mock_list_tasks
    client.describe_tasks.side_effect = mock_describe_tasks
    service.set_desired_count(len(RESPONSE_LIST_TASKS_110))
    action = EcsAction(client, CLUSTER_NAME, SERVICE_NAME)
    is_deployed = action.is_deployed(service)

    assert is_deployed is True
Exemplo 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(service.cluster, service.name, service.desired_count,
                                                  service.task_definition)
Exemplo n.º 5
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(service.cluster, service.name)
Exemplo n.º 6
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(service.cluster, service.name)
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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(service.cluster,
                                                  service.name,
                                                  service.desired_count,
                                                  service.task_definition)
Exemplo n.º 10
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(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'
Exemplo n.º 11
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'
Exemplo n.º 12
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(
        task_definition.family,
        task_definition.containers,
        task_definition.volumes,
        task_definition.role_arn,
    )
    client.deregister_task_definition.assert_called_once_with(
        task_definition.arn)
Exemplo n.º 13
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".'
Exemplo n.º 14
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.'
Exemplo n.º 15
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(
        task_definition.family,
        task_definition.containers,
        task_definition.volumes,
        task_definition.role_arn,
    )
    client.deregister_task_definition.assert_called_once_with(
        task_definition.arn
    )
Exemplo n.º 16
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,
        additional_properties={
            u'networkMode': u'host',
            u'placementConstraints': {},
            u'unknownProperty': u'lorem-ipsum'
        })
Exemplo n.º 17
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'
Exemplo n.º 18
0
def test_ecs_action_init_with_invalid_cluster():
    with pytest.raises(EcsConnectionError) as excinfo:
        client = EcsTestClient(u'access_key', u'secret_key')
        EcsAction(client, u'invliad-cluster', u'test-service')
    assert str(excinfo.value) == u'An error occurred (ClusterNotFoundException) when calling the DescribeServices ' \
                                 u'operation: Cluster not found.'
Exemplo n.º 19
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)
Exemplo n.º 20
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
Exemplo n.º 21
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
Exemplo n.º 22
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.set_desired_count(0)
    is_deployed = action.is_deployed(service)
    assert is_deployed is True
Exemplo n.º 23
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'
Exemplo n.º 24
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
Exemplo n.º 25
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
Exemplo n.º 26
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
Exemplo n.º 27
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