diff --git a/test/integration/cleanup_gce.py b/test/integration/cleanup_gce.py index 9b1645e93e..58b74ca324 100644 --- a/test/integration/cleanup_gce.py +++ b/test/integration/cleanup_gce.py @@ -98,5 +98,7 @@ if __name__ == '__main__': try: # Delete matching instances delete_gce_resources(gce.list_nodes, 'name', opts) + # Delete matching disks + delete_gce_resources(gce.list_volumes, 'name', opts) except KeyboardInterrupt, e: print "\nExiting on user command." diff --git a/test/integration/gce.yml b/test/integration/gce.yml index 75287abab1..6e314315c5 100644 --- a/test/integration/gce.yml +++ b/test/integration/gce.yml @@ -2,4 +2,5 @@ gather_facts: true roles: - { role: test_gce, tags: test_gce } - # TODO: tests for gce_net, gce_pd, etc. + - { role: test_gce_pd, tags: test_gce_pd } + # TODO: tests for gce_lb, gce_net, gc_storage diff --git a/test/integration/roles/test_gce_pd/defaults/main.yml b/test/integration/roles/test_gce_pd/defaults/main.yml new file mode 100644 index 0000000000..1564808d79 --- /dev/null +++ b/test/integration/roles/test_gce_pd/defaults/main.yml @@ -0,0 +1,6 @@ +--- +# defaults file for test_gce +instance_name: "{{ resource_prefix|lower }}" +service_account_email: "{{ gce_service_account_email }}" +pem_file: "{{ gce_pem_file }}" +project_id: "{{ gce_project_id }}" diff --git a/test/integration/roles/test_gce_pd/tasks/main.yml b/test/integration/roles/test_gce_pd/tasks/main.yml new file mode 100644 index 0000000000..e7c7f15fbe --- /dev/null +++ b/test/integration/roles/test_gce_pd/tasks/main.yml @@ -0,0 +1,126 @@ +# TODO: need tests for read/write mode. + +# ============================================================ +- name: test missing name + gce_pd: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + 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 state=present (expected changed=true) + gce_pd: + name: "{{ instance_name }}" + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + state: present + register: result + +- name: assert state=present (expected changed=true) + assert: + that: + - 'result.changed' + - 'result.name == "{{ instance_name }}"' + - 'result.size_gb == 10' # default size + - 'result.zone == "us-central1-b"' # default zone + - 'result.state == "present"' + +# ============================================================ +- name: test state=present (expected changed=false) + gce_pd: + name: "{{ instance_name }}" + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + state: present + register: result + +- name: assert state=present (expected changed=false) + assert: + that: + - 'not result.changed' + - 'result.name == "{{ instance_name }}"' + - 'result.state == "present"' + +# ============================================================ +- name: test state=absent (expected changed=true) + gce_pd: + name: "{{ instance_name }}" + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + state: absent + register: result + +- name: assert state=absent (expected changed=true) + assert: + that: + - 'result.changed' + - 'result.name == "{{ instance_name }}"' + - 'result.state == "absent"' + +# ============================================================ +- name: test state=absent (expected changed=false) + gce_pd: + name: "{{ instance_name }}" + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + state: absent + register: result + +- name: assert state=absent (expected changed=false) + assert: + that: + - 'not result.changed' + - 'result.name == "{{ instance_name }}"' + - 'result.state == "absent"' + +# ============================================================ +- name: test non-default size/zone + gce_pd: + name: "{{ instance_name }}" + size_gb: 5 + zone: us-central1-a + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + state: present + register: result + +- name: assert non-default size/zone + assert: + that: + - 'result.changed' + - 'result.name == "{{ instance_name }}"' + - 'result.size_gb == 5' + - 'result.zone == "us-central1-a"' + - 'result.state == "present"' + +# ============================================================ +- name: test non-default size/zone (state=absent) + gce_pd: + name: "{{ instance_name }}" + size_gb: 5 + zone: us-central1-a + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + state: absent + register: result + +- name: assert non-default size/zone (state=absent) + assert: + that: + - 'result.changed' + - 'result.name == "{{ instance_name }}"' + - 'result.state == "absent"'