Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Dec 9, 2023
1 parent 18e753d commit b5e1699
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 28 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Ansible Collection - ansibleguy.nftables

[![Functional Test Status](https://badges.ansibleguy.net/nftables.collection.test.svg)](https://github.com/ansibleguy/collection_nftables/blob/latest/scripts/test.sh)
[![Lint](https://github.com/ansibleguy/collection_nftables/actions/workflows/lint.yml/badge.svg?branch=latest)](https://github.com/ansibleguy/collection_nftables/actions/workflows/lint.yml)
[![Unit Tests](https://github.com/ansibleguy/collection_nftables/actions/workflows/test.yml/badge.svg)](https://github.com/ansibleguy/collection_nftables/actions/workflows/test.yml)
[![Molecule Test Status](https://badges.ansibleguy.net/collection_nftables.molecule.svg)](https://github.com/ansibleguy/collection_nftables/blob/latest/roles/)
[![Ansible Galaxy](https://badges.ansibleguy.net/galaxy.badge.svg)](https://galaxy.ansible.com/ui/repo/published/ansibleguy/nftables)
[![Docs](https://readthedocs.org/projects/nftables_ansible/badge/?version=latest&style=flat)](https://nftables.ansibleguy.net)

[![Functional Test Status](https://badges.ansibleguy.net/nftables.collection.test.svg)](https://github.com/ansibleguy/collection_nftables/blob/latest/scripts/test.sh)
[![YamlLint Test Status](https://badges.ansibleguy.net/collection_nftables.yamllint.svg)](https://github.com/ansibleguy/_meta_cicd/blob/latest/templates/usr/local/bin/cicd/yamllint.sh.j2)
[![PyLint Test Status](https://badges.ansibleguy.net/collection_nftables.pylint.svg)](https://github.com/ansibleguy/_meta_cicd/blob/latest/templates/usr/local/bin/cicd/pylint.sh.j2)
[![Ansible-Lint Test Status](https://badges.ansibleguy.net/collection_nftables.ansiblelint.svg)](https://github.com/ansibleguy/_meta_cicd/blob/latest/templates/usr/local/bin/cicd/ansiblelint.sh.j2)
[![Ansible Galaxy](https://badges.ansibleguy.net/galaxy.badge.svg)](https://galaxy.ansible.com/ui/repo/published/ansibleguy/nftables)
[![Docs](https://readthedocs.org/projects/nftables_ansible/badge/?version=latest&style=flat)](https://nftables.ansibleguy.net)

Functional Test Logs: [Short](https://badges.ansibleguy.net/log/collection_nftables_test_short.log), [Full](https://badges.ansibleguy.net/log/collection_nftables_test.log)

Expand Down Expand Up @@ -76,7 +76,7 @@ You might want to install it using Ansible:
```yaml
- name: Installing NFTables
ansible.builtin.package:
name: ['nftables'] # or ['nftables', 'python3-nftables]
name: ['nftables'] # or ['nftables', 'python3-nftables']

- name: Installing NFTables python-module
ansible.builtin.pip:
Expand Down
4 changes: 3 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ source "$(dirname "$0")/test_prep.sh" # shared
echo ''
echo '##### STARTING #####'

ansible-playbook -k -K -i inventory/hosts.yml test.yml "$@"
echo "EXECUTING: ansible-playbook -i inventory/hosts.yml test.yml ${ARG_FLAGS}"
# shellcheck disable=SC2046
ansible-playbook -i inventory/hosts.yml test.yml $ARG_FLAGS

rm -rf "$TMP_DIR"

Expand Down
4 changes: 3 additions & 1 deletion scripts/test_cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ source "$(dirname "$0")/test_prep.sh" # shared
echo ''
echo '##### STARTING #####'

ansible-playbook -k -K -i inventory/hosts.yml cleanup.yml "$@"
echo "EXECUTING: ansible-playbook -i inventory/hosts.yml cleanup.yml ${ARG_FLAGS}"
# shellcheck disable=SC2046
ansible-playbook -i inventory/hosts.yml cleanup.yml $ARG_FLAGS

rm -rf "$TMP_DIR"

Expand Down
10 changes: 10 additions & 0 deletions scripts/test_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ then
then
TEST_PWD="$(cat "$TEST_PWD")"
fi
echo "CONFIG: User '${TEST_USER}', Port '${TEST_PORT}', VM '${TEST_VM}', CONTAINER '${TEST_CONT}'"
fi

cd "$(dirname "$0")/.."
Expand All @@ -27,3 +28,12 @@ export ANSIBLE_COLLECTIONS_PATH="$TMP_COL_DIR"
export ANSIBLE_INVENTORY_UNPARSED_WARNING=False

cd "${COL_DIR}/tests/"

ARG_FLAGS=''
for arg in "$@"
do
if [[ $arg == -* ]]
then
ARG_FLAGS="${ARG_FLAGS} ${arg}"
fi
done
8 changes: 5 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Both must be reachable by SSH as **we are using Ansible directly for integration

You can also only set-up one of these test-systems.

But you will have to run Ansible by using the `--limit container` or `--limit vm` argument.
But you will have to run Ansible by using the `--limit=container` or `--limit=vm` argument.

Python libraries: `apt install python3-nftables python3-packaging`

### Virtual Machine

Expand Down Expand Up @@ -81,7 +83,7 @@ Parameters you add to the test-script execution will be passed to `ansible-playb
Examples:

* Enable difference-mode: `bash scripts/test.sh -D`
* Limit the execution: `bash scripts/test.sh --limit container`
* Only test one module: `bash scripts/test.sh -e test_module=list`
* Limit the execution: `bash scripts/test.sh --limit=container`
* Only test one module: `bash scripts/test.sh -e=test_module=list`

If a testing fails you might need/want to run the cleanup: `bash scripts/test_cleanup.sh`
10 changes: 5 additions & 5 deletions tests/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
- name: Testing NFTables Modules - Cleanup
hosts: testing
become: true
gather_facts: true
gather_facts: false
vars:
ansible_host: "{{ lookup('ansible.builtin.env', ansible_host_env_var) | default(ansible_host) }}"
ansible_port: "{{ lookup('ansible.builtin.env', 'TEST_PORT') | default(ansible_port) }}"
ansible_user: "{{ lookup('ansible.builtin.env', 'TEST_USER') | default(ansible_user) }}"
ansible_sudo_pass: "{{ lookup('ansible.builtin.env', 'TEST_PWD') | default(ansible_sudo_pass) }}"
ansible_host: "{{ lookup('ansible.builtin.env', ansible_host_env_var) | default(_ansible_host) }}"
ansible_port: "{{ lookup('ansible.builtin.env', 'TEST_PORT') | default(_ansible_port) }}"
ansible_user: "{{ lookup('ansible.builtin.env', 'TEST_USER') | default(_ansible_user) }}"
ansible_sudo_pass: "{{ lookup('ansible.builtin.env', 'TEST_PWD') | default(_ansible_sudo_pass) }}"
test_module: 'all'

tasks:
Expand Down
8 changes: 4 additions & 4 deletions tests/inventory/host_vars/container.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---

ansible_host: '0.0.0.0' # ADD YOUR IP
ansible_user: 'dummy' # ADD YOUR USER
ansible_sudo_pass: '' # ADD YOUR PWD
ansible_port: 22
_ansible_host: '0.0.0.0' # ADD YOUR IP
_ansible_user: 'dummy' # ADD YOUR USER
_ansible_sudo_pass: '' # ADD YOUR PWD
_ansible_port: 22

ansible_host_env_var: 'TEST_CONT'
8 changes: 4 additions & 4 deletions tests/inventory/host_vars/vm.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---

ansible_host: '0.0.0.0' # ADD YOUR IP
ansible_user: 'dummy' # ADD YOUR USER
ansible_sudo_pass: '' # ADD YOUR PWD
ansible_port: 22
_ansible_host: '0.0.0.0' # ADD YOUR IP
_ansible_user: 'dummy' # ADD YOUR USER
_ansible_sudo_pass: '' # ADD YOUR PWD
_ansible_port: 22

ansible_host_env_var: 'TEST_VM'
10 changes: 5 additions & 5 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
- name: Testing NFTables Modules
hosts: testing
become: true
gather_facts: true
gather_facts: false
vars:
ansible_host: "{{ lookup('ansible.builtin.env', ansible_host_env_var) | default(ansible_host) }}"
ansible_port: "{{ lookup('ansible.builtin.env', 'TEST_PORT') | default(ansible_port) }}"
ansible_user: "{{ lookup('ansible.builtin.env', 'TEST_USER') | default(ansible_user) }}"
ansible_sudo_pass: "{{ lookup('ansible.builtin.env', 'TEST_PWD') | default(ansible_sudo_pass) }}"
ansible_host: "{{ lookup('ansible.builtin.env', ansible_host_env_var) | default(_ansible_host) }}"
ansible_port: "{{ lookup('ansible.builtin.env', 'TEST_PORT') | default(_ansible_port) }}"
ansible_user: "{{ lookup('ansible.builtin.env', 'TEST_USER') | default(_ansible_user) }}"
ansible_sudo_pass: "{{ lookup('ansible.builtin.env', 'TEST_PWD') | default(_ansible_sudo_pass) }}"
test_module: 'all'

tasks:
Expand Down

0 comments on commit b5e1699

Please sign in to comment.