diff options
Diffstat (limited to 'ansible_collections/community/digitalocean/tests')
20 files changed, 270 insertions, 36 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 index d742bfd2a..9803b403c 100644 --- a/ansible_collections/community/digitalocean/tests/integration/integration_config.yml.template +++ b/ansible_collections/community/digitalocean/tests/integration/integration_config.yml.template @@ -2,3 +2,4 @@ do_api_key: ${DO_API_KEY} aws_access_key_id: ${AWS_ACCESS_KEY_ID} aws_secret_access_key: ${AWS_SECRET_ACCESS_KEY} +pr_number: ${PR_NUMBER} 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 index 0e52c2cb0..b9c97fa83 100644 --- 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 @@ -1,5 +1,5 @@ do_region: nyc1 -volume_name: gh-ci-volume +volume_name: gh-ci-volume-0-{{ pr_number }} volume_size: 15 volume_down_size: 10 volume_up_size: 20 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 index e69de29bb..7a68b11da 100644 --- 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 @@ -0,0 +1 @@ +disabled 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 index e69de29bb..7a68b11da 100644 --- 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 @@ -0,0 +1 @@ +disabled 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 index 312f53e85..9ab0fe9ec 100644 --- 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 @@ -1,6 +1,6 @@ do_region: nyc1 -droplet_name: gh-ci-droplet -droplet_image: ubuntu-18-04-x64 +droplet_name: gh-ci-droplet-0-{{ pr_number }} +droplet_image: ubuntu-22-04-x64 droplet_size: s-1vcpu-1gb droplet_new_size: s-1vcpu-2gb project_name: gh-ci-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 index 79177be26..69e0c7807 100644 --- 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 @@ -439,8 +439,8 @@ 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] }}" + - (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: @@ -490,8 +490,8 @@ 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') }}" + - (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: 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 index 30cbae2de..f80c4eed9 100644 --- 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 @@ -1,5 +1,5 @@ do_region: nyc1 -droplet_name: gh-ci-droplet -droplet_image: ubuntu-18-04-x64 +droplet_name: gh-ci-droplet-1-{{ pr_number }} +droplet_image: ubuntu-22-04-x64 droplet_size: s-1vcpu-1gb project_name: gh-ci-project 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 index 6dd5f7421..8b69c43c8 100644 --- 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 @@ -1,15 +1,16 @@ do_region: nyc1 +test_project_name: test-kubernetes -cluster_name: gh-ci-k8s +cluster_name: gh-ci-k8s-0-{{ pr_number }} cluster_version: latest cluster_node_pools: - - name: gh-ci-k8s-workers + - name: gh-ci-k8s-workers-0-{{ pr_number }} size: s-1vcpu-2gb count: 1 -cluster_ha_name: gh-ci-ha-k8s +cluster_ha_name: gh-ci-ha-k8s-1-{{ pr_number }} cluster_ha_version: latest cluster_ha_node_pools: - - name: gh-ci-k8s-ha-workers + - name: gh-ci-k8s-ha-workers-1-{{ pr_number }} 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 index 4d605fa79..3635a824b 100644 --- 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 @@ -57,6 +57,28 @@ - result.failed - result.msg == "Kubernetes cluster not found" + - name: Ensure the test project is absent + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ test_project_name }}" + register: project + + - name: Verify test project is absent + ansible.builtin.assert: + that: + - not project.changed + + - name: Create test project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ test_project_name }}" + purpose: Just trying out DigitalOcean + description: This is a test project + environment: Development + register: project + - name: Create the Kubernetes cluster community.digitalocean.digital_ocean_kubernetes: oauth_token: "{{ do_api_key }}" @@ -65,6 +87,7 @@ version: "{{ cluster_version }}" region: "{{ do_region }}" node_pools: "{{ cluster_node_pools }}" + project_name: "{{ test_project_name }}" return_kubeconfig: false wait_timeout: 600 register: result @@ -74,6 +97,8 @@ that: - result.changed - result.data.name == cluster_name + - result.data.kubeconfig is defined + - result.data.kubeconfig | length > 0 - name: Gather information about the Kubernetes cluster community.digitalocean.digital_ocean_kubernetes_info: @@ -103,6 +128,19 @@ - result.data.kubeconfig is defined - result.data.kubeconfig | length > 0 + - name: Get test project resources + community.digitalocean.digital_ocean_project_resource_info: + oauth_token: "{{ do_api_key }}" + name: "{{ test_project_name }}" + register: resources + + - name: Verify kubernetes cluster is present + ansible.builtin.assert: + that: + - resources.data is defined + - resources.data | length == 1 + - resources.data[0].urn == 'do:kubernetes:' + result.data.id + - name: Give the cloud a minute to settle ansible.builtin.pause: minutes: 1 @@ -227,3 +265,10 @@ return_kubeconfig: false wait_timeout: 600 ignore_errors: true # Should this fail, we'll clean it up next run + + - name: Delete test project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ test_project_name }}" + 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/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_kubernetes_info/defaults/main.yml index c1f5ba32b..905687a30 100644 --- 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 @@ -1,8 +1,8 @@ do_region: nyc1 -cluster_name: gh-ci-k8s +cluster_name: gh-ci-k8s-2-{{ pr_number }} cluster_version: latest cluster_node_pools: - - name: gh-ci-k8s-workers + - name: gh-ci-k8s-workers-2-{{ pr_number }} 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 index a0787f33a..4648e40be 100644 --- 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 @@ -16,8 +16,7 @@ register: result ignore_errors: true # expected to fail - - name: Verify Kubernetes cluster information is not found + - name: Verify Kubernetes cluster information is not changed 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/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_load_balancer/defaults/main.yml index a2386cb7f..d1649b1dd 100644 --- 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 @@ -1,6 +1,6 @@ do_region: nyc1 -droplet_name: gh-ci-droplet -droplet_image: ubuntu-18-04-x64 +droplet_name: gh-ci-droplet-2-{{ pr_number }} +droplet_image: ubuntu-22-04-x64 droplet_size: s-1vcpu-1gb lb_name: gh-ci-loadbalancer lb_size: lb-small 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 index e69de29bb..7a68b11da 100644 --- 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 @@ -0,0 +1 @@ +disabled 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 index c25f2f804..f3267faac 100644 --- 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 @@ -1,5 +1,5 @@ do_region: nyc1 -droplet_name: gh-ci-droplet -droplet_image: ubuntu-18-04-x64 +droplet_name: gh-ci-droplet-3-{{ pr_number }} +droplet_image: ubuntu-22-04-x64 droplet_size: s-1vcpu-1gb alert_email: mamercad@gmail.com diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/aliases b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/aliases new file mode 100644 index 000000000..7a68b11da --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/aliases @@ -0,0 +1 @@ +disabled diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/defaults/main.yml new file mode 100644 index 000000000..8b54ada0a --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/defaults/main.yml @@ -0,0 +1,2 @@ +--- +test_project_name: test-project-resources diff --git a/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/tasks/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/tasks/main.yml new file mode 100644 index 000000000..3b311898e --- /dev/null +++ b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_project_resource_info/tasks/main.yml @@ -0,0 +1,156 @@ +--- +- 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 project is absent + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ test_project_name }}" + register: project + + - name: Verify project is absent + ansible.builtin.assert: + that: + - not project.changed + + - name: Create test project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ test_project_name }}" + purpose: Just trying out DigitalOcean + description: This is a test project + environment: Development + register: project + + - name: Create some resource (block storage) + community.digitalocean.digital_ocean_block_storage: + state: present + oauth_token: "{{ do_api_key }}" + command: create + region: fra1 + block_size: 1 + volume_name: fra1-test-project-resources + project: "{{ test_project_name }}" + register: resource + + - name: Get project resources by name + community.digitalocean.digital_ocean_project_resource_info: + oauth_token: "{{ do_api_key }}" + name: "{{ test_project_name }}" + register: resources + + - name: Verify resource is present + ansible.builtin.assert: + that: + - resources.data is defined + - resources.data | length == 1 + - resources.data[0].urn == resource.resources.urn + + - name: Get project resources by id + community.digitalocean.digital_ocean_project_resource_info: + oauth_token: "{{ do_api_key }}" + id: "{{ project.data.project.id }}" + register: resources + + - name: Verify resource is present + ansible.builtin.assert: + that: + - resources.data is defined + - resources.data | length == 1 + - resources.data[0].urn == resource.resources.urn + + - name: Get all projects + community.digitalocean.digital_ocean_project_info: + oauth_token: "{{ do_api_key }}" + register: projects + + - name: Extract currently default project + ansible.builtin.set_fact: + default_project: "{{ projects.data | selectattr('is_default') | first }}" + + - name: Make test project default one + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ project.data.project.name }}" + purpose: "{{ project.data.project.purpose }}" + description: "{{ project.data.project.description }}" + environment: "{{ project.data.project.environment }}" + is_default: true + register: project + + - name: Get project resources of default + community.digitalocean.digital_ocean_project_resource_info: + oauth_token: "{{ do_api_key }}" + register: resources + + - name: Verify resource is present + ansible.builtin.assert: + that: + - resources.data is defined + - resources.data | length == 1 + - resources.data[0].urn == resource.resources.urn + + - name: Get project resources by name + community.digitalocean.digital_ocean_project_resource_info: + oauth_token: "{{ do_api_key }}" + name: "{{ test_project_name }}" + register: resources + + - name: Verify resource is present + ansible.builtin.assert: + that: + - resources.data is defined + - resources.data | length == 1 + - resources.data[0].urn == resource.resources.urn + + - name: Get project resources by id + community.digitalocean.digital_ocean_project_resource_info: + oauth_token: "{{ do_api_key }}" + id: "{{ project.data.project.id }}" + register: resources + + - name: Verify resource is present + ansible.builtin.assert: + that: + - resources.data is defined + - resources.data | length == 1 + - resources.data[0].urn == resource.resources.urn + + - name: Change back default project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: present + name: "{{ default_project.name }}" + purpose: "{{ default_project.purpose }}" + description: "{{ default_project.description }}" + environment: "{{ default_project.environment }}" + is_default: true + register: default_project + + always: + + - name: Delete the resource (block storage) + community.digitalocean.digital_ocean_block_storage: + state: absent + oauth_token: "{{ do_api_key }}" + command: create + region: fra1 + volume_name: fra1-test-project-resources + project: "{{ test_project_name }}" + ignore_errors: true # Should this fail, we'll clean it up next run + + - name: Delete test project + community.digitalocean.digital_ocean_project: + oauth_token: "{{ do_api_key }}" + state: absent + name: "{{ test_project_name }}" + 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/defaults/main.yml b/ansible_collections/community/digitalocean/tests/integration/targets/digital_ocean_snapshot/defaults/main.yml index d1396ae47..ad696e889 100644 --- 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 @@ -1,9 +1,9 @@ do_region: nyc1 -droplet_name: gh-ci-droplet -droplet_image: ubuntu-18-04-x64 +droplet_name: gh-ci-droplet-4-{{ pr_number }} +droplet_image: ubuntu-22-04-x64 droplet_size: s-1vcpu-1gb snapshot_name: gh-ci-snapshot -volume_name: gh-ci-volume +volume_name: gh-ci-volume-4-{{ pr_number }} volume_size: 15 volume_down_size: 10 volume_up_size: 20 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 index 340f36109..2f9062699 100644 --- a/ansible_collections/community/digitalocean/tests/unit/plugins/inventory/test_digitalocean.py +++ b/ansible_collections/community/digitalocean/tests/unit/plugins/inventory/test_digitalocean.py @@ -8,7 +8,7 @@ __metaclass__ = type import pytest -from ansible.errors import AnsibleError, AnsibleParserError +from ansible.errors import AnsibleError from ansible.inventory.data import InventoryData from ansible.template import Templar from ansible.parsing.dataloader import DataLoader @@ -208,7 +208,7 @@ def test_populate_groups_sanitization(inventory, mocker, transform): 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") }}', + "oauth_token": '{{ lookup("random_choice", "my-do-token") }}', "pagination": 100, } return options.get(option) 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 index cfb0f59b6..e919aa450 100644 --- 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 @@ -4,6 +4,7 @@ __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.general.tests.unit.compat.mock import DEFAULT from ansible_collections.community.digitalocean.plugins.modules.digital_ocean_kubernetes import ( DOKubernetes, ) @@ -12,6 +13,7 @@ from ansible_collections.community.digitalocean.plugins.modules.digital_ocean_ku class TestDOKubernetes(unittest.TestCase): def test_get_by_id_when_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -21,6 +23,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_by_id_when_not_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -30,6 +33,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_all_clusters_when_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -39,6 +43,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_all_clusters_when_not_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -48,11 +53,13 @@ class TestDOKubernetes(unittest.TestCase): def test_get_by_name_none(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) self.assertIsNone(k.get_by_name(None)) def test_get_by_name_found(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.get_all_clusters = MagicMock() k.get_all_clusters.return_value = {"kubernetes_clusters": [{"name": "foo"}]} @@ -60,6 +67,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_by_name_not_found(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.get_all_clusters = MagicMock() k.get_all_clusters.return_value = {"kubernetes_clusters": [{"name": "foo"}]} @@ -67,6 +75,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_kubernetes_kubeconfig_when_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -76,6 +85,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_kubernetes_kubeconfig_when_not_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -85,6 +95,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_kubernetes_when_found(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.get_by_name = MagicMock() k.get_by_name.return_value = {"id": 42} @@ -92,6 +103,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_kubernetes_when_not_found(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.get_by_name = MagicMock() k.get_by_name.return_value = None @@ -99,6 +111,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_kubernetes_options_when_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -108,6 +121,7 @@ class TestDOKubernetes(unittest.TestCase): def test_get_kubernetes_options_when_not_ok(self): module = MagicMock() + module.params.get.return_value = False k = DOKubernetes(module) k.rest = MagicMock() k.rest.get = MagicMock() @@ -117,6 +131,7 @@ class TestDOKubernetes(unittest.TestCase): def test_ensure_running_when_running(self): module = MagicMock() + module.params.get.return_value = False module.fail_json = MagicMock() k = DOKubernetes(module) @@ -137,6 +152,7 @@ class TestDOKubernetes(unittest.TestCase): def test_ensure_running_when_not_running(self): module = MagicMock() + module.params.get.return_value = False module.fail_json = MagicMock() k = DOKubernetes(module) @@ -158,14 +174,19 @@ class TestDOKubernetes(unittest.TestCase): def test_create_ok(self): module = MagicMock() + + def side_effect(*args, **kwargs): + if "project_name" == args[0]: + return False + if "regions" == args[0]: + return "nyc1" + return DEFAULT + + module.params.get.side_effect = side_effect 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() @@ -190,21 +211,25 @@ class TestDOKubernetes(unittest.TestCase): 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() + + def side_effect(*args, **kwargs): + if "project_name" == args[0]: + return False + if "regions" == args[0]: + return "nyc1" + return DEFAULT + + module.params.get.side_effect = side_effect 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() @@ -229,13 +254,13 @@ class TestDOKubernetes(unittest.TestCase): 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.params.get.return_value = False module.exit_json = MagicMock() k = DOKubernetes(module) @@ -252,6 +277,7 @@ class TestDOKubernetes(unittest.TestCase): def test_delete_not_ok(self): module = MagicMock() + module.params.get.return_value = False module.exit_json = MagicMock() k = DOKubernetes(module) |