Skip to content

Commit b6eab1f

Browse files
authored
Merge pull request #458 from henrywang/aws_cli
test: use aws-cli to deploy aws instance instead of ansible module
2 parents 4e5f9d9 + cd722a2 commit b6eab1f

File tree

4 files changed

+58
-68
lines changed

4 files changed

+58
-68
lines changed

plans/install-upgrade.fmf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ prepare:
1111
- jq
1212
- python3-devel
1313
- unzip
14+
- how: shell
15+
script: ansible-galaxy collection install community.general ansible.posix
1416
execute:
1517
how: tmt
1618

@@ -27,9 +29,5 @@ execute:
2729
- when: arch != x86_64 and arch != aarch64
2830
enabled: false
2931
prepare+:
30-
- how: shell
31-
script: |
32-
pip install boto3 botocore
33-
ansible-galaxy collection install amazon.aws community.general ansible.posix
3432
- how: shell
3533
script: curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip" && unzip awscliv2.zip && sudo ./aws/install

tests/integration/playbooks/deploy-aws.yaml

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
ssh_key_pub: ""
99
inventory_file: ""
1010
download_node: "{{ lookup('env', 'DOWNLOAD_NODE') | default('', true) }}"
11-
ami_id: ""
1211
ami:
1312
x86_64:
1413
rhel-9-4: ami-044442bf4326c9933
@@ -41,61 +40,72 @@
4140
random_instance_type: "{{ lookup('env', 'instance_type') | default(instance_type[arch][instance_type_index], true) }}"
4241

4342
- name: "get available zone for instance {{ random_instance_type }}"
44-
shell: aws ec2 describe-instance-type-offerings --location-type availability-zone --filters="Name=instance-type,Values={{ random_instance_type }}" --query InstanceTypeOfferings | jq -r '.[0].Location'
43+
shell: |
44+
aws ec2 describe-instance-type-offerings \
45+
--location-type availability-zone \
46+
--filters="Name=instance-type,Values={{ random_instance_type }}" \
47+
--query InstanceTypeOfferings | jq -r '.[0].Location'
4548
register: ec2_zone
4649
when: "'rhel' not in test_os"
4750

4851
- name: get subnet
49-
amazon.aws.ec2_vpc_subnet_info:
50-
filters:
51-
"tag:Name": "kite-ci"
52-
"availabilityZone": "{{ ec2_zone.stdout }}"
52+
shell: |
53+
aws ec2 describe-subnets \
54+
--output json \
55+
--filters "Name=tag:Name,Values=kite-ci" "Name=availabilityZone,Values={{ ec2_zone.stdout }}" | \
56+
jq -r ".Subnets[0].SubnetId"
5357
register: ec2_vpc_subnet
5458
when: "'rhel' not in test_os"
5559

5660
- set_fact:
57-
subnet_id: "{{ ec2_vpc_subnet.subnets[0].subnet_id }}"
61+
subnet_id: "{{ ec2_vpc_subnet.stdout }}"
5862
when: "'rhel' not in test_os"
5963

6064
- name: get virtqe subnet
61-
amazon.aws.ec2_vpc_subnet_info:
62-
filters:
63-
"tag:Name": "InternalA-virtqe"
65+
shell: |
66+
aws ec2 describe-subnets \
67+
--output json \
68+
--filters "Name=tag:Name,Values=InternalA-virtqe" | \
69+
jq -r ".Subnets[0].SubnetId"
6470
register: ec2_vpc_subnet
6571
when: '"rhel" in test_os'
6672

6773
- set_fact:
68-
subnet_id: "{{ ec2_vpc_subnet.subnets[0].subnet_id }}"
74+
subnet_id: "{{ ec2_vpc_subnet.stdout }}"
6975
when: "'rhel' in test_os"
7076

7177
- name: get security group
72-
amazon.aws.ec2_security_group_info:
73-
filters:
74-
"tag:Name": "kite-ci"
78+
shell: |
79+
aws ec2 describe-security-groups \
80+
--filters="Name=tag:Name,Values=kite-ci" \
81+
--output json | \
82+
jq -r ".SecurityGroups[0].GroupId"
7583
register: ec2_security_group
7684
when: "'rhel' not in test_os"
7785

7886
- set_fact:
79-
group_id: "{{ ec2_security_group.security_groups[0].group_id }}"
87+
group_id: "{{ ec2_security_group.stdout }}"
8088
when: "'rhel' not in test_os"
8189

8290
- name: get virtqe security group
83-
amazon.aws.ec2_security_group_info:
84-
filters:
85-
"tag:Name": "bootc-test"
91+
shell: |
92+
aws ec2 describe-security-groups \
93+
--filters="Name=tag:Name,Values=bootc-test" \
94+
--output json | \
95+
jq -r ".SecurityGroups[0].GroupId"
8696
register: ec2_security_group
8797
when: "'rhel' in test_os"
8898

8999
- set_fact:
90-
group_id: "{{ ec2_security_group.security_groups[0].group_id }}"
100+
group_id: "{{ ec2_security_group.stdout }}"
91101
when: "'rhel' in test_os"
92102

