-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[PR #1716/86c60b49 backport][stable-5] ecs: integration test and new purge parameters This is a backport of PR #1716 as merged into main (86c60b4). SUMMARY Make the ecs_cluster integration test work again ecs_service - new parameter purge_placement_constraints and purge_placement_strategy. Otherwise it is impossible to remove those placements without breaking backwards compatibility. purge_placement_constraints in the integration test purge_placement_strategy in the integration test required by mattclay/aws-terminator#210 (comment) ISSUE TYPE Bugfix Pull Request Docs Pull Request Feature Pull Request COMPONENT NAME ecs_service ADDITIONAL INFORMATION works for me again ansible-test integration --python 3.10 ecs_cluster --docker --allow-unsupported ... PLAY RECAP ********************************************************************* testhost : ok=143 changed=69 unreachable=0 failed=0 skipped=1 rescued=0 ignored=6 Reviewed-by: Mark Chappell
- Loading branch information
1 parent
56d548a
commit 6744af6
Showing
10 changed files
with
1,516 additions
and
1,357 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
changelogs/fragments/ecs_service_and_ecs_integration_test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
minor_changes: | ||
- ecs_service - new parameter ``purge_placement_strategy`` to have the ability to remove the placement strategy of an ECS Service (https://github.com/ansible-collections/community.aws/pull/1716). | ||
- ecs_service - new parameter ``purge_placement_constraints`` to have the ability to remove the placement constraints of an ECS Service (https://github.com/ansible-collections/community.aws/pull/1716). | ||
trivial: | ||
- ecs_cluster - rework and repair ecs_cluster integration test. | ||
deprecated_features: | ||
- ecs_service - In a release after 2024-06-01, tha default value of ``purge_placement_strategy`` will be change from ``false`` to ``true`` (https://github.com/ansible-collections/community.aws/pull/1716). | ||
- ecs_service - In a release after 2024-06-01, tha default value of ``purge_placement_constraints`` will be change from ``false`` to ``true`` (https://github.com/ansible-collections/community.aws/pull/1716). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
# reason: slow | ||
# Tests take around 15 minutes to run | ||
unsupported | ||
time=20m | ||
|
||
cloud/aws | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
dependencies: [] | ||
dependencies: | ||
- role: setup_botocore_pip | ||
vars: | ||
botocore_version: "1.24.14" |
147 changes: 147 additions & 0 deletions
147
tests/integration/targets/ecs_cluster/tasks/01_create_requirements.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
- name: ensure IAM service role exists | ||
iam_role: | ||
name: "{{ ecs_service_role_name }}" | ||
assume_role_policy_document: "{{ lookup('file','ecs-trust-policy.json') }}" | ||
state: present | ||
create_instance_profile: yes | ||
managed_policy: | ||
- AmazonEC2ContainerServiceRole | ||
wait: True | ||
|
||
- name: ensure AWSServiceRoleForECS role exists | ||
iam_role_info: | ||
name: AWSServiceRoleForECS | ||
register: iam_role_result | ||
|
||
# # This should happen automatically with the right permissions... | ||
#- name: fail if AWSServiceRoleForECS role does not exist | ||
# fail: | ||
# msg: > | ||
# Run `aws iam create-service-linked-role --aws-service-name=ecs.amazonaws.com ` to create | ||
# a linked role for AWS VPC load balancer management | ||
# when: not iam_role_result.iam_roles | ||
|
||
- name: create a VPC to work in | ||
ec2_vpc_net: | ||
cidr_block: 10.0.0.0/16 | ||
state: present | ||
name: '{{ resource_prefix }}_ecs_cluster' | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_ecs_cluster' | ||
register: setup_vpc | ||
|
||
- name: create a key pair to use for creating an ec2 instance | ||
ec2_key: | ||
name: '{{ resource_prefix }}_ecs_cluster' | ||
state: present | ||
when: ec2_keypair is not defined # allow override in cloud-config-aws.ini | ||
register: setup_key | ||
|
||
- name: create subnets | ||
ec2_vpc_subnet: | ||
az: '{{ aws_region }}{{ item.zone }}' | ||
tags: | ||
Name: '{{ resource_prefix }}_ecs_cluster-subnet-{{ item.zone }}' | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
cidr: "{{ item.cidr }}" | ||
state: present | ||
register: setup_subnet | ||
with_items: | ||
- zone: a | ||
cidr: 10.0.1.0/24 | ||
- zone: b | ||
cidr: 10.0.2.0/24 | ||
|
||
- name: create an internet gateway so that ECS agents can talk to ECS | ||
ec2_vpc_igw: | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
state: present | ||
register: igw | ||
|
||
- name: create a security group to use for creating an ec2 instance | ||
ec2_group: | ||
name: '{{ resource_prefix }}_ecs_cluster-sg' | ||
description: 'created by Ansible integration tests' | ||
state: present | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
rules: # allow all ssh traffic but nothing else | ||
- ports: 22 | ||
cidr_ip: 0.0.0.0/0 | ||
register: setup_sg | ||
|
||
- set_fact: | ||
# As a lookup plugin we don't have access to module_defaults | ||
connection_args: | ||
region: "{{ aws_region }}" | ||
aws_access_key: "{{ aws_access_key }}" | ||
aws_secret_key: "{{ aws_secret_key }}" | ||
aws_security_token: "{{ security_token | default(omit) }}" | ||
no_log: True | ||
|
||
- name: set image id fact | ||
set_fact: | ||
ecs_image_id: "{{ lookup('aws_ssm', '/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id', **connection_args) }}" | ||
|
||
- name: provision ec2 instance to create an image | ||
ec2_instance: | ||
key_name: '{{ ec2_keypair|default(setup_key.key.name) }}' | ||
instance_type: t3.micro | ||
state: present | ||
image_id: '{{ ecs_image_id }}' | ||
wait: yes | ||
user_data: "{{ user_data }}" | ||
instance_role: "{{ ecs_service_role_name }}" | ||
tags: | ||
Name: '{{ resource_prefix }}_ecs_agent' | ||
security_group: '{{ setup_sg.group_id }}' | ||
vpc_subnet_id: '{{ setup_subnet.results[0].subnet.id }}' | ||
register: setup_instance | ||
|
||
- name: create target group | ||
elb_target_group: | ||
name: "{{ ecs_target_group_name }}1" | ||
state: present | ||
protocol: HTTP | ||
port: 8080 | ||
modify_targets: no | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
target_type: instance | ||
health_check_interval: 5 | ||
health_check_timeout: 2 | ||
healthy_threshold_count: 2 | ||
unhealthy_threshold_count: 2 | ||
register: elb_target_group_instance | ||
|
||
- name: create second target group to use ip target_type | ||
elb_target_group: | ||
name: "{{ ecs_target_group_name }}2" | ||
state: present | ||
protocol: HTTP | ||
port: 8080 | ||
modify_targets: no | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
target_type: ip | ||
health_check_interval: 5 | ||
health_check_timeout: 2 | ||
healthy_threshold_count: 2 | ||
unhealthy_threshold_count: 2 | ||
register: elb_target_group_ip | ||
|
||
- name: create load balancer | ||
elb_application_lb: | ||
name: "{{ ecs_load_balancer_name }}" | ||
state: present | ||
scheme: internal | ||
security_groups: '{{ setup_sg.group_id }}' | ||
subnets: "{{ setup_subnet.results | map(attribute='subnet.id') | list }}" | ||
listeners: | ||
- Protocol: HTTP | ||
Port: 80 | ||
DefaultActions: | ||
- Type: forward | ||
TargetGroupName: "{{ ecs_target_group_name }}1" | ||
- Protocol: HTTP | ||
Port: 81 | ||
DefaultActions: | ||
- Type: forward | ||
TargetGroupName: "{{ ecs_target_group_name }}2" |
76 changes: 76 additions & 0 deletions
76
tests/integration/targets/ecs_cluster/tasks/10_ecs_cluster.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# cluster "{{ ecs_cluster_name }}" is used for ecs_service tests | ||
- name: create an ECS cluster | ||
ecs_cluster: | ||
name: "{{ ecs_cluster_name }}" | ||
state: present | ||
register: ecs_cluster | ||
|
||
- name: check that ecs_cluster changed | ||
assert: | ||
that: | ||
- ecs_cluster.changed | ||
|
||
- name: immutable create same ECS cluster | ||
ecs_cluster: | ||
name: "{{ ecs_cluster_name }}" | ||
state: present | ||
register: ecs_cluster_again | ||
|
||
- name: check that ecs_cluster did not change | ||
assert: | ||
that: | ||
- not ecs_cluster_again.changed | ||
|
||
- name: create an ECS cluster to test capacity provider strategy | ||
ecs_cluster: | ||
name: "{{ ecs_cluster_name }}-cps" | ||
state: present | ||
register: ecs_cluster | ||
|
||
- name: add capacity providers and strategy | ||
ecs_cluster: | ||
name: "{{ ecs_cluster_name }}-cps" | ||
state: present | ||
purge_capacity_providers: True | ||
capacity_providers: | ||
- FARGATE | ||
- FARGATE_SPOT | ||
capacity_provider_strategy: | ||
- capacity_provider: FARGATE | ||
base: 1 | ||
weight: 1 | ||
- capacity_provider: FARGATE_SPOT | ||
weight: 100 | ||
register: ecs_cluster_update | ||
|
||
- name: check that ecs_cluster was correctly updated | ||
assert: | ||
that: | ||
- ecs_cluster_update.changed | ||
- ecs_cluster_update.cluster is defined | ||
- ecs_cluster_update.cluster.capacityProviders is defined | ||
- "'FARGATE' in ecs_cluster_update.cluster.capacityProviders" | ||
|
||
- name: immutable add capacity providers and strategy | ||
ecs_cluster: | ||
name: "{{ ecs_cluster_name }}-cps" | ||
state: present | ||
purge_capacity_providers: True | ||
capacity_providers: | ||
- FARGATE | ||
- FARGATE_SPOT | ||
capacity_provider_strategy: | ||
- capacity_provider: FARGATE | ||
base: 1 | ||
weight: 1 | ||
- capacity_provider: FARGATE_SPOT | ||
weight: 100 | ||
register: ecs_cluster_update | ||
|
||
- name: check that ecs_cluster was correctly updated | ||
assert: | ||
that: | ||
- not ecs_cluster_update.changed | ||
- ecs_cluster_update.cluster is defined | ||
- ecs_cluster_update.cluster.capacityProviders is defined | ||
- "'FARGATE' in ecs_cluster_update.cluster.capacityProviders" |
Oops, something went wrong.