nixbot

builds

failed treefmt-check checks.x86_64-linux.treefmt · build #249 · raw

1treefmt v2.5.0traversed 396 files2emitted 361 files for processing3formatted 361 files (11 changed) in 878ms4 M docs/gen-ssh-config.sh5 M docs/generate-host-info.sh6 M docs/generate-lldp-graph.sh7 M docs/get-lldp-neighbors.sh8 M docs/hosts/README.md9 M docs/hosts/eta.md10 M docs/hosts/psi.md11 M docs/hosts/rho.md12 M docs/hosts/tau.md13 M tasks.py14 M tests/test_generate_network_topology.py15diff --git a/docs/gen-ssh-config.sh b/docs/gen-ssh-config.sh16index 7d7300d..575c5a6 10075517--- a/docs/gen-ssh-config.sh18+++ b/docs/gen-ssh-config.sh19@@ -3,10 +3,10 @@ set -euo pipefail20 21 user=${1:-}22 23-if [[ -z "$user" ]]; then24- echo "Missing username"25- echo "Usage: $(basename "$0") username"26- exit 127+if [[ -z $user ]]; then28+ echo "Missing username"29+ echo "Usage: $(basename "$0") username"30+ exit 131 fi32 33 # GitHub directory pages change independently of this script; use the stable API.34@@ -28,20 +28,20 @@ Host eta35 EOF36 37 curl -fsSL \38- -H 'Accept: application/vnd.github+json' \39- -H 'X-GitHub-Api-Version: 2022-11-28' \40- 'https://api.github.com/repos/SBEE-Lab/infra/contents/hosts?ref=main' \41- > "$tempfile"42-machines=$(grep -oE '"name"[[:space:]]*:[[:space:]]*"[^"]+\.nix"' "$tempfile" \43- | sed -E 's/.*"([^"]+)\.nix"/\1/' \44- | sort -u)45+ -H 'Accept: application/vnd.github+json' \46+ -H 'X-GitHub-Api-Version: 2022-11-28' \47+ 'https://api.github.com/repos/SBEE-Lab/infra/contents/hosts?ref=main' \48+ >"$tempfile"49+machines=$(grep -oE '"name"[[:space:]]*:[[:space:]]*"[^"]+\.nix"' "$tempfile" |50+ sed -E 's/.*"([^"]+)\.nix"/\1/' |51+ sort -u)52 53 while read -r machine; do54- if [[ -z "$machine" || "$machine" == "eta" ]]; then55- continue56- fi57+ if [[ -z $machine || $machine == "eta" ]]; then58+ continue59+ fi60 61- cat <<EOF62+ cat <<EOF63 Host $machine64 HostName $machine.sjanglab.org65 User $user66@@ -50,4 +50,4 @@ Host $machine67 ProxyJump eta68 69 EOF70-done <<< "$machines"71+done <<<"$machines"72diff --git a/docs/generate-host-info.sh b/docs/generate-host-info.sh73index c213cd5..3e61dcd 10075574--- a/docs/generate-host-info.sh75+++ b/docs/generate-host-info.sh76@@ -1,9 +1,9 @@77 #!/usr/bin/env bash78 set -euo pipefail79 80-if [[ -z "${1:-}" ]]; then81- echo "Usage: $(basename "$0") host" >&282- exit 183+if [[ -z ${1:-} ]]; then84+ echo "Usage: $(basename "$0") host" >&285+ exit 186 fi87 88 target=$189@@ -13,15 +13,15 @@ lstopo="$hostname.lstopo.svg"90 printf '# %s91 92 ```93-' "$hostname" > "$report"94-ssh "$target" -- "nix-shell -p 'inxi.override { withRecommends = true; }' --run 'sudo inxi -F -a -i --slots -xxx -c0 -z -m'" >> "$report"95+' "$hostname" >"$report"96+ssh "$target" -- "nix-shell -p 'inxi.override { withRecommends = true; }' --run 'sudo inxi -F -a -i --slots -xxx -c0 -z -m'" >>"$report"97 tempfile=$(mktemp -t sbee-host-info.XXXXXX)98-sed -E 's/(uuid: )[^ ]+/\1<filter>/g' "$report" > "$tempfile"99+sed -E 's/(uuid: )[^ ]+/\1<filter>/g' "$report" >"$tempfile"100 mv "$tempfile" "$report"101 ssh "$target" -- "nix-shell -p hwloc -p dmidecode --run 'sudo lstopo /tmp/$hostname.lstopo.svg'"102 scp "$target:/tmp/$hostname.lstopo.svg" "$lstopo"103 ssh "$target" -- "sudo rm /tmp/$hostname.lstopo.svg"104 printf '```105 ![hardware topology](%s)106-' "$lstopo" >> "$report"107+' "$lstopo" >>"$report"108 echo "wrote $report" >&2109diff --git a/docs/generate-lldp-graph.sh b/docs/generate-lldp-graph.sh110index facbd2f..7fbaa06 100755111--- a/docs/generate-lldp-graph.sh112+++ b/docs/generate-lldp-graph.sh113@@ -1,9 +1,9 @@114 #!/usr/bin/env bash115 set -euo pipefail116 117-if (( BASH_VERSINFO[0] < 4 )); then118- echo "$(basename "$0") requires Bash 4 or newer" >&2119- exit 1120+if ((BASH_VERSINFO[0] < 4)); then121+ echo "$(basename "$0") requires Bash 4 or newer" >&2122+ exit 1123 fi124 125 report="../graph.md"126@@ -11,60 +11,60 @@ url="https://github.com/SBEE-Lab/infra/blob/main/docs/hosts"127 declare -A interfaces128 129 {130- echo '```mermaid'131- echo ' graph TD'132+ echo '```mermaid'133+ echo ' graph TD'134 135- for host_file in *; do136- [[ -f "$host_file" ]] || continue137- while read -r neighbor; do138- [[ -z "$neighbor" ]] && continue139- host_interface=$(echo "$neighbor" | cut -d' ' -f1)140- link_speed=$(echo "$neighbor" | cut -d' ' -f2)141- neighbor_interface=$(echo "$neighbor" | cut -d' ' -f3 | tr -cd '[:alnum:]._-')142- neighbor_name=$(echo "$neighbor" | cut -d' ' -f4 | tr -cd '[:alnum:]._-')143+ for host_file in *; do144+ [[ -f $host_file ]] || continue145+ while read -r neighbor; do146+ [[ -z $neighbor ]] && continue147+ host_interface=$(echo "$neighbor" | cut -d' ' -f1)148+ link_speed=$(echo "$neighbor" | cut -d' ' -f2)149+ neighbor_interface=$(echo "$neighbor" | cut -d' ' -f3 | tr -cd '[:alnum:]._-')150+ neighbor_name=$(echo "$neighbor" | cut -d' ' -f4 | tr -cd '[:alnum:]._-')151 152- interfaces[$host_file]+=" $host_interface"153- interfaces[$neighbor_name]+=" $neighbor_interface"154+ interfaces[$host_file]+=" $host_interface"155+ interfaces[$neighbor_name]+=" $neighbor_interface"156 157- echo " ${host_file}.${host_interface}[\"$host_interface\"]-- $link_speed ---${neighbor_name}.${neighbor_interface}[\"$neighbor_interface\"]"158- done < "$host_file"159- done160+ echo " ${host_file}.${host_interface}[\"$host_interface\"]-- $link_speed ---${neighbor_name}.${neighbor_interface}[\"$neighbor_interface\"]"161+ done <"$host_file"162+ done163 164- for host in "${!interfaces[@]}"; do165- interfaces[$host]=$(xargs -n 1 <<< "${interfaces[$host]}" | sort -u | xargs)166- echo " subgraph $host"167- for interface in ${interfaces[$host]}; do168- echo " ${host}.${interface}[\"$interface\"]"169- done170- echo " end"171+ for host in "${!interfaces[@]}"; do172+ interfaces[$host]=$(xargs -n 1 <<<"${interfaces[$host]}" | sort -u | xargs)173+ echo " subgraph $host"174+ for interface in ${interfaces[$host]}; do175+ echo " ${host}.${interface}[\"$interface\"]"176 done177+ echo " end"178+ done179 180- for host in "${!interfaces[@]}"; do181- [[ -f "../$host.md" ]] || continue182- for interface in ${interfaces[$host]}; do183- echo " click ${host}.${interface} \"$url/$host.md\" \"$host\""184- done185+ for host in "${!interfaces[@]}"; do186+ [[ -f "../$host.md" ]] || continue187+ for interface in ${interfaces[$host]}; do188+ echo " click ${host}.${interface} \"$url/$host.md\" \"$host\""189 done190+ done191 192- echo '```'193-} > "$report"194+ echo '```'195+} >"$report"196 197 # Remove inverse duplicate links.198 while true; do199- duplicate=""200- while read -r link; do201- interface_1=$(awk '{print $1}' <<< "$link" | rev | cut -c 3- | rev)202- link_speed=$(awk '{print $2}' <<< "$link")203- interface_2=$(awk '{print $3}' <<< "$link" | cut -c 4-)204- candidate="$interface_2-- $link_speed ---$interface_1"205- if grep -q -F "$candidate" "$report"; then206- duplicate=$candidate207- break208- fi209- done < <(grep -E -- '-- [[:digit:]]+[GM] ---' "$report")210+ duplicate=""211+ while read -r link; do212+ interface_1=$(awk '{print $1}' <<<"$link" | rev | cut -c 3- | rev)213+ link_speed=$(awk '{print $2}' <<<"$link")214+ interface_2=$(awk '{print $3}' <<<"$link" | cut -c 4-)215+ candidate="$interface_2-- $link_speed ---$interface_1"216+ if grep -q -F "$candidate" "$report"; then217+ duplicate=$candidate218+ break219+ fi220+ done < <(grep -E -- '-- [[:digit:]]+[GM] ---' "$report")221 222- [[ -n "$duplicate" ]] || break223- tempfile=$(mktemp -t sbee-lldp-graph.XXXXXX)224- awk -v pattern="$duplicate" 'index($0, pattern) == 0' "$report" > "$tempfile"225- mv "$tempfile" "$report"226+ [[ -n $duplicate ]] || break227+ tempfile=$(mktemp -t sbee-lldp-graph.XXXXXX)228+ awk -v pattern="$duplicate" 'index($0, pattern) == 0' "$report" >"$tempfile"229+ mv "$tempfile" "$report"230 done231diff --git a/docs/get-lldp-neighbors.sh b/docs/get-lldp-neighbors.sh232index 01f8d12..1396412 100755233--- a/docs/get-lldp-neighbors.sh234+++ b/docs/get-lldp-neighbors.sh235@@ -1,9 +1,9 @@236 #!/usr/bin/env bash237 set -euo pipefail238 239-if [[ -z "${1:-}" ]]; then240- echo "Usage: $(basename "$0") host" >&2241- exit 1242+if [[ -z ${1:-} ]]; then243+ echo "Usage: $(basename "$0") host" >&2244+ exit 1245 fi246 247 target=$1248@@ -12,17 +12,17 @@ report="$hostname"249 lldp=$(ssh "$target" -- networkctl lldp --json=short)250 251 while IFS=$' ' read -r interface neighbor_interface neighbor_name; do252- [[ -z "$interface" ]] && continue253- link_speed=$(ssh "$target" -- cat "/sys/class/net/$interface/speed" < /dev/null)254+ [[ -z $interface ]] && continue255+ link_speed=$(ssh "$target" -- cat "/sys/class/net/$interface/speed" </dev/null)256 257- if (( link_speed >= 1000 )); then258- speed="$((link_speed / 1000))G"259- else260- speed="${link_speed}M"261- fi262- echo "$interface $speed $neighbor_interface $neighbor_name"263+ if ((link_speed >= 1000)); then264+ speed="$((link_speed / 1000))G"265+ else266+ speed="${link_speed}M"267+ fi268+ echo "$interface $speed $neighbor_interface $neighbor_name"269 done < <(270- python3 -c '271+ python3 -c '272 import json273 import sys274 275@@ -37,7 +37,7 @@ for interface in data.get("Neighbors", []):276 )277 remote_name = neighbor.get("SystemName") or neighbor.get("ChassisID")278 print(name, remote_interface, remote_name, sep="\t")279-' <<< "$lldp"280-) > "$report"281+' <<<"$lldp"282+) >"$report"283 284 echo "wrote $report" >&2285diff --git a/docs/hosts/README.md b/docs/hosts/README.md286index 388bc1b..2d07aaf 100644287--- a/docs/hosts/README.md288+++ b/docs/hosts/README.md289@@ -10,7 +10,7 @@290 291 ## 하드웨어 보고서292 293-저장소 devShell에서 전체 inventory를 갱신합니다. 대상은 [공용 SSH 설정](../dev/ssh-access.md#공용-ssh-설정)에 등록되어 있어야 하며 원격 `sudo` 권한이 필요합니다.294+저장소 devShell에서 전체 inventory를 갱신합니다. 대상은 [공용 SSH 설정](../dev/ssh-access.md#%EA%B3%B5%EC%9A%A9-ssh-%EC%84%A4%EC%A0%95)에 등록되어 있어야 하며 원격 `sudo` 권한이 필요합니다.295 296 ```bash297 nix develop298diff --git a/docs/hosts/eta.md b/docs/hosts/eta.md299index ee45ad6..94c55e3 100644300--- a/docs/hosts/eta.md301+++ b/docs/hosts/eta.md302@@ -98,4 +98,5 @@ Info:303 Packages: pm: nix-default pkgs: 0 pm: nix-sys pkgs: 588 libs: 58 pm: nix-usr pkgs: 0 Compilers:304 gcc: 15.3.0 Client: Sudo v: 1.9.17p2 inxi: 3.3.41305 ```306+307 ![hardware topology](eta.lstopo.svg)308diff --git a/docs/hosts/psi.md b/docs/hosts/psi.md309index 8756e00..945eec5 100644310--- a/docs/hosts/psi.md311+++ b/docs/hosts/psi.md312@@ -187,4 +187,5 @@ Info:313 Packages: pm: nix-default pkgs: 0 pm: nix-sys pkgs: 557 libs: 86 pm: nix-usr pkgs: 0 Compilers:314 gcc: 15.3.0 Client: Sudo v: 1.9.17p2 inxi: 3.3.41315 ```316+317 ![hardware topology](psi.lstopo.svg)318diff --git a/docs/hosts/rho.md b/docs/hosts/rho.md319index 9bb6663..2f011ab 100644320--- a/docs/hosts/rho.md321+++ b/docs/hosts/rho.md322@@ -130,4 +130,5 @@ Info:323 Packages: pm: nix-default pkgs: 0 pm: nix-sys pkgs: 438 libs: 54 pm: nix-usr pkgs: 0 Compilers:324 gcc: 15.3.0 Client: Sudo v: 1.9.17p2 inxi: 3.3.41325 ```326+327 ![hardware topology](rho.lstopo.svg)328diff --git a/docs/hosts/tau.md b/docs/hosts/tau.md329index 22e4222..4894ab2 100644330--- a/docs/hosts/tau.md331+++ b/docs/hosts/tau.md332@@ -130,4 +130,5 @@ Info:333 Packages: pm: nix-default pkgs: 0 pm: nix-sys pkgs: 555 libs: 84 pm: nix-usr pkgs: 0 Compilers:334 gcc: 15.3.0 Client: Sudo v: 1.9.17p2 inxi: 3.3.41335 ```336+337 ![hardware topology](tau.lstopo.svg)338diff --git a/tasks.py b/tasks.py339index de1b8a0..a8a9250 100755340--- a/tasks.py341+++ b/tasks.py342@@ -187,11 +187,10 @@ def update_lldp_info(c: Any, hosts: str = "") -> None:343 graph_script = ROOT / "docs" / "generate-lldp-graph.sh"344 output_dir.mkdir(parents=True, exist_ok=True)345 346- with TemporaryDirectory(prefix="lldp-", dir=output_dir) as lldp_dir:347- with c.cd(lldp_dir):348- for host in inventory_hostnames(hosts):349- c.run(f"{shlex.quote(str(collect_script))} {shlex.quote(host)}")350- c.run(shlex.quote(str(graph_script)))351+ with TemporaryDirectory(prefix="lldp-", dir=output_dir) as lldp_dir, c.cd(lldp_dir):352+ for host in inventory_hostnames(hosts):353+ c.run(f"{shlex.quote(str(collect_script))} {shlex.quote(host)}")354+ c.run(shlex.quote(str(graph_script)))355 356 357 @task358diff --git a/tests/test_generate_network_topology.py b/tests/test_generate_network_topology.py359index 67c98fa..5aee91a 100644360--- a/tests/test_generate_network_topology.py361+++ b/tests/test_generate_network_topology.py362@@ -2,7 +2,6 @@ import importlib.util363 import unittest364 from pathlib import Path365 366-367 SCRIPT = Path(__file__).parents[1] / "docs" / "generate-network-topology.py"368 369