vars: Improve logging for migration
This commit is contained in:
@@ -80,6 +80,7 @@ class StoreBase(ABC):
|
||||
generator: "Generator",
|
||||
var: "Var",
|
||||
value: bytes,
|
||||
is_migration: bool = False,
|
||||
) -> Path | None:
|
||||
if self.exists(generator, var.name):
|
||||
if self.is_secret_store:
|
||||
@@ -92,15 +93,15 @@ class StoreBase(ABC):
|
||||
old_val = None
|
||||
old_val_str = "<not set>"
|
||||
new_file = self._set(generator, var, value)
|
||||
action_str = "Migrated" if is_migration else "Updated"
|
||||
if self.is_secret_store:
|
||||
print(f"Updated secret var {generator.name}/{var.name}\n")
|
||||
print(f"{action_str} secret var {generator.name}/{var.name}\n")
|
||||
else:
|
||||
if value != old_val:
|
||||
print(
|
||||
f"Updated var {generator.name}/{var.name}\n"
|
||||
f" old: {old_val_str}\n"
|
||||
f" new: {string_repr(value)}"
|
||||
)
|
||||
msg = f"{action_str} var {generator.name}/{var.name}"
|
||||
if not is_migration:
|
||||
msg += f"\n old: {old_val_str}\n new: {string_repr(value)}"
|
||||
print(msg)
|
||||
else:
|
||||
print(
|
||||
f"Var {generator.name}/{var.name} remains unchanged: {old_val_str}"
|
||||
|
||||
@@ -315,10 +315,10 @@ def _migrate_file(
|
||||
|
||||
if file.secret:
|
||||
old_value = machine.secret_facts_store.get(service_name, fact_name)
|
||||
machine.secret_vars_store.set(generator, file, old_value)
|
||||
machine.secret_vars_store.set(generator, file, old_value, is_migration=True)
|
||||
else:
|
||||
old_value = machine.public_facts_store.get(service_name, fact_name)
|
||||
machine.public_vars_store.set(generator, file, old_value)
|
||||
machine.public_vars_store.set(generator, file, old_value, is_migration=True)
|
||||
|
||||
|
||||
def _migrate_files(
|
||||
|
||||
@@ -842,6 +842,7 @@ def test_migration(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
flake: ClanFlake,
|
||||
sops_setup: SopsSetup,
|
||||
capture_output: CaptureOutput,
|
||||
) -> None:
|
||||
config = flake.machines["my_machine"]
|
||||
config["nixpkgs"]["hostPlatform"] = "x86_64-linux"
|
||||
@@ -860,7 +861,10 @@ def test_migration(
|
||||
monkeypatch.chdir(flake.path)
|
||||
sops_setup.init()
|
||||
cli.run(["facts", "generate", "--flake", str(flake.path), "my_machine"])
|
||||
with capture_output as output:
|
||||
cli.run(["vars", "generate", "--flake", str(flake.path), "my_machine"])
|
||||
assert "Migrated var my_generator/my_value" in output.out
|
||||
assert "Migrated secret var my_generator/my_secret" in output.out
|
||||
in_repo_store = in_repo.FactStore(
|
||||
Machine(name="my_machine", flake=FlakeId(str(flake.path)))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user