def test_list_ec2_spot(aws_region, aws_tags, result_count):
    """Verify list ec2 spot function."""
    tag_key = aws_tags[0]["Key"]
    tag_value = "".join(aws_tags[0]["Values"])
    launch_ec2_spot(3, aws_region, "tostop", "true")
    spot_list = SpotScheduler(aws_region)
    taglist = spot_list.list_spot(tag_key, tag_value)
    assert len(list(taglist)) == result_count
def test_terminate_ec2_spot(aws_region, tag_key, tag_value, result_count):
    """Verify terminate ec2 spot instance."""
    client = boto3.client("ec2", region_name=aws_region)

    launch_ec2_spot(3, aws_region, "tostop", "true")
    spot_scheduler = SpotScheduler(aws_region)
    spot_scheduler.terminate(tag_key, tag_value)
    instances = client.describe_instances()["Reservations"][0]["Instances"]
    assert len(instances) == 3
    for instance in instances:
        assert instance["State"] == result_count
def test_terminate_spot_scheduler(aws_region, tag_key, tag_value,
                                  result_count):
    """Verify terminate spot scheduler class method."""
    client = boto3.client("ec2", region_name=aws_region)
    instances = launch_ec2_spot(2, aws_region, tag_key, tag_value)
    instance_ids = [x["InstanceId"] for x in instances["Instances"]]

    try:
        client.get_waiter("instance_running").wait(InstanceIds=instance_ids)
        spot_scheduler = SpotScheduler(aws_region)
        spot_scheduler.terminate("tostop-spot-test-1", "true")
        if tag_key == "tostop-spot-test-1" and tag_value == "true":
            client.get_waiter("instance_terminated").wait(
                InstanceIds=instance_ids)

        ec2_describe = client.describe_instances(InstanceIds=instance_ids)
        for ec2 in ec2_describe["Reservations"][0]["Instances"]:
            assert ec2["State"] == result_count
    finally:
        # Clean aws account
        client.terminate_instances(InstanceIds=instance_ids)
コード例 #4
0
def test_list_ec2_spot(aws_region, tag_key, tag_value, result_count):
    """Verify list ec2 spot function."""
    launch_ec2_spot(3, aws_region, "tostop", "true")
    spot_list = SpotScheduler(aws_region)
    taglist = spot_list.list_spot(tag_key, tag_value)
    assert len(list(taglist)) == result_count