Ejemplo n.º 1
0
def test_start_asg_scheduler(aws_region, asg_tag, scheduler_tag, result_count):
    """Verify start asg scheduler class method."""
    client = boto3.client("autoscaling", region_name=aws_region)
    launch_conf_name = "lc-test" + str(randint(0, 1000000000))
    asg_name = "asg-test" + str(randint(0, 1000000000))
    tag_key = asg_tag[0]["Key"]
    tag_value = "".join(asg_tag[0]["Values"])
    launch_asg(aws_region, tag_key, tag_value, launch_conf_name, asg_name)

    try:
        client.suspend_processes(AutoScalingGroupName=asg_name)
        asg_scheduler = AutoscalingScheduler(aws_region)
        asg_scheduler.cloudwatch_alarm = CloudWatchAlarmScheduler(aws_region)
        asg_scheduler.start(scheduler_tag)

        suspend_process = client.describe_auto_scaling_groups(
            AutoScalingGroupNames=[asg_name]
        )["AutoScalingGroups"][0]["SuspendedProcesses"]
        assert len([x["ProcessName"] for x in suspend_process]) == result_count
    finally:
        # Clean aws account
        client.delete_auto_scaling_group(AutoScalingGroupName=asg_name,
                                         ForceDelete=True)
        client.delete_launch_configuration(
            LaunchConfigurationName=launch_conf_name)
def test_list_autoscaling_group(aws_region, aws_tags, result_count):
    """Verify list autoscaling group function."""
    launch_asg(aws_region, "tostop", "true")
    tag_key = aws_tags[0]["Key"]
    tag_value = "".join(aws_tags[0]["Values"])
    asg_scheduler = AutoscalingScheduler(aws_region)
    taglist = asg_scheduler.list_groups(tag_key, tag_value)
    assert len(list(taglist)) == result_count
def test_asg_instance_stop(aws_region, tag_key, tag_value, result_count):
    """Verify autoscaling instances stop function."""
    client = boto3.client("ec2", region_name=aws_region)

    launch_asg(aws_region, "tostop", "true")
    asg_scheduler = AutoscalingScheduler(aws_region)
    asg_scheduler.stop(tag_key, tag_value)
    asg_instance = client.describe_instances()["Reservations"][0]["Instances"]
    assert len(asg_instance) == 3
    for instance in asg_instance:
        assert instance["State"] == result_count
def test_stop_asg_scheduler(aws_region, tag_key, tag_value, result_count):
    """Verify stop asg scheduler class method."""
    client = boto3.client("autoscaling", region_name=aws_region)
    launch_conf_name = "lc-test" + str(randint(0, 1000000000))
    asg_name = "asg-test" + str(randint(0, 1000000000))
    launch_asg(aws_region, tag_key, tag_value, launch_conf_name, asg_name)

    try:
        asg_scheduler = AutoscalingScheduler(aws_region)
        asg_scheduler.stop("tostop-asg-test-1", "true")

        suspend_process = client.describe_auto_scaling_groups(
            AutoScalingGroupNames=[asg_name]
        )["AutoScalingGroups"][0]["SuspendedProcesses"]
        assert len([x["ProcessName"] for x in suspend_process]) == result_count
    finally:
        # Clean aws account
        client.delete_auto_scaling_group(AutoScalingGroupName=asg_name,
                                         ForceDelete=True)
        client.delete_launch_configuration(
            LaunchConfigurationName=launch_conf_name)
def test_list_autoscaling_instance(aws_region, asg_name, result_count):
    """Verify list autoscaling instance function"""
    launch_asg(aws_region, "tostop", "true")
    asg_scheduler = AutoscalingScheduler(aws_region)
    taglist = asg_scheduler.list_instances(asg_name)
    assert len(list(taglist)) == result_count
def test_list_autoscaling_group(aws_region, tag_key, tag_value, result_count):
    """Verify list autoscaling group function."""
    launch_asg(aws_region, "tostop", "true")
    asg_scheduler = AutoscalingScheduler(aws_region)
    taglist = asg_scheduler.list_groups(tag_key, tag_value)
    assert len(list(taglist)) == result_count