mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-12 12:32:05 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcbe52e722 | ||
|
|
1e711d4da8 | ||
|
|
4b2dc4f974 | ||
|
|
eb0aeeb318 | ||
|
|
f3d3696093 | ||
|
|
e3da2f28fd | ||
|
|
bb599542e8 | ||
|
|
6560fb1c53 | ||
|
|
20084d119e |
@@ -3,6 +3,7 @@ profile: production
|
|||||||
|
|
||||||
exclude_paths:
|
exclude_paths:
|
||||||
- .ansible/
|
- .ansible/
|
||||||
|
- .github/
|
||||||
- tests/integration
|
- tests/integration
|
||||||
- tests/unit
|
- tests/unit
|
||||||
- tests/sanity
|
- tests/sanity
|
||||||
@@ -3,3 +3,4 @@
|
|||||||
plugins/connection/kubectl.py no-changed-when
|
plugins/connection/kubectl.py no-changed-when
|
||||||
# false positive result
|
# false positive result
|
||||||
plugins/connection/kubectl.py var-naming[no-reserved]
|
plugins/connection/kubectl.py var-naming[no-reserved]
|
||||||
|
plugins/connection/kubectl.py jinja[invalid]
|
||||||
|
|||||||
4
.github/workflows/linters.yaml
vendored
4
.github/workflows/linters.yaml
vendored
@@ -20,4 +20,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: run-ansible-lint
|
- name: run-ansible-lint
|
||||||
uses: ansible/ansible-lint@v25.1.2
|
uses: ansible/ansible-lint@main
|
||||||
|
with:
|
||||||
|
gh_action_ref: "v25.5.0"
|
||||||
|
|||||||
@@ -26,3 +26,4 @@ ignore: |
|
|||||||
.tox
|
.tox
|
||||||
.ansible
|
.ansible
|
||||||
tests/output
|
tests/output
|
||||||
|
plugins/connection/kubectl.py
|
||||||
|
|||||||
@@ -4,6 +4,19 @@ Kubernetes Collection Release Notes
|
|||||||
|
|
||||||
.. contents:: Topics
|
.. contents:: Topics
|
||||||
|
|
||||||
|
v5.4.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This release updates the ``helm_registry_auth`` module to match the behavior of ``helm >= 3.18.0`` which reports a successful logout regardless of the current state (i.e., no idempotency).
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- Module ``helm_registry_auth`` does not support idempotency with ``helm >= 3.18.0`` (https://github.com/ansible-collections/kubernetes.core/pull/946)
|
||||||
|
|
||||||
v5.3.0
|
v5.3.0
|
||||||
======
|
======
|
||||||
|
|
||||||
@@ -123,6 +136,14 @@ Bugfixes
|
|||||||
- helm - use ``reuse-values`` when running ``helm diff`` command (https://github.com/ansible-collections/kubernetes.core/issues/680).
|
- helm - use ``reuse-values`` when running ``helm diff`` command (https://github.com/ansible-collections/kubernetes.core/issues/680).
|
||||||
- integrations test helm_kubeconfig - set helm version to v3.10.3 to avoid incompatability with new bitnami charts (https://github.com/ansible-collections/kubernetes.core/pull/670).
|
- integrations test helm_kubeconfig - set helm version to v3.10.3 to avoid incompatability with new bitnami charts (https://github.com/ansible-collections/kubernetes.core/pull/670).
|
||||||
|
|
||||||
|
v3.3.1
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This release fixes the CI issues with the ``linters`` workflow.
|
||||||
|
|
||||||
v3.3.0
|
v3.3.0
|
||||||
======
|
======
|
||||||
|
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
|||||||
# Also needs to be updated in galaxy.yml
|
# Also needs to be updated in galaxy.yml
|
||||||
VERSION = 5.2.0
|
VERSION = 5.4.0
|
||||||
|
|
||||||
TEST_ARGS ?= ""
|
TEST_ARGS ?= ""
|
||||||
PYTHON_VERSION ?= `python -c 'import platform; print(".".join(platform.python_version_tuple()[0:2]))'`
|
PYTHON_VERSION ?= `python -c 'import platform; print(".".join(platform.python_version_tuple()[0:2]))'`
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ You can also include it in a `requirements.yml` file and install it via `ansible
|
|||||||
---
|
---
|
||||||
collections:
|
collections:
|
||||||
- name: kubernetes.core
|
- name: kubernetes.core
|
||||||
version: 5.3.0
|
version: 5.4.0
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installing the Kubernetes Python Library
|
### Installing the Kubernetes Python Library
|
||||||
|
|||||||
@@ -900,6 +900,12 @@ releases:
|
|||||||
- 798-drain-pdb-error-message.yaml
|
- 798-drain-pdb-error-message.yaml
|
||||||
- readme_template_update.yml
|
- readme_template_update.yml
|
||||||
release_date: '2025-01-20'
|
release_date: '2025-01-20'
|
||||||
|
3.3.1:
|
||||||
|
changes:
|
||||||
|
release_summary: This release fixes the CI issues with the ``linters`` workflow.
|
||||||
|
fragments:
|
||||||
|
- release_summary.yml
|
||||||
|
release_date: '2025-03-26'
|
||||||
4.0.0:
|
4.0.0:
|
||||||
changes:
|
changes:
|
||||||
bugfixes:
|
bugfixes:
|
||||||
@@ -1023,13 +1029,13 @@ releases:
|
|||||||
- module_utils/k8s/service - fix issue when trying to delete resource using
|
- module_utils/k8s/service - fix issue when trying to delete resource using
|
||||||
`delete_options` and `check_mode=true` (https://github.com/ansible-collections/kubernetes.core/issues/892).
|
`delete_options` and `check_mode=true` (https://github.com/ansible-collections/kubernetes.core/issues/892).
|
||||||
minor_changes:
|
minor_changes:
|
||||||
- Bump version of ansible-lint to 25.1.2 (https://github.com/ansible-collections/kubernetes.core/pull/919).
|
- kubernetes.core - Bump version of ``ansible-lint`` to ``25.1.2`` (https://github.com/ansible-collections/kubernetes.core/pull/919).
|
||||||
- action/k8s_info - update templating mechanism with changes from ``ansible-core
|
- action/k8s_info - update templating mechanism with changes from ``ansible-core
|
||||||
2.19`` (https://github.com/ansible-collections/kubernetes.core/pull/888).
|
2.19`` (https://github.com/ansible-collections/kubernetes.core/pull/888).
|
||||||
- helm - add reset_then_reuse_values support to helm module (https://github.com/ansible-collections/kubernetes.core/issues/803).
|
- helm - add ``reset_then_reuse_values`` support to helm module (https://github.com/ansible-collections/kubernetes.core/issues/803).
|
||||||
- helm - add support for ``insecure_skip_tls_verify`` option to helm and helm_repository(https://github.com/ansible-collections/kubernetes.core/issues/694).
|
- helm - add support for ``insecure_skip_tls_verify`` option to helm and ``helm_repository`` (https://github.com/ansible-collections/kubernetes.core/issues/694).
|
||||||
release_summary: This release includes minor changes, bug fixes and also bumps
|
release_summary: This release includes minor changes, bug fixes and also bumps
|
||||||
ansible-lint version to ``25.1.2``.
|
``ansible-lint`` version to ``25.1.2``.
|
||||||
fragments:
|
fragments:
|
||||||
- 20250324-k8s_info-templating.yaml
|
- 20250324-k8s_info-templating.yaml
|
||||||
- 5.3.0.yml
|
- 5.3.0.yml
|
||||||
@@ -1038,3 +1044,15 @@ releases:
|
|||||||
- 898-k8s-dont-delete-in-check-mode.yaml
|
- 898-k8s-dont-delete-in-check-mode.yaml
|
||||||
- 919-update-ansible-lint-version.yaml
|
- 919-update-ansible-lint-version.yaml
|
||||||
release_date: '2025-05-16'
|
release_date: '2025-05-16'
|
||||||
|
5.4.0:
|
||||||
|
changes:
|
||||||
|
minor_changes:
|
||||||
|
- Module ``helm_registry_auth`` does not support idempotency with ``helm >= 3.18.0``
|
||||||
|
(https://github.com/ansible-collections/kubernetes.core/pull/946).
|
||||||
|
release_summary: This release updates the ``helm_registry_auth`` module to match the behavior of ``helm >= 3.18.0`` which reports a successful logout regardless of the current state (i.e., no idempotency).
|
||||||
|
fragments:
|
||||||
|
- 20250411-kubeconfig-no_log-revert.yaml
|
||||||
|
- 20250503-fix-unit-tests.yml
|
||||||
|
- 20250605-fix-helm_registry_auth-integration_test.yaml
|
||||||
|
- 5.4.0.yml
|
||||||
|
release_date: '2025-08-12'
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ Parameters
|
|||||||
<div>Desired state of the registry.</div>
|
<div>Desired state of the registry.</div>
|
||||||
<div>If set to V(present) attempt to log in to the remote registry server using the URL specified in O(host).</div>
|
<div>If set to V(present) attempt to log in to the remote registry server using the URL specified in O(host).</div>
|
||||||
<div>If set to V(absent) attempt to log out from the remote registry server using the URL specified in O(host).</div>
|
<div>If set to V(absent) attempt to log out from the remote registry server using the URL specified in O(host).</div>
|
||||||
|
<div>As helm >= 3.18.0 reports successful logout even if the user is not logged in, this module will report a change regardless of the current state.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ tags:
|
|||||||
- openshift
|
- openshift
|
||||||
- okd
|
- okd
|
||||||
- cluster
|
- cluster
|
||||||
version: 5.3.0
|
version: 5.4.0
|
||||||
build_ignore:
|
build_ignore:
|
||||||
- .DS_Store
|
- .DS_Store
|
||||||
- "*.tar.gz"
|
- "*.tar.gz"
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ options:
|
|||||||
- Desired state of the registry.
|
- Desired state of the registry.
|
||||||
- If set to V(present) attempt to log in to the remote registry server using the URL specified in O(host).
|
- If set to V(present) attempt to log in to the remote registry server using the URL specified in O(host).
|
||||||
- If set to V(absent) attempt to log out from the remote registry server using the URL specified in O(host).
|
- If set to V(absent) attempt to log out from the remote registry server using the URL specified in O(host).
|
||||||
|
- As helm >= 3.18.0 reports successful logout even if the user is not logged in, this module will report a change regardless of the current state.
|
||||||
required: false
|
required: false
|
||||||
default: present
|
default: present
|
||||||
choices: ['present', 'absent']
|
choices: ['present', 'absent']
|
||||||
@@ -129,6 +130,9 @@ failed:
|
|||||||
from ansible_collections.kubernetes.core.plugins.module_utils.helm import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.helm import (
|
||||||
AnsibleHelmModule,
|
AnsibleHelmModule,
|
||||||
)
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.version import (
|
||||||
|
LooseVersion,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def arg_spec():
|
def arg_spec():
|
||||||
@@ -231,6 +235,13 @@ def main():
|
|||||||
command=helm_cmd,
|
command=helm_cmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
helm_version = module.get_helm_version()
|
||||||
|
if LooseVersion(helm_version) >= LooseVersion("3.18.0") and state == "absent":
|
||||||
|
# https://github.com/ansible-collections/kubernetes.core/issues/944
|
||||||
|
module.warn(
|
||||||
|
"The helm_registry_auth is not idempotent with helm >= 3.18.0, always report a change."
|
||||||
|
)
|
||||||
|
|
||||||
module.exit_json(changed=changed, stdout=out, stderr=err, command=helm_cmd)
|
module.exit_json(changed=changed, stdout=out, stderr=err, command=helm_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,3 +13,11 @@
|
|||||||
that:
|
that:
|
||||||
- helm_missing_binary is failed
|
- helm_missing_binary is failed
|
||||||
- "'No such file or directory' in helm_missing_binary.msg"
|
- "'No such file or directory' in helm_missing_binary.msg"
|
||||||
|
when: ansible_version.full is version('2.20', '<')
|
||||||
|
|
||||||
|
- name: Assert that helm is not installed (ansible 2.20+)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- helm_missing_binary is failed
|
||||||
|
- "'Error executing command' in helm_missing_binary.msg"
|
||||||
|
when: ansible_version.full is version('2.20', '>=')
|
||||||
|
|||||||
@@ -108,15 +108,19 @@
|
|||||||
assert:
|
assert:
|
||||||
that: "'Removing login credentials' in _helm_registry_auth_logout.stderr"
|
that: "'Removing login credentials' in _helm_registry_auth_logout.stderr"
|
||||||
|
|
||||||
- name: Test logout idempotency
|
- name: Test idempotency of logout with helm < 3.18.0
|
||||||
helm_registry_auth:
|
when: _helm_version.stdout is ansible.builtin.version('v3.18.0', '<')
|
||||||
host: localhost:{{ registry_port }}
|
block:
|
||||||
state: absent
|
|
||||||
register: _helm_registry_auth_logout_idempotency
|
|
||||||
|
|
||||||
- name: Assert logout operation did not report change
|
- name: Test logout idempotency
|
||||||
ansible.builtin.assert:
|
helm_registry_auth:
|
||||||
that: _helm_registry_auth_logout_idempotency is not changed
|
host: localhost:{{ registry_port }}
|
||||||
|
state: absent
|
||||||
|
register: _helm_registry_auth_logout_idempotency
|
||||||
|
|
||||||
|
- name: Assert logout operation did not report change
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: _helm_registry_auth_logout_idempotency is not changed
|
||||||
|
|
||||||
- name: Ensure that not able to push to the registry
|
- name: Ensure that not able to push to the registry
|
||||||
ansible.builtin.shell: >-
|
ansible.builtin.shell: >-
|
||||||
@@ -133,8 +137,7 @@
|
|||||||
# Helm binary prints the message to stderr
|
# Helm binary prints the message to stderr
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- "'push access denied' in _save_chart.stderr"
|
- "'push access denied' in _save_chart.stderr or 'basic credential not found' in _save_chart.stderr"
|
||||||
- "'authorization failed' in _save_chart.stderr"
|
|
||||||
- "_save_chart.rc != 0"
|
- "_save_chart.rc != 0"
|
||||||
- "'localhost:{{ registry_port }}' not in _config_json.content | b64decode"
|
- "'localhost:{{ registry_port }}' not in _config_json.content | b64decode"
|
||||||
|
|
||||||
@@ -155,7 +158,8 @@
|
|||||||
- name: Assert that the registry is not logged in and auth data is not saved
|
- name: Assert that the registry is not logged in and auth data is not saved
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- "'401 Unauthorized' in _helm_registry_auth_wrong.stderr"
|
- "'401' in _helm_registry_auth_wrong.stderr"
|
||||||
|
- "'unauthorized' in _helm_registry_auth_wrong.stderr | lower"
|
||||||
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.command"
|
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.command"
|
||||||
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stdout"
|
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stdout"
|
||||||
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stderr"
|
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stderr"
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
plugins/module_utils/client/discovery.py import-3.9!skip
|
|
||||||
plugins/module_utils/client/discovery.py import-3.10!skip
|
|
||||||
plugins/module_utils/client/discovery.py import-3.11!skip
|
|
||||||
plugins/module_utils/client/resource.py import-3.9!skip
|
|
||||||
plugins/module_utils/client/resource.py import-3.10!skip
|
|
||||||
plugins/module_utils/client/resource.py import-3.11!skip
|
|
||||||
plugins/module_utils/k8sdynamicclient.py import-3.9!skip
|
|
||||||
plugins/module_utils/k8sdynamicclient.py import-3.10!skip
|
|
||||||
plugins/module_utils/k8sdynamicclient.py import-3.11!skip
|
|
||||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
|
||||||
plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc
|
|
||||||
plugins/modules/k8s_service.py validate-modules:parameter-type-not-in-doc
|
|
||||||
tests/unit/module_utils/fixtures/clusteroperator.yml yamllint!skip
|
|
||||||
tests/unit/module_utils/fixtures/definitions.yml yamllint!skip
|
|
||||||
tests/unit/module_utils/fixtures/deployments.yml yamllint!skip
|
|
||||||
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
|
|
||||||
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
|
|
||||||
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
|
|
||||||
plugins/modules/k8s.py validate-modules:return-syntax-error
|
|
||||||
plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
|
||||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
|
||||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
|
||||||
tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
|
||||||
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
plugins/module_utils/client/discovery.py import-3.9!skip
|
|
||||||
plugins/module_utils/client/discovery.py import-3.10!skip
|
|
||||||
plugins/module_utils/client/discovery.py import-3.11!skip
|
plugins/module_utils/client/discovery.py import-3.11!skip
|
||||||
plugins/module_utils/client/resource.py import-3.9!skip
|
plugins/module_utils/client/discovery.py import-3.12!skip
|
||||||
plugins/module_utils/client/resource.py import-3.10!skip
|
plugins/module_utils/client/discovery.py import-3.13!skip
|
||||||
plugins/module_utils/client/resource.py import-3.11!skip
|
plugins/module_utils/client/resource.py import-3.11!skip
|
||||||
plugins/module_utils/k8sdynamicclient.py import-3.9!skip
|
plugins/module_utils/client/resource.py import-3.12!skip
|
||||||
plugins/module_utils/k8sdynamicclient.py import-3.10!skip
|
plugins/module_utils/client/resource.py import-3.13!skip
|
||||||
plugins/module_utils/k8sdynamicclient.py import-3.11!skip
|
plugins/module_utils/k8sdynamicclient.py import-3.11!skip
|
||||||
|
plugins/module_utils/k8sdynamicclient.py import-3.12!skip
|
||||||
|
plugins/module_utils/k8sdynamicclient.py import-3.13!skip
|
||||||
plugins/module_utils/version.py pylint!skip
|
plugins/module_utils/version.py pylint!skip
|
||||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||||
plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc
|
||||||
@@ -2,50 +2,57 @@ from __future__ import absolute_import, division, print_function
|
|||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import json
|
import re
|
||||||
|
|
||||||
import kubernetes
|
import kubernetes
|
||||||
import pytest
|
import pytest
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.core import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.core import (
|
||||||
AnsibleK8SModule,
|
AnsibleK8SModule,
|
||||||
)
|
)
|
||||||
|
from mock import MagicMock, patch
|
||||||
|
|
||||||
MINIMAL_K8S_VERSION = "24.2.0"
|
MINIMAL_K8S_VERSION = "24.2.0"
|
||||||
UNSUPPORTED_K8S_VERSION = "11.0.0"
|
UNSUPPORTED_K8S_VERSION = "11.0.0"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("stdin", [{}], indirect=["stdin"])
|
class FakeAnsibleModule:
|
||||||
def test_no_warn(monkeypatch, stdin, capfd):
|
def __init__(self, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def exit_json(self):
|
||||||
|
raise SystemExit(0)
|
||||||
|
|
||||||
|
|
||||||
|
@patch.object(AnsibleK8SModule, "warn")
|
||||||
|
def test_no_warn(m_ansible_k8s_module_warn, monkeypatch, capfd):
|
||||||
monkeypatch.setattr(kubernetes, "__version__", MINIMAL_K8S_VERSION)
|
monkeypatch.setattr(kubernetes, "__version__", MINIMAL_K8S_VERSION)
|
||||||
|
|
||||||
module = AnsibleK8SModule(argument_spec={})
|
m_ansible_k8s_module_warn.side_effect = print
|
||||||
|
module = AnsibleK8SModule(argument_spec={}, module_class=FakeAnsibleModule)
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
module.exit_json()
|
module.exit_json()
|
||||||
out, err = capfd.readouterr()
|
out, err = capfd.readouterr()
|
||||||
|
m_ansible_k8s_module_warn.assert_not_called()
|
||||||
return_value = json.loads(out)
|
|
||||||
|
|
||||||
assert return_value.get("exception") is None
|
|
||||||
assert return_value.get("warnings") is None
|
|
||||||
assert return_value.get("failed") is None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("stdin", [{}], indirect=["stdin"])
|
@patch.object(AnsibleK8SModule, "warn")
|
||||||
def test_warn_on_k8s_version(monkeypatch, stdin, capfd):
|
def test_warn_on_k8s_version(m_ansible_k8s_module_warn, monkeypatch, capfd):
|
||||||
monkeypatch.setattr(kubernetes, "__version__", UNSUPPORTED_K8S_VERSION)
|
monkeypatch.setattr(kubernetes, "__version__", UNSUPPORTED_K8S_VERSION)
|
||||||
|
|
||||||
module = AnsibleK8SModule(argument_spec={})
|
m_ansible_k8s_module_warn.side_effect = print
|
||||||
|
module = AnsibleK8SModule(argument_spec={}, module_class=FakeAnsibleModule)
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
module.exit_json()
|
module.exit_json()
|
||||||
|
|
||||||
|
m_ansible_k8s_module_warn.assert_called_once()
|
||||||
out, err = capfd.readouterr()
|
out, err = capfd.readouterr()
|
||||||
|
assert (
|
||||||
return_value = json.loads(out)
|
re.search(
|
||||||
|
r"kubernetes<([0-9]+\.[0-9]+\.[0-9]+) is not supported or tested. Some features may not work.",
|
||||||
assert return_value.get("warnings") is not None
|
out,
|
||||||
warnings = return_value["warnings"]
|
)
|
||||||
assert len(warnings) == 1
|
is not None
|
||||||
assert "kubernetes" in str(warnings[0])
|
)
|
||||||
assert MINIMAL_K8S_VERSION in str(warnings[0])
|
|
||||||
|
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -58,9 +65,17 @@ dependencies = [
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"stdin,desired,actual,result", [({}, *d) for d in dependencies], indirect=["stdin"]
|
"stdin,desired,actual,result", [({}, *d) for d in dependencies], indirect=["stdin"]
|
||||||
)
|
)
|
||||||
def test_has_at_least(monkeypatch, stdin, desired, actual, result, capfd):
|
@patch.object(AnsibleK8SModule, "warn")
|
||||||
|
def test_has_at_least(
|
||||||
|
m_ansible_k8s_module_warn, monkeypatch, stdin, desired, actual, result, capfd
|
||||||
|
):
|
||||||
monkeypatch.setattr(kubernetes, "__version__", actual)
|
monkeypatch.setattr(kubernetes, "__version__", actual)
|
||||||
|
|
||||||
|
def fake_warn(x):
|
||||||
|
print(x)
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
m_ansible_k8s_module_warn.side_effect = fake_warn
|
||||||
module = AnsibleK8SModule(argument_spec={})
|
module = AnsibleK8SModule(argument_spec={})
|
||||||
|
|
||||||
assert module.has_at_least("kubernetes", desired) is result
|
assert module.has_at_least("kubernetes", desired) is result
|
||||||
@@ -80,11 +95,18 @@ def test_requires_fails_with_message(
|
|||||||
monkeypatch, stdin, dependency, version, msg, capfd
|
monkeypatch, stdin, dependency, version, msg, capfd
|
||||||
):
|
):
|
||||||
monkeypatch.setattr(kubernetes, "__version__", "24.2.0")
|
monkeypatch.setattr(kubernetes, "__version__", "24.2.0")
|
||||||
module = AnsibleK8SModule(argument_spec={})
|
module = AnsibleK8SModule(argument_spec={}, module_class=FakeAnsibleModule)
|
||||||
|
|
||||||
|
def fake_fail_json(**kwargs):
|
||||||
|
print(f"Printing message => {kwargs}")
|
||||||
|
print(kwargs.get("msg"))
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
module.fail_json = MagicMock()
|
||||||
|
module.fail_json.side_effect = fake_fail_json
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
module.requires(dependency, version)
|
module.requires(dependency, version)
|
||||||
|
module.fail_json.assert_called_once()
|
||||||
out, err = capfd.readouterr()
|
out, err = capfd.readouterr()
|
||||||
return_value = json.loads(out)
|
assert msg in out
|
||||||
|
|
||||||
assert return_value.get("failed")
|
|
||||||
assert msg in return_value.get("msg")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user