From 64a5dcde312be8b2533081cae175589b5ff25d44 Mon Sep 17 00:00:00 2001 From: Macwan Nevil Date: Mon, 23 Jan 2023 22:43:10 +0530 Subject: [PATCH] ec2: default values in ec2 fleet (#5856) --- moto/ec2/models/fleets.py | 10 ++++++---- moto/ec2/responses/fleets.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/moto/ec2/models/fleets.py b/moto/ec2/models/fleets.py index 656506f7e..8597f54ef 100644 --- a/moto/ec2/models/fleets.py +++ b/moto/ec2/models/fleets.py @@ -1,7 +1,7 @@ +import datetime from collections import defaultdict from moto.ec2.models.spot_requests import SpotFleetLaunchSpec - from .core import TaggedEC2Resource from ..utils import ( random_fleet_id, @@ -39,7 +39,7 @@ class Fleet(TaggedEC2Resource): self.replace_unhealthy_instances = replace_unhealthy_instances self.terminate_instances_with_expiration = terminate_instances_with_expiration self.fleet_type = fleet_type - self.valid_from = valid_from + self.valid_from = valid_from or datetime.datetime.now(tz=datetime.timezone.utc) self.valid_until = valid_until tag_map = convert_tag_spec(tag_specifications).get("fleet", {}) self.add_tags(tag_map) @@ -102,12 +102,14 @@ class Fleet(TaggedEC2Resource): target_capacity_specification.get("TotalTargetCapacity") ) self.spot_target_capacity = int( - target_capacity_specification.get("SpotTargetCapacity") + target_capacity_specification.get("SpotTargetCapacity", 0) ) if self.spot_target_capacity > 0: self.create_spot_requests(self.spot_target_capacity) self.on_demand_target_capacity = int( - target_capacity_specification.get("OnDemandTargetCapacity") + target_capacity_specification.get( + "OnDemandTargetCapacity", self.target_capacity + ) ) if self.on_demand_target_capacity > 0: self.create_on_demand_requests(self.on_demand_target_capacity) diff --git a/moto/ec2/responses/fleets.py b/moto/ec2/responses/fleets.py index dc8b31f56..a22f61620 100644 --- a/moto/ec2/responses/fleets.py +++ b/moto/ec2/responses/fleets.py @@ -30,7 +30,9 @@ class Fleets(BaseResponse): target_capacity_specification = self._get_multi_param_dict( "TargetCapacitySpecification" ) - launch_template_configs = self._get_multi_param("LaunchTemplateConfigs") + launch_template_configs = self._get_multi_param( + param_prefix="LaunchTemplateConfigs" + ) excess_capacity_termination_policy = self._get_param( "ExcessCapacityTerminationPolicy" @@ -209,8 +211,12 @@ DESCRIBE_FLEETS_TEMPLATE = """