93103
- name: config ssh keypair used by test
94-
amazon.aws.ec2_key:
95-
name: "kp-bootc-{{ random_num }}"
96-
key_material: "{{ lookup('file', ssh_key_pub) }}"
97-
tags:
98-
name: "bootc-test"
104+
shell: |
105+
aws ec2 import-key-pair \
106+
--key-name "kp-bootc-{{ random_num }}" \
107+
--public-key-material "fileb://{{ ssh_key_pub }}" \
108+
--tag-specification 'ResourceType=key-pair,Tags=[{Key=Name,Value=bootc-test}]'
99109
100110
- name: generate ec2_run_instance script
101111
template:
@@ -112,14 +122,16 @@
112122
instance_json: "{{ result_instance.stdout | from_json }}"
113123

114124
- name: wait for instance running
115-
shell: aws ec2 describe-instances --instance-ids {{ instance_json.Instances[0].InstanceId }} --query 'Reservations[0].Instances[0].State.Name' --output text
116-
register: describe_result
117-
retries: 60
118-
delay: 5
119-
until: describe_result.stdout == "running"
125+
shell: |
126+
aws ec2 wait instance-running \
127+
--instance-ids {{ instance_json.Instances[0].InstanceId }}
120128
121129
- name: get instance public ip
122-
shell: aws ec2 describe-instances --instance-ids {{ instance_json.Instances[0].InstanceId }} --query 'Reservations[*].Instances[*].PublicIpAddress' --output text
130+
shell: |
131+
aws ec2 describe-instances \
132+
--instance-ids {{ instance_json.Instances[0].InstanceId }} \
133+
--query 'Reservations[*].Instances[*].PublicIpAddress' \
134+
--output text
123135
register: ip_result
124136
when: "'rhel' not in test_os"
125137

@@ -128,7 +140,11 @@
128140
when: "'rhel' not in test_os"
129141

130142
- name: get instance private ip
131-
shell: aws ec2 describe-instances --instance-ids {{ instance_json.Instances[0].InstanceId }} --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text
143+
shell: |
144+
aws ec2 describe-instances \
145+
--instance-ids {{ instance_json.Instances[0].InstanceId }} \
146+
--query 'Reservations[*].Instances[*].PrivateIpAddress' \
147+
--output text
132148
register: ip_result
133149
when: "'rhel' in test_os"
134150

@@ -174,11 +190,3 @@
174190
option: instance_id
175191
value: "{{ instance_json.Instances[0].InstanceId }}"
176192
no_extra_spaces: true
177-
178-
- name: write AWS ami id to inventory file
179-
community.general.ini_file:
180-
path: "{{ inventory_file }}"
181-
section: cloud:vars
182-
option: ami_id
183-
value: "{{ ami_id }}"
184-
no_extra_spaces: true

tests/integration/playbooks/remove.yaml

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,18 @@
77
- name: Remove AWS resources
88
block:
99
- name: terminate instance
10-
amazon.aws.ec2_instance:
11-
instance_ids: "{{ instance_id }}"
12-
state: absent
13-
wait: true
10+
shell: |
11+
aws ec2 terminate-instances \
12+
--instance-ids "{{ instance_id }}"
1413
ignore_errors: true
1514

1615
- name: wait until instance terminated
17-
amazon.aws.ec2_instance_info:
18-
instance_ids:
19-
- "{{ instance_id }}"
20-
register: result_instance_status
21-
retries: 30
22-
delay: 10
23-
until: result_instance_status.instances[0].state.name == "terminated"
16+
shell: |
17+
aws ec2 wait instance-terminated \
18+
--instance-ids "{{ instance_id }}"
2419
2520
- name: remove ec2 key
26-
amazon.aws.ec2_key:
27-
name: "kp-bootc-{{ random_num }}"
28-
state: absent
29-
30-
- name: Deregister AMI (delete associated snapshots too)
31-
amazon.aws.ec2_ami:
32-
image_id: "{{ ami_id }}"
33-
delete_snapshot: true
34-
state: absent
35-
when: ami_id != ""
21+
shell: |
22+
aws ec2 delete-key-pair \
23+
--key-name "kp-bootc-{{ random_num }}"
3624
when: platform == "aws"

tests/integration/playbooks/templates/ec2_run_instance.j2

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
{% if test_os.startswith('rhel') %}
1010
--user-data file://user-data \
1111
{% endif %}
12-
{% if ami_id == "" %}
1312
--image-id {{ ami[arch][test_os] }} \
14-
{% else %}
15-
--image-id {{ ami_id }} \
16-
{% endif %}
1713
--instance-market-options MarketType=spot,SpotOptions=\{MaxPrice=0.1,SpotInstanceType=one-time,InstanceInterruptionBehavior=terminate\} \
1814
--instance-type {{ random_instance_type }} \
1915
--key-name kp-bootc-{{ random_num }} \

0 commit comments

Comments
 (0)