mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Refactor of consul modules (#7826)
* Extract common functionality. * Refactor duplicated code into module_utils. * Fixed ansible-test issues. * Address review comments. * Revert changes to consul_acl. It uses deprecated APIs disabled since Consul 1.11 (which is EOL), don't bother updating the module anymore. * Remove unused code. * Merge token into default doc fragment. * JSON all the way down. * extract validation tests into custom file and prep for requests removal. * Removed dependency on requests. * Initial test for consul_kv. * fixup license headers. * Revert changes to consul.py since it utilizes python-consul. * Disable the lookup test for now. * Fix python 2.7 support. * Address review comments. * Address review comments. * Addec changelog fragment. * Mark ConsulModule as private.
This commit is contained in:
parent
cd77d67efb
commit
44679e71a2
10 changed files with 365 additions and 476 deletions
76
tests/integration/targets/consul/tasks/consul_general.yml
Normal file
76
tests/integration/targets/consul/tasks/consul_general.yml
Normal file
|
@ -0,0 +1,76 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: ensure unknown scheme fails
|
||||
consul_session:
|
||||
state: info
|
||||
id: dummy
|
||||
scheme: non_existent
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
||||
- name: ensure SSL certificate is checked
|
||||
consul_session:
|
||||
state: info
|
||||
id: dummy
|
||||
port: 8501
|
||||
scheme: https
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: previous task should fail since certificate is not known
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- "'certificate verify failed' in result.msg"
|
||||
|
||||
- name: ensure SSL certificate isn't checked when validate_certs is disabled
|
||||
consul_session:
|
||||
state: info
|
||||
id: dummy
|
||||
port: 8501
|
||||
scheme: https
|
||||
token: "{{ consul_management_token }}"
|
||||
validate_certs: false
|
||||
register: result
|
||||
|
||||
- name: previous task should succeed since certificate isn't checked
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: ensure a secure connection is possible
|
||||
consul_session:
|
||||
state: info
|
||||
id: dummy
|
||||
port: 8501
|
||||
scheme: https
|
||||
token: "{{ consul_management_token }}"
|
||||
ca_path: '{{ remote_dir }}/cert.pem'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: ensure connection errors are handled properly
|
||||
consul_session:
|
||||
state: info
|
||||
id: dummy
|
||||
token: "{{ consul_management_token }}"
|
||||
port: 1234
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result.msg.startswith('Could not connect to consul agent at localhost:1234, error was')
|
57
tests/integration/targets/consul/tasks/consul_kv.yml
Normal file
57
tests/integration/targets/consul/tasks/consul_kv.yml
Normal file
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
# Copyright (c) 2024, Florian Apolloner (@apollo13)
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Create a key
|
||||
consul_kv:
|
||||
key: somekey
|
||||
value: somevalue
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.data.Value == 'somevalue'
|
||||
|
||||
#- name: Test the lookup
|
||||
# assert:
|
||||
# that:
|
||||
# - lookup('community.general.consul_kv', 'somekey', token=consul_management_token) == 'somevalue'
|
||||
|
||||
- name: Update a key with the same data
|
||||
consul_kv:
|
||||
key: somekey
|
||||
value: somevalue
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.data.Value == 'somevalue'
|
||||
|
||||
- name: Remove a key from the store
|
||||
consul_kv:
|
||||
key: somekey
|
||||
state: absent
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.data.Value == 'somevalue'
|
||||
|
||||
- name: Remove a non-existant key from the store
|
||||
consul_kv:
|
||||
key: somekey
|
||||
state: absent
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- not result.data
|
|
@ -80,65 +80,6 @@
|
|||
that:
|
||||
- result is failed
|
||||
|
||||
- name: ensure unknown scheme fails
|
||||
consul_session:
|
||||
state: info
|
||||
id: '{{ session_id }}'
|
||||
scheme: non_existent
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
||||
- name: ensure SSL certificate is checked
|
||||
consul_session:
|
||||
state: info
|
||||
id: '{{ session_id }}'
|
||||
port: 8501
|
||||
scheme: https
|
||||
token: "{{ consul_management_token }}"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: previous task should fail since certificate is not known
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- "'certificate verify failed' in result.msg"
|
||||
|
||||
- name: ensure SSL certificate isn't checked when validate_certs is disabled
|
||||
consul_session:
|
||||
state: info
|
||||
id: '{{ session_id }}'
|
||||
port: 8501
|
||||
scheme: https
|
||||
token: "{{ consul_management_token }}"
|
||||
validate_certs: false
|
||||
register: result
|
||||
|
||||
- name: previous task should succeed since certificate isn't checked
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: ensure a secure connection is possible
|
||||
consul_session:
|
||||
state: info
|
||||
id: '{{ session_id }}'
|
||||
port: 8501
|
||||
scheme: https
|
||||
token: "{{ consul_management_token }}"
|
||||
environment:
|
||||
REQUESTS_CA_BUNDLE: '{{ remote_dir }}/cert.pem'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: delete a session
|
||||
consul_session:
|
||||
state: absent
|
||||
|
|
|
@ -89,6 +89,8 @@
|
|||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- import_tasks: consul_general.yml
|
||||
- import_tasks: consul_kv.yml
|
||||
- import_tasks: consul_session.yml
|
||||
- import_tasks: consul_policy.yml
|
||||
- import_tasks: consul_role.yml
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue