Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows: check for missing mac_overrides #941

Merged
merged 2 commits into from
Sep 10, 2024
Merged
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
58 changes: 58 additions & 0 deletions .github/checks/check-mac-override-missing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Initialize a variable to track if any errors are found
error_found=0

# Define patterns for location files and model files
location_files='locations/*.yml'
model_files='group_vars/model_*.yml'

# Find all models that require a mac_override
declare -A mac_override_required_models

for model_file_path in $model_files; do
# Extract model name from file path
model_file=$(basename "$model_file_path" .yml)
model_name=${model_file#model_}

# Check if the model requires mac_override
requires_mac_override=$(yq '.requires_mac_override' "$model_file_path" | tr -d '"')

# Store the result in the associative array
mac_override_required_models["$model_name"]=$requires_mac_override
done

# Find all missing mac_overrides
for location_file in $location_files; do
# Get hosts as a single YAML block to minimize calls to yq
hosts=$(yq '.hosts' "$location_file")

# Loop through each host entry
for i in $(seq 0 $(($(echo "$hosts" | yq '. | length') - 1))); do
hostname=$(echo "$hosts" | yq ".[$i].hostname" | tr -d '"')
model=$(echo "$hosts" | yq ".[$i].model" | tr -d '"')
mac_override=$(echo "$hosts" | yq ".[$i].mac_override" | tr -d '"')

# Convert model name to match the model file format (underscore instead of hyphen)
model_name=${model//-/_}

# Check if the model requires mac_override using the associative array
requires_mac_override=${mac_override_required_models["$model_name"]}

if [ "$requires_mac_override" = "true" ]; then
if [ "$mac_override" == "null" ]; then
# Output the missing mac_override details immediately
echo "Host $hostname (model: $model) in $location_file is missing mac_override."
error_found=1
fi
fi
done
done

# Exit with a non-zero status code if any errors were found
if [ "$error_found" -eq 1 ]; then
exit 1
else
echo "No MAC override issues found."
fi

17 changes: 17 additions & 0 deletions .github/workflows/check-mac-override-missing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Check missing mac_overrides

on: [push, pull_request] # yamllint disable-line rule:truthy

jobs:
check-mac-override-missing:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run mac_override missing check
run: |
./.github/checks/check-mac-override-missing.sh
4 changes: 4 additions & 0 deletions group_vars/model_dlink_covr_x1860_a1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ dsa_ports:
- internet
- ethernet

# Mac address can be read with the following command:
# cat /dev/mtdblock$(grep -w 'config2' /proc/mtd | sed -n 's/^mtd\([0-9]\+\):.*/\1/p') | grep -o 'factory_mac=[^ ]*' | cut -d= -f2
requires_mac_override: true

wireless_devices:
- name: 11a_standard
band: 5g
Expand Down
4 changes: 4 additions & 0 deletions group_vars/model_mikrotik_sxtsq_2_lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ model_nice: SXTsq Lite2

int_port: eth0

# Mac address can be read with the following command:
# cat /sys/firmware/mikrotik/hard_config/mac_base
requires_mac_override: true

wireless_devices:
- name: 11g_standard
band: 2g
Expand Down
4 changes: 4 additions & 0 deletions group_vars/model_mikrotik_sxtsq_5_ac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ model__packages__to_merge:
dsa_ports:
- lan

# Mac address can be read with the following command:
# cat /sys/firmware/mikrotik/hard_config/mac_base
requires_mac_override: true

wireless_devices:
- name: 11a_standard
band: 5g
Expand Down
4 changes: 4 additions & 0 deletions group_vars/model_netgear_wax202.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ dsa_ports:
- lan2
- lan3

# Mac address can be read with the following command:
# cat /dev/mtdblock$(grep -w 'Config' /proc/mtd | sed -n 's/^mtd\([0-9]\+\):.*/\1/p') | grep -o 'mac=[^ ]*' | cut -d= -f2
requires_mac_override: true

wireless_devices:
- name: 11a_standard
band: 5g
Expand Down
2 changes: 2 additions & 0 deletions group_vars/model_netgear_wax220.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ brand_nice: NETGEAR
model_nice: WAX220
int_port: eth0

requires_mac_override: true

wireless_devices:
- name: 11a_standard
band: 5g
Expand Down
Loading