mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
[PR #11678/d06c83eb backport][stable-12] etcd3: re-enable and fix tests, add unit tests (#11680)
etcd3: re-enable and fix tests, add unit tests (#11678)
* etcd3: re-enable and fix tests, add unit tests
- Add unit tests for community.general.etcd3 module (12 tests covering
state=present/absent, idempotency, check mode, and error paths)
- Fix integration test setup: update etcd binary to v3.6.9 (from v3.2.14),
download from GitHub releases, add health-check retry loop after start
- Work around etcd3 Python library incompatibility with protobuf >= 4.x
by setting PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- Update to FQCNs throughout integration tests
- Re-enable both etcd3 and lookup_etcd3 integration targets
Fixes https://github.com/ansible-collections/community.general/issues/322
* improve use of multiple context managers
---------
(cherry picked from commit d06c83eb68)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,89 +5,49 @@
|
||||
####################################################################
|
||||
|
||||
# setup etcd3 for integration tests on module/lookup
|
||||
# Copyright 2017, Jean-Philippe Evrard <jean-philippe@evrard.me>
|
||||
# Copyright 2020, SCC France, Eric Belhomme <ebelhomme@fr.scc.com>
|
||||
# Copyright (c) 2017, Jean-Philippe Evrard <jean-philippe@evrard.me>
|
||||
# Copyright (c) 2020, SCC France, Eric Belhomme <ebelhomme@fr.scc.com>
|
||||
# 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: Install etcd3 Python library
|
||||
ansible.builtin.pip:
|
||||
name: "{{ etcd3_pip_module }}"
|
||||
state: present
|
||||
|
||||
# setup etcd3 for supported distros
|
||||
- block:
|
||||
- name: Check if etcdctl is already usable
|
||||
ansible.builtin.command: "{{ etcd3_path }}/etcdctl --endpoints=localhost:2379 endpoint health"
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: etcd3_health_check
|
||||
|
||||
- include_vars: '{{ item }}'
|
||||
with_first_found:
|
||||
- files:
|
||||
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml'
|
||||
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml'
|
||||
- '{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml'
|
||||
- '{{ ansible_facts.os_family }}.yml'
|
||||
- 'default.yml'
|
||||
paths: '../vars'
|
||||
- name: Set up etcd3 binary
|
||||
when: etcd3_health_check.rc != 0
|
||||
block:
|
||||
- name: Ensure clean download directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ etcd3_download_location }}"
|
||||
state: absent
|
||||
|
||||
- name: Upgrade setuptools python2 module
|
||||
pip:
|
||||
name: setuptools<45
|
||||
extra_args: --upgrade
|
||||
state: present
|
||||
when: python_suffix == ''
|
||||
- name: Create download directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ etcd3_download_location }}"
|
||||
state: directory
|
||||
|
||||
- name: Install etcd3 python modules
|
||||
pip:
|
||||
name: "{{ etcd3_pip_module }}"
|
||||
extra_args: --only-binary grpcio
|
||||
state: present
|
||||
- name: Download etcd3
|
||||
ansible.builtin.unarchive:
|
||||
src: "{{ etcd3_download_url }}"
|
||||
dest: "{{ etcd3_download_location }}"
|
||||
remote_src: true
|
||||
|
||||
# Check if re-installing etcd3 is required
|
||||
- name: Check if etcd3ctl exists for reuse.
|
||||
shell: "ETCDCTL_API=3 {{ etcd3_path }}/etcdctl --endpoints=localhost:2379 get foo"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
- name: Start etcd3
|
||||
ansible.builtin.shell: "nohup {{ etcd3_path }}/etcd > /tmp/etcd3.log 2>&1 &"
|
||||
changed_when: true
|
||||
|
||||
- name: Wait for etcd3 to be ready
|
||||
ansible.builtin.command: "{{ etcd3_path }}/etcdctl --endpoints=localhost:2379 endpoint health"
|
||||
register: etcd3_ready
|
||||
until: etcd3_ready.rc == 0
|
||||
retries: 10
|
||||
delay: 3
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: _testetcd3ctl
|
||||
|
||||
- block:
|
||||
# Installing etcd3
|
||||
- name: If can't reuse, prepare download folder
|
||||
file:
|
||||
path: "{{ etcd3_download_location }}"
|
||||
state: directory
|
||||
register: _etcddownloadexists
|
||||
when:
|
||||
- _testetcd3ctl.rc != 0
|
||||
|
||||
- name: Delete download folder if already exists (to start clean)
|
||||
file:
|
||||
path: "{{ etcd3_download_location }}"
|
||||
state: absent
|
||||
when:
|
||||
- _etcddownloadexists is not changed
|
||||
|
||||
- name: Recreate download folder if purged
|
||||
file:
|
||||
path: "{{ etcd3_download_location }}"
|
||||
state: directory
|
||||
when:
|
||||
- _etcddownloadexists is not changed
|
||||
|
||||
- name: Download etcd3
|
||||
unarchive:
|
||||
src: "{{ etcd3_download_url }}"
|
||||
dest: "{{ etcd3_download_location }}"
|
||||
remote_src: true
|
||||
|
||||
# Running etcd3 and kill afterwards if it wasn't running before.
|
||||
- name: Run etcd3
|
||||
shell: "{{ etcd3_path }}/etcd &"
|
||||
register: _etcd3run
|
||||
changed_when: true
|
||||
|
||||
# - name: kill etcd3
|
||||
# command: "pkill etcd"
|
||||
|
||||
when:
|
||||
- _testetcd3ctl.rc != 0
|
||||
|
||||
when:
|
||||
- ansible_facts.distribution | lower ~ "-" ~ ansible_facts.distribution_major_version | lower != 'centos-6'
|
||||
|
||||
Reference in New Issue
Block a user