Exemple #1
0
def test_instance_unhealthy_count_names(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    asg_names = ['AutoScalingGroup-A']
    client.describe_auto_scaling_groups.return_value = {
        "AutoScalingGroups": [{
            "AutoScalingGroupName": "AutoScalingGroup-A",
            "Instances": [
                {
                    "InstanceId": "i-012345678901",
                    "HealthStatus": "Healthy"
                },
                {
                    "InstanceId": "i-012345678902",
                    "HealthStatus": "Healthy"
                },
                {
                    "InstanceId": "i-012345678903",
                    "HealthStatus": "Unhealthy"
                }
            ]}]}
    response = instance_count_by_health(asg_names, count_healthy=False)
    client.describe_auto_scaling_groups.assert_called_with(
        AutoScalingGroupNames=asg_names)
    assert response == 1
def test_instance_unhealthy_count_tags(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    tags = [{"Key": "TestKey", "Value": "TestValue"}]
    client.get_paginator.return_value.paginate.return_value = [
        {
            "Tags": [
                {
                    "ResourceId": "AutoScalingGroup-A",
                    "ResourceType": "auto-scaling-group",
                    "Key": "TestKey",
                    "Value": "TestValue",
                }
            ]
        }
    ]

    client.describe_auto_scaling_groups.return_value = {
        "AutoScalingGroups": [
            {
                "AutoScalingGroupName": "AutoScalingGroup-A",
                "Instances": [
                    {"InstanceId": "i-012345678901", "HealthStatus": "Healthy"},
                    {"InstanceId": "i-012345678902", "HealthStatus": "Healthy"},
                    {"InstanceId": "i-012345678903", "HealthStatus": "Unhealthy"},
                ],
                "Tags": [
                    {
                        "ResourceId": "AutoScalingGroup-A",
                        "Key": "TestKey",
                        "Value": "TestValue",
                    }
                ],
            }
        ]
    }
    response = instance_count_by_health(tags=tags, count_healthy=False)
    client.get_paginator.return_value.paginate.assert_called_with(
        Filters=[{"Name": "TestKey", "Values": ["TestValue"]}]
    )
    client.describe_auto_scaling_groups.assert_called_with(
        AutoScalingGroupNames=["AutoScalingGroup-A"]
    )
    assert response == 1