Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Techdebt: Update TF tests #6661

Merged
merged 1 commit into from
Aug 21, 2023
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: 1 addition & 1 deletion .github/workflows/test_terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
service: ${{ fromJson(needs.prepare_list.outputs.matrix) }}
go-version: [1.18.x]
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
5 changes: 5 additions & 0 deletions moto/acmpca/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(
certificate_authority_configuration: Dict[str, Any],
certificate_authority_type: str,
revocation_configuration: Dict[str, Any],
security_standard: Optional[str],
):
self.id = mock_random.uuid4()
self.arn = (
Expand All @@ -40,6 +41,7 @@ def __init__(
self.updated_at: Optional[float] = None
self.status = "PENDING_CERTIFICATE"
self.usage_mode = "SHORT_LIVED_CERTIFICATE"
self.security_standard = security_standard or "FIPS_140_2_LEVEL_3_OR_HIGHER"

common_name = self.certificate_authority_configuration.get("Subject", {}).get(
"CommonName", "Moto.org"
Expand Down Expand Up @@ -170,6 +172,7 @@ def to_json(self) -> Dict[str, Any]:
"CreatedAt": self.created_at,
"Status": self.status,
"UsageMode": self.usage_mode,
"KeyStorageSecurityStandard": self.security_standard,
}
if self.updated_at:
dct["LastStateChangeAt"] = self.updated_at
Expand All @@ -196,6 +199,7 @@ def create_certificate_authority(
certificate_authority_configuration: Dict[str, Any],
revocation_configuration: Dict[str, Any],
certificate_authority_type: str,
security_standard: Optional[str],
tags: List[Dict[str, str]],
) -> str:
"""
Expand All @@ -207,6 +211,7 @@ def create_certificate_authority(
certificate_authority_configuration=certificate_authority_configuration,
certificate_authority_type=certificate_authority_type,
revocation_configuration=revocation_configuration,
security_standard=security_standard,
)
self.certificate_authorities[authority.arn] = authority
if tags:
Expand Down
2 changes: 2 additions & 0 deletions moto/acmpca/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def create_certificate_authority(self) -> str:
)
revocation_configuration = params.get("RevocationConfiguration")
certificate_authority_type = params.get("CertificateAuthorityType")
security_standard = params.get("KeyStorageSecurityStandard")
tags = params.get("Tags")
certificate_authority_arn = self.acmpca_backend.create_certificate_authority(
certificate_authority_configuration=certificate_authority_configuration,
revocation_configuration=revocation_configuration,
certificate_authority_type=certificate_authority_type,
security_standard=security_standard,
tags=tags,
)
return json.dumps(dict(CertificateAuthorityArn=certificate_authority_arn))
Expand Down
61 changes: 60 additions & 1 deletion moto/autoscaling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
ASG_NAME_TAG = "aws:autoscaling:groupName"


class InstanceState(object):
class InstanceState:
def __init__(
self,
instance: "Instance",
Expand Down Expand Up @@ -382,6 +382,20 @@ def set_string_propagate_at_launch_booleans_on_tags(
return tags


class FakeWarmPool(CloudFormationModel):
def __init__(
self,
max_capacity: Optional[int],
min_size: Optional[int],
pool_state: Optional[str],
instance_reuse_policy: Optional[Dict[str, bool]],
):
self.max_capacity = max_capacity
self.min_size = min_size or 0
self.pool_state = pool_state or "Stopped"
self.instance_reuse_policy = instance_reuse_policy


class FakeAutoScalingGroup(CloudFormationModel):
def __init__(
self,
Expand Down Expand Up @@ -449,6 +463,7 @@ def __init__(
self.set_desired_capacity(desired_capacity)

self.metrics: List[str] = []
self.warm_pool: Optional[FakeWarmPool] = None

@property
def tags(self) -> List[Dict[str, str]]:
Expand Down Expand Up @@ -815,6 +830,23 @@ def append_target_groups(self, target_group_arns: List[str]) -> None:
def enable_metrics_collection(self, metrics: List[str]) -> None:
self.metrics = metrics or []

def put_warm_pool(
self,
max_capacity: Optional[int],
min_size: Optional[int],
pool_state: Optional[str],
instance_reuse_policy: Optional[Dict[str, bool]],
) -> None:
self.warm_pool = FakeWarmPool(
max_capacity=max_capacity,
min_size=min_size,
pool_state=pool_state,
instance_reuse_policy=instance_reuse_policy,
)

def get_warm_pool(self) -> Optional[FakeWarmPool]:
return self.warm_pool


class AutoScalingBackend(BaseBackend):
def __init__(self, region_name: str, account_id: str):
Expand Down Expand Up @@ -1546,5 +1578,32 @@ def enable_metrics_collection(self, group_name: str, metrics: List[str]) -> None
group = self.describe_auto_scaling_groups([group_name])[0]
group.enable_metrics_collection(metrics)

def put_warm_pool(
self,
group_name: str,
max_capacity: Optional[int],
min_size: Optional[int],
pool_state: Optional[str],
instance_reuse_policy: Optional[Dict[str, bool]],
) -> None:
group = self.describe_auto_scaling_groups([group_name])[0]
group.put_warm_pool(
max_capacity=max_capacity,
min_size=min_size,
pool_state=pool_state,
instance_reuse_policy=instance_reuse_policy,
)

def describe_warm_pool(self, group_name: str) -> Optional[FakeWarmPool]:
"""
Pagination is not yet implemented. Does not create/return any Instances currently.
"""
group = self.describe_auto_scaling_groups([group_name])[0]
return group.get_warm_pool()

def delete_warm_pool(self, group_name: str) -> None:
group = self.describe_auto_scaling_groups([group_name])[0]
group.warm_pool = None


autoscaling_backends = BackendDict(AutoScalingBackend, "autoscaling")
106 changes: 106 additions & 0 deletions moto/autoscaling/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,35 @@ def enable_metrics_collection(self) -> str:
template = self.response_template(ENABLE_METRICS_COLLECTION_TEMPLATE)
return template.render()

def put_warm_pool(self) -> str:
params = self._get_params()
group_name = params.get("AutoScalingGroupName")
max_capacity = params.get("MaxGroupPreparedCapacity")
min_size = params.get("MinSize")
pool_state = params.get("PoolState")
instance_reuse_policy = params.get("InstanceReusePolicy")
self.autoscaling_backend.put_warm_pool(
group_name=group_name, # type: ignore[arg-type]
max_capacity=max_capacity,
min_size=min_size,
pool_state=pool_state,
instance_reuse_policy=instance_reuse_policy,
)
template = self.response_template(PUT_WARM_POOL_TEMPLATE)
return template.render()

def describe_warm_pool(self) -> str:
group_name = self._get_param("AutoScalingGroupName")
warm_pool = self.autoscaling_backend.describe_warm_pool(group_name=group_name)
template = self.response_template(DESCRIBE_WARM_POOL_TEMPLATE)
return template.render(pool=warm_pool)

def delete_warm_pool(self) -> str:
group_name = self._get_param("AutoScalingGroupName")
self.autoscaling_backend.delete_warm_pool(group_name=group_name)
template = self.response_template(DELETE_WARM_POOL_TEMPLATE)
return template.render()


CREATE_LAUNCH_CONFIGURATION_TEMPLATE = """<CreateLaunchConfigurationResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
<ResponseMetadata>
Expand Down Expand Up @@ -774,6 +803,28 @@ def enable_metrics_collection(self) -> str:
</Overrides>
{% endif %}
</LaunchTemplate>
{% if group.mixed_instance_policy.get("InstancesDistribution") %}
<InstancesDistribution>
{% if group.mixed_instance_policy.get("InstancesDistribution").get("OnDemandAllocationStrategy") %}
<OnDemandAllocationStrategy>{{ group.mixed_instance_policy.get("InstancesDistribution").get("OnDemandAllocationStrategy") }}</OnDemandAllocationStrategy>
{% endif %}
{% if group.mixed_instance_policy.get("InstancesDistribution").get("OnDemandBaseCapacity") %}
<OnDemandBaseCapacity>{{ group.mixed_instance_policy.get("InstancesDistribution").get("OnDemandBaseCapacity") }}</OnDemandBaseCapacity>
{% endif %}
{% if group.mixed_instance_policy.get("InstancesDistribution").get("OnDemandPercentageAboveBaseCapacity") %}
<OnDemandPercentageAboveBaseCapacity>{{ group.mixed_instance_policy.get("InstancesDistribution").get("OnDemandPercentageAboveBaseCapacity") }}</OnDemandPercentageAboveBaseCapacity>
{% endif %}
{% if group.mixed_instance_policy.get("InstancesDistribution").get("SpotAllocationStrategy") %}
<SpotAllocationStrategy>{{ group.mixed_instance_policy.get("InstancesDistribution").get("SpotAllocationStrategy") }}</SpotAllocationStrategy>
{% endif %}
{% if group.mixed_instance_policy.get("InstancesDistribution").get("SpotInstancePools") %}
<SpotInstancePools>{{ group.mixed_instance_policy.get("InstancesDistribution").get("SpotInstancePools") }}</SpotInstancePools>
{% endif %}
{% if group.mixed_instance_policy.get("InstancesDistribution").get("SpotMaxPrice") %}
<SpotMaxPrice>{{ group.mixed_instance_policy.get("InstancesDistribution").get("SpotMaxPrice") }}</SpotMaxPrice>
{% endif %}
</InstancesDistribution>
{% endif %}
</MixedInstancesPolicy>
{% elif group.launch_template %}
<LaunchTemplate>
Expand Down Expand Up @@ -864,6 +915,18 @@ def enable_metrics_collection(self) -> str:
</EnabledMetrics>
{% endif %}
<ServiceLinkedRoleARN>{{ group.service_linked_role }}</ServiceLinkedRoleARN>
{% if group.warm_pool %}
<WarmPoolConfiguration>
<MaxGroupPreparedCapacity>{{ group.warm_pool.max_capacity }}</MaxGroupPreparedCapacity>
<MinSize>{{ group.warm_pool.min_size or 0 }}</MinSize>
{% if group.warm_pool.pool_state %}
<PoolState>{{ group.warm_pool.pool_state }}</PoolState>
{% endif %}
<InstanceReusePolicy>
<ReuseOnScaleIn>{{ 'true' if group.warm_pool.instance_reuse_policy["ReuseOnScaleIn"] else 'false' }}</ReuseOnScaleIn>
</InstanceReusePolicy>
</WarmPoolConfiguration>
{% endif %}
</member>
{% endfor %}
</AutoScalingGroups>
Expand Down Expand Up @@ -1386,3 +1449,46 @@ def enable_metrics_collection(self) -> str:
<RequestId></RequestId>
</ResponseMetadata>
</EnableMetricsCollectionResponse>"""


PUT_WARM_POOL_TEMPLATE = """<PutWarmPoolResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
<ResponseMetadata>
<RequestId></RequestId>
</ResponseMetadata>
<PutWarmPoolResult></PutWarmPoolResult>
</PutWarmPoolResponse>"""


DESCRIBE_WARM_POOL_TEMPLATE = """<DescribeWarmPoolResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
<ResponseMetadata>
<RequestId></RequestId>
</ResponseMetadata>
<DescribeWarmPoolResult>
{% if pool %}
<WarmPoolConfiguration>
{% if pool.max_capacity %}
<MaxGroupPreparedCapacity>{{ pool.max_capacity }}</MaxGroupPreparedCapacity>
{% endif %}
<MinSize>{{ pool.min_size }}</MinSize>
{% if pool.pool_state %}
<PoolState>{{ pool.pool_state }}</PoolState>
{% endif %}
{% if pool.instance_reuse_policy %}
<InstanceReusePolicy>
<ReuseOnScaleIn>{{ 'true' if pool.instance_reuse_policy["ReuseOnScaleIn"] else 'false' }}</ReuseOnScaleIn>
</InstanceReusePolicy>
{% endif %}
</WarmPoolConfiguration>
{% endif %}
<Instances>
</Instances>
</DescribeWarmPoolResult>
</DescribeWarmPoolResponse>"""


DELETE_WARM_POOL_TEMPLATE = """<DeleteWarmPoolResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
<ResponseMetadata>
<RequestId></RequestId>
</ResponseMetadata>
<DeleteWarmPoolResult></DeleteWarmPoolResult>
</DeleteWarmPoolResponse>"""
1 change: 1 addition & 0 deletions moto/awslambda/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ def to_dict(self) -> Dict[str, Any]:
"Cors": self.config.get("Cors"),
"CreationTime": self.created,
"LastModifiedTime": self.last_modified,
"InvokeMode": self.config.get("InvokeMode") or "Buffered",
}

def update(self, new_config: Dict[str, Any]) -> None:
Expand Down
31 changes: 27 additions & 4 deletions moto/batch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,33 @@ def __init__(
self.propagate_tags = propagate_tags

if self.container_properties is not None:
if "resourceRequirements" not in self.container_properties:
self.container_properties["resourceRequirements"] = []
if "secrets" not in self.container_properties:
self.container_properties["secrets"] = []
# Set some default values
default_values: Dict[str, List[Any]] = {
"command": [],
"resourceRequirements": [],
"secrets": [],
"environment": [],
"mountPoints": [],
"ulimits": [],
"volumes": [],
}
for key, val in default_values.items():
if key not in self.container_properties:
self.container_properties[key] = val

# Set default FARGATE configuration
if "FARGATE" in (self.platform_capabilities or []):
if "fargatePlatformConfiguration" not in self.container_properties:
self.container_properties["fargatePlatformConfiguration"] = {
"platformVersion": "LATEST"
}

# Remove any empty environment variables
self.container_properties["environment"] = [
env_var
for env_var in self.container_properties["environment"]
if env_var.get("value") != ""
]

self._validate()
self.revision += 1
Expand Down
1 change: 1 addition & 0 deletions moto/cloudformation/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ def set_stack_policy(self) -> str:
{% if stackset.description %}
<Description>{{ stackset.description }}</Description>
{% endif %}
<ManagedExecution><Active>false</Active></ManagedExecution>
</StackSet>
</DescribeStackSetResult>
<ResponseMetadata>
Expand Down
2 changes: 2 additions & 0 deletions moto/cloudfront/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def __init__(self, config: Dict[str, Any]):
self.read_timeout = config.get("OriginReadTimeout") or 30
protocols = config.get("OriginSslProtocols", {}).get("Items") or {}
self.ssl_protocols = protocols.get("SslProtocol") or []
if isinstance(self.ssl_protocols, str):
self.ssl_protocols = [self.ssl_protocols]


class Origin:
Expand Down
Loading