Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
test: use aws cli to deploy aws instance instead of ansible module
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaofeng Wang <[email protected]>
  • Loading branch information
henrywang committed Mar 31, 2024
1 parent 110a47d commit 4de962f
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 61 deletions.
2 changes: 0 additions & 2 deletions bib-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ case "$IMAGE_TYPE" in
"$TEST_IMAGE_URL"

greenprint "Deploy $IMAGE_TYPE instance"
sudo curl -L -o - "https://github.com/vmware/govmomi/releases/latest/download/govc_$(uname -s)_$(uname -m).tar.gz" | sudo tar -C /usr/local/bin -xvzf - govc

DATACENTER_70="Datacenter7.0"
DATASTORE_70="datastore-80"
DATACENTER_70_POOL="/Datacenter7.0/host/Automation/Resources"
Expand Down
20 changes: 17 additions & 3 deletions os-replace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ EOF
;;
esac

greenprint "Configure container build arch"
case "$ARCH" in
"x86_64")
BUILD_PLATFORM="linux/amd64"
;;
"aarch64")
BUILD_PLATFORM="linux/arm64"
;;
*)
redprint "Variable ARCH has to be defined"
exit 1
;;
esac

if [[ ${AIR_GAPPED-} -eq 1 ]];then
if [[ ${PLATFORM} == "libvirt" ]]; then
AIR_GAPPED_DIR="$TEMPDIR"/virtiofs
Expand Down Expand Up @@ -128,9 +142,9 @@ cat "$INSTALL_CONTAINERFILE"

greenprint "Build $TEST_OS installation container image"
if [[ "$LAYERED_IMAGE" == "useradd-ssh" ]]; then
podman build --tls-verify=false --retry=5 --retry-delay=10 --build-arg "sshpubkey=$(cat "${SSH_KEY_PUB}")" -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$LAYERED_DIR"
podman build --platform "$BUILD_PLATFORM" --tls-verify=false --retry=5 --retry-delay=10 --build-arg "sshpubkey=$(cat "${SSH_KEY_PUB}")" -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$LAYERED_DIR"
else
podman build --tls-verify=false --retry=5 --retry-delay=10 -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$LAYERED_DIR"
podman build --platform "$BUILD_PLATFORM" --tls-verify=false --retry=5 --retry-delay=10 -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$LAYERED_DIR"
fi

greenprint "Push $TEST_OS installation container image"
Expand Down Expand Up @@ -194,7 +208,7 @@ RUN dnf -y install wget && \
EOF

greenprint "Build $TEST_OS upgrade container image"
podman build --tls-verify=false --retry=5 --retry-delay=10 -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" -f "$UPGRADE_CONTAINERFILE" .
podman build --platform "$BUILD_PLATFORM" --tls-verify=false --retry=5 --retry-delay=10 -t "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" -f "$UPGRADE_CONTAINERFILE" .
greenprint "Push $TEST_OS upgrade container image"
retry podman push --tls-verify=false --quiet "${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}" "$TEST_IMAGE_URL"

Expand Down
77 changes: 47 additions & 30 deletions playbooks/deploy-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,61 +53,72 @@
- layered_image | default('') == "nvidia" and arch == "aarch64"

- name: "get available zone for instance {{ random_instance_type }}"
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'
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'
register: ec2_zone
when: "'rhel' not in test_os"

- name: get subnet
amazon.aws.ec2_vpc_subnet_info:
filters:
"tag:Name": "kite-ci"
"availabilityZone": "{{ ec2_zone.stdout }}"
shell: |
aws ec2 describe-subnets \
--output json \
--filters "Name=tag:Name,Values=kite-ci" "Name=availabilityZone,Values={{ ec2_zone.stdout }}" | \
jq -r ".Subnets[0].SubnetId"
register: ec2_vpc_subnet
when: "'rhel' not in test_os"

