From 9bcb68012919e3d42ef046051d09c4146c12fea0 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Wed, 15 Jul 2020 15:58:33 +0200 Subject: [PATCH 1/2] enable tests --- .github/workflows/integration.yml | 118 +++--- plugins/modules/exo_dns_domain.py | 2 +- plugins/modules/exo_dns_record.py | 2 +- tests/legacy/exoscale.yml | 6 + .../roles/test_exoscale_dns/defaults/main.yml | 4 + .../roles/test_exoscale_dns/tasks/main.yml | 347 ++++++++++++++++++ 6 files changed, 418 insertions(+), 61 deletions(-) create mode 100644 tests/legacy/exoscale.yml create mode 100644 tests/legacy/roles/test_exoscale_dns/defaults/main.yml create mode 100644 tests/legacy/roles/test_exoscale_dns/tasks/main.yml diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index d8e6feb..b0b1461 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -17,9 +17,9 @@ jobs: runner-os: - ubuntu-latest ansible-version: - - git+https://github.com/ansible/ansible.git@devel + - devel runner-python-version: - - 3.8 + - 3.6 steps: - uses: actions/checkout@v1 - name: Set up Python ${{ matrix.runner-python-version }} @@ -37,7 +37,7 @@ jobs: pip install --user - ${{ matrix.ansible-version }} + https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz - name: Build a collection tarball run: >- ~/.local/bin/ansible-galaxy @@ -52,59 +52,59 @@ jobs: collection path: .cache/collection-tarballs - # sanity-test-collection-via-containers: - # name: Sanity in container via Python ${{ matrix.python-version }} - # needs: - # - build-collection-artifact - # runs-on: ${{ matrix.runner-os }} - # strategy: - # fail-fast: false - # matrix: - # runner-os: - # - ubuntu-latest - # runner-python-version: - # - 3.6 - # ansible-version: - # - git+https://github.com/ansible/ansible.git@devel - # steps: - # - name: Set up Python ${{ matrix.runner-python-version }} - # uses: actions/setup-python@v1 - # with: - # python-version: ${{ matrix.runner-python-version }} - # - name: Set up pip cache - # uses: actions/cache@v1 - # with: - # path: ~/.cache/pip - # key: ${{ runner.os }}-pip-${{ github.ref }}-sanity-containers - # restore-keys: | - # ${{ runner.os }}-pip- - # ${{ runner.os }}- - # - name: Install Ansible ${{ matrix.ansible-version }} - # run: >- - # python -m - # pip - # install - # --user - # ${{ matrix.ansible-version }} - # - name: Download migrated collection artifacts - # uses: actions/download-artifact@v1 - # with: - # name: >- - # collection - # path: .cache/collection-tarballs - # - name: Install the collection tarball - # run: >- - # ~/.local/bin/ansible-galaxy - # collection - # install - # .cache/collection-tarballs/*.tar.gz - # - name: Run collection sanity tests - # run: >- - # ~/.local/bin/ansible-test - # sanity - # --color - # --requirements - # --docker - # -vvv - # working-directory: >- - # /home/runner/.ansible/collections/ansible_collections/ngine_io/exoscale + sanity-test-collection-via-containers: + name: Sanity in container via Python ${{ matrix.python-version }} + needs: + - build-collection-artifact + runs-on: ${{ matrix.runner-os }} + strategy: + fail-fast: false + matrix: + runner-os: + - ubuntu-latest + runner-python-version: + - 3.6 + ansible-version: + - devel + steps: + - name: Set up Python ${{ matrix.runner-python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.runner-python-version }} + - name: Set up pip cache + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ github.ref }}-sanity-containers + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install Ansible ${{ matrix.ansible-version }} + run: >- + python -m + pip + install + --user + https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz + - name: Download migrated collection artifacts + uses: actions/download-artifact@v1 + with: + name: >- + collection + path: .cache/collection-tarballs + - name: Install the collection tarball + run: >- + ~/.local/bin/ansible-galaxy + collection + install + .cache/collection-tarballs/*.tar.gz + - name: Run collection sanity tests + run: >- + ~/.local/bin/ansible-test + sanity + --color + --requirements + --docker + -vvv + working-directory: >- + /home/runner/.ansible/collections/ansible_collections/ngine_io/exoscale diff --git a/plugins/modules/exo_dns_domain.py b/plugins/modules/exo_dns_domain.py index 7cbe064..334c5c0 100644 --- a/plugins/modules/exo_dns_domain.py +++ b/plugins/modules/exo_dns_domain.py @@ -15,7 +15,7 @@ description: - Create and remove domain records. author: "René Moser (@resmo)" -version_added: "1.0.0" +version_added: "0.1.0" options: name: description: diff --git a/plugins/modules/exo_dns_record.py b/plugins/modules/exo_dns_record.py index 7011f2c..8da3491 100644 --- a/plugins/modules/exo_dns_record.py +++ b/plugins/modules/exo_dns_record.py @@ -15,7 +15,7 @@ description: - Create, update and delete records. author: "René Moser (@resmo)" -version_added: "1.0.0" +version_added: "0.1.0" options: name: description: diff --git a/tests/legacy/exoscale.yml b/tests/legacy/exoscale.yml new file mode 100644 index 0000000..dbe5bb1 --- /dev/null +++ b/tests/legacy/exoscale.yml @@ -0,0 +1,6 @@ +--- +- hosts: localhost + gather_facts: no + roles: + - role: test_exoscale_dns + tags: test_exoscale_dns diff --git a/tests/legacy/roles/test_exoscale_dns/defaults/main.yml b/tests/legacy/roles/test_exoscale_dns/defaults/main.yml new file mode 100644 index 0000000..a98c869 --- /dev/null +++ b/tests/legacy/roles/test_exoscale_dns/defaults/main.yml @@ -0,0 +1,4 @@ +--- +exo_dns_domain_name: example.com +exo_dns_record_name_web: web +exo_dns_record_name_mx: mx diff --git a/tests/legacy/roles/test_exoscale_dns/tasks/main.yml b/tests/legacy/roles/test_exoscale_dns/tasks/main.yml new file mode 100644 index 0000000..1b0ecb6 --- /dev/null +++ b/tests/legacy/roles/test_exoscale_dns/tasks/main.yml @@ -0,0 +1,347 @@ +--- +- name: setup + ngine_io.exoscale.exo_dns_domain: + name: "{{ exo_dns_domain_name }}" + state: absent + register: result +- name: verify setup + assert: + that: + - result is successful + +- name: test fail if missing name + ngine_io.exoscale.exo_dns_domain: + register: result + ignore_errors: true +- name: verify results of fail if missing params + assert: + that: + - result is failed + - 'result.msg == "missing required arguments: name"' + +- name: test create a domain + ngine_io.exoscale.exo_dns_domain: + name: "{{ exo_dns_domain_name }}" + register: result +- name: verify results of test create a domain + assert: + that: + - result is changed + - 'result.exo_dns_domain.name == "{{ exo_dns_domain_name }}"' + +- name: test create a domain idempotence + ngine_io.exoscale.exo_dns_domain: + name: "{{ exo_dns_domain_name }}" + register: result +- name: verify results of test create a domain idempotence + assert: + that: + - result is not changed + - 'result.exo_dns_domain.name == "{{ exo_dns_domain_name }}"' + +- name: test fail if missing required params + ngine_io.exoscale.exo_dns_record: + register: result + ignore_errors: true +- name: verify results of test fail if missing required params + assert: + that: + - result is failed + - 'result.msg == "missing required arguments: domain"' + +- name: test fail if missing required params state=present + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "" + register: result + ignore_errors: true +- name: verify results of test fail if missing required params state=present + assert: + that: + - result is failed + - 'result.msg == "state is present but all of the following are missing: content"' + +- name: test create a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + content: 1.2.3.4 + register: result +- name: verify results of test create a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.4"' + +- name: test create a record idempotence + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + content: 1.2.3.4 + register: result +- name: verify results of test create a record + assert: + that: + - result is not changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.4"' + +- name: test update a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + content: 1.2.3.5 + ttl: 7200 + register: result +- name: verify results of test update a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.5"' + - 'result.exo_dns_record.ttl == 7200' + +- name: test update a record idempotence + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + content: 1.2.3.5 + ttl: 7200 + register: result +- name: verify results of test update a record idempotence + assert: + that: + - result is not changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.5"' + - 'result.exo_dns_record.ttl == 7200' + +- name: test delete a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + state: absent + register: result +- name: verify results of test create a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.5"' + - 'result.exo_dns_record.ttl == 7200' + +- name: test delete a record idempotence + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + state: absent + register: result +- name: verify results of test create a record idempotence + assert: + that: + - result is not changed + +- name: setup an existing MX record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + record_type: MX + name: "" + content: "mx2.{{ exo_dns_domain_name }}" + prio: 10 + register: result +- name: verify results of test create a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == ""' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "mx2.{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.prio == 10' + +- name: test create a MX record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + record_type: MX + name: "" + content: "mx1.{{ exo_dns_domain_name }}" + prio: 10 + register: result +- name: verify results of test create a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == ""' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "mx1.{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.prio == 10' + +- name: test update a MX record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + record_type: MX + name: "" + content: "mx1.{{ exo_dns_domain_name }}" + prio: 20 + tags: foo + register: result +- name: verify results of test create a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == ""' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "mx1.{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.prio == 20' + tags: foo + +- name: test delete a MX record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + record_type: MX + name: "" + content: "mx1.{{ exo_dns_domain_name }}" + state: absent + register: result +- name: verify results of test delete a MX record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == ""' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "mx1.{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.prio == 20' + +- name: test delete a MX record idempotence + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + record_type: MX + name: "" + content: "mx1.{{ exo_dns_domain_name }}" + state: absent + register: result +- name: verify results of test delete a MX record idempotence + assert: + that: + - result is not changed + +- name: test create first multiple a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + multiple: yes + content: 1.2.3.4 + register: result +- name: verify results of test create first multiple a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.4"' + +- name: test create another similar a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + multiple: yes + content: 1.2.3.5 + register: result +- name: verify results of test create another similar a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.5"' + - 'result.exo_dns_record.ttl == 3600' + +- name: test update another similar a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + multiple: yes + content: 1.2.3.5 + ttl: 7200 + register: result +- name: verify results of test create another similar a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.5"' + - 'result.exo_dns_record.ttl == 7200' + +- name: test create first multiple a record idempotence + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + multiple: yes + content: 1.2.3.4 + register: result +- name: verify results of test create first multiple a record idempotence + assert: + that: + - result is not changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.4"' + +- name: test delete similar a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + multiple: yes + content: 1.2.3.5 + state: absent + register: result +- name: verify results of test delete similar a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.5"' + +- name: test delete first similar a record + ngine_io.exoscale.exo_dns_record: + domain: "{{ exo_dns_domain_name }}" + name: "{{ exo_dns_record_name_web }}" + multiple: yes + content: 1.2.3.4 + state: absent + register: result +- name: verify results of test delete first similar a record + assert: + that: + - result is changed + - 'result.exo_dns_record.name == "{{ exo_dns_record_name_web }}"' + - 'result.exo_dns_record.domain == "{{ exo_dns_domain_name }}"' + - 'result.exo_dns_record.content == "1.2.3.4"' + +- name: test delete a domain + ngine_io.exoscale.exo_dns_domain: + name: "{{ exo_dns_domain_name }}" + state: absent + register: result +- name: verify results of test delete a domain + assert: + that: + - result is changed + - 'result.exo_dns_domain.name == "{{ exo_dns_domain_name }}"' + +- name: test delete a domain idempotence + ngine_io.exoscale.exo_dns_domain: + name: "{{ exo_dns_domain_name }}" + state: absent + register: result +- name: verify results of test delete a domain idempotence + assert: + that: + - result is not changed From c5a6244659385bcd473fcbce9339f6b6072708eb Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Wed, 15 Jul 2020 16:12:35 +0200 Subject: [PATCH 2/2] add metaclass and future-import boilerplates --- plugins/module_utils/exoscale.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/module_utils/exoscale.py b/plugins/module_utils/exoscale.py index 2ba83f4..44933b1 100644 --- a/plugins/module_utils/exoscale.py +++ b/plugins/module_utils/exoscale.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Copyright (c) 2016, René Moser # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +from __future__ import absolute_import, division, print_function +__metaclass__ = type import os