mirror of https://github.com/ansible/ansible.git
ec2_instance.py: Add CpuOptions to EC2 (#43799)
* ec2_instance.py: Add CpuOptions to EC2 * ec2_instance_facts.py: Add CpuOptions to EC2 facts * ec2_instance.py: LooseVersion and pylint indentation * Implement nested cpu_options dict * Fix botocore required version * ec2_instance: Split integration tests to add executions with old botocore versions * Ensure runme.sh is executablepull/44390/head
parent
401c45384e
commit
3921f34253
@ -0,0 +1,5 @@
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
|
||||
roles:
|
||||
- ec2_instance
|
@ -0,0 +1,52 @@
|
||||
- name: set connection information for all tasks
|
||||
set_fact:
|
||||
aws_connection_info: &aws_connection_info
|
||||
aws_access_key: "{{ aws_access_key }}"
|
||||
aws_secret_key: "{{ aws_secret_key }}"
|
||||
security_token: "{{ security_token }}"
|
||||
region: "{{ aws_region }}"
|
||||
no_log: true
|
||||
|
||||
- name: create c4.large instance with cpu_options
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-c4large-1-threads-per-core"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
||||
instance_type: c4.large
|
||||
cpu_options:
|
||||
core_count: 1
|
||||
threads_per_core: 1
|
||||
<<: *aws_connection_info
|
||||
register: instance_creation
|
||||
|
||||
- name: instance with cpu_options created with the right options
|
||||
assert:
|
||||
that:
|
||||
- instance_creation is success
|
||||
- instance_creation is changed
|
||||
- "instance_creation.instances[0].cpu_options.core_count == 1"
|
||||
- "instance_creation.instances[0].cpu_options.threads_per_core == 1"
|
||||
|
||||
- name: modify cpu_options on existing instance (warning displayed)
|
||||
ec2_instance:
|
||||
state: present
|
||||
name: "{{ resource_prefix }}-test-c4large-1-threads-per-core"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
|
||||
instance_type: c4.large
|
||||
cpu_options:
|
||||
core_count: 1
|
||||
threads_per_core: 2
|
||||
<<: *aws_connection_info
|
||||
register: cpu_options_update
|
||||
ignore_errors: yes
|
||||
|
||||
- name: modify cpu_options has no effect on existing instance
|
||||
assert:
|
||||
that:
|
||||
- cpu_options_update is success
|
||||
- cpu_options_update is not changed
|
@ -0,0 +1,38 @@
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
vars:
|
||||
resource_prefix: 'ansible-testing'
|
||||
|
||||
tasks:
|
||||
- block:
|
||||
- name: set up aws connection info
|
||||
set_fact:
|
||||
aws_connection_info: &aws_connection_info
|
||||
aws_access_key: "{{ aws_access_key }}"
|
||||
aws_secret_key: "{{ aws_secret_key }}"
|
||||
security_token: "{{ security_token }}"
|
||||
region: "{{ aws_region }}"
|
||||
no_log: True
|
||||
|
||||
- name: Include vars file in roles/ec2_instance/defaults/main.yml
|
||||
include_vars:
|
||||
file: 'roles/ec2_instance/defaults/main.yml'
|
||||
|
||||
- name: create c4.large with cpu options (fails gracefully)
|
||||
ec2_instance:
|
||||
state: present
|
||||
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-ec2"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
instance_type: c4.large
|
||||
cpu_options:
|
||||
core_count: 1
|
||||
threads_per_core: 1
|
||||
<<: *aws_connection_info
|
||||
register: ec2_instance_cpu_options_creation
|
||||
ignore_errors: yes
|
||||
|
||||
- name: check that graceful error message is returned when creation with cpu_options and old botocore
|
||||
assert:
|
||||
that:
|
||||
- ec2_instance_cpu_options_creation.failed
|
||||
- 'ec2_instance_cpu_options_creation.msg == "cpu_options is only supported with botocore >= 1.10.16"'
|
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We don't set -u here, due to pypa/virtualenv#150
|
||||
set -ex
|
||||
|
||||
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
||||
|
||||
trap 'rm -rf "${MYTMPDIR}"' EXIT
|
||||
|
||||
# This is needed for the ubuntu1604py3 tests
|
||||
# Ubuntu patches virtualenv to make the default python2
|
||||
# but for the python3 tests we need virtualenv to use python3
|
||||
PYTHON=${ANSIBLE_TEST_PYTHON_INTERPRETER:-python}
|
||||
|
||||
# Test graceful failure for older versions of botocore
|
||||
export ANSIBLE_ROLES_PATH=../
|
||||
virtualenv --system-site-packages --python "${PYTHON}" "${MYTMPDIR}/botocore-less-than-1.10.16"
|
||||
source "${MYTMPDIR}/botocore-less-than-1.10.16/bin/activate"
|
||||
"${PYTHON}" -m pip install 'botocore<1.10.16' boto3
|
||||
ansible-playbook -i ../../inventory -e @../../integration_config.yml -e @../../cloud-config-aws.yml -v playbooks/version_fail.yml "$@"
|
||||
|
||||
# Run full test suite
|
||||
virtualenv --system-site-packages --python "${PYTHON}" "${MYTMPDIR}/botocore-recent"
|
||||
source "${MYTMPDIR}/botocore-recent/bin/activate"
|
||||
$PYTHON -m pip install 'botocore>=1.10.16' boto3
|
||||
ansible-playbook -i ../../inventory -e @../../integration_config.yml -e @../../cloud-config-aws.yml -v playbooks/full_test.yml "$@"
|
Loading…
Reference in New Issue