- set_fact:
subnet_id: "{{ ec2_vpc_subnet.subnets[0].subnet_id }}"
subnet_id: "{{ ec2_vpc_subnet.stdout }}"
when: "'rhel' not in test_os"

- name: get virtqe subnet
amazon.aws.ec2_vpc_subnet_info:
filters:
"tag:Name": "InternalA-virtqe"
shell: |
aws ec2 describe-subnets \
--output json \
--filters "Name=tag:Name,Values=InternalA-virtqe" | \
jq -r ".Subnets[0].SubnetId"
register: ec2_vpc_subnet
when: '"rhel" in test_os'

- set_fact:
subnet_id: "{{ ec2_vpc_subnet.subnets[0].subnet_id }}"
subnet_id: "{{ ec2_vpc_subnet.stdout }}"
when: "'rhel' in test_os"

- name: get security group
amazon.aws.ec2_security_group_info:
filters:
"tag:Name": "kite-ci"
shell: |
aws ec2 describe-security-groups \
--filters="Name=tag:Name,Values=kite-ci" \
--output json | \
jq -r ".SecurityGroups[0].GroupId"
register: ec2_security_group
when: "'rhel' not in test_os"

- set_fact:
group_id: "{{ ec2_security_group.security_groups[0].group_id }}"
group_id: "{{ ec2_security_group.stdout }}"
when: "'rhel' not in test_os"

- name: get virtqe security group
amazon.aws.ec2_security_group_info:
filters:
"tag:Name": "bootc-test"
shell: |
aws ec2 describe-security-groups \
--filters="Name=tag:Name,Values=bootc-test" \
--output json | \
jq -r ".SecurityGroups[0].GroupId"
register: ec2_security_group
when: "'rhel' in test_os"

- set_fact:
group_id: "{{ ec2_security_group.security_groups[0].group_id }}"
group_id: "{{ ec2_security_group.stdout }}"
when: "'rhel' in test_os"

- name: config ssh keypair used by test
amazon.aws.ec2_key:
name: "kp-bootc-{{ random_num }}"
key_material: "{{ lookup('file', ssh_key_pub) }}"
tags:
name: "bootc-test"
shell: |
aws ec2 import-key-pair \
--key-name "kp-bootc-{{ random_num }}" \
--public-key-material "fileb://{{ ssh_key_pub }}" \
--tag-specification 'ResourceType=key-pair,Tags=[{Key=Name,Value=bootc-test}]'
- name: generate ec2_run_instance script
template:
Expand All @@ -124,14 +135,16 @@
instance_json: "{{ result_instance.stdout | from_json }}"

- name: wait for instance running
shell: aws ec2 describe-instances --instance-ids {{ instance_json.Instances[0].InstanceId }} --query 'Reservations[0].Instances[0].State.Name' --output text
register: describe_result
retries: 60
delay: 5
until: describe_result.stdout == "running"
shell: |
aws ec2 wait instance-running \
--instance-ids {{ instance_json.Instances[0].InstanceId }}
- name: get instance public ip
shell: aws ec2 describe-instances --instance-ids {{ instance_json.Instances[0].InstanceId }} --query 'Reservations[*].Instances[*].PublicIpAddress' --output text
shell: |
aws ec2 describe-instances \
--instance-ids {{ instance_json.Instances[0].InstanceId }} \
--query 'Reservations[*].Instances[*].PublicIpAddress' \
--output text
register: ip_result
when: "'rhel' not in test_os"

Expand All @@ -140,7 +153,11 @@
when: "'rhel' not in test_os"

- name: get instance private ip
shell: aws ec2 describe-instances --instance-ids {{ instance_json.Instances[0].InstanceId }} --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text
shell: |
aws ec2 describe-instances \
--instance-ids {{ instance_json.Instances[0].InstanceId }} \
--query 'Reservations[*].Instances[*].PrivateIpAddress' \
--output text
register: ip_result
when: "'rhel' in test_os"

