diff --git a/.gitignore b/.gitignore index 52039a3033..4f12e1da9a 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ debian/ # Vim swap files *.swp *.swo +credentials.yml diff --git a/test/integration/Makefile b/test/integration/Makefile index a169aa9dd1..7cdae607df 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -1,4 +1,4 @@ -all: non_destructive destructive check_mode test_hash # amazon rackspace +all: non_destructive destructive check_mode test_hash non_destructive: ansible-playbook non_destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS) @@ -12,3 +12,17 @@ check_mode: test_hash: ANSIBLE_HASH_BEHAVIOUR=replace ansible-playbook test_hash.yml -i inventory -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook test_hash.yml -i inventory -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' + +cloud: amazon rackspace + +credentials.yml: + @echo "No credentials.yml file found. A file named 'credentials.yml' is needed to provide credentials needed to run cloud tests." + @exit 1 + +amazon: credentials.yml + ansible-playbook amazon.yml -i inventory -e @integration_config.yml -e @credentials.yml -v $(TEST_FLAGS) + @# FIXME - Cleanup won't run if the previous tests fail + python cleanup_ec2.py -y + +rackspace: credentials.yml + ansible-playbook rackspace.yml -i inventory -e @integration_config.yml -e @credentials.yml -v $(TEST_FLAGS) diff --git a/test/integration/amazon.yml b/test/integration/amazon.yml index a6ba60c13e..6fe692067a 100644 --- a/test/integration/amazon.yml +++ b/test/integration/amazon.yml @@ -1,4 +1,14 @@ - hosts: testhost - gather_facts: True - roles: [] - + gather_facts: true + roles: + - { role: test_ec2_key, tags: test_ec2_key } + - { role: test_ec2_group, tags: test_ec2_group } + #- { role: test_ec2_vpc, tags: test_ec2_vpc } + #- { role: test_ec2_vol, tags: test_ec2_vol } + #- { role: test_ec2_tag, tags: test_ec2_tag } + #- { role: test_ec2_facts, tags: test_ec2_facts } + #- { role: test_ec2_elb_lb, tags: test_ec2_elb_lb } + #- { role: test_ec2_eip, tags: test_ec2_eip } + #- { role: test_ec2_elb, tags: test_ec2_elb } + #- { role: test_ec2_ami, tags: test_ec2_ami } + #- { role: test_ec2, tags: test_ec2 } diff --git a/test/integration/cleanup_ec2.py b/test/integration/cleanup_ec2.py new file mode 100644 index 0000000000..08d54751aa --- /dev/null +++ b/test/integration/cleanup_ec2.py @@ -0,0 +1,79 @@ +''' +Find and delete AWS resources matching the provided --match string. Unless +--yes|-y is provided, the prompt for confirmation prior to deleting resources. +Please use caution, you can easily delete you're *ENTIRE* EC2 infrastructure. +''' + +import os +import re +import sys +import boto +import optparse +import yaml + +def delete_aws_resources(get_func, attr, opts): + for item in get_func(): + val = getattr(item, attr) + if re.search(opts.match_re, val): + prompt_and_delete("Delete object with %s=%s? [y/n]: " % (attr, val), opts.assumeyes) + +def prompt_and_delete(prompt, assumeyes): + while not assumeyes: + assumeyes = raw_input(prompt) + obj.delete() + +def parse_args(): + # Load details from credentials.yml + default_aws_access_key = os.environ.get('AWS_ACCESS_KEY', None) + default_aws_secret_key = os.environ.get('AWS_SECRET_KEY', None) + if os.path.isfile('credentials.yml'): + credentials = yaml.load(open('credentials.yml', 'r')) + + if default_aws_access_key is None: + default_aws_access_key = credentials['ec2_access_key'] + if default_aws_secret_key is None: + default_aws_secret_key = credentials['ec2_secret_key'] + + parser = optparse.OptionParser(usage="%s [options]" % (sys.argv[0],), + description=__doc__) + parser.add_option("--access", + action="store", dest="ec2_access_key", + default=default_aws_access_key, + help="Amazon ec2 access id. Can use EC2_ACCESS_KEY environment variable, or a values from credentials.yml.") + parser.add_option("--secret", + action="store", dest="ec2_secret_key", + default=default_aws_secret_key, + help="Amazon ec2 secret key. Can use EC2_SECRET_KEY environment variable, or a values from credentials.yml.") + parser.add_option("--credentials", "-c", + action="store", dest="credential_file", + default="credentials.yml", + help="YAML file to read cloud credentials (default: %default)") + parser.add_option("--yes", "-y", + action="store_true", dest="assumeyes", + default=False, + help="Don't prompt for confirmation") + parser.add_option("--match", + action="store", dest="match_re", + default="^ansible-testing-", + help="Regular expression used to find AWS resources (default: %default)") + + (opts, args) = parser.parse_args() + for required in ['ec2_access_key', 'ec2_secret_key']: + if getattr(opts, required) is None: + parser.error("Missing required parameter: --%s" % required) + + return (opts, args) + +if __name__ == '__main__': + + (opts, args) = parse_args() + + # Connect to AWS + aws = boto.connect_ec2(aws_access_key_id=opts.ec2_access_key, + aws_secret_access_key=opts.ec2_secret_key) + + # Delete matching keys + delete_aws_resources(aws.get_all_key_pairs, 'name', opts) + + # Delete matching groups + delete_aws_resources(aws.get_all_security_groups, 'name', opts) diff --git a/test/integration/group_vars/amazon b/test/integration/group_vars/amazon new file mode 100644 index 0000000000..3d7209ef1b --- /dev/null +++ b/test/integration/group_vars/amazon @@ -0,0 +1,3 @@ +--- +ec2_url: ec2.amazonaws.com +ec2_region: us-east-1 diff --git a/test/integration/host_vars/testhost b/test/integration/host_vars/testhost index a2480317e5..facd519959 100644 --- a/test/integration/host_vars/testhost +++ b/test/integration/host_vars/testhost @@ -5,3 +5,6 @@ d: 4 role_var_beats_inventory: 'should_not_see_this' test_hash: host_vars_testhost: "this is in host_vars/testhost" + +# Support execution from within a virtualenv +ansible_python_interpreter: ${VIRTUAL_ENV-/usr}/bin/python diff --git a/test/integration/inventory b/test/integration/inventory index 65fc130a23..d89301f866 100644 --- a/test/integration/inventory +++ b/test/integration/inventory @@ -25,3 +25,5 @@ groups_tree_var=3000 grandparent_var=2000 overridden_in_parent=2000 +[amazon:children] +local diff --git a/test/integration/roles/setup_ec2/tasks/common.yml b/test/integration/roles/setup_ec2/tasks/common.yml new file mode 100644 index 0000000000..bf23f539a9 --- /dev/null +++ b/test/integration/roles/setup_ec2/tasks/common.yml @@ -0,0 +1,119 @@ +--- + +# ============================================================ +- name: test with no parameters + action: "{{module_name}}" + register: result + ignore_errors: true + +- name: assert failure when called with no parameters + assert: + that: + - 'result.failed' + - 'result.msg == "missing required arguments: name"' + +# ============================================================ +- name: test with only name + action: "{{module_name}} name={{ec2_key_name}}" + register: result + ignore_errors: true + +- name: assert failure when called with only 'name' + assert: + that: + - 'result.failed' + - 'result.msg == "Either region or ec2_url must be specified"' + +# ============================================================ +- name: test invalid region parameter + action: "{{module_name}} name='{{ec2_key_name}}' region='asdf querty 1234'" + register: result + ignore_errors: true + +- name: assert invalid region parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("value of region must be one of:")' + +# ============================================================ +- name: test valid region parameter + action: "{{module_name}} name='{{ec2_key_name}}' region='{{ec2_region}}'" + register: result + ignore_errors: true + +- name: assert valid region parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test environment variable EC2_REGION + action: "{{module_name}} name='{{ec2_key_name}}'" + environment: + EC2_REGION: '{{ec2_region}}' + register: result + ignore_errors: true + +- name: assert environment variable EC2_REGION + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test invalid ec2_url parameter + action: "{{module_name}} name='{{ec2_key_name}}'" + environment: + EC2_URL: bogus.example.com + register: result + ignore_errors: true + +- name: assert invalid ec2_url parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test valid ec2_url parameter + action: "{{module_name}} name='{{ec2_key_name}}'" + environment: + EC2_URL: '{{ec2_url}}' + register: result + ignore_errors: true + +- name: assert valid ec2_url parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test credentials from environment + action: "{{module_name}} name='{{ec2_key_name}}'" + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: bogus_access_key + EC2_SECRET_KEY: bogus_secret_key + register: result + ignore_errors: true + +- name: assert ec2_key with valid ec2_url + assert: + that: + - 'result.failed' + - '"EC2ResponseError: 401 Unauthorized" in result.msg' + +# ============================================================ +- name: test credential parameters + action: "{{module_name}} name='{{ec2_key_name}}' ec2_region='{{ec2_region}}' ec2_access_key=bogus_access_key ec2_secret_key=bogus_secret_key" + register: result + ignore_errors: true + +- name: assert credential parameters + assert: + that: + - 'result.failed' + - '"EC2ResponseError: 401 Unauthorized" in result.msg' diff --git a/test/integration/roles/setup_ec2/tasks/main.yml b/test/integration/roles/setup_ec2/tasks/main.yml new file mode 100644 index 0000000000..d8add692df --- /dev/null +++ b/test/integration/roles/setup_ec2/tasks/main.yml @@ -0,0 +1,55 @@ +# common setup tasks for ec2 module tests +# (c) 2014, James Laska + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- name: generate random string + shell: python -c "import string,random; print ''.join(random.choice(string.ascii_lowercase) for _ in xrange(8));" + register: random_string + tags: + - prepare + +- name: create random file + shell: mktemp /tmp/id_rsa.XXXXXX + register: sshkey + tags: + - prepare + +- name: generate sshkey + shell: echo 'y' | ssh-keygen -P '' -f {{sshkey.stdout}} + tags: + - prepare + +- name: record key_material + command: cat {{sshkey.stdout}}.pub + register: key_material + tags: + - prepare + +- name: record fingerprint + shell: ssh-keygen -lf {{sshkey.stdout}}.pub | awk '{print $2}' + register: fingerprint + tags: + - prepare + +- name: set facts for future roles + set_fact: + random_string: '{{random_string.stdout}}' + sshkey: '{{sshkey.stdout}}' + key_material: '{{key_material.stdout}}' + fingerprint: '{{fingerprint.stdout}}' + tags: + - prepare diff --git a/test/integration/roles/test_ec2/README.md b/test/integration/roles/test_ec2/README.md new file mode 100644 index 0000000000..54af02ff51 --- /dev/null +++ b/test/integration/roles/test_ec2/README.md @@ -0,0 +1,38 @@ +Role Name +======== + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +------------------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/test/integration/roles/test_ec2/defaults/main.yml b/test/integration/roles/test_ec2/defaults/main.yml new file mode 100644 index 0000000000..bd3bf77ca0 --- /dev/null +++ b/test/integration/roles/test_ec2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2 diff --git a/test/integration/roles/test_ec2/handlers/main.yml b/test/integration/roles/test_ec2/handlers/main.yml new file mode 100644 index 0000000000..38167ee5a6 --- /dev/null +++ b/test/integration/roles/test_ec2/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for test_ec2 diff --git a/test/integration/roles/test_ec2/meta/main.yml b/test/integration/roles/test_ec2/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2/tasks/main.yml b/test/integration/roles/test_ec2/tasks/main.yml new file mode 100644 index 0000000000..19a8f12aeb --- /dev/null +++ b/test/integration/roles/test_ec2/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2 diff --git a/test/integration/roles/test_ec2/vars/main.yml b/test/integration/roles/test_ec2/vars/main.yml new file mode 100644 index 0000000000..7008594fb8 --- /dev/null +++ b/test/integration/roles/test_ec2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2 diff --git a/test/integration/roles/test_ec2_ami/defaults/main.yml b/test/integration/roles/test_ec2_ami/defaults/main.yml new file mode 100644 index 0000000000..ec51507c21 --- /dev/null +++ b/test/integration/roles/test_ec2_ami/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_ami diff --git a/test/integration/roles/test_ec2_ami/meta/main.yml b/test/integration/roles/test_ec2_ami/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_ami/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_ami/tasks/main.yml b/test/integration/roles/test_ec2_ami/tasks/main.yml new file mode 100644 index 0000000000..523d465c34 --- /dev/null +++ b/test/integration/roles/test_ec2_ami/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_ami diff --git a/test/integration/roles/test_ec2_ami/vars/main.yml b/test/integration/roles/test_ec2_ami/vars/main.yml new file mode 100644 index 0000000000..edb7a0b7cc --- /dev/null +++ b/test/integration/roles/test_ec2_ami/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_ami diff --git a/test/integration/roles/test_ec2_eip/defaults/main.yml b/test/integration/roles/test_ec2_eip/defaults/main.yml new file mode 100644 index 0000000000..0fdf99bb9c --- /dev/null +++ b/test/integration/roles/test_ec2_eip/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_eip diff --git a/test/integration/roles/test_ec2_eip/meta/main.yml b/test/integration/roles/test_ec2_eip/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_eip/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_eip/tasks/main.yml b/test/integration/roles/test_ec2_eip/tasks/main.yml new file mode 100644 index 0000000000..6d8b49e4fc --- /dev/null +++ b/test/integration/roles/test_ec2_eip/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_eip diff --git a/test/integration/roles/test_ec2_eip/vars/main.yml b/test/integration/roles/test_ec2_eip/vars/main.yml new file mode 100644 index 0000000000..48e38c487b --- /dev/null +++ b/test/integration/roles/test_ec2_eip/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_eip diff --git a/test/integration/roles/test_ec2_elb/defaults/main.yml b/test/integration/roles/test_ec2_elb/defaults/main.yml new file mode 100644 index 0000000000..523798bbcc --- /dev/null +++ b/test/integration/roles/test_ec2_elb/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_elb diff --git a/test/integration/roles/test_ec2_elb/meta/main.yml b/test/integration/roles/test_ec2_elb/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_elb/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_elb/tasks/main.yml b/test/integration/roles/test_ec2_elb/tasks/main.yml new file mode 100644 index 0000000000..0e68d3698e --- /dev/null +++ b/test/integration/roles/test_ec2_elb/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_elb diff --git a/test/integration/roles/test_ec2_elb/vars/main.yml b/test/integration/roles/test_ec2_elb/vars/main.yml new file mode 100644 index 0000000000..415390f64a --- /dev/null +++ b/test/integration/roles/test_ec2_elb/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_elb diff --git a/test/integration/roles/test_ec2_elb_lb/defaults/main.yml b/test/integration/roles/test_ec2_elb_lb/defaults/main.yml new file mode 100644 index 0000000000..234720c640 --- /dev/null +++ b/test/integration/roles/test_ec2_elb_lb/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_elb_lb diff --git a/test/integration/roles/test_ec2_elb_lb/meta/main.yml b/test/integration/roles/test_ec2_elb_lb/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_elb_lb/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_elb_lb/tasks/main.yml b/test/integration/roles/test_ec2_elb_lb/tasks/main.yml new file mode 100644 index 0000000000..684d8f35ec --- /dev/null +++ b/test/integration/roles/test_ec2_elb_lb/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_elb_lb diff --git a/test/integration/roles/test_ec2_elb_lb/vars/main.yml b/test/integration/roles/test_ec2_elb_lb/vars/main.yml new file mode 100644 index 0000000000..79194af1ef --- /dev/null +++ b/test/integration/roles/test_ec2_elb_lb/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_elb_lb diff --git a/test/integration/roles/test_ec2_facts/defaults/main.yml b/test/integration/roles/test_ec2_facts/defaults/main.yml new file mode 100644 index 0000000000..c25743914a --- /dev/null +++ b/test/integration/roles/test_ec2_facts/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_facts diff --git a/test/integration/roles/test_ec2_facts/meta/main.yml b/test/integration/roles/test_ec2_facts/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_facts/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_facts/tasks/main.yml b/test/integration/roles/test_ec2_facts/tasks/main.yml new file mode 100644 index 0000000000..8ea9fcf1f8 --- /dev/null +++ b/test/integration/roles/test_ec2_facts/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_facts diff --git a/test/integration/roles/test_ec2_facts/vars/main.yml b/test/integration/roles/test_ec2_facts/vars/main.yml new file mode 100644 index 0000000000..bb8f6c1875 --- /dev/null +++ b/test/integration/roles/test_ec2_facts/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_facts diff --git a/test/integration/roles/test_ec2_group/defaults/main.yml b/test/integration/roles/test_ec2_group/defaults/main.yml new file mode 100644 index 0000000000..e10da44d84 --- /dev/null +++ b/test/integration/roles/test_ec2_group/defaults/main.yml @@ -0,0 +1,5 @@ +--- +# defaults file for test_ec2_group +ec2_group_name: 'ansible-testing-{{ random_string }}' +ec2_group_description: 'Created by ansible integration tests' + diff --git a/test/integration/roles/test_ec2_group/meta/main.yml b/test/integration/roles/test_ec2_group/meta/main.yml new file mode 100644 index 0000000000..1f64f1169a --- /dev/null +++ b/test/integration/roles/test_ec2_group/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + - setup_ec2 diff --git a/test/integration/roles/test_ec2_group/tasks/main.yml b/test/integration/roles/test_ec2_group/tasks/main.yml new file mode 100644 index 0000000000..b2be85d58e --- /dev/null +++ b/test/integration/roles/test_ec2_group/tasks/main.yml @@ -0,0 +1,250 @@ +--- +# A Note about ec2 environment variable name preference: +# - EC2_URL -> AWS_URL +# - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY +# - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY +# - EC2_REGION -> AWS_REGION +# + +# - include: ../../setup_ec2/tasks/common.yml module_name=ec2_group + +# ============================================================ +- name: test failure with no parameters + ec2_group: + register: result + ignore_errors: true + +- name: assert failure with no parameters + assert: + that: + - 'result.failed' + - 'result.msg == "missing required arguments: description,name"' + +# ============================================================ +- name: test failure with only name + ec2_group: + name='{{ec2_group_name}}' + register: result + ignore_errors: true + +- name: assert failure with only name + assert: + that: + - 'result.failed' + - 'result.msg == "missing required arguments: description"' + +# ============================================================ +- name: test failure with only description + ec2_group: + description='{{ec2_group_description}}' + register: result + ignore_errors: true + +- name: assert failure with only description + assert: + that: + - 'result.failed' + - 'result.msg == "missing required arguments: name"' + +# ============================================================ +- name: test invalid region parameter + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + region='asdf querty 1234' + register: result + ignore_errors: true + +- name: assert invalid region parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("value of region must be one of:")' + +# ============================================================ +- name: test valid region parameter + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + region='{{ec2_region}}' + register: result + ignore_errors: true + +- name: assert valid region parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test environment variable EC2_REGION + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + environment: + EC2_REGION: '{{ec2_region}}' + register: result + ignore_errors: true + +- name: assert environment variable EC2_REGION + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test invalid ec2_url parameter + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + environment: + EC2_URL: bogus.example.com + register: result + ignore_errors: true + +- name: assert invalid ec2_url parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test valid ec2_url parameter + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + environment: + EC2_URL: '{{ec2_url}}' + register: result + ignore_errors: true + +- name: assert valid ec2_url parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test credentials from environment + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: bogus_access_key + EC2_SECRET_KEY: bogus_secret_key + register: result + ignore_errors: true + +- name: assert ec2_group with valid ec2_url + assert: + that: + - 'result.failed' + - '"EC2ResponseError: 401 Unauthorized" in result.msg' + +# ============================================================ +- name: test credential parameters + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + ec2_region='{{ec2_region}}' + ec2_access_key='bogus_access_key' + ec2_secret_key='bogus_secret_key' + register: result + ignore_errors: true + +- name: assert credential parameters + assert: + that: + - 'result.failed' + - '"EC2ResponseError: 401 Unauthorized" in result.msg' + +# ============================================================ +- name: test state=absent + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + ec2_region='{{ec2_region}}' + ec2_access_key='{{ec2_access_key}}' + ec2_secret_key='{{ec2_secret_key}}' + state=absent + register: result + +- name: assert state=absent + assert: + that: + - '"failed" not in result' + +# ============================================================ +- name: test state=present (expected changed=true) + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + ec2_region='{{ec2_region}}' + ec2_access_key='{{ec2_access_key}}' + ec2_secret_key='{{ec2_secret_key}}' + state=present + register: result + +- name: assert state=present (expected changed=true) + assert: + that: + - 'result.changed' + - 'result.group_id.startswith("sg-")' + - 'result.item == ""' + +# ============================================================ +- name: test state=present (expected changed=false) + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + ec2_region='{{ec2_region}}' + ec2_access_key='{{ec2_access_key}}' + ec2_secret_key='{{ec2_secret_key}}' + state=present + register: result + +- name: assert state=present (expected changed=false) + assert: + that: + - 'not result.changed' + - 'result.group_id.startswith("sg-")' + - 'result.item == ""' + +# ============================================================ +- name: test state=absent (expected changed=true) + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + state=absent + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: '{{ec2_access_key}}' + EC2_SECRET_KEY: '{{ec2_secret_key}}' + register: result + +- name: assert state=absent (expected changed=true) + assert: + that: + - 'result.changed' + - 'not result.group_id' + - 'result.item == ""' + +# ============================================================ +- name: test state=absent (expected changed=false) + ec2_group: + name='{{ec2_group_name}}' + description='{{ec2_group_description}}' + state=absent + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: '{{ec2_access_key}}' + EC2_SECRET_KEY: '{{ec2_secret_key}}' + register: result + +- name: assert state=absent (expected changed=false) + assert: + that: + - 'not result.changed' + - 'not result.group_id' + - 'result.item == ""' diff --git a/test/integration/roles/test_ec2_key/defaults/main.yml b/test/integration/roles/test_ec2_key/defaults/main.yml new file mode 100644 index 0000000000..2242ea0709 --- /dev/null +++ b/test/integration/roles/test_ec2_key/defaults/main.yml @@ -0,0 +1,3 @@ +--- +# defaults file for test_ec2_key +ec2_key_name: 'ansible-testing-{{ random_string }}' diff --git a/test/integration/roles/test_ec2_key/meta/main.yml b/test/integration/roles/test_ec2_key/meta/main.yml new file mode 100644 index 0000000000..1f64f1169a --- /dev/null +++ b/test/integration/roles/test_ec2_key/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + - setup_ec2 diff --git a/test/integration/roles/test_ec2_key/tasks/main.yml b/test/integration/roles/test_ec2_key/tasks/main.yml new file mode 100644 index 0000000000..f8f05d1853 --- /dev/null +++ b/test/integration/roles/test_ec2_key/tasks/main.yml @@ -0,0 +1,337 @@ +--- +# A Note about ec2 environment variable name preference: +# - EC2_URL -> AWS_URL +# - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY +# - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY +# - EC2_REGION -> AWS_REGION +# +# TODO - name: test 'region' parameter +# TODO - name: test 'state=absent' parameter for existing key +# TODO - name: test 'state=absent' parameter for missing key +# TODO - name: test 'validate_certs' parameter + +# ============================================================ +# - include: ../../setup_ec2/tasks/common.yml module_name=ec2_key + +# ============================================================ +- name: test with no parameters + ec2_key: + register: result + ignore_errors: true + +- name: assert failure when called with no parameters + assert: + that: + - 'result.failed' + - 'result.msg == "missing required arguments: name"' + +# ============================================================ +- name: test with only name + ec2_key: + name={{ec2_key_name}} + register: result + ignore_errors: true + +- name: assert failure when called with only 'name' + assert: + that: + - 'result.failed' + - 'result.msg == "Either region or ec2_url must be specified"' + +# ============================================================ +- name: test invalid region parameter + ec2_key: + name={{ec2_key_name}} + region='asdf querty 1234' + register: result + ignore_errors: true + +- name: assert invalid region parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("value of region must be one of:")' + +# ============================================================ +- name: test valid region parameter + ec2_key: + name={{ec2_key_name}} + region={{ec2_region}} + register: result + ignore_errors: true + +- name: assert valid region parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test environment variable EC2_REGION + ec2_key: + name={{ec2_key_name}} + environment: + EC2_REGION: '{{ec2_region}}' + register: result + ignore_errors: true + +- name: assert environment variable EC2_REGION + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test invalid ec2_url parameter + ec2_key: + name={{ec2_key_name}} + environment: + EC2_URL: bogus.example.com + register: result + ignore_errors: true + +- name: assert invalid ec2_url parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test valid ec2_url parameter + ec2_key: + name={{ec2_key_name}} + environment: + EC2_URL: '{{ec2_url}}' + register: result + ignore_errors: true + +- name: assert valid ec2_url parameter + assert: + that: + - 'result.failed' + - 'result.msg.startswith("No handler was ready to authenticate.")' + +# ============================================================ +- name: test credentials from environment + ec2_key: + name={{ec2_key_name}} + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: bogus_access_key + EC2_SECRET_KEY: bogus_secret_key + register: result + ignore_errors: true + +- name: assert ec2_key with valid ec2_url + assert: + that: + - 'result.failed' + - '"EC2ResponseError: 401 Unauthorized" in result.msg' + +# ============================================================ +- name: test credential parameters + ec2_key: + name={{ec2_key_name}} + ec2_region={{ec2_region}} + ec2_access_key=bogus_access_key + ec2_secret_key=bogus_secret_key + register: result + ignore_errors: true + +- name: assert credential parameters + assert: + that: + - 'result.failed' + - '"EC2ResponseError: 401 Unauthorized" in result.msg' + +# ============================================================ +- name: test state=absent with key_material + ec2_key: + name='{{ec2_key_name}}' + ec2_region={{ec2_region}} + ec2_access_key={{ec2_access_key}} + ec2_secret_key={{ec2_secret_key}} + state=absent + register: result + +- name: assert state=absent with key_material + assert: + that: + - '"failed" not in result' + +# ============================================================ +- name: test state=present without key_material + ec2_key: + name='{{ec2_key_name}}' + ec2_region={{ec2_region}} + ec2_access_key={{ec2_access_key}} + ec2_secret_key={{ec2_secret_key}} + state=present + register: result + +- name: assert state=present without key_material + assert: + that: + - 'result.changed' + - '"failed" not in result' + - '"key" in result' + - '"name" in result.key' + - '"fingerprint" in result.key' + - '"private_key" in result.key' + - 'result.key.name == "{{ec2_key_name}}"' + +# ============================================================ +- name: test state=absent without key_material + ec2_key: + name='{{ec2_key_name}}' + state=absent + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: '{{ec2_access_key}}' + EC2_SECRET_KEY: '{{ec2_secret_key}}' + register: result + +- name: assert state=absent without key_material + assert: + that: + - 'result.changed' + - '"failed" not in result' + - '"key" in result' + - 'result.key == None' + +# ============================================================ +- name: test state=present with key_material + ec2_key: + name='{{ec2_key_name}}' + key_material='{{key_material}}' + state=present + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: '{{ec2_access_key}}' + EC2_SECRET_KEY: '{{ec2_secret_key}}' + register: result + +- name: assert state=present with key_material + assert: + that: + - '"failed" not in result' + - 'result.changed == True' + - '"key" in result' + - '"name" in result.key' + - 'result.key.name == "{{ec2_key_name}}"' + - '"fingerprint" in result.key' + - '"private_key" not in result.key' + # FIXME - why don't the fingerprints match? + # - 'result.key.fingerprint == "{{fingerprint}}"' + +# ============================================================ +- name: test state=absent with key_material + ec2_key: + name='{{ec2_key_name}}' + key_material='{{key_material}}' + ec2_region='{{ec2_region}}' + ec2_access_key='{{ec2_access_key}}' + ec2_secret_key='{{ec2_secret_key}}' + state=absent + register: result + +- name: assert state=absent with key_material + assert: + that: + - 'result.changed' + - '"failed" not in result' + - '"key" in result' + - 'result.key == None' + +# ============================================================ +- name: test state=present with key_material with_files (expect changed=true) + ec2_key: + name='{{ec2_key_name}}' + state=present + key_material='{{ item }}' + with_file: sshkey ~ '.pub' + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: '{{ec2_access_key}}' + EC2_SECRET_KEY: '{{ec2_secret_key}}' + register: result + +- name: assert state=present with key_material with_files (expect changed=true) + assert: + that: + - 'result.msg == "All items completed"' + - 'result.changed == True' + - '"results" in result' + - '"item" in result.results[0]' + - '"key" in result.results[0]' + - '"name" in result.results[0].key' + - 'result.results[0].key.name == "{{ec2_key_name}}"' + - '"fingerprint" in result.results[0].key' + - '"private_key" not in result.results[0].key' + # FIXME - why doesn't result.key.fingerprint == {{fingerprint}} + # - 'result.key.fingerprint == "{{fingerprint}}"' + +# ============================================================ +- name: test state=present with key_material with_files (expect changed=false) + ec2_key: + name='{{ec2_key_name}}' + state=present + key_material='{{ item }}' + with_file: sshkey ~ '.pub' + environment: + EC2_REGION: '{{ec2_region}}' + EC2_ACCESS_KEY: '{{ec2_access_key}}' + EC2_SECRET_KEY: '{{ec2_secret_key}}' + register: result + +- name: assert state=present with key_material with_files (expect changed=false) + assert: + that: + - 'result.msg == "All items completed"' + - 'not result.changed' + - '"results" in result' + - '"item" in result.results[0]' + - '"key" in result.results[0]' + - '"name" in result.results[0].key' + - 'result.results[0].key.name == "{{ec2_key_name}}"' + - '"fingerprint" in result.results[0].key' + - '"private_key" not in result.results[0].key' + # FIXME - why doesn't result.key.fingerprint == {{fingerprint}} + # - 'result.key.fingerprint == "{{fingerprint}}"' + +# ============================================================ +- name: test state=absent with key_material (expect changed=true) + ec2_key: + name='{{ec2_key_name}}' + ec2_region='{{ec2_region}}' + ec2_access_key='{{ec2_access_key}}' + ec2_secret_key='{{ec2_secret_key}}' + key_material='{{key_material}}' + state=absent + register: result + +- name: assert state=absent with key_material (expect changed=true) + assert: + that: + - 'result.changed' + - '"failed" not in result' + - '"key" in result' + - 'result.key == None' + +# ============================================================ +- name: test state=absent (expect changed=false) + ec2_key: + name='{{ec2_key_name}}' + ec2_region='{{ec2_region}}' + ec2_access_key='{{ec2_access_key}}' + ec2_secret_key='{{ec2_secret_key}}' + state=absent + register: result + +- name: assert state=absent with key_material (expect changed=false) + assert: + that: + - 'not result.changed' + - '"failed" not in result' + - '"key" in result' + - 'result.key == None' diff --git a/test/integration/roles/test_ec2_tag/defaults/main.yml b/test/integration/roles/test_ec2_tag/defaults/main.yml new file mode 100644 index 0000000000..6aa39c7360 --- /dev/null +++ b/test/integration/roles/test_ec2_tag/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_tag diff --git a/test/integration/roles/test_ec2_tag/meta/main.yml b/test/integration/roles/test_ec2_tag/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_tag/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_tag/tasks/main.yml b/test/integration/roles/test_ec2_tag/tasks/main.yml new file mode 100644 index 0000000000..213ca4689e --- /dev/null +++ b/test/integration/roles/test_ec2_tag/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_tag diff --git a/test/integration/roles/test_ec2_tag/vars/main.yml b/test/integration/roles/test_ec2_tag/vars/main.yml new file mode 100644 index 0000000000..c2d0654aef --- /dev/null +++ b/test/integration/roles/test_ec2_tag/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_tag diff --git a/test/integration/roles/test_ec2_vol/defaults/main.yml b/test/integration/roles/test_ec2_vol/defaults/main.yml new file mode 100644 index 0000000000..9e806468b5 --- /dev/null +++ b/test/integration/roles/test_ec2_vol/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_vol diff --git a/test/integration/roles/test_ec2_vol/meta/main.yml b/test/integration/roles/test_ec2_vol/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_vol/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_vol/tasks/main.yml b/test/integration/roles/test_ec2_vol/tasks/main.yml new file mode 100644 index 0000000000..0f0d046bf5 --- /dev/null +++ b/test/integration/roles/test_ec2_vol/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_vol diff --git a/test/integration/roles/test_ec2_vol/vars/main.yml b/test/integration/roles/test_ec2_vol/vars/main.yml new file mode 100644 index 0000000000..362fe8115c --- /dev/null +++ b/test/integration/roles/test_ec2_vol/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_vol diff --git a/test/integration/roles/test_ec2_vpc/defaults/main.yml b/test/integration/roles/test_ec2_vpc/defaults/main.yml new file mode 100644 index 0000000000..4487c4a8d8 --- /dev/null +++ b/test/integration/roles/test_ec2_vpc/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test_ec2_vpc diff --git a/test/integration/roles/test_ec2_vpc/meta/main.yml b/test/integration/roles/test_ec2_vpc/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_ec2_vpc/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_ec2_vpc/tasks/main.yml b/test/integration/roles/test_ec2_vpc/tasks/main.yml new file mode 100644 index 0000000000..28cad8e522 --- /dev/null +++ b/test/integration/roles/test_ec2_vpc/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for test_ec2_vpc diff --git a/test/integration/roles/test_ec2_vpc/vars/main.yml b/test/integration/roles/test_ec2_vpc/vars/main.yml new file mode 100644 index 0000000000..e0fe3ae8e4 --- /dev/null +++ b/test/integration/roles/test_ec2_vpc/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_vpc