Skip to content

Commit

Permalink
Add test-deps to integration test workflow (#343)
Browse files Browse the repository at this point in the history
* Add test-deps to integration test workflow
  • Loading branch information
mamercad authored Jan 4, 2024
1 parent 93de533 commit 06e6529
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 206 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ansible-test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ jobs:
target: ${{ matrix.module }}
target-python-version: ${{ matrix.versions.python }}
testing-type: integration
test-deps: >-
ansible.netcommon
ansible.utils
community.general
4 changes: 4 additions & 0 deletions .github/workflows/pull-request-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ jobs:
target: ${{ matrix.module }}
target-python-version: ${{ matrix.versions.python }}
testing-type: integration
test-deps: >-
ansible.netcommon
ansible.utils
community.general
2 changes: 2 additions & 0 deletions changelogs/fragments/342-collection-requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- ci - add test-deps to integration test workflows (https://github.com/ansible-collections/community.digitalocean/issues/342).
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ do_region: nyc1
droplet_name: gh-ci-droplet-4-{{ pr_number }}
droplet_image: ubuntu-22-04-x64
droplet_size: s-1vcpu-1gb
snapshot_name: gh-ci-snapshot
snapshot_name: gh-ci-snapshot-4-{{ pr_number }}
volume_name: gh-ci-volume-4-{{ pr_number }}
volume_size: 15
volume_down_size: 10
Expand Down
101 changes: 101 additions & 0 deletions tests/integration/targets/digital_ocean_snapshot/tasks/droplet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
- name: Droplet snapshot block
block:
- name: Ensure Droplet is absent (leftover)
community.digitalocean.digital_ocean_droplet:
oauth_token: "{{ do_api_key }}"
state: absent
name: "{{ droplet_name }}"
unique_name: true
region: "{{ do_region }}"
image: "{{ droplet_image }}"
size: "{{ droplet_size }}"
ignore_errors: true # In case one was left from previous run
register: droplet_cleanup

- name: Give the cloud a minute to settle
when: droplet_cleanup is changed
ansible.builtin.pause:
minutes: 1

- name: Create the Droplet
community.digitalocean.digital_ocean_droplet:
oauth_token: "{{ do_api_key }}"
state: active
name: "{{ droplet_name }}"
unique_name: true
region: "{{ do_region }}"
image: "{{ droplet_image }}"
size: "{{ droplet_size }}"
wait_timeout: 500
register: result

- name: Verify Droplet is present
ansible.builtin.assert:
that:
- result.changed
- result.data is defined
- result.data.droplet is defined
- result.data.droplet.name is defined
- result.data.droplet.name == droplet_name
- result.data.droplet.status in ["new", "active", "available"]

- name: Set a fact for the Droplet id
ansible.builtin.set_fact:
droplet_id: "{{ result.data.droplet.id }}"

- name: Snapshot the Droplet
community.digitalocean.digital_ocean_snapshot:
state: present
snapshot_type: droplet
snapshot_name: "{{ snapshot_name }}"
droplet_id: "{{ droplet_id }}"
oauth_token: "{{ do_api_key }}"
wait_timeout: 500
register: result

- name: Verify snapshot is present
ansible.builtin.assert:
that:
- result.changed
- result.msg is search("Created snapshot")

- name: Gather information about Droplet snapshots
community.digitalocean.digital_ocean_snapshot_info:
snapshot_type: droplet
oauth_token: "{{ do_api_key }}"
register: snapshot_info

- name: Set a fact for the snapshot id
delegate_to: localhost
ansible.builtin.set_fact:
snapshot_id: "{{ item.id }}"
loop: "{{ snapshot_info.data | community.general.json_query(name) }}"
vars:
name: "[?name=='{{ snapshot_name }}']"

- name: Delete the Droplet snapshot
when: snapshot_id is defined
community.digitalocean.digital_ocean_snapshot:
state: absent
snapshot_id: "{{ snapshot_id }}"
oauth_token: "{{ do_api_key }}"
register: result

- name: Verify Droplet snapshot is absent
when: snapshot_id is defined
ansible.builtin.assert:
that:
- result.changed
- result.msg is search("Deleted snapshot")

always:
- name: Delete the Droplet
community.digitalocean.digital_ocean_droplet:
oauth_token: "{{ do_api_key }}"
state: absent
name: "{{ droplet_name }}"
unique_name: true
region: "{{ do_region }}"
image: "{{ droplet_image }}"
size: "{{ droplet_size }}"
ignore_errors: true # Should this fail, we'll clean it up next run
211 changes: 6 additions & 205 deletions tests/integration/targets/digital_ocean_snapshot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,209 +8,10 @@
- do_api_key is not defined
- do_api_key | length == 0

#
# Droplet snapshot
#
- name: Include Droplet snapshot tasks
ansible.builtin.include_tasks:
file: droplet.yml

- name: Ensure Droplet is absent (leftover)
community.digitalocean.digital_ocean_droplet:
oauth_token: "{{ do_api_key }}"
state: absent
name: "{{ droplet_name }}"
unique_name: true
region: "{{ do_region }}"
image: "{{ droplet_image }}"
size: "{{ droplet_size }}"
ignore_errors: true # In case one was left from previous run

- name: Create the Droplet
community.digitalocean.digital_ocean_droplet:
oauth_token: "{{ do_api_key }}"
state: active
name: "{{ droplet_name }}"
unique_name: true
region: "{{ do_region }}"
image: "{{ droplet_image }}"
size: "{{ droplet_size }}"
wait_timeout: 500
register: result

- name: Verify Droplet is present
ansible.builtin.assert:
that:
- result.changed
- result.data is defined
- result.data.droplet is defined
- result.data.droplet.name is defined
- result.data.droplet.name == droplet_name
- result.data.droplet.status in ["new", "active", "available"]

- name: Set a fact for the Droplet id
ansible.builtin.set_fact:
droplet_id: "{{ result.data.droplet.id }}"

- name: Snapshot the Droplet
community.digitalocean.digital_ocean_snapshot:
state: present
snapshot_type: droplet
snapshot_name: "{{ snapshot_name }}"
droplet_id: "{{ droplet_id }}"
oauth_token: "{{ do_api_key }}"
wait_timeout: 500
register: result

- name: Verify snapshot is present
ansible.builtin.assert:
that:
- result.changed
- not result.failed
- result.msg is search("Created snapshot")

- name: Gather information about all snapshots
community.digitalocean.digital_ocean_snapshot_info:
oauth_token: "{{ do_api_key }}"
register: snapshot_info

- name: Set a fact for the snapshot id
ansible.builtin.set_fact:
snapshot_id: "{{ item.id }}"
loop: "{{ snapshot_info.data | community.general.json_query(name) }}"
vars:
name: "[?name=='{{ snapshot_name }}']"

- name: Verify snapshot id is defined
ansible.builtin.assert:
that:
- snapshot_id is defined

- name: Delete the snapshot
community.digitalocean.digital_ocean_snapshot:
state: absent
snapshot_id: "{{ snapshot_id }}"
oauth_token: "{{ do_api_key }}"
register: result

- name: Verify snapshot is absent
ansible.builtin.assert:
that:
- result.changed
- not result.failed
- result.msg is search("Deleted snapshot")

#
# Volume snapshot
#

- name: Ensure volume is absent (leftover)
community.digitalocean.digital_ocean_block_storage:
oauth_token: "{{ do_api_key }}"
command: create
state: absent
volume_name: "{{ volume_name }}"
region: "{{ do_region }}"
block_size: "{{ volume_size }}"
ignore_errors: true # In case one was left from previous run

- name: Create a volume
community.digitalocean.digital_ocean_block_storage:
oauth_token: "{{ do_api_key }}"
command: create
state: present
volume_name: "{{ volume_name }}"
region: "{{ do_region }}"
block_size: "{{ volume_size }}"
register: result

- name: Verify volume is present
ansible.builtin.assert:
that:
- result.changed
- not result.failed

- name: Set a fact for the volume id
ansible.builtin.set_fact:
volume_id: "{{ result.id }}"

- name: Snapshot the volume
community.digitalocean.digital_ocean_snapshot:
state: present
snapshot_type: volume
snapshot_name: "{{ snapshot_name }}"
volume_id: "{{ volume_id }}"
oauth_token: "{{ do_api_key }}"
wait_timeout: 500
register: result

- name: Verify snapshot is present
ansible.builtin.assert:
that:
- result.changed
- not result.failed
- result.msg is search("Created snapshot")

- name: Get information about all snapshots
community.digitalocean.digital_ocean_snapshot_info:
oauth_token: "{{ do_api_key }}"
register: snapshot_info

- name: Set a fact for the snapshot id
ansible.builtin.set_fact:
snapshot_id: "{{ item.id }}"
loop: "{{ snapshot_info.data | community.general.json_query(name) }}"
vars:
name: "[?name=='{{ snapshot_name }}']"

- name: Verify snapshot id is defined
ansible.builtin.assert:
that:
- snapshot_id is defined

- name: Delete the snapshot
community.digitalocean.digital_ocean_snapshot:
state: absent
snapshot_id: "{{ snapshot_id }}"
oauth_token: "{{ do_api_key }}"
register: result

- name: Verify snapshot is absent
ansible.builtin.assert:
that:
- result.changed
- not result.failed
- result.msg is search("Deleted snapshot")

- name: Remove the volume
community.digitalocean.digital_ocean_block_storage:
oauth_token: "{{ do_api_key }}"
command: create
state: absent
volume_name: "{{ volume_name }}"
region: "{{ do_region }}"
register: result

- name: Verify the volume is deleted
ansible.builtin.assert:
that:
- result.changed

always:

- name: Delete the Droplet
community.digitalocean.digital_ocean_droplet:
oauth_token: "{{ do_api_key }}"
state: absent
name: "{{ droplet_name }}"
unique_name: true
region: "{{ do_region }}"
image: "{{ droplet_image }}"
size: "{{ droplet_size }}"
ignore_errors: true # Should this fail, we'll clean it up next run

- name: Remove the volume
community.digitalocean.digital_ocean_block_storage:
oauth_token: "{{ do_api_key }}"
command: create
state: absent
volume_name: "{{ volume_name }}"
region: "{{ do_region }}"
ignore_errors: true # Should this fail, we'll clean it up next run
- name: Include volume snapshot tasks
ansible.builtin.include_tasks:
file: volume.yml
Loading

0 comments on commit 06e6529

Please sign in to comment.