Expand Down
43 changes: 25 additions & 18 deletions playbooks/remove.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,38 @@
- name: Remove AWS resources
block:
- name: terminate instance
amazon.aws.ec2_instance:
instance_ids: "{{ instance_id }}"
state: absent
wait: true
shell: |
aws ec2 terminate-instances \
--instance-ids "{{ instance_id }}"
ignore_errors: true

- name: wait until instance terminated
amazon.aws.ec2_instance_info:
instance_ids:
- "{{ instance_id }}"
register: result_instance_status
retries: 30
delay: 10
until: result_instance_status.instances[0].state.name == "terminated"
shell: |
aws ec2 wait instance-terminated \
--instance-ids "{{ instance_id }}"
- name: remove ec2 key
amazon.aws.ec2_key:
name: "kp-bootc-{{ random_num }}"
state: absent
shell: |
aws ec2 delete-key-pair \
--key-name "kp-bootc-{{ random_num }}"
- name: Deregister AMI (delete associated snapshots too)
amazon.aws.ec2_ami:
image_id: "{{ ami_id }}"
delete_snapshot: true
state: absent
block:
- name: Get snapshot ID
shell: |
aws ec2 describe-images \
--image-ids "{{ ami_id }}" \
--query 'Images[0].[BlockDeviceMappings][0][0].Ebs.SnapshotId' \
--output text
register: snapshot_result
- name: Deregister AMI
shell: |
aws ec2 deregister-image \
--image-id "{{ ami_id }}"
- name: Delete snapshot
shell: |
aws ec2 delete-snapshot \
--snapshot-id "{{ snapshot_result.stdout }}"
when: ami_id != ""
when: platform == "aws"

Expand Down
12 changes: 8 additions & 4 deletions tmt/plans/bib-image.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ prepare:
- unzip
- how: shell
script: |
pip install boto3 botocore openstacksdk
ansible-galaxy collection install openstack.cloud community.general community.libvirt amazon.aws ansible.posix
- how: shell
script: curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip" && unzip awscliv2.zip && sudo ./aws/install
pip install openstacksdk
ansible-galaxy collection install openstack.cloud community.general community.libvirt ansible.posix
execute:
how: tmt

Expand All @@ -30,6 +28,9 @@ execute:
adjust+:
- when: arch != x86_64 and arch != aarch64
enabled: false
prepare+:
- how: shell
script: curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install

/qcow2:
summary: Use bib generate qcow2 image and test locally (nested)
Expand Down Expand Up @@ -65,6 +66,9 @@ execute:
adjust+:
- when: arch != x86_64
enabled: false
prepare+:
- how: shell
script: curl -L -o - "https://github.com/vmware/govmomi/releases/latest/download/govc_$(uname -s)_$(uname -m).tar.gz" | sudo tar -C /usr/local/bin -xvzf - govc

/iso:
summary: Use bib generate ISO image and test locally (nested)
Expand Down
9 changes: 5 additions & 4 deletions tmt/plans/os-replace.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ prepare:
- unzip
- how: shell
script: |
pip install boto3 botocore openstacksdk
ansible-galaxy collection install openstack.cloud community.general community.libvirt amazon.aws ansible.posix
- how: shell
script: curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
pip install openstacksdk
ansible-galaxy collection install openstack.cloud community.general community.libvirt ansible.posix
- how: shell
script: curl -kLO ${CERT_URL}/certs/Current-IT-Root-CAs.pem --output-dir /etc/pki/ca-trust/source/anchors && update-ca-trust
execute:
Expand Down Expand Up @@ -57,6 +55,9 @@ execute:
adjust+:
- when: arch != x86_64 and arch != aarch64
enabled: false
prepare+:
- how: shell
script: curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install

/azure:
summary: Run os-replace test on azure
Expand Down

0 comments on commit 4de962f

Please sign in to comment.