|
2 | 2 |
|
3 | 3 | import boto3 |
4 | 4 | import pytest |
| 5 | +from botocore.client import ClientError |
5 | 6 |
|
6 | 7 | from moto import mock_aws |
7 | 8 | from moto.core.types import Base64EncodedString |
8 | 9 | from tests import EXAMPLE_AMI_ID |
| 10 | +from tests.test_ec2.helpers import assert_dryrun_error |
9 | 11 |
|
10 | 12 | from . import ec2_aws_verified |
11 | 13 |
|
@@ -68,6 +70,52 @@ def test_launch_template_is_created_properly(ec2_client=None): |
68 | 70 | assert template["LatestVersionNumber"] == 1 |
69 | 71 |
|
70 | 72 |
|
| 73 | +@pytest.mark.aws_verified |
| 74 | +@ec2_aws_verified() |
| 75 | +def test_create_fleet_dryrun(ec2_client=None): |
| 76 | + with launch_template_context() as ctxt: |
| 77 | + # Attempting to create a fleet with DryRun=True should raise an error |
| 78 | + with pytest.raises(ClientError) as ex: |
| 79 | + fleets_before = len(ctxt.ec2.describe_fleets()["Fleets"]) |
| 80 | + reservations_before = len(ctxt.ec2.describe_instances()["Reservations"]) |
| 81 | + |
| 82 | + ctxt.ec2.create_fleet( |
| 83 | + DryRun=True, |
| 84 | + ExcessCapacityTerminationPolicy="terminate", |
| 85 | + LaunchTemplateConfigs=[ |
| 86 | + { |
| 87 | + "LaunchTemplateSpecification": { |
| 88 | + "LaunchTemplateId": ctxt.lt_id, |
| 89 | + "Version": "1", |
| 90 | + }, |
| 91 | + }, |
| 92 | + ], |
| 93 | + TargetCapacitySpecification={ |
| 94 | + "DefaultTargetCapacityType": "spot", |
| 95 | + "OnDemandTargetCapacity": 0, |
| 96 | + "SpotTargetCapacity": 1, |
| 97 | + "TotalTargetCapacity": 1, |
| 98 | + }, |
| 99 | + SpotOptions={ |
| 100 | + "AllocationStrategy": "lowest-price", |
| 101 | + }, |
| 102 | + Type="maintain", |
| 103 | + ValidFrom="2020-01-01T00:00:00Z", |
| 104 | + ValidUntil="2020-12-31T00:00:00Z", |
| 105 | + ) |
| 106 | + |
| 107 | + # Verify the error is the expected DryRun error |
| 108 | + assert_dryrun_error(ex) |
| 109 | + |
| 110 | + # Verify no fleets were created |
| 111 | + fleets_res = ctxt.ec2.describe_fleets() |
| 112 | + assert len(fleets_res["Fleets"]) == fleets_before |
| 113 | + |
| 114 | + # Verify no instances were created |
| 115 | + instances_res = ctxt.ec2.describe_instances() |
| 116 | + assert len(instances_res["Reservations"]) == reservations_before |
| 117 | + |
| 118 | + |
71 | 119 | @mock_aws |
72 | 120 | def test_create_spot_fleet_with_lowest_price(): |
73 | 121 | conn = boto3.client("ec2", region_name="us-west-2") |
|
0 commit comments