From 97a1b7ded15132fc5ae95186eaebb2149df600e5 Mon Sep 17 00:00:00 2001 From: Tom Melendez Date: Thu, 22 Sep 2016 11:40:57 -0700 Subject: [PATCH] Integration Playbook for Google Cloud DNS module. (#17698) --- test/integration/gce.yml | 1 + test/integration/gce_credentials.py | 2 +- .../roles/test_gcdns/defaults/main.yml | 7 + .../roles/test_gcdns/tasks/main.yml | 471 ++++++++++++++++++ .../roles/test_gce_mig/defaults/main.yml | 2 +- 5 files changed, 481 insertions(+), 2 deletions(-) create mode 100644 test/integration/roles/test_gcdns/defaults/main.yml create mode 100644 test/integration/roles/test_gcdns/tasks/main.yml diff --git a/test/integration/gce.yml b/test/integration/gce.yml index 7fde28d8f87..e54074ef328 100644 --- a/test/integration/gce.yml +++ b/test/integration/gce.yml @@ -4,4 +4,5 @@ - { role: test_gce, tags: test_gce } - { role: test_gce_pd, tags: test_gce_pd } - { role: test_gce_mig, tags: test_gce_mig } + - { role: test_gcdns, tags: test_gcdns } # TODO: tests for gce_lb, gce_net, gc_storage diff --git a/test/integration/gce_credentials.py b/test/integration/gce_credentials.py index 805c66fa992..526fe2bc540 100644 --- a/test/integration/gce_credentials.py +++ b/test/integration/gce_credentials.py @@ -23,7 +23,7 @@ def add_credentials_options(parser): credentials = yaml.load(open('credentials.yml', 'r')) default_service_account_email = credentials[ 'gce_service_account_email'] - default_pem_file = credentials['gce_credentials_file'] + default_pem_file = credentials['gce_pem_file'] default_project_id = credentials['gce_project_id'] parser.add_option( diff --git a/test/integration/roles/test_gcdns/defaults/main.yml b/test/integration/roles/test_gcdns/defaults/main.yml new file mode 100644 index 00000000000..86270b5d677 --- /dev/null +++ b/test/integration/roles/test_gcdns/defaults/main.yml @@ -0,0 +1,7 @@ +--- +# defaults file for test_gcdns +dnszone_name: "{{ resource_prefix|lower }}.com." +dnszone_id: "{{ resource_prefix|lower }}-com" +service_account_email: "{{ gce_service_account_email }}" +pem_file: "{{ gce_pem_file }}" +project_id: "{{ gce_project_id }}" diff --git a/test/integration/roles/test_gcdns/tasks/main.yml b/test/integration/roles/test_gcdns/tasks/main.yml new file mode 100644 index 00000000000..4a1b53507a2 --- /dev/null +++ b/test/integration/roles/test_gcdns/tasks/main.yml @@ -0,0 +1,471 @@ +# gcdns Integration Test Playbook +# ============================================================ +- name: Creating a zone without parameters + gcdns_zone: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + register: result + ignore_errors: true + tags: + - param-check +- name: Assert created a zone without parameters + assert: + that: + - 'result.changed == False' + - 'result.msg == "missing required arguments: zone"' +# ============================================================ +- name: Creating a zone with a description + gcdns_zone: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + description: "This is an awesome zone" + register: result + tags: + - zone +- name: Assert created a zone with a description + assert: + that: + - 'result.changed' + - 'result.zone == "{{ dnszone_name }}"' + - 'result.description == "This is an awesome zone"' + +# ============================================================ +- name: Create an A record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + record: "www1.{{ dnszone_name }}" + type: A + value: '1.2.3.4' + register: result + tags: + - A + - record +- name: Assert creation of an A record + assert: + that: + - 'result.changed' + - 'result.ttl == 300' + - 'result.type == "A"' + - 'result.record == "www1.{{ dnszone_name }}"' + - 'result.record_data|length == 1' + - 'result.record_data[0] == "1.2.3.4"' + +# ============================================================ +- name: Overwrite an A record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + record: "www1.{{ dnszone_name }}" + type: A + value: '5.6.7.8' + overwrite: true + register: result + tags: + - A + - record +- name: Assert overwrite of an A record + assert: + that: + - 'result.changed' + - 'result.ttl == 300' + - 'result.type == "A"' + - 'result.record == "www1.{{ dnszone_name }}"' + - 'result.record_data|length == 1' + - 'result.record_data[0] == "5.6.7.8"' + +# ============================================================ +- name: Create a CNAME record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "www2.{{ dnszone_name }}" + type: CNAME + value: "www.{{ dnszone_name }}" + register: result + tags: + - CNAME + - record +- name: Assert creation of CNAME record + assert: + that: + - 'result.changed' + - 'result.type == "CNAME"' + - 'result.zone_id == "{{ dnszone_id }}"' + - 'result.record == "www2.{{ dnszone_name }}"' + - 'result.record_data[0] == "www.{{ dnszone_name }}"' + +# ============================================================ +- name: Create an MX record with a custom TTL + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "{{ dnszone_name }}" + type: MX + ttl: 3600 + value: "10 mail.{{ dnszone_name }}" + register: result + tags: + - MX + - record +- name: Assert creation of MX record + assert: + that: + - 'result.changed' + - 'result.type == "MX"' + - 'result.zone_id == "{{ dnszone_id }}"' + - 'result.record_data[0] == "10 mail.{{ dnszone_name }}"' + +# ============================================================ +- name: Create multiple A records with the same name + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "{{ dnszone_name }}" + type: A + record_data: + - '192.0.2.23' + - '10.4.5.6' + - '198.51.100.5' + - '203.0.113.10' + register: result + tags: + - multi-A + - record +- name: Assert creation of multiple A records with the same name + assert: + that: + - 'result.changed' + - 'result.zone == "{{ dnszone_name }}"' + - 'result.record == "{{ dnszone_name }}"' + - 'result.record_data|length == 4' + +# ============================================================ +- name: Change the value of an existing record with multiple values + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "{{ dnszone_name }}" + type: A + record_data: + - '192.0.2.23' + - '192.0.2.42' + - '198.51.100.5' + - '203.0.113.10' + overwrite: true + register: result + tags: + - multi-A + - record + +- name: Assert + assert: + that: + - 'result.changed' + - 'result.record_data|length == 4' + +# ============================================================ +- name: Create an AAAA record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + record: "www1.{{ dnszone_name }}" + type: AAAA + value: "fd00:db8::1" + register: result + tags: + - AAAA + - record +- name: Assert creation of AAAA record + assert: + that: + - 'result.changed' + - 'result.type == "AAAA"' + - 'result.zone == "{{ dnszone_name }}"' + - 'result.zone_id == "{{ dnszone_id }}"' + - 'result.record == "www1.{{ dnszone_name }}"' + - 'result.record_data[0] == "fd00:db8::1"' + +# ============================================================ +- name: Create a PTR record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + record: "{{ dnszone_name }}" + type: PTR + value: "10.5.168.192.{{ dnszone_name }}arpa." + register: result + tags: + - PTR + - record +- name: Assert creation of PTR record + assert: + that: + - 'result.changed' + - 'result.record_data[0] == "10.5.168.192.{{ dnszone_name }}arpa."' + +# ============================================================ +- name: Create an NS record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + record: "subdomain.{{ dnszone_name }}" + type: NS + ttl: 21600 + record_data: + - 'ns-cloud-d1.googledomains.com.' + - 'ns-cloud-d2.googledomains.com.' + - 'ns-cloud-d3.googledomains.com.' + - 'ns-cloud-d4.googledomains.com.' + register: result + tags: + - NS + - record +- name: Assert creation of NS record + assert: + that: + - 'result.changed' + - 'result.record_data|length == 4' + - 'result.ttl == 21600' + - 'result.type == "NS"' +# ============================================================ +- name: Create a TXT record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "{{ dnszone_name }}" + type: TXT + record_data: + - '"v=spf1 include:_spf.google.com -all"' + - '"hello " "world"' + register: result + tags: + - TXT + - record +- name: Assert creation of TXT record + assert: + that: + - 'result.changed' + - 'result.zone_id == "{{ dnszone_id }}"' + - 'result.record_data|length == 2' + +# ============================================================ +- name: Remove an A record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + record: "www1.{{ dnszone_name }}" + type: A + value: "5.6.7.8" + state: absent + register: result + tags: + - A + - record +- name: Assert removal of A record + assert: + that: + - 'result.changed' + - 'result.state == "absent"' +# ============================================================ +- name: Remove a CNAME record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "www2.{{ dnszone_name }}" + type: CNAME + value: "www.{{ dnszone_name }}" + state: absent + register: result + tags: + - CNAME + - record +- name: Assert removal of CNAME record + assert: + that: + - 'result.changed' + - 'result.state == "absent"' + +# ============================================================ +- name: Remove an MX record with a custom TTL. + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "{{ dnszone_name }}" + type: MX + ttl: 3600 + value: "10 mail.{{ dnszone_name }}" + state: absent + register: result + tags: + - MX + - record +- name: Assert removal of MX record + assert: + that: + - 'result.changed' + - 'result.state == "absent"' + +# ============================================================ +- name: Remove multiple A records with the same name. + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone_id: "{{ dnszone_id }}" + record: "{{ dnszone_name }}" + type: A + record_data: + - '192.0.2.23' + - '192.0.2.42' + - '198.51.100.5' + - '203.0.113.10' + state: absent + register: result + tags: + - multi-A + - record +- name: Assert + assert: + that: + - 'result.changed' + - 'result.state == "absent"' + + +# ============================================================ +- name: Remove an AAAA record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + record: "www1.{{ dnszone_name }}" + zone: "{{ dnszone_name }}" + type: AAAA + value: 'fd00:db8::1' + state: absent + register: result + tags: + - AAAA + - record +- name: Assert + assert: + that: + - 'result.changed' + - 'result.state == "absent"' + +# ============================================================ +- name: Remove a PTR record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + record: "{{ dnszone_name }}" + zone: "{{ dnszone_name }}" + type: PTR + value: "10.5.168.192.{{ dnszone_name }}arpa." + state: absent + register: result + tags: + - PTR + - record +- name: Assert remove a PTR record + assert: + that: + - 'result.changed' + - 'result.state == "absent"' + +# ============================================================ +- name: Remove an NS record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + record: "subdomain.{{ dnszone_name }}" + type: NS + ttl: 21600 + record_data: + - 'ns-cloud-d1.googledomains.com.' + - 'ns-cloud-d2.googledomains.com.' + - 'ns-cloud-d3.googledomains.com.' + - 'ns-cloud-d4.googledomains.com.' + state: absent + register: result + tags: + - NS + - record +- name: Assert removal of NS record + assert: + that: + - 'result.changed' + - 'result.state == "absent"' +# ============================================================ +- name: Remove a TXT record + gcdns_record: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + record: '{{ dnszone_name }}' + zone_id: "{{ dnszone_id }}" + type: TXT + record_data: + - '"v=spf1 include:_spf.google.com -all"' + - '"hello " "world"' + state: absent + register: result + tags: + - TXT + - record +- name: Assert removed TXT record + assert: + that: + - 'result.changed' + - 'result.state == "absent"' + - 'result.record_data|length == 2' + +# ============================================================ +- name: Remove the zone + gcdns_zone: + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" + project_id: "{{ project_id }}" + zone: "{{ dnszone_name }}" + state: absent + register: result + ignore_errors: true + tags: + - zone +- name: Assert removal of zone + assert: + that: + - 'result.changed' + - 'result.state == "absent"' diff --git a/test/integration/roles/test_gce_mig/defaults/main.yml b/test/integration/roles/test_gce_mig/defaults/main.yml index 1fa8050435e..fa20478af70 100644 --- a/test/integration/roles/test_gce_mig/defaults/main.yml +++ b/test/integration/roles/test_gce_mig/defaults/main.yml @@ -2,7 +2,7 @@ # defaults file for test_gce_mig mig_name: "{{ resource_prefix|lower }}" service_account_email: "{{ gce_service_account_email }}" -pem_file: "{{ gce_credentials_file }}" +pem_file: "{{ gce_pem_file }}" project_id: "{{ gce_project_id }}" zone: "us-central1-c" instance_template_name: "my-instance-template-1"