mirror of
https://github.com/jmcorgan/fips.git
synced 2026-07-30 19:46:15 +00:00
Ethernet edges get a veth pair created in the host namespace and then moved into the containers, named from the node ids alone. ethernet-mesh and ethernet-only both connect n01 to n04 and always run together, so one tore down the other's live link. Hash the scenario suffix to four hex characters and insert those after the vh prefix; 15 characters is far too few to carry the suffix itself. The names are now run-specific and never regenerated, so the delete-before-create no longer reclaims an interface an earlier run abandoned. ci-cleanup.sh takes over, deriving the names from the suffixes a run's teardown hands it. It is the first thing that script removes that is neither a docker object nor labelled, so an unscoped reap can sever a running bare simulation's links; testing/README.md and the --reap help say so.
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""Scoping suffix for names that live in a global namespace."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import os
|
|
import sys
|
|
|
|
|
|
def name_suffix() -> str:
|
|
"""Return the suffix appended to globally-scoped names.
|
|
|
|
Docker container names and the generated-config directory are shared
|
|
across every simulation running on the host, so the harness exports
|
|
``FIPS_CI_NAME_SUFFIX`` to keep concurrent runs and concurrent
|
|
scenarios apart. The suffix is empty when the variable is unset, so a
|
|
bare ``chaos.sh`` run renders exactly the same names as it always has.
|
|
"""
|
|
return os.environ.get("FIPS_CI_NAME_SUFFIX", "")
|
|
|
|
|
|
def veth_token(suffix: str) -> str:
|
|
"""Shorten a name suffix to four hex characters.
|
|
|
|
Host interface names have only 15 characters to work with, far fewer
|
|
than the suffix needs, so concurrent scenarios are told apart by a
|
|
hash of it instead. Empty for an empty suffix, so a bare run's
|
|
interface names are unchanged.
|
|
"""
|
|
if not suffix:
|
|
return ""
|
|
return hashlib.sha1(suffix.encode()).hexdigest()[:4]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Print the token for each suffix given on the command line, one per
|
|
# line. ci-cleanup.sh reaps host interfaces by token and calls this
|
|
# rather than re-deriving the hash, so widening the token here cannot
|
|
# leave the reaper matching the old width.
|
|
for arg in sys.argv[1:]:
|
|
print(veth_token(arg))
|