Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions moto/ec2/responses/fleets.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def create_fleet(self) -> ActionResult:

tag_specifications = self._get_param("TagSpecifications", [])

self.error_on_dryrun()

request = self.ec2_backend.create_fleet(
on_demand_options=on_demand_options,
spot_options=spot_options,
Expand Down
48 changes: 48 additions & 0 deletions tests/test_ec2/test_fleets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import boto3
import pytest
from botocore.client import ClientError

from moto import mock_aws
from moto.core.types import Base64EncodedString
from tests import EXAMPLE_AMI_ID
from tests.test_ec2.helpers import assert_dryrun_error

from . import ec2_aws_verified

Expand Down Expand Up @@ -68,6 +70,52 @@ def test_launch_template_is_created_properly(ec2_client=None):
assert template["LatestVersionNumber"] == 1


@pytest.mark.aws_verified
@ec2_aws_verified()
def test_create_fleet_dryrun(ec2_client=None):
with launch_template_context() as ctxt:
# Attempting to create a fleet with DryRun=True should raise an error
with pytest.raises(ClientError) as ex:
fleets_before = len(ctxt.ec2.describe_fleets()["Fleets"])
reservations_before = len(ctxt.ec2.describe_instances()["Reservations"])

ctxt.ec2.create_fleet(
DryRun=True,
ExcessCapacityTerminationPolicy="terminate",
LaunchTemplateConfigs=[
{
"LaunchTemplateSpecification": {
"LaunchTemplateId": ctxt.lt_id,
"Version": "1",
},
},
],
TargetCapacitySpecification={
"DefaultTargetCapacityType": "spot",
"OnDemandTargetCapacity": 0,
"SpotTargetCapacity": 1,
"TotalTargetCapacity": 1,
},
SpotOptions={
"AllocationStrategy": "lowest-price",
},
Type="maintain",
ValidFrom="2020-01-01T00:00:00Z",
ValidUntil="2020-12-31T00:00:00Z",
)

# Verify the error is the expected DryRun error
assert_dryrun_error(ex)

# Verify no fleets were created
fleets_res = ctxt.ec2.describe_fleets()
assert len(fleets_res["Fleets"]) == fleets_before

# Verify no instances were created
instances_res = ctxt.ec2.describe_instances()
assert len(instances_res["Reservations"]) == reservations_before


@mock_aws
def test_create_spot_fleet_with_lowest_price():
conn = boto3.client("ec2", region_name="us-west-2")
Expand Down
Loading