diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:04:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:04:41 +0000 |
commit | 975f66f2eebe9dadba04f275774d4ab83f74cf25 (patch) | |
tree | 89bd26a93aaae6a25749145b7e4bca4a1e75b2be /ansible_collections/community/digitalocean/tests | |
parent | Initial commit. (diff) | |
download | ansible-975f66f2eebe9dadba04f275774d4ab83f74cf25.tar.xz ansible-975f66f2eebe9dadba04f275774d4ab83f74cf25.zip |
Adding upstream version 7.7.0+dfsg.upstream/7.7.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/digitalocean/tests')
125 files changed, 4066 insertions, 0 deletions
diff --git a/ansible_collections/community/digitalocean/tests/integration/integration_config.yml.template b/ansible_collections/community/digitalocean/tests/integration/integration_config.yml.template new file mode 100644 index 000000000..d742bfd2a --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/integration_config.yml.template @@ -0,0 +1,4 @@ +--- +do_api_key: ${DO_API_KEY} +aws_access_key_id: ${AWS_ACCESS_KEY_ID} +aws_secret_access_key: ${AWS_SECRET_ACCESS_KEY} diff --git a/ansible_collections/community/digitalocean/tests/integration/requirements.txt b/ansible_collections/community/digitalocean/tests/integration/requirements.txt new file mode 100644 index 000000000..1a82e9a34 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/requirements.txt @@ -0,0 +1,2 @@ +jmespath +boto3 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_account_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_account_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_account_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_account_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_account_info/tasks/main.yml new file mode 100644 index 000000000..95f7cbf9d --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_account_info/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Query account information + community.digitalocean.digital_ocean_account_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify account information idempotency and format + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data.droplet_limit is defined + - result.data.droplet_limit > 0 + - result.data.email is defined + - result.data.email_verified is defined + - result.data.floating_ip_limit is defined + - result.data.floating_ip_limit > 0 + - result.data.status == "active" + - result.data.status_message is defined + - result.data.uuid is defined + - result.data.volume_limit > 0 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/tasks/main.yml new file mode 100644 index 000000000..669d43b08 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_balance_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather balance information + community.digitalocean.digital_ocean_balance_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify balance info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/defaults/main.yml new file mode 100644 index 000000000..0e52c2cb0 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/defaults/main.yml @@ -0,0 +1,7 @@ +do_region: nyc1 +volume_name: gh-ci-volume +volume_size: 15 +volume_down_size: 10 +volume_up_size: 20 +timeout: 900 +project_name: gh-ci-project diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/tasks/main.yml new file mode 100644 index 000000000..5d24d0627 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_block_storage/tasks/main.yml @@ -0,0 +1,138 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Ensure the volume is absent + 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 volume is absent + ansible.builtin.assert: + that: + - not result.changed + + - 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 + + - name: Resize to same size + 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 resizing to same size is ignored + ansible.builtin.assert: + that: + - not result.changed + + - name: Shrink the 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_down_size }}" + ignore_errors: true + register: result + + - name: Verify shrinking fails + ansible.builtin.assert: + that: + - result.failed + + - name: Grow the 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_up_size }}" + timeout: "{{ timeout }}" + register: result + + - name: Verify growing volume succeeded + ansible.builtin.assert: + that: + - result.changed + + - 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 + + - name: Create a volume (and associate with Project) + 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 }}" + project: "{{ project_name }}" + register: result + + - name: Verify volume is present + ansible.builtin.assert: + that: + - result.changed + - result.assign_status is defined + - result.assign_status == "assigned" + - result.msg is defined + - "'Assigned do:volume' in result.msg" + - result.resources is defined + - result.resources.status is defined + - result.resources.status == "assigned" + + always: + + - 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 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/defaults/main.yml new file mode 100644 index 000000000..17810a67e --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/defaults/main.yml @@ -0,0 +1,2 @@ +endpoint: ansible-gh-ci-space-0.nyc3.cdn.digitaloceanspaces.com +origin: ansible-gh-ci-space-0.nyc3.digitaloceanspaces.com diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/tasks/main.yml new file mode 100644 index 000000000..e1f5af515 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints/tasks/main.yml @@ -0,0 +1,67 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Create DigitalOcean CDN Endpoint + community.digitalocean.digital_ocean_cdn_endpoints: + state: present + oauth_token: "{{ do_api_key }}" + origin: "{{ origin }}" + register: result + + - name: Verify CDN Endpoints created + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.endpoint is defined + - result.data.endpoint.endpoint == endpoint + - result.data.endpoint.origin == origin + - result.data.endpoint.ttl == 3600 + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Update DigitalOcean CDN Endpoint (change ttl to 600, default is 3600) + community.digitalocean.digital_ocean_cdn_endpoints: + state: present + oauth_token: "{{ do_api_key }}" + origin: "{{ origin }}" + ttl: 600 + register: result + + - name: Verify CDN Endpoints updated + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.endpoint is defined + - result.data.endpoint.endpoint == endpoint + - result.data.endpoint.origin == origin + - result.data.endpoint.ttl == 600 + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + always: + + - name: Delete DigitalOcean CDN Endpoint + community.digitalocean.digital_ocean_cdn_endpoints: + state: absent + oauth_token: "{{ do_api_key }}" + origin: "{{ origin }}" + register: result + + - name: Verify CDN Endpoints deleted + ansible.builtin.assert: + that: + - result.changed + - "'Deleted CDN Endpoint' in result.msg " diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/tasks/main.yml new file mode 100644 index 000000000..ff29d7793 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_cdn_endpoints_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather CDN Endpoints information + community.digitalocean.digital_ocean_cdn_endpoints_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify CDN Endpoints fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/defaults/main.yml new file mode 100644 index 000000000..60055b0b9 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/defaults/main.yml @@ -0,0 +1,3 @@ +cert_name: gh-ci-cert +cert_key: "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDurdsTUxVhbokw\nWddnOTsst0GniShyldeEhGZZM8lO1qSedzeIlV/Hx5ja/bPvNGq30FoapGSAOfFS\nutRmrUwJc9M9UmgHXawOMoTkW8t4C2Uexzbys1iUpcZpArvqnFx317KBW41ukXzC\n9SSEtIWJE1FlunuaTV+8pmD+/1yb/3xSMp+NPspMLUo+K77uKgfY3cwooxQx5N8C\n0aEYfM2jwyQUM4QMLGJB3Xy5zwEBL10K7ZSS4Rgs2W5BLYNsgx5lFqIzvUPsdEe6\nXw1yFBXoC/inJosV0UNkS+qUAdd36PDsd79jaOtwfNW7Bbv2QnG6Byhl7E7Rzi8L\nOKsXAmMPAgMBAAECggEAKCI70EgMNFHt559zxPuuo5o9A/rgPkRL9RB+VUmL9CHL\nlInfYKwdau55GXnHo9VgjIAQZqJ188nKdmrMBGfnfT9oqcsNiw+JOunrxqpY0Fq6\nKi69YpodrwEhF89J4e1g7xXqAi5u3cTBAddOyLHCMoZ5DW4KEqwoCQTBEp/F5sT/\n6YsYEeLD6qUi8h66XXY4eLS+VHKWv1Eqms09OMJBrxj3Q9jrlmqX+ZDPE/hnkdKM\nPLo4fkSIDZ7rZ8NBEmhwWkH9eeJoZSS9rCXxwdyZ2r4B7ptFU7iYYCilgmXjo3pf\n3WdNn/gbyRvu/9jz2zWYG7Etkq+S/SX4URIvC3xtIQKBgQD/iurZYLvOaRG0GBN1\nHeor7wQ0zi0ej+haizSqS2tZUQUZhtHQCCV/fXsajVMoKuNGnG2Oqos2wWGzuEqH\nk9M9J2lMvXTMM0m1UsP3x+1ViAREzCX+/U81Y1oIuZNhF5prSR2VWtcLRs+OdK+R\npa/uwoDYl0yJrW+kXUZ6s2MmfQKBgQDvGzZEbpsx14+b7V+kIRP0eEVnMS6dOD5C\n9T9MVfRQJSYm3+RdVb9fjsAIq/wXCwcXeHqDJ683sb2VBlzI+sEZZWSsz8UF54IJ\n+YCOvxjR3BWIQsSdN3/ShCB9hQzY13qVEXvq3QrF1mzhh8E34Kkbg86TXVNZbcFg\nbBlmPr6JewKBgQDALjI2rvgu4HfO8DhZ4NiGl+ea6t+l12ZQCdbep3+hGTxzmR/b\nivTgb3cQXe6HC9IG/YerPnkaAc8/gL6UPckkeapIa0cWdw/czNTSWMoVhAhp0PpW\nTRyvsvs4CpBa+YxJWSBlfX6yXVuk7/5F08x/DEooGYkXFZcbjoZ9qsFLZQKBgACX\nTqEIrPWIlOBLy+q58jSuf21r37OfyfecZ5WmuL3h+aAq+YOJjLmNvsfGtQ7Rhij2\nsUbVuEco91EA/QW6KPQJHiCXOuNy2Q1xQnIX4tXR93Ooxpek5Xn9vZ7Rz2BR2Am6\nS1YfScGHcCl2jnG26nQY9U/D8UrNTKcSXVW1Xf81AoGAXA0+CaJXT72fedDkS6sL\nbW+YdgWkLj07jEhCE84PXHa3nlx2SkPtk0nEUJXOuZklt0PWlBUDxQLWncgqkdO7\n4JcbuolfnQVVMc/gKdcrEPNToJ7/VDAqJwC5CGxDhLOF+oR/cjiLRwrzHTdluIu4\n/qL2ac+WzLPvIRyzKSnGkWQ=\n-----END PRIVATE KEY-----" +cert_crt: "-----BEGIN CERTIFICATE-----\nMIID4DCCAsgCCQD9sx3XPtsBxzANBgkqhkiG9w0BAQsFADCBsTELMAkGA1UEBhMC\nVVMxETAPBgNVBAgMCE5ldyBZb3JrMREwDwYDVQQHDAhOZXcgWW9yazEaMBgGA1UE\nCgwRRGlnaXRhbE9jZWFuLCBJbmMxEjAQBgNVBAsMCUNvbW11bml0eTEjMCEGA1UE\nAwwaY29tbXVuaXR5LmRpZ2l0YWxvY2Vhbi5jb20xJzAlBgkqhkiG9w0BCQEWGG5v\ncmVwbHlAZGlnaXRhbG9jZWFuLmNvbTAeFw0yMTA0MTcxNTEwNTBaFw0yMjA0MTcx\nNTEwNTBaMIGxMQswCQYDVQQGEwJVUzERMA8GA1UECAwITmV3IFlvcmsxETAPBgNV\nBAcMCE5ldyBZb3JrMRowGAYDVQQKDBFEaWdpdGFsT2NlYW4sIEluYzESMBAGA1UE\nCwwJQ29tbXVuaXR5MSMwIQYDVQQDDBpjb21tdW5pdHkuZGlnaXRhbG9jZWFuLmNv\nbTEnMCUGCSqGSIb3DQEJARYYbm9yZXBseUBkaWdpdGFsb2NlYW4uY29tMIIBIjAN\nBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7q3bE1MVYW6JMFnXZzk7LLdBp4ko\ncpXXhIRmWTPJTtaknnc3iJVfx8eY2v2z7zRqt9BaGqRkgDnxUrrUZq1MCXPTPVJo\nB12sDjKE5FvLeAtlHsc28rNYlKXGaQK76pxcd9eygVuNbpF8wvUkhLSFiRNRZbp7\nmk1fvKZg/v9cm/98UjKfjT7KTC1KPiu+7ioH2N3MKKMUMeTfAtGhGHzNo8MkFDOE\nDCxiQd18uc8BAS9dCu2UkuEYLNluQS2DbIMeZRaiM71D7HRHul8NchQV6Av4pyaL\nFdFDZEvqlAHXd+jw7He/Y2jrcHzVuwW79kJxugcoZexO0c4vCzirFwJjDwIDAQAB\nMA0GCSqGSIb3DQEBCwUAA4IBAQBFaoyvk2naUJLTmUjANhbSMqTmOcfZ6fGv0EKu\nm9LJEPMX0CbFWQABvE3/9o6wAlTHc92WLdHhc3hhhIsWpEMIQ7fm9k+RVOJzFAHw\nOEOB3QIrX1t1tEoISlYLr3IbI1lAzOE8PN1A9I8Jtdl1cJ49Bk4eX84P1Zxa2Lqm\nrzQM+J23jmWdVaTehXxjYGMVlmlphBfXlTy8Of5EZGfZPSRf95y3l8I8v+cPDF1Z\nk/2JCDsiG0knAtOJnagKLy/uWdewMeRhL6uzXvijWa/RFGT2aipV3psFc1fvcJI4\nJ8RFsYZPkxQo6f2l3G+GOdOdL34O919TsTYmLdcQ6+pvkwKH\n-----END CERTIFICATE-----" diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/tasks/main.yml new file mode 100644 index 000000000..5deeb3f91 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate/tasks/main.yml @@ -0,0 +1,61 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Create a certificate + community.digitalocean.digital_ocean_certificate: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ cert_name }}" + private_key: "{{ cert_key }}" + leaf_certificate: "{{ cert_crt }}" + register: result + + - name: Ensure certificate was created + ansible.builtin.assert: + that: + - result.changed + - result.response is defined + - result.response.certificate is defined + - result.response.certificate.id is defined + - result.response.certificate.name is defined + - result.response.certificate.name == cert_name + + - name: Store the certificate id + ansible.builtin.set_fact: + certificate_id: "{{ result.response.certificate.id }}" + + - name: Gather information about the certificate + community.digitalocean.digital_ocean_certificate_info: + oauth_token: "{{ do_api_key }}" + certificate_id: "{{ certificate_id }}" + register: result + + - name: Ensure certificate information was gathered + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data | length == 1 + - result.data.0.name is defined + - result.data.0.name == cert_name + + always: + + - name: Delete a certificate + community.digitalocean.digital_ocean_certificate: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ cert_name }}" + register: result + + - name: Ensure certificate was removed + ansible.builtin.assert: + that: + - result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/defaults/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/tasks/main.yml new file mode 100644 index 000000000..8b4749f89 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_certificate_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather certificate information + community.digitalocean.digital_ocean_certificate_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify certificate information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/defaults/main.yml new file mode 100644 index 000000000..31c197f76 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/defaults/main.yml @@ -0,0 +1,7 @@ +do_region: nyc1 +database_name: gh-ci-database +database_engine: redis +database_size: db-s-1vcpu-1gb +database_num_nodes: 1 +database_wait_timeout: 900 +project_name: gh-ci-project diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/tasks/main.yml new file mode 100644 index 000000000..f14af9139 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database/tasks/main.yml @@ -0,0 +1,176 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Ensure database is absent (leftover) + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + ignore_errors: true # In case one was left from previous run + register: result + + - name: Ensure database is absent + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + register: result + + - name: Verify database is absent + ansible.builtin.assert: + that: + - not result.changed + + - name: Create the database + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + wait_timeout: "{{ database_wait_timeout }}" + register: result + + - name: Verify database is present + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.database is defined + - result.data.database.name is defined + - result.data.database.name == database_name + + - name: Create the database (again; idempotency check) + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + wait_timeout: "{{ database_wait_timeout }}" + register: result + + - name: Verify database is present + ansible.builtin.assert: + that: + - not result.changed + + - name: Fetch all databases + community.digitalocean.digital_ocean_database_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Ensure all databases found + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + + - name: Fetch this database + community.digitalocean.digital_ocean_database_info: + oauth_token: "{{ do_api_key }}" + name: "{{ database_name }}" + register: result + + - name: Ensure all databases found + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data.database is defined + - result.data.database.name is defined + - result.data.database.name == database_name + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Delete the database + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + register: result + + - name: Verify the database is deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Create the database (and associate with Project) + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + wait_timeout: "{{ database_wait_timeout }}" + project: "{{ project_name }}" + register: result + + - name: Verify database is present + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.database is defined + - result.data.database.name is defined + - result.data.database.name == database_name + - result.assign_status is defined + - result.assign_status == "assigned" + - result.msg is defined + - "'Assigned do:dbaas' in result.msg" + - result.resources is defined + - result.resources.status is defined + - result.resources.status == "assigned" + + always: + + - name: Delete the database + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + register: result + + - name: Verify the database is deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Delete the database (again; idempotency check) + community.digitalocean.digital_ocean_database: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ database_name }}" + region: "{{ do_region }}" + engine: "{{ database_engine }}" + size: "{{ database_size }}" + register: result + + - name: Verify the database is deleted + ansible.builtin.assert: + that: + - not result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/tasks/main.yml new file mode 100644 index 000000000..e526cef12 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_database_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Fetch all databases + community.digitalocean.digital_ocean_database_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Ensure all databases found + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/defaults/main.yml new file mode 100644 index 000000000..12e61b609 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/defaults/main.yml @@ -0,0 +1,2 @@ +domain_name: 0bb54d769d27ae8b4d16c8abddb7c03b767b4fa2.com +project_name: gh-ci-project diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/tasks/main.yml new file mode 100644 index 000000000..25bf7c0b7 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain/tasks/main.yml @@ -0,0 +1,124 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Create the domain + community.digitalocean.digital_ocean_domain: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ domain_name }}" + ip: 127.0.0.1 + register: result + + - name: Ensure domain was created + ansible.builtin.assert: + that: + - result.changed + - result.domain is defined + - result.domain.name is defined + - result.domain.name == domain_name + + - name: Fetch domain information + community.digitalocean.digital_ocean_domain_info: + oauth_token: "{{ do_api_key }}" + domain_name: "{{ domain_name }}" + register: result + + - name: Ensure domain was found + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data | length == 1 + + - name: Create A record for domain + community.digitalocean.digital_ocean_domain_record: + oauth_token: "{{ do_api_key }}" + state: present + domain: "{{ domain_name }}" + type: A + name: www + data: 127.0.0.1 + register: result + + - name: Ensure domain record was created + ansible.builtin.assert: + that: + - result.changed + - not result.failed + - result.result.name == "www" + - result.result.data == "127.0.0.1" + + - name: Create AAAA record for domain + community.digitalocean.digital_ocean_domain_record: + oauth_token: "{{ do_api_key }}" + state: present + domain: "{{ domain_name }}" + type: AAAA + name: www2 + data: 0000:0000:0000:0000:0000:0000:0000:0001 + register: result + + - name: Ensure domain record was created + ansible.builtin.assert: + that: + - result.changed + - not result.failed + - result.result.name == "www2" + - result.result.data == "0000:0000:0000:0000:0000:0000:0000:0001" + + - name: Delete the domain + community.digitalocean.digital_ocean_domain: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ domain_name }}" + register: result + + - name: Ensure domain was deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Create the domain (and assign to Project) + community.digitalocean.digital_ocean_domain: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ domain_name }}" + ip: 127.0.0.1 + project: "{{ project_name }}" + register: result + + - name: Ensure domain was created + ansible.builtin.assert: + that: + - result.changed + - result.domain is defined + - result.domain.name is defined + - result.domain.name == domain_name + - result.assign_status is defined + - result.assign_status == "assigned" + - result.msg is defined + - "'Assigned do:domain' in result.msg" + - result.resources is defined + - result.resources.status is defined + - result.resources.status == "assigned" + + always: + + - name: Delete the domain + community.digitalocean.digital_ocean_domain: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ domain_name }}" + register: result + + - name: Ensure domain was deleted + ansible.builtin.assert: + that: + - result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/tasks/main.yml new file mode 100644 index 000000000..314442d82 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather domain information + community.digitalocean.digital_ocean_domain_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify domain information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/defaults/main.yml new file mode 100644 index 000000000..7faa7ae7a --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/defaults/main.yml @@ -0,0 +1,8 @@ +domain: a692934f7a1ffbe552dd.net +record_id: 296972271 +record_data: ns3.digitalocean.com +non_existent_domain: a692934f7a1ffbe552ddxxxxxxxxxx.net +non_existent_record_id: 29697227101010101010 +cname_record_id: 297696356 # cname foo +cname_record_data: bar.a692934f7a1ffbe552dd.net +cname_record_type: CNAME diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/tasks/main.yml new file mode 100644 index 000000000..4b76b5f42 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_domain_record_info/tasks/main.yml @@ -0,0 +1,107 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Get domain records for existing domain + community.digitalocean.digital_ocean_domain_record_info: + oauth_token: "{{ do_api_key }}" + domain: "{{ domain }}" + register: result + + - name: Verify domain information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data.records is defined + - result.data.records | type_debug == "list" + + - name: Get domain records for non-existent domain + community.digitalocean.digital_ocean_domain_record_info: + oauth_token: "{{ do_api_key }}" + domain: "{{ non_existent_domain }}" + register: result + + - name: Verify domain information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is not defined + - result.msg is defined + - result.msg is search("Error getting domain records") + + - name: Get NS domain records for existing domain + community.digitalocean.digital_ocean_domain_record_info: + oauth_token: "{{ do_api_key }}" + domain: "{{ domain }}" + type: NS + register: result + + - name: Verify domain information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data.records is defined + - result.data.records | type_debug == "list" + - result.data.records | community.general.json_query('[*].type') | unique | length == 1 + - result.data.records | community.general.json_query('[*].type') | unique | first == "NS" + + - name: Get specific domain record by ID + community.digitalocean.digital_ocean_domain_record_info: + oauth_token: "{{ do_api_key }}" + domain: "{{ domain }}" + record_id: "{{ record_id }}" + register: result + + - name: Verify domain information fetched + ansible.builtin.assert: + that: + - not result.changed + - not result.failed + - result.data is defined + - result.data.records is defined + - result.data.records | length == 1 + - result.data.records.0.id == record_id + - result.data.records.0.data == record_data + + - name: Get non-existent domain record by ID + community.digitalocean.digital_ocean_domain_record_info: + oauth_token: "{{ do_api_key }}" + domain: "{{ domain }}" + record_id: "{{ non_existent_record_id }}" + register: result + + - name: Verify domain information fetched + ansible.builtin.assert: + that: + - not result.changed + - not result.failed + - result.data is defined + - result.data.records is defined + - result.data.records | length == 0 + + - name: Get specific domain record by ID (CNAME) + community.digitalocean.digital_ocean_domain_record_info: + oauth_token: "{{ do_api_key }}" + domain: "{{ domain }}" + record_id: "{{ cname_record_id }}" + register: result + + - name: Verify domain information fetched (CNAME) + ansible.builtin.assert: + that: + - not result.changed + - not result.failed + - result.data is defined + - result.data.records is defined + - result.data.records | length == 1 + - result.data.records.0.id == cname_record_id + - result.data.records.0.data == cname_record_data + - result.data.records.0.type == cname_record_type diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/defaults/main.yml new file mode 100644 index 000000000..312f53e85 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/defaults/main.yml @@ -0,0 +1,14 @@ +do_region: nyc1 +droplet_name: gh-ci-droplet +droplet_image: ubuntu-18-04-x64 +droplet_size: s-1vcpu-1gb +droplet_new_size: s-1vcpu-2gb +project_name: gh-ci-project +firewall_name: gh-ci-firewall +firewall_inbound_rules: + - protocol: "tcp" + ports: "9999" + sources: + addresses: ["0.0.0.0/0", "::/0"] +firewall_outbound_rules: [] +secondary_project_name: test-project diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/tasks/main.yml new file mode 100644 index 000000000..79177be26 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet/tasks/main.yml @@ -0,0 +1,511 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - 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: result + + - name: Ensure Droplet is absent + 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 }}" + register: result + + - name: Verify Droplet is absent + ansible.builtin.assert: + that: + - not result.changed + + - name: Create the Droplet (invalid region) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + region: xyz1 + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + ignore_errors: true # Expected to fail + register: result + + - name: Verify invalid region fails + ansible.builtin.assert: + that: + - result.msg is search("invalid region") + + - name: Create the Droplet (sleep_interval > wait_timeout) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + sleep_interval: 1000 + wait_timeout: 500 + ignore_errors: true # Expected to fail + register: result + + - name: Verify invalid sleep_interval fails + ansible.builtin.assert: + that: + - result.msg is search("Sleep interval") + - result.msg is search("should be less") + + - name: Create the Droplet (sleep_interval <= 0) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + sleep_interval: -100 + wait_timeout: 500 + ignore_errors: true # Expected to fail + register: result + + - name: Verify invalid sleep_interval fails + ansible.builtin.assert: + that: + - result.msg is search("Sleep interval") + - result.msg is search("should be greater") + + - name: Create the Droplet (present, not unique_name, and non-default project) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: false + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + wait_timeout: 500 + project: "{{ secondary_project_name }}" + register: result + + - name: Verify Droplet is present (from present, not unique_name, and non-default project) + ansible.builtin.assert: + that: + - result.changed + - result.data.droplet.name == droplet_name + - result.data.droplet.status in ["new", "active", "available"] + - result.assign_status == "assigned" + - result.msg is search("Assigned") + - result.msg is search("to project " ~ secondary_project_name) + # issue #220: droplet.networks.v4 is empty when unique_name != true + - result.data.droplet.networks.v4 != [] + + - name: Destroy the Droplet (absent, by ID only) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: absent + id: "{{ result.data.droplet.id }}" + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + register: result + + - name: Verify Droplet is absent (from absent, by ID only) + ansible.builtin.assert: + that: + - result.changed + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Create the Droplet (present, unique_name, and non-default project) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + wait_timeout: 500 + project: "{{ secondary_project_name }}" + register: result + + - name: Verify Droplet is present (from present) + ansible.builtin.assert: + that: + - result.changed + - result.data.droplet.name == droplet_name + - result.data.droplet.status in ["new", "active", "available"] + - result.assign_status == "assigned" + - result.msg is search("Assigned") + - result.msg is search("to project " ~ secondary_project_name) + + - name: Destroy the Droplet (absent, by unique name and ID) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ droplet_name }}" + unique_name: true + id: "{{ result.data.droplet.id }}" + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + register: result + + - name: Verify Droplet is absent (from absent, by unique name and ID) + ansible.builtin.assert: + that: + - result.changed + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Create the Droplet (present, unique_name, default project) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + 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 (from present) + ansible.builtin.assert: + that: + - result.changed + - result.data.droplet.name == droplet_name + - result.data.droplet.status in ["new", "active", "available"] + + - name: Create the same Droplet again (present, unique_name, default project) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + wait_timeout: 500 + register: result + + - name: Verify Droplet is already present (from present, unique_name, default project) + ansible.builtin.assert: + that: + - not result.changed + - result.data.droplet.name == droplet_name + - result.data.droplet.status in ["new", "active", "available"] + + - name: Destroy the Droplet (absent, by unique name only) + 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 }}" + register: result + + - name: Verify Droplet is absent (from absent, by unique name only) + ansible.builtin.assert: + that: + - result.changed + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Create the Droplet (active) + 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: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Verify Droplet is present (from active) + 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: Delete the Droplet (absent) + 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 }}" + register: result + + - name: Verify Droplet is absent (from absent) + ansible.builtin.assert: + that: + - result.changed + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Create the Droplet (inactive) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: inactive + name: "{{ droplet_name }}" + unique_name: true + region: "{{ do_region }}" + image: "{{ droplet_image }}" + size: "{{ droplet_size }}" + wait_timeout: 1500 + register: result + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Verify Droplet is present (and off) + 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 == "off" + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Resize the Droplet (and active) + 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_new_size }}" + wait_timeout: 1500 + register: result + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Verify Droplet is active and resized + 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 == "active" + - result.data.droplet.size_slug is defined + - result.data.droplet.size_slug == droplet_new_size + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Delete the Droplet (always) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ droplet_name }}" + unique_name: true + region: "{{ do_region }}" + ignore_errors: true # Should this fail, we'll clean it up next run + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Create the Droplet (and assign to Project) + 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 + project: "{{ project_name }}" + register: result + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Verify Droplet is present (from active) + 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"] + - result.assign_status is defined + - result.assign_status == "assigned" + - result.msg is defined + - "'Assigned do:droplet' in result.msg" + - result.resources is defined + - result.resources.status is defined + - result.resources.status == "assigned" + # Droplet plus firewall tests + - name: Create a test firewall + community.digitalocean.digital_ocean_firewall: + oauth_token: "{{ do_api_key }}" + name: "{{ firewall_name }}" + state: present + inbound_rules: "{{ firewall_inbound_rules }}" + outbound_rules: "{{ firewall_outbound_rules }}" + droplet_ids: [] + register: testing_firewall + + - name: Verify firewall was created + ansible.builtin.assert: + that: + - testing_firewall is defined + - testing_firewall.changed is true + + - name: Create a new droplet and add to the above firewall + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + firewall: ["{{ firewall_name }}"] + size: "{{ droplet_size }}" + region: "{{ do_region }}" + image: "{{ droplet_image }}" + wait_timeout: 500 + register: firewall_droplet + + - name: Verify the droplet has created and has firewall applied + ansible.builtin.assert: + that: + - firewall_droplet is defined + - firewall_droplet.changed is true + + - name: Check our firewall for the new droplet + community.digitalocean.digital_ocean_firewall_info: + oauth_token: "{{ do_api_key }}" + name: "{{ firewall_name }}" + register: firewall_settings + + - name: Verify details of firewall with droplet + ansible.builtin.assert: + that: + - firewall_settings is defined + - "{{ (firewall_settings.data | map(attribute='droplet_ids'))[0] | length > 0 }}" + - "{{ firewall_droplet.data.droplet.id }} in {{ (firewall_settings.data | map(attribute='droplet_ids'))[0] }}" + + - name: Rerun on above droplet without removing firewall + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + firewall: ["{{ firewall_name }}"] + size: "{{ droplet_size }}" + region: "{{ do_region }}" + image: "{{ droplet_image }}" + wait_timeout: 500 + register: firewall_droplet_unchanged + + - name: Verify things were not changed when firewall was present but unchanged + ansible.builtin.assert: + that: + - firewall_droplet_unchanged is defined + - firewall_droplet_unchanged.changed is false + + - name: Rerun on above droplet and remove firewall + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ droplet_name }}" + unique_name: true + firewall: [] + size: "{{ droplet_size }}" + region: "{{ do_region }}" + image: "{{ droplet_image }}" + wait_timeout: 500 + register: firewall_droplet_removal + + - name: Verify things were changed for firewall removal + ansible.builtin.assert: + that: + - firewall_droplet_removal is defined + - firewall_droplet_removal.changed is true + + - name: Check our firewall for the droplet being removed + community.digitalocean.digital_ocean_firewall_info: + oauth_token: "{{ do_api_key }}" + name: "{{ firewall_name }}" + register: firewall_settings_removal + + - name: Verify details of firewall with droplet + ansible.builtin.assert: + that: + - firewall_settings_removal is defined + - "{{ (firewall_settings_removal.data | map(attribute='droplet_ids'))[0] | length == 0 }}" + - "{{ firewall_droplet.data.droplet.id }} not in {{ firewall_settings_removal.data | map(attribute='droplet_ids') }}" + + always: + + - name: Delete the Firewall (always) + community.digitalocean.digital_ocean_firewall: + oauth_token: "{{ do_api_key }}" + name: "{{ firewall_name }}" + state: absent + + - name: Delete the Droplet (always) + community.digitalocean.digital_ocean_droplet: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ droplet_name }}" + unique_name: true + region: "{{ do_region }}" + ignore_errors: true # Should this fail, we'll clean it up next run diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/defaults/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/tasks/main.yml new file mode 100644 index 000000000..e68f9eb5f --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_droplet_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather droplet information + community.digitalocean.digital_ocean_droplet_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify droplet info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/defaults/main.yml new file mode 100644 index 000000000..08ce300a4 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/defaults/main.yml @@ -0,0 +1,7 @@ +firewall_name: gh-ci-firewall +firewall_inbound_rules: + - protocol: "tcp" + ports: "9999" + sources: + addresses: ["0.0.0.0/0", "::/0"] +firewall_outbound_rules: [] diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/tasks/main.yml new file mode 100644 index 000000000..d125e34ed --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall/tasks/main.yml @@ -0,0 +1,52 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Create a Firewall + community.digitalocean.digital_ocean_firewall: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ firewall_name }}" + inbound_rules: "{{ firewall_inbound_rules }}" + outbound_rules: "{{ firewall_outbound_rules }}" + register: result + + - name: Verify Firewall created + ansible.builtin.assert: + that: + - result.changed + + - name: Find the Firewall + community.digitalocean.digital_ocean_firewall_info: + oauth_token: "{{ do_api_key }}" + name: "{{ firewall_name }}" + register: result + + - name: Verify Firewall found + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data | length == 1 + - result.data.0.name is defined + - result.data.0.name == firewall_name + + always: + + - name: Delete a Firewall + community.digitalocean.digital_ocean_firewall: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ firewall_name }}" + register: result + + - name: Verify Firewall deleted + ansible.builtin.assert: + that: + - result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/defaults/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/tasks/main.yml new file mode 100644 index 000000000..c14d43a91 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_firewall_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather firewall information + community.digitalocean.digital_ocean_firewall_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify firewall information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/defaults/main.yml new file mode 100644 index 000000000..30cbae2de --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/defaults/main.yml @@ -0,0 +1,5 @@ +do_region: nyc1 +droplet_name: gh-ci-droplet +droplet_image: ubuntu-18-04-x64 +droplet_size: s-1vcpu-1gb +project_name: gh-ci-project diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/tasks/main.yml new file mode 100644 index 000000000..875c1211d --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip/tasks/main.yml @@ -0,0 +1,205 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about all Floating IPs + community.digitalocean.digital_ocean_floating_ip_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify we retrieved all Floating IPs + ansible.builtin.assert: + that: + - not result.changed + - not result.failed + + - name: Delete existing Floating IPs + community.digitalocean.digital_ocean_floating_ip: + state: absent + ip: "{{ item.ip }}" + oauth_token: "{{ do_api_key }}" + loop: "{{ result.floating_ips }}" + + - name: Create the testing Droplet (active) + 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: droplet_result + + - name: Verify Droplet is active + ansible.builtin.assert: + that: + - droplet_result.changed + - droplet_result.data is defined + - droplet_result.data.droplet is defined + - droplet_result.data.droplet.name is defined + - droplet_result.data.droplet.name == droplet_name + - droplet_result.data.droplet.status == "active" + + - name: Create a Floating IP and assign to Project + community.digitalocean.digital_ocean_floating_ip: + state: present + region: "{{ do_region }}" + oauth_token: "{{ do_api_key }}" + project: "{{ project_name }}" + register: floating_ip + + - name: Verify that a Floating IP was created (and assigned to Project) + ansible.builtin.assert: + that: + - floating_ip.changed + - floating_ip.assign_status is defined + - floating_ip.assign_status == "assigned" + - floating_ip.msg is defined + - "'Assigned do:floatingip' in floating_ip.msg" + - floating_ip.resources is defined + - floating_ip.resources.status is defined + - floating_ip.resources.status == "assigned" + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Delete the Floating IP + community.digitalocean.digital_ocean_floating_ip: + state: absent + ip: "{{ floating_ip.data.floating_ip.ip }}" + region: "{{ do_region }}" + oauth_token: "{{ do_api_key }}" + register: result + when: + - floating_ip.data.floating_ip.ip is defined + + - name: Verify that a Floating IP was deleted + ansible.builtin.assert: + that: + - result.changed + when: + - floating_ip.data.floating_ip.ip is defined + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: "Create a Floating IP" + community.digitalocean.digital_ocean_floating_ip: + state: present + region: "{{ do_region }}" + oauth_token: "{{ do_api_key }}" + register: floating_ip + + - name: Verify that a Floating IP was created + ansible.builtin.assert: + that: + - floating_ip.changed + + - name: Gather information about all Floating IPs + community.digitalocean.digital_ocean_floating_ip_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify we retrieved all Floating IPs + ansible.builtin.assert: + that: + - not result.changed + - not result.failed + + - name: Find our Floating IP + set_fact: + ci_floating_ip: "{{ result.floating_ips | selectattr('ip', 'equalto', floating_ip.data.floating_ip.ip) }}" + register: result_find + + - name: Verify we found our Floating IP + ansible.builtin.assert: + that: + - not result_find.changed + - not result_find.failed + - result_find.ansible_facts.ci_floating_ip is defined + - result_find.ansible_facts.ci_floating_ip | length == 1 + + - name: Attach the Floating IP + community.digitalocean.digital_ocean_floating_ip: + state: attached + ip: "{{ floating_ip.data.floating_ip.ip }}" + droplet_id: "{{ droplet_result.data.droplet.id }}" + oauth_token: "{{ do_api_key }}" + register: attach_result + when: + - floating_ip.data.floating_ip.ip is defined + - droplet_result.data.droplet.id is defined + + - name: Verify that a Floating IP was attached + ansible.builtin.assert: + that: + - attach_result.changed + when: + - floating_ip.data.floating_ip.ip is defined + - droplet_result.data.droplet.id is defined + - attach_result is defined + + - name: Detach the Floating IP + community.digitalocean.digital_ocean_floating_ip: + state: detached + ip: "{{ floating_ip.data.floating_ip.ip }}" + oauth_token: "{{ do_api_key }}" + register: detach_result + when: + - floating_ip.data.floating_ip.ip is defined + - droplet_result.data.droplet.id is defined + - attach_result.changed + + - name: Verify that a Floating IP was detached + ansible.builtin.assert: + that: + - detach_result.changed + when: + - floating_ip.data.floating_ip.ip is defined + - droplet_result.data.droplet.id is defined + - detach_result is defined + + always: + + - name: Delete the Floating IP + community.digitalocean.digital_ocean_floating_ip: + state: absent + ip: "{{ floating_ip.data.floating_ip.ip }}" + region: "{{ do_region }}" + oauth_token: "{{ do_api_key }}" + register: result + when: + - floating_ip.data.floating_ip.ip is defined + + - name: Verify that a Floating IP was deleted + ansible.builtin.assert: + that: + - result.changed + when: + - floating_ip.data.floating_ip.ip is defined + + - name: Destroy the Droplet (absent) + 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 }}" + register: destroy_result + + - name: Verify Droplet is absent (from absent) + ansible.builtin.assert: + that: + - destroy_result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/defaults/main.yml new file mode 100644 index 000000000..ae70fbd78 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/defaults/main.yml @@ -0,0 +1 @@ +do_region: nyc1 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/tasks/main.yml new file mode 100644 index 000000000..017724dd0 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_floating_ip_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about all Floating IPs + community.digitalocean.digital_ocean_floating_ip_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify we retrieved all Floating IPs + ansible.builtin.assert: + that: + - not result.changed + - not result.failed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/defaults/main.yml new file mode 100644 index 000000000..dc89a90d3 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/defaults/main.yml @@ -0,0 +1 @@ +image_type: distribution diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/tasks/main.yml new file mode 100644 index 000000000..5813b7212 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_image_info/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about all images + community.digitalocean.digital_ocean_image_info: + oauth_token: "{{ do_api_key }}" + image_type: "{{ image_type }}" + register: result + + - name: Verify image info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/defaults/main.yml new file mode 100644 index 000000000..6dd5f7421 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/defaults/main.yml @@ -0,0 +1,15 @@ +do_region: nyc1 + +cluster_name: gh-ci-k8s +cluster_version: latest +cluster_node_pools: + - name: gh-ci-k8s-workers + size: s-1vcpu-2gb + count: 1 + +cluster_ha_name: gh-ci-ha-k8s +cluster_ha_version: latest +cluster_ha_node_pools: + - name: gh-ci-k8s-ha-workers + size: s-1vcpu-2gb + count: 3 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/tasks/main.yml new file mode 100644 index 000000000..4d605fa79 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes/tasks/main.yml @@ -0,0 +1,229 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Ensure Kubernetes cluster is absent + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ cluster_name }}" + version: "{{ cluster_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_node_pools }}" + return_kubeconfig: false + wait_timeout: 600 + register: result + + - name: Verify Kubernetes cluster is absent + ansible.builtin.assert: + that: + - not result.changed + + - name: Ensure Kubernetes cluster is absent (ha) + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ cluster_ha_name }}" + version: "{{ cluster_ha_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_ha_node_pools }}" + return_kubeconfig: false + wait_timeout: 600 + register: result + + - name: Verify Kubernetes cluster is absent (ha) + ansible.builtin.assert: + that: + - not result.changed + + - name: Gather information about nonexistent Kubernetes cluster + community.digitalocean.digital_ocean_kubernetes_info: + oauth_token: "{{ do_api_key }}" + name: nonexistent-cluster + return_kubeconfig: true + register: result + ignore_errors: true # expected to fail + + - name: Verify nonexistent Kubernetes cluster is failed + ansible.builtin.assert: + that: + - not result.changed + - result.failed + - result.msg == "Kubernetes cluster not found" + + - name: Create the Kubernetes cluster + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ cluster_name }}" + version: "{{ cluster_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_node_pools }}" + return_kubeconfig: false + wait_timeout: 600 + register: result + + - name: Verify Kubernetes cluster is present + ansible.builtin.assert: + that: + - result.changed + - result.data.name == cluster_name + + - name: Gather information about the Kubernetes cluster + community.digitalocean.digital_ocean_kubernetes_info: + oauth_token: "{{ do_api_key }}" + name: "{{ cluster_name }}" + return_kubeconfig: false + register: result + + - name: Verify Kubernetes cluster information is found + ansible.builtin.assert: + that: + - not result.changed + - result.data.name == cluster_name + + - name: Gather information about the Kubernetes cluster (with kubeconfig) + community.digitalocean.digital_ocean_kubernetes_info: + oauth_token: "{{ do_api_key }}" + name: "{{ cluster_name }}" + return_kubeconfig: true + register: result + + - name: Verify Kubernetes cluster information is found + ansible.builtin.assert: + that: + - not result.changed + - result.data.name == cluster_name + - result.data.kubeconfig is defined + - result.data.kubeconfig | length > 0 + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Delete the Kubernetes cluster + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ cluster_name }}" + version: "{{ cluster_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_node_pools }}" + return_kubeconfig: false + wait_timeout: 600 + register: result + + - name: Verify the Kubernetes cluster is deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + # FIXME: https://github.com/ansible-collections/community.digitalocean/issues/204 + # @mamercad: I'm asking internally why this isn't done automatically. + - name: Delete the Kubernetes cluster tag + community.digitalocean.digital_ocean_tag: + oauth_token: "{{ do_api_key }}" + state: absent + name: "k8s:{{ result.data.id }}" + + - name: Create the Kubernetes cluster (ha) + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ cluster_ha_name }}" + version: "{{ cluster_ha_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_ha_node_pools }}" + return_kubeconfig: false + wait_timeout: 1200 + ha: true + register: result + + - name: Verify Kubernetes cluster is present (ha) + ansible.builtin.assert: + that: + - result.changed + - result.data.name == cluster_ha_name + - result.data.ha is true + + - name: Gather information about the Kubernetes cluster (ha) + community.digitalocean.digital_ocean_kubernetes_info: + oauth_token: "{{ do_api_key }}" + name: "{{ cluster_ha_name }}" + return_kubeconfig: true + register: result + + - name: Verify Kubernetes cluster information is found (ha) + ansible.builtin.assert: + that: + - not result.changed + - result.data.kubeconfig | length > 0 + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Delete the Kubernetes cluster + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ cluster_ha_name }}" + version: "{{ cluster_ha_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_ha_node_pools }}" + return_kubeconfig: false + wait_timeout: 600 + register: result + + - name: Verify the Kubernetes cluster is deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + # FIXME: https://github.com/ansible-collections/community.digitalocean/issues/204 + # @mamercad: I'm asking internally why this isn't done automatically. + - name: Delete the Kubernetes cluster tag + community.digitalocean.digital_ocean_tag: + oauth_token: "{{ do_api_key }}" + state: absent + name: "k8s:{{ result.data.id }}" + + always: + + - name: Delete the Kubernetes cluster + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ cluster_name }}" + version: "{{ cluster_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_node_pools }}" + return_kubeconfig: false + wait_timeout: 600 + ignore_errors: true # Should this fail, we'll clean it up next run + + - name: Delete the Kubernetes cluster (ha) + community.digitalocean.digital_ocean_kubernetes: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ cluster_ha_name }}" + version: "{{ cluster_ha_version }}" + region: "{{ do_region }}" + node_pools: "{{ cluster_ha_node_pools }}" + return_kubeconfig: false + wait_timeout: 600 + ignore_errors: true # Should this fail, we'll clean it up next run diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/defaults/main.yml new file mode 100644 index 000000000..c1f5ba32b --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/defaults/main.yml @@ -0,0 +1,8 @@ +do_region: nyc1 + +cluster_name: gh-ci-k8s +cluster_version: latest +cluster_node_pools: + - name: gh-ci-k8s-workers + size: s-1vcpu-2gb + count: 1 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/tasks/main.yml new file mode 100644 index 000000000..a0787f33a --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about the Kubernetes cluster + community.digitalocean.digital_ocean_kubernetes_info: + oauth_token: "{{ do_api_key }}" + name: "{{ cluster_name }}" + return_kubeconfig: false + register: result + ignore_errors: true # expected to fail + + - name: Verify Kubernetes cluster information is not found + ansible.builtin.assert: + that: + - not result.changed + - not result.data.name is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/defaults/main.yml new file mode 100644 index 000000000..a2386cb7f --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/defaults/main.yml @@ -0,0 +1,8 @@ +do_region: nyc1 +droplet_name: gh-ci-droplet +droplet_image: ubuntu-18-04-x64 +droplet_size: s-1vcpu-1gb +lb_name: gh-ci-loadbalancer +lb_size: lb-small +project_name: gh-ci-project +lb_tag: test-tag diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/tasks/main.yml new file mode 100644 index 000000000..d04d18b66 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/tasks/main.yml @@ -0,0 +1,202 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - 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: Ensure Load Balancer is absent (leftover) + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ lb_name }}" + region: "{{ do_region }}" + ignore_errors: true # In case one was left from previous run + + - name: Create the Droplet (active) + 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: droplet + + - name: Verify Droplet is present (from active) + ansible.builtin.assert: + that: + - droplet.changed + - droplet.data is defined + - droplet.data.droplet is defined + - droplet.data.droplet.name is defined + - droplet.data.droplet.name == droplet_name + - droplet.data.droplet.status in ["new", "active", "available"] + + - name: Create the Load Balancer (present) + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ lb_name }}" + droplet_ids: + - "{{ droplet.data.droplet.id }}" + region: "{{ do_region }}" + register: lb + + - name: Verify Load Balancer is present (from present) + ansible.builtin.assert: + that: + - lb.changed + - lb.data is defined + - lb.data.load_balancer is defined + - lb.data.load_balancer.name is defined + - lb.data.load_balancer.name == lb_name + - lb.data.load_balancer.status in ["new", "active", "available"] + + - name: Delete the Load Balancer + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ lb_name }}" + region: "{{ do_region }}" + register: result + + - name: Verify Load Balancer is deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Create the Load Balancer (and assign to Project) + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ lb_name }}" + droplet_ids: + - "{{ droplet.data.droplet.id }}" + region: "{{ do_region }}" + project: "{{ project_name }}" + register: lb + + - name: Verify Load Balancer is present (from present) + ansible.builtin.assert: + that: + - lb.changed + - lb.data is defined + - lb.data.load_balancer is defined + - lb.data.load_balancer.name is defined + - lb.data.load_balancer.name == lb_name + - lb.data.load_balancer.status in ["new", "active", "available"] + - lb.assign_status is defined + - lb.assign_status == "assigned" + - lb.msg is defined + - "'Assigned do:loadbalancer' in lb.msg" + - lb.resources is defined + - lb.resources.status is defined + - lb.resources.status == "assigned" + + - name: Delete the Load Balancer + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ lb_name }}" + region: "{{ do_region }}" + register: result + + - name: Verify Load Balancer is deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Create the Load Balancer (invalid tag + droplet_ids) + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ lb_name }}" + droplet_ids: + - "{{ droplet.data.droplet.id }}" + tag: "{{ lb_tag }}" + region: "{{ do_region }}" + ignore_errors: true # Expected to fail + register: result + + - name: Verify invalid tag + droplet_ids fails + ansible.builtin.assert: + that: + - result.msg is search("mutually exclusive: tag|droplet_ids") + + - name: Create the Load Balancer (missing tag + droplet_ids) + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ lb_name }}" + region: "{{ do_region }}" + ignore_errors: true # Expected to fail + register: result + + - name: Verify missing tag + droplet_ids fails + ansible.builtin.assert: + that: + - result.msg is search("missing: tag, droplet_ids") + + - name: Create the Load Balancer (using tag) + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ lb_name }}" + tag: "{{ lb_tag }}" + region: "{{ do_region }}" + register: lb + + - name: Verify Load Balancer is present (from present) + ansible.builtin.assert: + that: + - lb.data is defined + - lb.data.load_balancer is defined + - lb.data.load_balancer.tag is defined + - lb.data.load_balancer.tag == lb_tag + - lb.data.load_balancer.status in ["new", "active", "available"] + + 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 }}" + register: result + + - name: Verify Droplet is deleted + ansible.builtin.assert: + that: + - result.changed + + - name: Delete the Load Balancer + community.digitalocean.digital_ocean_load_balancer: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ lb_name }}" + region: "{{ do_region }}" + register: result + + - name: Verify Load Balancer is deleted + ansible.builtin.assert: + that: + - result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/tasks/main.yml new file mode 100644 index 000000000..df420820e --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about all load balancers + community.digitalocean.digital_ocean_load_balancer_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify load balancer information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/defaults/main.yml new file mode 100644 index 000000000..c25f2f804 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/defaults/main.yml @@ -0,0 +1,5 @@ +do_region: nyc1 +droplet_name: gh-ci-droplet +droplet_image: ubuntu-18-04-x64 +droplet_size: s-1vcpu-1gb +alert_email: mamercad@gmail.com diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/tasks/main.yml new file mode 100644 index 000000000..d2a4d55ab --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_monitoring_alerts/tasks/main.yml @@ -0,0 +1,135 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - 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: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Create the Droplet (active) + 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: droplet + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Verify Droplet is present (from active) + ansible.builtin.assert: + that: + - droplet.changed + - droplet.data is defined + - droplet.data.droplet is defined + - droplet.data.droplet.name is defined + - droplet.data.droplet.name == droplet_name + - droplet.data.droplet.status in ["new", "active", "available"] + + - name: Create Droplet Monitoring alerts policy + community.digitalocean.digital_ocean_monitoring_alerts: + state: present + oauth_token: "{{ do_api_key }}" + alerts: + email: ["{{ alert_email }}"] + slack: [] + compare: GreaterThan + description: Droplet load1 alert + enabled: true + entities: ["{{ droplet.data.droplet.id }}"] + tags: ["my_alert_tag"] + type: v1/insights/droplet/load_1 + value: 3.14159 + window: 5m + register: monitoring_alert_policy + + - name: Verify Monitoring alerts policy is present + ansible.builtin.assert: + that: + - monitoring_alert_policy.changed + - monitoring_alert_policy.data is defined + + - name: Create Droplet Monitoring alerts policy + community.digitalocean.digital_ocean_monitoring_alerts: + state: present + oauth_token: "{{ do_api_key }}" + alerts: + email: ["{{ alert_email }}"] + slack: [] + compare: GreaterThan + description: Droplet load1 alert + enabled: true + entities: ["{{ droplet.data.droplet.id }}"] + tags: ["my_alert_tag"] + type: v1/insights/droplet/load_1 + value: 3.14159 + window: 5m + register: monitoring_alert_policy + + - name: Verify Monitoring alerts policy is not changed (idempotency) + ansible.builtin.assert: + that: + - not monitoring_alert_policy.changed + - monitoring_alert_policy.data is defined + + - name: Get Droplet Monitoring alerts polices + community.digitalocean.digital_ocean_monitoring_alerts_info: + oauth_token: "{{ do_api_key }}" + register: monitoring_alerts + + - name: Verify Monitoring alerts has data and is not changed + ansible.builtin.assert: + that: + - not monitoring_alerts.changed + - monitoring_alerts.data is defined + + - name: Delete Droplet Monitoring alerts policy + community.digitalocean.digital_ocean_monitoring_alerts: + state: absent + oauth_token: "{{ do_api_key }}" + uuid: "{{ monitoring_alert_policy.data.uuid }}" + register: result + + - name: Verify Monitoring alerts policy 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 }}" + register: result + + - name: Verify Droplet is deleted + ansible.builtin.assert: + that: + - result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/tasks/main.yml new file mode 100644 index 000000000..c7b2e35c1 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project/tasks/main.yml @@ -0,0 +1,183 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Ensure Project is absent (leftover) + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: absent + name: "my-test-project" + register: result + with_items: + - "my-test-project" + - "my-updated-test-project" + + - name: Verify Project is absent + ansible.builtin.assert: + that: + - not result.changed + + - name: Create the Project (present) + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "my-test-project" + purpose: "IoT" + description: "This is a test project" + environment: "Development" + register: result + + - name: Verify Project is present (from present) + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.project is defined + - result.data.project.name is defined + - result.data.project.name == "my-test-project" + + - name: Create the Project (existing, no changes) + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "my-test-project" + purpose: "IoT" + description: "This is a test project" + environment: "Development" + register: result + + - name: Verify Project is present (from existing) + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data.project is defined + - result.data.project.name is defined + - result.data.project.name == "my-test-project" + + - name: Update the project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "my-test-project" + purpose: "IoT" + description: "This is a test project" + environment: "Production" + register: result + + - name: Verify Project is updated + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.project is defined + - result.data.project.name is defined + - result.data.project.name == "my-test-project" + - result.data.project.environment == "Production" + + - name: Update the project name + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "my-updated-test-project" + id: "{{ result.data.project.id }}" + purpose: "IoT" + description: "This is a test project" + environment: "Production" + register: uresult + + - name: Verify Project name is updated + ansible.builtin.assert: + that: + - uresult.changed + - uresult.data is defined + - uresult.data.project is defined + - uresult.data.project.name is defined + - uresult.data.project.name == "my-updated-test-project" + - uresult.data.project.id == result.data.project.id + + - name: Update the project name with non-standard purpose + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "my-updated-test-project" + purpose: "test" + description: "This is a test project" + environment: "Production" + register: result + + - name: Verify Project is updated with non-standard purpose + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.project is defined + - result.data.project.name is defined + - result.data.project.name == "my-updated-test-project" + - result.data.project.purpose == 'Other: test' + + - name: Update the project name with non-standard purpose (no change) + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "my-updated-test-project" + purpose: "test" + description: "This is a test project" + environment: "Production" + register: result + + - name: Verify Project is updated with non-standard purpose (no change) + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data.project is defined + - result.data.project.name is defined + - result.data.project.name == "my-updated-test-project" + - result.data.project.purpose == 'Other: test' + + - name: Delete non-existent project + community.digitalocean.digital_ocean_project: + name: my-non-existant-project + state: absent + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify project deletion (non-existing project) + ansible.builtin.assert: + that: + - not result.changed + + - name: Delete test project + community.digitalocean.digital_ocean_project: + name: "my-updated-test-project" + oauth_token: "{{ do_api_key }}" + state: absent + register: result + + - name: Verify project deletion + ansible.builtin.assert: + that: + - result.changed + + always: + + - name: Delete the Project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: absent + name: "my-test-project" + ignore_errors: true # Should this fail, we'll clean it up next run + + - name: Delete the updated project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: absent + name: "my-updated-test-project" + ignore_errors: true # Should this fail, we'll clean it up next run diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/defaults/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/tasks/main.yml new file mode 100644 index 000000000..189405c78 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather project information + community.digitalocean.digital_ocean_project_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify project info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/tasks/main.yml new file mode 100644 index 000000000..b3129130f --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_region_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about all regions + community.digitalocean.digital_ocean_region_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify region info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/tasks/main.yml new file mode 100644 index 000000000..504779b8f --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_size_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about all sizes + community.digitalocean.digital_ocean_size_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify size info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/defaults/main.yml new file mode 100644 index 000000000..d1396ae47 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/defaults/main.yml @@ -0,0 +1,9 @@ +do_region: nyc1 +droplet_name: gh-ci-droplet +droplet_image: ubuntu-18-04-x64 +droplet_size: s-1vcpu-1gb +snapshot_name: gh-ci-snapshot +volume_name: gh-ci-volume +volume_size: 15 +volume_down_size: 10 +volume_up_size: 20 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/tasks/main.yml new file mode 100644 index 000000000..6a5e38166 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/tasks/main.yml @@ -0,0 +1,216 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + # + # Droplet snapshot + # + + - 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 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/defaults/main.yml new file mode 100644 index 000000000..3289b3869 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/defaults/main.yml @@ -0,0 +1 @@ +snapshot_type: all diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/tasks/main.yml new file mode 100644 index 000000000..e39f95a53 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot_info/tasks/main.yml @@ -0,0 +1,58 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about snapshots (all) + community.digitalocean.digital_ocean_snapshot_info: + oauth_token: "{{ do_api_key }}" + snapshot_type: "all" + register: result + + - name: Verify snapshot info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + + - name: Gather information about snapshots (droplets) + community.digitalocean.digital_ocean_snapshot_info: + oauth_token: "{{ do_api_key }}" + snapshot_type: "droplet" + register: result + + - name: Verify snapshot info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + + - name: Gather information about snapshots (volumes) + community.digitalocean.digital_ocean_snapshot_info: + oauth_token: "{{ do_api_key }}" + snapshot_type: "volume" + register: result + + - name: Verify snapshot info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + + - name: Gather information about snapshots (by_id) + community.digitalocean.digital_ocean_snapshot_info: + oauth_token: "{{ do_api_key }}" + snapshot_type: "by_id" + snapshot_id: "12345678" + ignore_errors: true + register: result + + - name: Verify that a non-existent snapshot failed + ansible.builtin.assert: + that: + - result.failed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/defaults/main.yml new file mode 100644 index 000000000..493a28a8a --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/defaults/main.yml @@ -0,0 +1,2 @@ +space_name: gh-ci-space-1 +space_region: nyc3 diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/tasks/main.yml new file mode 100644 index 000000000..84f947b69 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces/tasks/main.yml @@ -0,0 +1,114 @@ +--- +- block: + + - name: Ensure Spaces API keys are provided + ansible.builtin.fail: + msg: aws_access_key_id and aws_secret_access_key should be defined in tests/integration/integration_config.yml + when: + - aws_access_key_id is not defined + - aws_access_key_id | length == 0 + - aws_secret_access_key is not defined + - aws_secret_access_key | length == 0 + + - name: Create Space {{ space_name }} in {{ space_region }} + community.digitalocean.digital_ocean_spaces: + state: present + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + name: "{{ space_name }}" + region: "{{ space_region }}" + register: result + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - result.changed + - result.data.space is defined + - result.data.space.name == "{{ space_name }}" + - result.data.space.region == "{{ space_region }}" + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Create Space {{ space_name }} in {{ space_region }} (again, test idempotency) + community.digitalocean.digital_ocean_spaces: + state: present + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + name: "{{ space_name }}" + region: "{{ space_region }}" + register: result + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - not result.changed + + - name: Delete Space {{ space_name }} in {{ space_region }} + community.digitalocean.digital_ocean_spaces: + state: absent + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + name: "{{ space_name }}" + region: "{{ space_region }}" + register: result + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - result.changed + - result.msg is search("Deleted Space") + + - name: Give the cloud a minute to settle + ansible.builtin.pause: + minutes: 1 + + - name: Delete Space {{ space_name }} in {{ space_region }} (again, test idempotency) + community.digitalocean.digital_ocean_spaces: + state: absent + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + name: "{{ space_name }}" + region: "{{ space_region }}" + register: result + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - not result.changed + - result.msg is search("No Space") + + - name: Create Space {{ space_name }} in xyz1 (test bad region) + community.digitalocean.digital_ocean_spaces: + state: present + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + name: "{{ space_name }}" + region: xyz1 + register: result + ignore_errors: true # Expected to fail + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - not result.changed + - result.exception is defined + - result.failed + + - name: Delete Space {{ space_name }} in xyz1 (test bad region) + community.digitalocean.digital_ocean_spaces: + state: absent + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + name: "{{ space_name }}" + region: xyz1 + register: result + ignore_errors: true # Expected to fail + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - not result.changed + - result.exception is defined + - result.failed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/tasks/main.yml new file mode 100644 index 000000000..0ed2491f9 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_spaces_info/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- block: + + - name: Ensure Spaces API keys are provided + ansible.builtin.fail: + msg: aws_access_key_id and aws_secret_access_key should be defined in tests/integration/integration_config.yml + when: + - aws_access_key_id is not defined + - aws_access_key_id | length == 0 + - aws_secret_access_key is not defined + - aws_secret_access_key | length == 0 + + - name: Get Spaces in nyc3 + community.digitalocean.digital_ocean_spaces_info: + state: present + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + region: nyc3 + register: result + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - not result.changed + - result.data.spaces is defined + + - name: Get Spaces in xyz1 (test bad region) + community.digitalocean.digital_ocean_spaces_info: + state: present + aws_access_key_id: "{{ aws_access_key_id }}" + aws_secret_access_key: "{{ aws_secret_access_key }}" + region: xyz1 + register: result + ignore_errors: true # Expected to fail + + - name: Verify Spaces info + ansible.builtin.assert: + that: + - not result.changed + - result.exception is defined + - result.failed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/defaults/main.yml new file mode 100644 index 000000000..f98a0a54d --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/defaults/main.yml @@ -0,0 +1,4 @@ +key_name: gh-ci-sshkey +dummy_ssh_pub_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDNnKfzimdn4+Tz2hlWRtZVl9N+QiN2XAkDMo/RTRD7I2NyIrzlMn+7Fg3lLjbkIDU44npzkFnneKrcnf/utniST7Isvbnvdz4B/hJcsbAaS8A9ZE0vgv8IvRETlkOszXuYl0mi12NlqHr8UhcKIzwvUpae421lzNpjKb72mIaZehefPT1E+p9qgMYTOvO+xa1Q/U1JxEYeygY228J9APkV5Elu/QWqgsoMVuSbiKhxIt8vvFo9x7pgKyc9hRbraMMcvdCDq5vl3PRjuW4nijft7Em2nt2vb4duUWgOhtCHIzNRDEJ1fX14lvT01UULr/vjC+r4/j+F288V8CWH3DCX33wGBaFVj7SF4EoK9XhccGslGoq5+8op9jPuLySRw19g41qcsmCB4v895fEoMjoIJvJVSOyjnszJyhIW/E5qNVKNnOR/IAu3OfR3HCDRGSQ7qhIu3xd1Cjai2V8xo17m4WOjnZ3mbIEJHsicOF+dWumVVm0aGF552Xl7jSyFGv4f6ML0SruKrJctvzILRfTsRUH2NFTDqvE1WmQ9pAfXmW9F5VFQ71yhKUIN7ItwR5yBYc1h7R7X5uYQ5JtFeG+nOvnedTUXvc6Pzx3WUWhuAEjFvXg66JoG2Vs4ReIE9lcPwCqh/aVMlhc4X2/O1GavnslhOt08nHmhNEUfP+fCyw== Dummy CI SSH Key +invalid_key_name: gi-ci-invalid-sshkey +invalid_ssh_pub_key: invalid diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/tasks/main.yml new file mode 100644 index 000000000..a5ab4d24a --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey/tasks/main.yml @@ -0,0 +1,68 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Create an invalid SSH key + community.digitalocean.digital_ocean_sshkey: + name: "{{ invalid_key_name }}" + ssh_pub_key: "{{ invalid_ssh_pub_key }}" + oauth_token: "{{ do_api_key }}" + ignore_errors: true + register: result + + - name: Verify that the invalid SSH key failed + ansible.builtin.assert: + that: + - result.failed + + - name: Create a valid SSH key + community.digitalocean.digital_ocean_sshkey: + name: "{{ key_name }}" + ssh_pub_key: "{{ dummy_ssh_pub_key }}" + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify that SSH key was created + ansible.builtin.assert: + that: + - result.changed + + - name: Fetch all SSH keys + community.digitalocean.digital_ocean_sshkey_info: + oauth_token: "{{ do_api_key }}" + register: ssh_keys + + - name: Find our dummy ci SSH key + set_fact: + ci_ssh_key: "{{ ssh_keys.data | selectattr('name', 'equalto', key_name) }}" + register: result_find + + - name: Verify that ci SSH key was found + ansible.builtin.assert: + that: + - not result_find.failed + - not result_find.changed + - result_find.ansible_facts is defined + - result_find.ansible_facts.ci_ssh_key is defined + - result_find.ansible_facts.ci_ssh_key.0 is defined + - result_find.ansible_facts.ci_ssh_key.0.name == key_name + + always: + + - name: Delete the SSH key + community.digitalocean.digital_ocean_sshkey: + state: "absent" + fingerprint: "{{ result.data.ssh_key.fingerprint }}" + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify that the SSH key was deleted + ansible.builtin.assert: + that: + - result.changed diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/defaults/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/tasks/main.yml new file mode 100644 index 000000000..1b9f9f66b --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_sshkey_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather SSH Key information + community.digitalocean.digital_ocean_sshkey_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify SSH key info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/defaults/main.yml new file mode 100644 index 000000000..b57bb6813 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/defaults/main.yml @@ -0,0 +1 @@ +tag_name: integration-test diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/tasks/main.yml new file mode 100644 index 000000000..c058b7a9a --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag/tasks/main.yml @@ -0,0 +1,68 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Create a new tag + community.digitalocean.digital_ocean_tag: + oauth_token: "{{ do_api_key }}" + name: "{{ tag_name }}" + state: present + register: create_tag + + - name: Create a new tag for idempotency + community.digitalocean.digital_ocean_tag: + oauth_token: "{{ do_api_key }}" + name: "{{ tag_name }}" + state: present + register: create_tag_idempotent + + - name: Verify tag created and idempotent + ansible.builtin.assert: + that: + - create_tag.changed == True + - create_tag_idempotent.changed == False + - create_tag.data.tag.name == tag_name + + - name: Gather information about tag with given name + community.digitalocean.digital_ocean_tag_info: + oauth_token: "{{ do_api_key }}" + tag_name: "{{ tag_name }}" + register: result_find + + - name: Verify that ci tag was found + ansible.builtin.assert: + that: + - not result_find.failed + - not result_find.changed + - result_find.data is defined + - result_find.data | length == 1 + - result_find.data.0.name is defined + - result_find.data.0.name == tag_name + + always: + + - name: Delete tag + community.digitalocean.digital_ocean_tag: + oauth_token: "{{ do_api_key }}" + name: integration-test + state: absent + register: delete_tag + + - name: Delete tag with idempotency + community.digitalocean.digital_ocean_tag: + oauth_token: '{{do_api_key}}' + name: integration-test-2 + state: absent + register: delete_tag_idempotent + + - name: Verify that tag was deleted + ansible.builtin.assert: + that: + - delete_tag.changed == True + - delete_tag_idempotent.changed == False diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/defaults/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/tasks/main.yml new file mode 100644 index 000000000..c2844033d --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_tag_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather tag information + community.digitalocean.digital_ocean_tag_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify tag information fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/tasks/main.yml new file mode 100644 index 000000000..a5b6262fc --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_volume_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Gather information about volumes + community.digitalocean.digital_ocean_volume_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify volume info fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/defaults/main.yml new file mode 100644 index 000000000..b296c04c4 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/defaults/main.yml @@ -0,0 +1,2 @@ +do_region: nyc1 +vpc_name: gh-ci-vpc diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/tasks/main.yml new file mode 100644 index 000000000..eed068a6c --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc/tasks/main.yml @@ -0,0 +1,69 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Create a VPC + community.digitalocean.digital_ocean_vpc: + state: present + oauth_token: "{{ do_api_key }}" + name: "{{ vpc_name }}" + region: "{{ do_region }}" + register: result + + - name: Verify VPC created + ansible.builtin.assert: + that: + - result.changed + - result.data is defined + - result.data.vpc is defined + - result.data.vpc != {} + - result.data.vpc.name == vpc_name + + - name: Set a fact for the VPC ID + ansible.builtin.set_fact: + vpc_id: "{{ result.data.vpc.id }}" + + - name: Fetch VPC members + community.digitalocean.digital_ocean_vpc_info: + oauth_token: "{{ do_api_key }}" + name: "{{ vpc_name }}" + members: true + register: result + + - name: Verify VPC members fetched + ansible.builtin.assert: + that: + - not result.changed + - result.data is defined + - result.data != {} + - result.data.links is defined + - result.data.members is defined + - result.data.meta is defined + + - name: Delete a VPC + community.digitalocean.digital_ocean_vpc: + state: absent + oauth_token: "{{ do_api_key }}" + name: "{{ vpc_name }}" + register: result + + - name: Verify VPC deleted + ansible.builtin.assert: + that: + - result.changed + + always: + + - name: Delete a VPC + community.digitalocean.digital_ocean_vpc: + state: absent + oauth_token: "{{ do_api_key }}" + name: "{{ vpc_name }}" + register: result + ignore_errors: true diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/aliases diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/defaults/main.yml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/defaults/main.yml diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/tasks/main.yml new file mode 100644 index 000000000..78a990f34 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_vpc_info/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- block: + + - name: Ensure API key is provided + ansible.builtin.fail: + msg: do_api_key should be defined in tests/integration/integration_config.yml + when: + - do_api_key is not defined + - do_api_key | length == 0 + + - name: Fetch all VPCs + community.digitalocean.digital_ocean_vpc_info: + oauth_token: "{{ do_api_key }}" + register: result + + - name: Verify VPCs fetched + ansible.builtin.assert: + that: + - not result.changed diff --git a/ansible_collections/community/digitalocean/tests/sanity/ignore-2.12.txt b/ansible_collections/community/digitalocean/tests/sanity/ignore-2.12.txt new file mode 100644 index 000000000..6fa082669 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/sanity/ignore-2.12.txt @@ -0,0 +1,12 @@ +plugins/modules/digital_ocean_spaces.py compile-2.6!skip +plugins/modules/digital_ocean_spaces_info.py compile-2.6!skip +plugins/modules/digital_ocean_spaces.py compile-2.7!skip +plugins/modules/digital_ocean_spaces_info.py compile-2.7!skip +plugins/modules/digital_ocean_spaces.py compile-3.5!skip +plugins/modules/digital_ocean_spaces_info.py compile-3.5!skip +plugins/modules/digital_ocean_spaces.py import-2.6!skip +plugins/modules/digital_ocean_spaces_info.py import-2.6!skip +plugins/modules/digital_ocean_spaces.py import-2.7!skip +plugins/modules/digital_ocean_spaces_info.py import-2.7!skip +plugins/modules/digital_ocean_spaces.py import-3.5!skip +plugins/modules/digital_ocean_spaces_info.py import-3.5!skip diff --git a/ansible_collections/community/digitalocean/tests/sanity/ignore-2.13.txt b/ansible_collections/community/digitalocean/tests/sanity/ignore-2.13.txt new file mode 100644 index 000000000..56f004672 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/sanity/ignore-2.13.txt @@ -0,0 +1,8 @@ +plugins/modules/digital_ocean_spaces.py compile-2.7!skip +plugins/modules/digital_ocean_spaces_info.py compile-2.7!skip +plugins/modules/digital_ocean_spaces.py compile-3.5!skip +plugins/modules/digital_ocean_spaces_info.py compile-3.5!skip +plugins/modules/digital_ocean_spaces.py import-2.7!skip +plugins/modules/digital_ocean_spaces_info.py import-2.7!skip +plugins/modules/digital_ocean_spaces.py import-3.5!skip +plugins/modules/digital_ocean_spaces_info.py import-3.5!skip diff --git a/ansible_collections/community/digitalocean/tests/sanity/ignore-2.9.txt b/ansible_collections/community/digitalocean/tests/sanity/ignore-2.9.txt new file mode 100644 index 000000000..f82d2f404 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/sanity/ignore-2.9.txt @@ -0,0 +1,3 @@ +plugins/modules/digital_ocean.py validate-modules:deprecation-mismatch +plugins/modules/digital_ocean.py validate-modules:invalid-documentation +plugins/modules/digital_ocean.py validate-modules:missing-main-call diff --git a/ansible_collections/community/digitalocean/tests/unit/plugins/inventory/test_digitalocean.py b/ansible_collections/community/digitalocean/tests/unit/plugins/inventory/test_digitalocean.py new file mode 100644 index 000000000..340f36109 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/unit/plugins/inventory/test_digitalocean.py @@ -0,0 +1,306 @@ +# Copyright (c) 2021 Ansible Project +# GNGeneral 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 pytest + +from ansible.errors import AnsibleError, AnsibleParserError +from ansible.inventory.data import InventoryData +from ansible.template import Templar +from ansible.parsing.dataloader import DataLoader +import ansible_collections.community.digitalocean.plugins.inventory.digitalocean as module_under_test +from ansible_collections.community.digitalocean.plugins.inventory.digitalocean import ( + InventoryModule, +) + + +@pytest.fixture() +def inventory(): + r = InventoryModule() + r.inventory = InventoryData() + r.templar = Templar(loader=DataLoader()) + return r + + +def test_verify_file_bad_config(inventory): + assert inventory.verify_file("digitalocean_foobar.yml") is False + + +@pytest.fixture() +def payload(): + return [ + { + "id": 3164444, + "name": "foo", + "memory": 1024, + "vcpus": 1, + "disk": 25, + "locked": False, + "status": "active", + "kernel": { + "id": 2233, + "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic", + "version": "3.13.0-37-generic", + }, + "image": { + "id": 6918990, + "name": "14.04 x64", + "distribution": "Ubuntu", + "slug": "ubuntu-16-04-x64", + }, + "size_slug": "s-1vcpu-1gb", + "networks": { + "v4": [ + { + "ip_address": "104.236.32.182", + "netmask": "255.255.192.0", + "gateway": "104.236.0.1", + "type": "public", + } + ], + "v6": [ + { + "ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001", + "netmask": 64, + "gateway": "2604:A880:0800:0010:0000:0000:0000:0001", + "type": "public", + } + ], + }, + "region": { + "name": "New York 3", + "slug": "nyc3", + }, + "tags": [], + "vpc_uuid": "f9b0769c-e118-42fb-a0c4-fed15ef69662", + }, + { + "id": 3164445, + "name": "bar", + "memory": 1024, + "vcpus": 1, + "disk": 25, + "locked": False, + "status": "active", + "kernel": { + "id": 2233, + "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic", + "version": "3.13.0-37-generic", + }, + "image": { + "id": 6918990, + "name": "14.04 x64", + "distribution": "Ubuntu", + "slug": "ubuntu-16-04-x64", + }, + "size_slug": "s-1vcpu-1gb", + "networks": { + "v4": [ + { + "ip_address": "104.236.32.185", + "netmask": "255.255.192.0", + "gateway": "104.236.0.1", + "type": "public", + } + ], + "v6": [ + { + "ip_address": "2604:A880:0800:0010:0000:0000:02DD:4004", + "netmask": 64, + "gateway": "2604:A880:0800:0010:0000:0000:0000:0001", + "type": "public", + } + ], + }, + "region": { + "name": "Frankfurt 1", + "slug": "fra1", + }, + "tags": [], + "vpc_uuid": "f9b0769c-e118-42fb-a0c4-fed15ef69662", + }, + ] + + +def get_option(option): + options = { + "attributes": ["id", "size_slug"], + "var_prefix": "do_", + "strict": False, + } + return options.get(option) + + +def test_populate_hostvars(inventory, payload, mocker): + inventory.get_option = mocker.MagicMock(side_effect=get_option) + + inventory._populate(payload) + + host_foo = inventory.inventory.get_host("foo") + host_bar = inventory.inventory.get_host("bar") + + assert host_foo.vars["do_id"] == 3164444 + assert host_bar.vars["do_size_slug"] == "s-1vcpu-1gb" + + # if a prefix is set, unprefixed attributes should not appear in host vars + assert "id" not in host_foo.vars + assert "size_slug" not in host_bar.vars + + +@pytest.mark.parametrize("transform", ["never", "ignore"]) +def test_populate_groups_no_sanitization(inventory, mocker, transform): + def get_option(opt): + return dict( + attributes=["id", "tags"], + var_prefix="do_", + keyed_groups=[dict(key="do_tags", prefix="", separator="")], + ).get(opt) + + inventory.get_option = mocker.MagicMock(side_effect=get_option) + mocker.patch("ansible.constants.TRANSFORM_INVALID_GROUP_CHARS", transform) + + inventory._populate( + [ + dict( + id=3164444, + name="test", + tags=["lower", "UPPER", "un_der", "col:on", "da-sh", "with_123"], + ), + ] + ) + + assert set( + ("all", "ungrouped", "lower", "UPPER", "un_der", "col:on", "da-sh", "with_123") + ) == set((inventory.inventory.groups.keys())) + + +@pytest.mark.parametrize("transform", ["always", "silently"]) +def test_populate_groups_sanitization(inventory, mocker, transform): + def get_option(opt): + return dict( + attributes=["id", "tags"], + var_prefix="x_", + keyed_groups=[dict(key="x_tags", prefix="", separator="")], + ).get(opt) + + inventory.get_option = mocker.MagicMock(side_effect=get_option) + mocker.patch("ansible.constants.TRANSFORM_INVALID_GROUP_CHARS", transform) + + inventory._populate( + [ + dict( + id=3164444, + name="test", + tags=["lower", "UPPER", "un_der", "col:on", "da-sh", "with_123"], + ), + ] + ) + + assert set( + ("all", "ungrouped", "lower", "UPPER", "un_der", "col_on", "da_sh", "with_123") + ) == set((inventory.inventory.groups.keys())) + + +def get_option_with_templated_api_token(option): + options = { + # "random_choice" with just a single input always returns the same result. + "api_token": '{{ lookup("random_choice", "my-do-token") }}', + "pagination": 100, + } + return options.get(option) + + +def test_get_payload_with_templated_api_token(inventory, mocker): + inventory.get_option = mocker.MagicMock( + side_effect=get_option_with_templated_api_token + ) + + mocker.patch(module_under_test.__name__ + ".Request") + RequestMock = module_under_test.Request + + req_instance = RequestMock.return_value + req_instance.get.return_value.read.return_value = '{"droplets": []}' + + inventory._get_payload() + + init_headers = RequestMock.call_args.kwargs["headers"] + assert init_headers["Authorization"] == "Bearer my-do-token" + + +def get_option_with_filters(option): + options = { + "attributes": ["id", "size_slug", "region"], + "var_prefix": "do_", + "strict": False, + "filters": [ + 'do_region.slug == "fra1"', + ], + } + return options.get(option) + + +def test_populate_hostvars_with_filters(inventory, payload, mocker): + inventory.get_option = mocker.MagicMock(side_effect=get_option_with_filters) + inventory._populate(payload) + + host_foo = inventory.inventory.get_host("foo") + host_bar = inventory.inventory.get_host("bar") + + assert host_foo is None + assert host_bar.vars["do_size_slug"] == "s-1vcpu-1gb" + + +def get_variables(): + return { + "do_region": { + "slug": "fra1", + }, + "do_tags": ["something"], + } + + +def test_passes_filters_accept_empty(inventory, mocker): + filters = [] + variables = get_variables() + assert inventory._passes_filters(filters, variables, "foo") + + +def test_passes_filters_accept(inventory, mocker): + filters = ['do_region.slug == "fra1"'] + variables = get_variables() + assert inventory._passes_filters(filters, variables, "foo") + + +def test_passes_filters_reject(inventory, mocker): + filters = ['do_region.slug == "nyc3"'] + variables = get_variables() + assert not inventory._passes_filters(filters, variables, "foo") + + +def test_passes_filters_reject_any(inventory, mocker): + filters = [ + 'do_region.slug == "fra1"', # accept + '"nope" in do_tags', # reject + ] + variables = get_variables() + assert not inventory._passes_filters(filters, variables, "foo") + + +def test_passes_filters_invalid_filters(inventory, mocker): + filters = ["not a valid filter"] + variables = get_variables() + assert not inventory._passes_filters(filters, variables, "foo") + + +def test_passes_filters_invalid_filters_strict(inventory, mocker): + filters = ["not a valid filter"] + variables = get_variables() + try: + inventory._passes_filters(filters, variables, "foo", True) + assert False, "expected _passes_filters() to raise AnsibleError" + except AnsibleError as e: + pass diff --git a/ansible_collections/community/digitalocean/tests/unit/plugins/modules/test_digital_ocean_kubernetes.py b/ansible_collections/community/digitalocean/tests/unit/plugins/modules/test_digital_ocean_kubernetes.py new file mode 100644 index 000000000..cfb0f59b6 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/unit/plugins/modules/test_digital_ocean_kubernetes.py @@ -0,0 +1,263 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.community.general.tests.unit.compat import unittest +from ansible_collections.community.general.tests.unit.compat.mock import MagicMock +from ansible_collections.community.digitalocean.plugins.modules.digital_ocean_kubernetes import ( + DOKubernetes, +) + + +class TestDOKubernetes(unittest.TestCase): + def test_get_by_id_when_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 200 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertEqual(k.get_by_id(), {"foo": "bar"}) + + def test_get_by_id_when_not_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 400 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertIsNone(k.get_by_id()) + + def test_get_all_clusters_when_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 200 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertEqual(k.get_all_clusters(), {"foo": "bar"}) + + def test_get_all_clusters_when_not_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 400 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertIsNone(k.get_all_clusters()) + + def test_get_by_name_none(self): + module = MagicMock() + k = DOKubernetes(module) + self.assertIsNone(k.get_by_name(None)) + + def test_get_by_name_found(self): + module = MagicMock() + k = DOKubernetes(module) + k.get_all_clusters = MagicMock() + k.get_all_clusters.return_value = {"kubernetes_clusters": [{"name": "foo"}]} + self.assertEqual(k.get_by_name("foo"), {"name": "foo"}) + + def test_get_by_name_not_found(self): + module = MagicMock() + k = DOKubernetes(module) + k.get_all_clusters = MagicMock() + k.get_all_clusters.return_value = {"kubernetes_clusters": [{"name": "foo"}]} + self.assertIsNone(k.get_by_name("foo2")) + + def test_get_kubernetes_kubeconfig_when_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 200 + k.rest.get.return_value.body = "kubeconfig" + self.assertEqual(k.get_kubernetes_kubeconfig(), "kubeconfig") + + def test_get_kubernetes_kubeconfig_when_not_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 400 + k.rest.get.return_value.body = "kubeconfig" + self.assertNotEqual(k.get_kubernetes_kubeconfig(), "kubeconfig") + + def test_get_kubernetes_when_found(self): + module = MagicMock() + k = DOKubernetes(module) + k.get_by_name = MagicMock() + k.get_by_name.return_value = {"id": 42} + self.assertEqual(k.get_kubernetes(), {"id": 42}) + + def test_get_kubernetes_when_not_found(self): + module = MagicMock() + k = DOKubernetes(module) + k.get_by_name = MagicMock() + k.get_by_name.return_value = None + self.assertIsNone(k.get_kubernetes()) + + def test_get_kubernetes_options_when_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.json = {"foo": "bar"} + k.rest.get.return_value.status_code = 200 + self.assertEqual(k.get_kubernetes_options(), {"foo": "bar"}) + + def test_get_kubernetes_options_when_not_ok(self): + module = MagicMock() + k = DOKubernetes(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.json = {"foo": "bar"} + k.rest.get.return_value.status_code = 400 + self.assertIsNone(k.get_kubernetes_options()) + + def test_ensure_running_when_running(self): + module = MagicMock() + module.fail_json = MagicMock() + + k = DOKubernetes(module) + k.end_time = 20 + k.wait_timeout = 1 + k.get_by_id = MagicMock() + + cluster = {"kubernetes_cluster": {"status": {"state": "running"}}} + + k.get_by_id.return_value = cluster + + time = MagicMock() + time.time = MagicMock() + time.time.return_value = 10 + time.sleep = MagicMock() + + self.assertEqual(k.ensure_running(), cluster) + + def test_ensure_running_when_not_running(self): + module = MagicMock() + module.fail_json = MagicMock() + + k = DOKubernetes(module) + k.end_time = 20 + k.wait_timeout = -100 + k.get_by_id = MagicMock() + + cluster = {"kubernetes_cluster": {"status": {"state": "stopped"}}} + + k.get_by_id.return_value = cluster + + time = MagicMock() + time.time = MagicMock() + time.time.return_value = 20 + time.sleep = MagicMock() + + # module.fail_json.assert_called() + assert True + + def test_create_ok(self): + module = MagicMock() + module.exit_json = MagicMock() + module.fail_json = MagicMock() + + k = DOKubernetes(module) + k.module = MagicMock() + k.module.params = MagicMock() + + k.module.params.return_value = {"region": "nyc1"} + + k.get_kubernetes_options = MagicMock() + + kubernetes_options = { + "options": { + "regions": [{"name": "New York 1", "slug": "nyc1"}], + "versions": [{"kubernetes_version": "1.18.8", "slug": "1.18.8-do.0"}], + "sizes": [{"name": "s-1vcpu-2gb", "slug": "s-1vcpu-2gb"}], + } + } + + k.get_kubernetes_options.return_value = kubernetes_options + + k.get_kubernetes = MagicMock() + k.get_kubernetes.return_value = {"foo": "bar"} + k.cluster_id = MagicMock() + k.cluster_id.return_value = 42 + + k.rest = MagicMock() + k.rest.post = MagicMock() + k.rest.post.return_value.json = {"kubernetes_cluster": {"id": 42}} + k.rest.post.return_value.status_code = 200 + k.ensure_running = MagicMock() + k.cluster_id = MagicMock() + k.module = MagicMock() + + k.create() + k.module.exit_json.assert_called() + + def test_create_not_ok(self): + module = MagicMock() + module.exit_json = MagicMock() + module.fail_json = MagicMock() + + k = DOKubernetes(module) + k.module = MagicMock() + k.module.params = MagicMock() + + k.module.params.return_value = {"region": "nyc1"} + + k.get_kubernetes_options = MagicMock() + + kubernetes_options = { + "options": { + "regions": [{"name": "New York 1", "slug": "nyc1"}], + "versions": [{"kubernetes_version": "1.18.8", "slug": "1.18.8-do.0"}], + "sizes": [{"name": "s-1vcpu-2gb", "slug": "s-1vcpu-2gb"}], + } + } + + k.get_kubernetes_options.return_value = kubernetes_options + + k.get_kubernetes = MagicMock() + k.get_kubernetes.return_value = {"foo": "bar"} + k.cluster_id = MagicMock() + k.cluster_id.return_value = 42 + + k.rest = MagicMock() + k.rest.post = MagicMock() + k.rest.post.return_value.json = {"kubernetes_cluster": {"id": 42}} + k.rest.post.return_value.status_code = 400 + k.ensure_running = MagicMock() + k.cluster_id = MagicMock() + k.module = MagicMock() + + k.create() + k.module.exit_json.assert_called() + + def test_delete_ok(self): + module = MagicMock() + module.exit_json = MagicMock() + + k = DOKubernetes(module) + + k.get_kubernetes = MagicMock() + + k.rest = MagicMock() + k.rest.delete = MagicMock() + k.rest.delete.return_value.id = 42 + k.rest.delete.return_value.status_code = 204 + + k.delete() + k.module.exit_json.assert_called() + + def test_delete_not_ok(self): + module = MagicMock() + module.exit_json = MagicMock() + + k = DOKubernetes(module) + + k.get_kubernetes = MagicMock() + k.get_kubernetes.return_value = None + + k.delete() + k.module.exit_json.assert_called() diff --git a/ansible_collections/community/digitalocean/tests/unit/plugins/modules/test_digital_ocean_kubernetes_info.py b/ansible_collections/community/digitalocean/tests/unit/plugins/modules/test_digital_ocean_kubernetes_info.py new file mode 100644 index 000000000..034c1c9cf --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/unit/plugins/modules/test_digital_ocean_kubernetes_info.py @@ -0,0 +1,116 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.community.general.tests.unit.compat import unittest +from ansible_collections.community.general.tests.unit.compat.mock import MagicMock +from ansible_collections.community.digitalocean.plugins.modules.digital_ocean_kubernetes_info import ( + DOKubernetesInfo, +) + + +class TestDOKubernetesInfo(unittest.TestCase): + def test_get_by_id_when_ok(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 200 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertEqual(k.get_by_id(), {"foo": "bar"}) + + def test_get_by_id_when_not_ok(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 400 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertIsNone(k.get_by_id()) + + def test_get_all_clusters_when_ok(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 200 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertEqual(k.get_all_clusters(), {"foo": "bar"}) + + def test_get_all_clusters_when_not_ok(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 400 + k.rest.get.return_value.json = {"foo": "bar"} + self.assertIsNone(k.get_all_clusters()) + + def test_get_by_name_none(self): + module = MagicMock() + k = DOKubernetesInfo(module) + self.assertIsNone(k.get_by_name(None)) + + def test_get_by_name_found(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.get_all_clusters = MagicMock() + k.get_all_clusters.return_value = {"kubernetes_clusters": [{"name": "foo"}]} + self.assertEqual(k.get_by_name("foo"), {"name": "foo"}) + + def test_get_by_name_not_found(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.get_all_clusters = MagicMock() + k.get_all_clusters.return_value = {"kubernetes_clusters": [{"name": "foo"}]} + self.assertIsNone(k.get_by_name("foo2")) + + def test_get_kubernetes_kubeconfig_when_ok(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 200 + k.rest.get.return_value.body = "kubeconfig" + self.assertEqual(k.get_kubernetes_kubeconfig(), "kubeconfig") + + def test_get_kubernetes_kubeconfig_when_not_ok(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.rest = MagicMock() + k.rest.get = MagicMock() + k.rest.get.return_value.status_code = 400 + k.rest.get.return_value.body = "kubeconfig" + self.assertNotEqual(k.get_kubernetes_kubeconfig(), "kubeconfig") + + def test_get_kubernetes_when_found(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.get_by_name = MagicMock() + k.get_by_name.return_value = {"id": 42} + self.assertEqual(k.get_kubernetes(), {"id": 42}) + + def test_get_kubernetes_when_not_found(self): + module = MagicMock() + k = DOKubernetesInfo(module) + k.get_by_name = MagicMock() + k.get_by_name.return_value = None + self.assertIsNone(k.get_kubernetes()) + + def test_get_when_found(self): + module = MagicMock() + module.exit_json = MagicMock() + k = DOKubernetesInfo(module) + k.get_kubernetes = MagicMock() + k.get_kubernetes_kubeconfig = MagicMock() + k.get() + module.exit_json.assert_called() + + def test_get_when_not_found(self): + module = MagicMock() + module.fail_json = MagicMock() + k = DOKubernetesInfo(module) + k.get_kubernetes = MagicMock() + k.get_kubernetes.return_value = None + k.get() + module.fail_json.assert_called() diff --git a/ansible_collections/community/digitalocean/tests/utils/render.sh b/ansible_collections/community/digitalocean/tests/utils/render.sh new file mode 100755 index 000000000..5ffcf1be8 --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/utils/render.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Renders tests/integration/integration_config.yml + +set -e +set -o pipefail +set -u + +function main() +{ + readonly template="$1"; shift + readonly content="$(cat "$template")" + + eval "echo \"$content\"" +} + +main "$@" |