generate_test_vars: fix it
This commit is contained in:
@@ -62,19 +62,18 @@ class Generator:
|
|||||||
def generators_from_flake(
|
def generators_from_flake(
|
||||||
cls: type["Generator"], machine_name: str, flake: "Flake"
|
cls: type["Generator"], machine_name: str, flake: "Flake"
|
||||||
) -> list["Generator"]:
|
) -> list["Generator"]:
|
||||||
config = nix_config()
|
|
||||||
system = config["system"]
|
|
||||||
|
|
||||||
# Get all generator metadata in one select (safe fields only)
|
# Get all generator metadata in one select (safe fields only)
|
||||||
generators_data = flake.select(
|
generators_data = flake.select_machine(
|
||||||
f'clanInternals.machines."{system}"."{machine_name}".config.clan.core.vars.generators.*.{{share,dependencies,migrateFact,prompts}}'
|
machine_name,
|
||||||
|
"config.clan.core.vars.generators.*.{share,dependencies,migrateFact,prompts}",
|
||||||
)
|
)
|
||||||
if not generators_data:
|
if not generators_data:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Get all file metadata in one select
|
# Get all file metadata in one select
|
||||||
files_data = flake.select(
|
files_data = flake.select_machine(
|
||||||
f'clanInternals.machines."{system}"."{machine_name}".config.clan.core.vars.generators.*.files.*.{{secret,deploy,owner,group,mode,neededFor}}'
|
machine_name,
|
||||||
|
"config.clan.core.vars.generators.*.files.*.{secret,deploy,owner,group,mode,neededFor}",
|
||||||
)
|
)
|
||||||
|
|
||||||
generators = []
|
generators = []
|
||||||
|
|||||||
@@ -44,6 +44,41 @@ def get_machine_names(repo_root: Path, check_attr: str, system: str) -> list[str
|
|||||||
return json.loads(out.stdout.strip())
|
return json.loads(out.stdout.strip())
|
||||||
|
|
||||||
|
|
||||||
|
class TestFlake(Flake):
|
||||||
|
"""
|
||||||
|
Flake class which is able to deal with not having an actual flake.
|
||||||
|
All nix build and eval calls will be forwarded to:
|
||||||
|
clan-core#checks.<system>.<test_name>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, check_attr: str, *args: Any, **kwargs: Any) -> None:
|
||||||
|
"""
|
||||||
|
Initialize the TestFlake with the check attribute.
|
||||||
|
"""
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.check_attr = check_attr
|
||||||
|
|
||||||
|
def select_machine(self, machine_name: str, selector: str) -> Any:
|
||||||
|
"""
|
||||||
|
Select a nix attribute for a specific machine.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
machine_name: The name of the machine
|
||||||
|
selector: The attribute selector string relative to the machine config
|
||||||
|
apply: Optional function to apply to the result
|
||||||
|
"""
|
||||||
|
from clan_lib.nix import nix_config
|
||||||
|
|
||||||
|
config = nix_config()
|
||||||
|
system = config["system"]
|
||||||
|
test_system = system
|
||||||
|
if system.endswith("-darwin"):
|
||||||
|
test_system = system.rstrip("darwin") + "linux"
|
||||||
|
|
||||||
|
full_selector = f'checks."{test_system}".{self.check_attr}.machinesCross.{system}."{machine_name}".{selector}'
|
||||||
|
return self.select(full_selector)
|
||||||
|
|
||||||
|
|
||||||
class TestMachine(Machine):
|
class TestMachine(Machine):
|
||||||
"""
|
"""
|
||||||
Machine class which is able to deal with not having an actual flake.
|
Machine class which is able to deal with not having an actual flake.
|
||||||
@@ -151,7 +186,7 @@ def main() -> None:
|
|||||||
if system.endswith("-darwin"):
|
if system.endswith("-darwin"):
|
||||||
test_system = system.rstrip("darwin") + "linux"
|
test_system = system.rstrip("darwin") + "linux"
|
||||||
|
|
||||||
flake = Flake(str(opts.repo_root))
|
flake = TestFlake(opts.check_attr, str(opts.repo_root))
|
||||||
machine_names = get_machine_names(
|
machine_names = get_machine_names(
|
||||||
opts.repo_root,
|
opts.repo_root,
|
||||||
opts.check_attr,
|
opts.check_attr,
|
||||||
@@ -164,6 +199,9 @@ def main() -> None:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# This hack is necessary because the sops store uses flake.path to find the machine keys
|
||||||
|
flake._path = opts.test_dir # noqa: SLF001
|
||||||
|
|
||||||
machines = [
|
machines = [
|
||||||
TestMachine(name, flake, test_dir, opts.check_attr) for name in machine_names
|
TestMachine(name, flake, test_dir, opts.check_attr) for name in machine_names
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user