Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/playbooks/checks/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Run preflight checks
hosts: localhost
gather_facts: false
tasks:
- name: Run IPv6 check script
command: "{{ playbook_dir }}/../../roles/ipv6_check/files/foreman_ipv6_check"
register: ipv6_check
failed_when: ipv6_check.rc != 0

13 changes: 13 additions & 0 deletions src/roles/ipv6_check/files/foreman_ipv6_check
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

RED=$(tput setaf 1 2>/dev/null)
RESET=$(tput sgr0 2>/dev/null)

if grep -q "ipv6.disable=1" /proc/cmdline ; then
echo "${RED}FAIL${RESET}: The kernel contains ipv6.disable=1 which breaks installation and upgrade."
echo "Remove this boot parameter and reboot before continuing."
exit 2
fi

echo "IPv6 check: OK"
exit 0
28 changes: 28 additions & 0 deletions tests/unit/test_foreman_ipv6_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import subprocess
import pytest
import os

TEST_DIR = os.path.dirname(os.path.abspath(__file__))
SCRIPT_PATH = os.path.abspath(os.path.join(TEST_DIR, "..", "..", "src", "roles", "ipv6_check", "files", "foreman-ipv6-check"))

if not os.path.exists(SCRIPT_PATH):
pytest.fail(f"Script not found at: {SCRIPT_PATH}")

def run_script_with_mocked_cmdline(cmdline_content):
"""Helper to mock /proc/cmdline using subprocess input."""
return subprocess.run(
["bash", "-c", f'echo "{cmdline_content}" | {SCRIPT_PATH}'],
text=True,
capture_output=True,
shell=False,
)

def test_ipv6_check_passes_on_valid_cmdline():
result = run_script_with_mocked_cmdline("quiet splash")
assert result.returncode == 0
assert "IPv6 check: OK" in result.stdout

def test_ipv6_check_fails_on_disabled_ipv6():
result = run_script_with_mocked_cmdline("quiet splash ipv6.disable=1")
assert result.returncode == 2
assert "FAIL" in result.stdout or result.stderr
Loading