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

Avoid per-test virtual environments where possible #467

Merged
merged 7 commits into from
Mar 10, 2021
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependencies:
- prepare_tests
- setup_ec2
- setup_remote_tmp_dir

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions tests/integration/targets/ec2_launch_template/runme.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- block:
- name: create c4.large template (failure expected)
ec2_launch_template:
state: present
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tpl"
instance_type: c4.large
register: ec2_lt
ignore_errors: yes

- name: check that graceful error message is returned when creation with cpu_options and old botocore
assert:
that:
- ec2_lt is failed
- 'ec2_lt.msg == "ec2_launch_template requires boto3 >= 1.6.0"'

always:
- name: delete the c4.large template just in case it was created
ec2_launch_template:
state: absent
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-tpl"
ignore_errors: yes
52 changes: 52 additions & 0 deletions tests/integration/targets/ec2_launch_template/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
- module_defaults:
group/aws:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block:

- set_fact:
virtualenv: "{{ remote_tmp_dir }}/virtualenv"
virtualenv_command: "{{ ansible_python_interpreter }} -m virtualenv"

- set_fact:
virtualenv_interpreter: "{{ virtualenv }}/bin/python"

- pip:
name: virtualenv

- pip:
name:
- 'boto3<1.6.0'
- botocore
- boto
- coverage<5
- cryptography
virtualenv: "{{ virtualenv }}"
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: no

- include_tasks: graceful_failure.yml
vars:
ansible_python_interpreter: "{{ virtualenv_interpreter }}"

- name: Find AMI to use
ec2_ami_info:
owners: 'amazon'
filters:
name: '{{ ec2_ami_name }}'
register: ec2_amis
- set_fact:
ec2_ami_image: '{{ ec2_amis.images[0].image_id }}'

- include_tasks: cpu_options.yml
- include_tasks: iam_instance_role.yml
- include_tasks: versions.yml

always:

- file:
path: "{{ virtualenv }}"
state: absent
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
# load balancer and target group names have to be less than 32 characters
# the 8 digit identifier at the end of resource_prefix helps determine during which test something
# was created and allows tests to be run in parallel
alb_name: "my-alb-{{ resource_prefix | regex_search('([0-9]+)$') }}"
tg_name: "my-tg-{{ resource_prefix | regex_search('([0-9]+)$') }}"
resource_short: "{{ '%0.8x'%((16**8) | random(seed=resource_prefix)) }}"
alb_name: "alb-test-{{ resource_short }}"
tg_name: "alb-test-{{ resource_short }}"
67 changes: 11 additions & 56 deletions tests/integration/targets/elb_application_lb/tasks/full_test.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
- name: elb_application_lb full_test
block:
# Setup
- name: create VPC
ec2_vpc_net:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
cidr_block: 10.228.228.0/22
name: '{{ resource_prefix }}_vpc'
state: present
register: vpc
- name: create internet gateway
ec2_vpc_igw:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
vpc_id: '{{ vpc.vpc.id }}'
state: present
tags:
Name: '{{ resource_prefix }}'
register: igw
- name: create public subnet
ec2_vpc_subnet:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
cidr: '{{ item.cidr }}'
az: '{{ aws_region}}{{ item.az }}'
vpc_id: '{{ vpc.vpc.id }}'
Expand All @@ -49,10 +38,6 @@
public: 'False'
register: subnets
- ec2_vpc_subnet_info:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
filters:
vpc-id: '{{ vpc.vpc.id }}'
register: vpc_subnets
Expand All @@ -62,10 +47,6 @@
private_subnets: '{{ vpc_subnets|community.general.json_query(''subnets[?tags.Public != `True`].id'') }}'
- name: create a route table
ec2_vpc_route_table:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
vpc_id: '{{ vpc.vpc.id }}'
tags:
Name: igw-route
Expand All @@ -76,10 +57,6 @@
gateway_id: '{{ igw.gateway_id }}'
register: route_table
- ec2_group:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
name: '{{ resource_prefix }}'
description: security group for Ansible ALB integration tests
state: present
Expand All @@ -92,41 +69,39 @@
register: sec_group
- name: create a target group for testing
elb_target_group:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
name: '{{ tg_name }}'
protocol: http
port: 80
vpc_id: '{{ vpc.vpc.id }}'
state: present
register: tg

# Run tests for graceful failure with an old version of botocore
- include_tasks: test_multiple_actions_fail.yml
vars:
ansible_python_interpreter: "{{ virtualenv_interpreter }}"

# Run main tests
- include_tasks: test_alb_bad_listener_options.yml
- include_tasks: test_alb_tags.yml
- include_tasks: test_creating_alb.yml
- include_tasks: test_alb_with_asg.yml
- include_tasks: test_modifying_alb_listeners.yml
- include_tasks: test_deleting_alb.yml
- include_tasks: test_multiple_actions.yml

always:
# Cleanup
- name: destroy ALB
elb_application_lb:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
name: '{{ alb_name }}'
state: absent
wait: true
wait_timeout: 600
ignore_errors: true

- name: destroy target group if it was created
elb_target_group:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
name: '{{ tg_name }}'
protocol: http
port: 80
Expand All @@ -142,10 +117,6 @@
ignore_errors: true
- name: destroy sec group
ec2_group:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
name: '{{ sec_group.group_name }}'
description: security group for Ansible ALB integration tests
state: absent
Expand All @@ -157,10 +128,6 @@
ignore_errors: true
- name: remove route table
ec2_vpc_route_table:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
vpc_id: '{{ vpc.vpc.id }}'
route_table_id: '{{ route_table.route_table.route_table_id }}'
lookup: id
Expand All @@ -172,10 +139,6 @@
ignore_errors: true
- name: destroy subnets
ec2_vpc_subnet:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
cidr: '{{ item.cidr }}'
vpc_id: '{{ vpc.vpc.id }}'
state: absent
Expand All @@ -191,10 +154,6 @@
ignore_errors: true
- name: destroy internet gateway
ec2_vpc_igw:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
vpc_id: '{{ vpc.vpc.id }}'
tags:
Name: '{{ resource_prefix }}'
Expand All @@ -206,10 +165,6 @@
ignore_errors: true
- name: destroy VPC
ec2_vpc_net:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
cidr_block: 10.228.228.0/22
name: '{{ resource_prefix }}_vpc'
state: absent
Expand Down
21 changes: 3 additions & 18 deletions tests/integration/targets/elb_application_lb/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
region: '{{ aws_region }}'
block:

# Prepare a virtual environment for multiple_actions_fail.yml
- set_fact:
virtualenv: "{{ remote_tmp_dir }}/virtualenv"
virtualenv_command: "{{ ansible_python_interpreter }} -m virtualenv"
Expand All @@ -30,25 +31,9 @@
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: no

- include_tasks: multiple_actions_fail.yml
vars:
ansible_python_interpreter: "{{ virtualenv_interpreter }}"


- pip:
name:
- 'botocore>=1.10.30'
- boto3
- boto
- coverage<5
- cryptography
virtualenv: "{{ virtualenv }}"
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: no

- include_tasks: full_test.yml
vars:
ansible_python_interpreter: "{{ virtualenv_interpreter }}"

always:

- file:
path: "{{ virtualenv }}"
Expand Down
Loading