Skip to content

Commit

Permalink
Modernize testing
Browse files Browse the repository at this point in the history
Without this, we would still test two different requirements,
a very old 2.10, and a relatively new ansible.

There is no reason to maintain the 2.10 testing framework, we
can simply modernize the whole system.

This allowed us to bump ansible-lint, and adopt the new lint
recommendations, which are adapted here.

I now also moved back to use Vagrant again, since the molecule
docker is AGAIN broken.

Fixes: #271
  • Loading branch information
evrardjp committed Feb 13, 2025
1 parent b0de11a commit f80a549
Show file tree
Hide file tree
Showing 24 changed files with 429 additions and 283 deletions.
6 changes: 6 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ skip_list:

warn_list: # or 'skip_list' to silence them completely
- experimental # all rules tagged as experimental

exclude_paths:
- .ansible
- .cache
- .venv
- molecule
19 changes: 0 additions & 19 deletions .github/workflows/molecule.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/monthly.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Monthly Molecule Test
name: Monthly Test
on:
schedule:
# Run on the 10th of each month at noon.
Expand All @@ -9,13 +9,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ansible: ["latest"]
tox: ["lint"]
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt remove ansible
sudo apt install tox
- name: Test with molecule using tox
- name: Lint test with tox
run: |
sudo -H -E tox -e ansible-${{ matrix.ansible }}
sudo -H -E tox -e lint
17 changes: 17 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Test
on: [push, pull_request]
jobs:
build:
runs-on: macos-10.15
strategy:
matrix:
tox: ["lint", "molecule_basic"]
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo pip install tox
- name: Test using tox
run: |
sudo -H -E tox -e ${{ matrix.tox }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.retry
*.log
.vagrant/
.ansible
35 changes: 0 additions & 35 deletions .yamllint

This file was deleted.

57 changes: 57 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# How to contribute to this

We welcome all contributions.

Main areas we need:
- Expose the newest features of keepalived into the template, by editing them in the template.
Please make sure your changes do NOT impact other user's templates!
we do not want keepalived to restart for no reason.

- Declare yourself as maintainer of a sub-part of the template.
We are welcoming ppl using keepalived to be part of something they do care about!
If you feel a part of the template is important for you, please mention it in the PR. We would like you to become maintainer and be pinged should the template change.

- Improve our CI.
Make sure our CI is always working by checking the last builds, and fix them in case an issue arise.

# Test requirements

- Tox
- Vagrant
- Virtualbox

We are back to vagrant and virtualbox after a while dealing with molecule docker,
but having many flaky builds and issues.
The interface is not stable, and I want something with very little maintainance.

# Add test coverage

Test coverage is not a goal in itself, basic testing is fine.

However, we welcome the testing of new distributions (especially if you remove an old one at the same time).

To do it, you need to do the following:
- Edit the meta/main.yml to add the distro
- Edit the molecule/basic/molecule.yml to add the vagrant box in need of testing.

For other test coverage, like features, please make sure to add a new tox target,
which calls for a different molecule scenario.

# How to run a lint test

Run `tox -e lint`.

# How to run a functional test

Run `tox -e functional`.
Should the build fail, run `tox -e functional -- --destroy==never` to keep your vagrant box running.

# Contributions that will be refused

- Moving back to molecule[docker]
- Moving back to vagrant and playbooks for testing without molecule
- Moving to vagrant with another driver than the default

# Contributions that will be accepted

Changes which passes testing especially if they have an optional test included proving their behaviour, tested in github actions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ No dependency
Example Playbook
----------------

See it in tests/keepalived-install-example.yml
See it in tests/keepalived-install-example.yml for a simple example (the one used in CI gating).
Please also check tests/keepalived-install-complex-example.yml for a more detailed example with more features (not gated).

Contributing
------------

Please read our CONTRIBUTING.md

License
-------
Expand Down
7 changes: 0 additions & 7 deletions ansible210-requirements.text

This file was deleted.

44 changes: 22 additions & 22 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@ keepalived_selinux_compile_rules:
- keepalived_ping
- keepalived_setpgid

#keepalived_package_state: "latest"
keepalived_package_state: "{{ ( (keepalived_use_latest_stable | default(true)) | bool) | ternary('latest','present') }}"
# keepalived_package_state: "latest"
keepalived_package_state: "{{ ((keepalived_use_latest_stable | default(true)) | bool) | ternary('latest', 'present') }}"

# Keepalived scripts can be defined that trigger notification scripts.
# Examples have been provided below and in the tests directory.
# keepalived_scripts:
#haproxy_check_script:
# check_script: "/etc/keepalived/haproxy_check.sh"
# ##if a src_check_script is defined, it will be uploaded from src_check_script
# ##on the deploy host to the check_script location. If the check_script needs
# ##parameters, you can define the location under dest_check_script.
# src_check_script: "{{ playbook_dir }}/../scripts/keepalived_haproxy_check.sh"
#haproxy_check_script:
# Here is an example with a command instead of a script.
# Add src_check_script if you want to run a script instead of a command
#check_script: "killall -0 haproxy"
# haproxy_check_script:
# check_script: "/etc/keepalived/haproxy_check.sh"
# # if a src_check_script is defined, it will be uploaded from src_check_script
# # on the deploy host to the check_script location. If the check_script needs
# # parameters, you can define the location under dest_check_script.
# src_check_script: "{{ playbook_dir }}/../scripts/keepalived_haproxy_check.sh"
# haproxy_check_script:
# # Here is an example with a command instead of a script.
# # Add src_check_script if you want to run a script instead of a command
# check_script: "killall -0 haproxy"
keepalived_scripts: {}

# Keepalived scripts may rely upon additional packages.
keepalived_scripts_packages: []

#This is the expiration time of your package manager cache.
#When expired, this role will require to update the package manger cache.
#This variable will be removed when the ansible upstream bugs will be fixed.
# This is the expiration time of your package manager cache.
# When expired, this role will require to update the package manger cache.
# This variable will be removed when the ansible upstream bugs will be fixed.
cache_timeout: 600

keepalived_instances: {}
keepalived_sync_groups: {}
keepalived_bind_on_non_local: False
keepalived_bind_on_non_local: false

# In case of VIP failover some applications might stuck on retrying to send
# data without updating ARP. This variable defines amount of retries kernel
Expand All @@ -64,17 +64,17 @@ keepalived_sysctl_tcp_retries: 8
# This list of strings will appear in the global_defs section of the
# keepalived configuration file.
# Example:
#keepalived_global_defs:
# - enable_script_security
# keepalived_global_defs:
# - enable_script_security

# Whether to add systemd overrides for keepalived:
# Wants=network-online.target
# After=network-online.target
keepalived_systemd_overrides: True
keepalived_systemd_overrides: true

# Whether to add systemd option Restart=always
# It depends on bool keepalived_systemd_overrides, so to add both must be True
keepalived_systemd_override_service_restart: False
keepalived_systemd_override_service_restart: false

# Set location of keepalived daemon options file path
# For Debian based systems it's usually /etc/default/keepalived
Expand All @@ -84,6 +84,6 @@ keepalived_daemon_options_file_path: "{{ _keepalived_daemon_options_file_path }}
# Overriding keepalived daemon extra arguments, which will be applied inside of
# the keepalived_daemon_options_file_path variable.
# Example:
#keepalived_daemon_default_options_overrides:
# - "DAEMON_ARGS='--snmp'"
# keepalived_daemon_default_options_overrides:
# - "DAEMON_ARGS='--snmp'"
keepalived_daemon_default_options_overrides: []
8 changes: 0 additions & 8 deletions dev-requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

- name: restart keepalived
- name: Restart keepalived
ansible.builtin.service:
name: "{{ keepalived_service_name }}"
state: "restarted"
register: _servicerestart
when:
- _servicestart is not changed

- name: reload keepalived
- name: Reload keepalived
ansible.builtin.service:
name: "{{ keepalived_service_name }}"
state: "reloaded"
Expand Down
50 changes: 24 additions & 26 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,28 @@
# limitations under the License.

galaxy_info:
role_name: "keepalived"
author: "evrardjp"
description: "This role installs and configure keepalived based on a simple dict"

license: "Apache-2.0"

min_ansible_version: "2.10"

platforms:
- name: "EL"
versions:
- "8"
- name: "Ubuntu"
versions:
- "xenial"
- "bionic"
- "focal"
- name: "Debian"
galaxy_tags:
- "clustering"
- "networking"
- "system"
- "vrrp"
- "vip"
- "lvs"

role_name: "keepalived"
author: "evrardjp"
description: "This role installs and configure keepalived based on a simple dict"
license: "Apache-2.0"
min_ansible_version: "2.10"
platforms:
- name: "EL"
versions:
- "8"
- name: "Ubuntu"
versions:
- "xenial"
- "bionic"
- "focal"
- "noble"
- "jammy"
- name: "Debian"
galaxy_tags:
- "clustering"
- "networking"
- "system"
- "vrrp"
- "vip"
- "lvs"
dependencies: []
15 changes: 15 additions & 0 deletions molecule/basic/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Setup keepalived
hosts: all
remote_user: vagrant
become: true
gather_facts: true
tasks:
- name: Define NIC to use for VRRP
ansible.builtin.set_fact:
vrrp_nic: "{{ (ansible_facts['interfaces'] | reject('equalto', 'lo') | sort)[-1] }}"
- name: Include keepalived scenario vars
ansible.builtin.include_vars: ../../tests/molecule-basic-scenario-vars.yml
- name: Include keepalived role
ansible.builtin.include_role:
name: evrardjp.keepalived
Loading

0 comments on commit f80a549

Please sign in to comment.