From 157f6319412dc3ea51b04d129741ebb3e3f7b61e Mon Sep 17 00:00:00 2001 From: Allen Sanabria Date: Mon, 28 Mar 2016 20:38:52 -0700 Subject: [PATCH 1/2] Updated module to be compliant with test cases. * Added integration tests * Added unit tests Originally from ansible/ansible-modules-extras@ee523be26c3d4677f0393dc9976ecd1778098324 --- test/integrations/group_vars/all.yml | 1 + .../roles/ec2_vpc_nat_gateway/tasks/main.yml | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/integrations/group_vars/all.yml create mode 100644 test/integrations/roles/ec2_vpc_nat_gateway/tasks/main.yml diff --git a/test/integrations/group_vars/all.yml b/test/integrations/group_vars/all.yml new file mode 100644 index 00000000000..8a3ccba7168 --- /dev/null +++ b/test/integrations/group_vars/all.yml @@ -0,0 +1 @@ +test_subnet_id: 'subnet-123456789' diff --git a/test/integrations/roles/ec2_vpc_nat_gateway/tasks/main.yml b/test/integrations/roles/ec2_vpc_nat_gateway/tasks/main.yml new file mode 100644 index 00000000000..f5ad5f50fc8 --- /dev/null +++ b/test/integrations/roles/ec2_vpc_nat_gateway/tasks/main.yml @@ -0,0 +1,76 @@ +- name: Launching NAT Gateway and allocate a new eip. + ec2_vpc_nat_gateway: + region: us-west-2 + state: present + subnet_id: "{{ test_subnet_id }}" + wait: yes + wait_timeout: 600 + register: nat + +- debug: + var: nat +- fail: + msg: "Failed to create" + when: '"{{ nat["changed"] }}" != "True"' + +- name: Launch a new gateway only if one does not exist already in this subnet. + ec2_vpc_nat_gateway: + if_exist_do_not_create: yes + region: us-west-2 + state: present + subnet_id: "{{ test_subnet_id }}" + wait: yes + wait_timeout: 600 + register: nat_idempotent + +- debug: + var: nat_idempotent +- fail: + msg: "Failed to be idempotent" + when: '"{{ nat_idempotent["changed"] }}" == "True"' + +- name: Launching NAT Gateway and allocate a new eip even if one already exists in the subnet. + ec2_vpc_nat_gateway: + region: us-west-2 + state: present + subnet_id: "{{ test_subnet_id }}" + wait: yes + wait_timeout: 600 + register: new_nat + +- debug: + var: new_nat +- fail: + msg: "Failed to create" + when: '"{{ new_nat["changed"] }}" != "True"' + +- name: Launching NAT Gateway with allocation id, this call is idempotent and will not create anything. + ec2_vpc_nat_gateway: + allocation_id: eipalloc-1234567 + region: us-west-2 + state: present + subnet_id: "{{ test_subnet_id }}" + wait: yes + wait_timeout: 600 + register: nat_with_eipalloc + +- debug: + var: nat_with_eipalloc +- fail: + msg: 'Failed to be idempotent.' + when: '"{{ nat_with_eipalloc["changed"] }}" == "True"' + +- name: Delete the 1st nat gateway and do not wait for it to finish + ec2_vpc_nat_gateway: + region: us-west-2 + nat_gateway_id: "{{ nat.nat_gateway_id }}" + state: absent + +- name: Delete the nat_with_eipalloc and release the eip + ec2_vpc_nat_gateway: + region: us-west-2 + nat_gateway_id: "{{ new_nat.nat_gateway_id }}" + release_eip: yes + state: absent + wait: yes + wait_timeout: 600 From 86c5eddb05d6623bc87f46ef56de89b599482911 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Mon, 31 Oct 2016 14:07:05 -0700 Subject: [PATCH 2/2] Move ec2_vpc_nat_gateway integration test role. --- test/integration/amazon.yml | 1 + .../roles/test_ec2_vpc_nat_gateway}/tasks/main.yml | 0 .../roles/test_ec2_vpc_nat_gateway/vars/main.yml} | 0 3 files changed, 1 insertion(+) rename test/{integrations/roles/ec2_vpc_nat_gateway => integration/roles/test_ec2_vpc_nat_gateway}/tasks/main.yml (100%) rename test/{integrations/group_vars/all.yml => integration/roles/test_ec2_vpc_nat_gateway/vars/main.yml} (100%) diff --git a/test/integration/amazon.yml b/test/integration/amazon.yml index c0fea475c92..a8931adf012 100644 --- a/test/integration/amazon.yml +++ b/test/integration/amazon.yml @@ -12,6 +12,7 @@ #- { role: test_ec2_ami, tags: test_ec2_ami } #- { role: test_ec2, tags: test_ec2 } - { role: test_ec2_asg, tags: test_ec2_asg } + - { role: test_ec2_vpc_nat_gateway, tags: test_ec2_vpc_nat_gateway } # complex test for ec2_elb, split up over multiple plays # since there is a setup component as well as the test which diff --git a/test/integrations/roles/ec2_vpc_nat_gateway/tasks/main.yml b/test/integration/roles/test_ec2_vpc_nat_gateway/tasks/main.yml similarity index 100% rename from test/integrations/roles/ec2_vpc_nat_gateway/tasks/main.yml rename to test/integration/roles/test_ec2_vpc_nat_gateway/tasks/main.yml diff --git a/test/integrations/group_vars/all.yml b/test/integration/roles/test_ec2_vpc_nat_gateway/vars/main.yml similarity index 100% rename from test/integrations/group_vars/all.yml rename to test/integration/roles/test_ec2_vpc_nat_gateway/vars/main.yml