Skip to content

Commit

Permalink
tests: helper for creating new EC2 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Sep 3, 2024
1 parent c656e4f commit a4979b7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mock/integration-tests/setup-box
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ with content similar to:
mock_rhn_pass=<your Red Hat account password>
... and then re-run this script.
If you have no IP_ADDRESS for testing, you may, e.g., create a new machine in
EC2 with group_vars/all.yaml file like:
infra_subnet: subnet-0995f6a466849f4c3
aws:
ssh_key: "praiskup"
image: ami-004f552bba0e5f64f
instance_type: t2.large
root_volume_size: 60
security_group: mock-testing
by running
$ ansible-playbook spawn-test-machine-ec2.yaml
PLAY [Start new machine] *****************
TASK [create the testing mock vm in ec2] *
changed: [localhost]
TASK [print ipv4] ************************
...
"Public IP: 18.234.135.130"
...
EOF
exit 1
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
40 changes: 40 additions & 0 deletions mock/integration-tests/setup-playbook/spawn-test-machine-ec2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
- name: "Start new machine"
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: "create the testing mock vm in ec2"
amazon.aws.ec2_instance:
name: "testing-mock"
state: running
profile: fedora-copr
region: us-east-1
key_name: "{{ aws.ssh_key }}"
count: 1
image_id: "{{ aws.image }}"
instance_type: "{{ aws.instance_type }}"
detailed_monitoring: true
network:
assign_public_ip: true
vpc_subnet_id: "{{ infra_subnet }}"
security_group: "{{ aws.security_group }}"
termination_protection: false
wait: true
tags:
FedoraGroup: copr
CoprPurpose: testing-mock
volumes:
- ebs:
volume_size: "{{ aws.root_volume_size }}"
encrypted: true
delete_on_termination: true
device_name: /dev/sda1
register: instances_started

- name: print ipv4
debug:
msg:
- "Instance ID: {{ instances_started.instances[0].instance_id }}"
- "Network ID: {{ instances_started.instances[0].network_interfaces[0].network_interface_id }}"
- "Unusable Public IP: {{ instances_started.instances[0].public_ip_address }}"

0 comments on commit a4979b7

Please sign in to comment.