api/machines: verify config by evaluating the .vm output
This fixes the problem where fileSystems were missing, or boot.loader was not set. SInce we want VMs anyways for now, this strategy aligns well
This commit is contained in:
@@ -44,7 +44,7 @@ def verify_machine_config(
|
|||||||
"--show-trace",
|
"--show-trace",
|
||||||
"--show-trace",
|
"--show-trace",
|
||||||
"--impure", # needed to access CLAN_MACHINE_SETTINGS_FILE
|
"--impure", # needed to access CLAN_MACHINE_SETTINGS_FILE
|
||||||
f".#nixosConfigurations.{machine_name}.config.system.build.toplevel.outPath",
|
f".#nixosConfigurations.{machine_name}.config.system.build.vm.outPath",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
# repro_env_break(work_dir=flake, env=env, cmd=cmd)
|
# repro_env_break(work_dir=flake, env=env, cmd=cmd)
|
||||||
|
|||||||
@@ -91,9 +91,12 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest)
|
|||||||
json_response = response.json()
|
json_response = response.json()
|
||||||
assert "schema" in json_response and "properties" in json_response["schema"]
|
assert "schema" in json_response and "properties" in json_response["schema"]
|
||||||
|
|
||||||
# an invalid config missing the fileSystems
|
# an invalid config setting some non-existent option
|
||||||
invalid_config = dict(
|
invalid_config = dict(
|
||||||
clan=dict(),
|
clan=dict(),
|
||||||
|
foo=dict(
|
||||||
|
bar=True,
|
||||||
|
),
|
||||||
services=dict(
|
services=dict(
|
||||||
nginx=dict(
|
nginx=dict(
|
||||||
enable=True,
|
enable=True,
|
||||||
@@ -101,18 +104,15 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest)
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# verify an invalid config (fileSystems missing) fails
|
# verify an invalid config (foo option does not exist)
|
||||||
response = api.put(
|
response = api.put(
|
||||||
f"/api/{test_flake_with_core.name}/machines/machine1/verify",
|
f"/api/{test_flake_with_core.name}/machines/machine1/verify",
|
||||||
json=invalid_config,
|
json=invalid_config,
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert (
|
assert "error: The option `foo' does not exist" in response.json()["error"]
|
||||||
"The ‘fileSystems’ option does not specify your root"
|
|
||||||
in response.json()["error"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# set come invalid config (fileSystems missing)
|
# set come invalid config (foo option does not exist)
|
||||||
response = api.put(
|
response = api.put(
|
||||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||||
json=invalid_config,
|
json=invalid_config,
|
||||||
@@ -124,23 +124,6 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest)
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == dict(clanImports=[], **invalid_config)
|
assert response.json() == dict(clanImports=[], **invalid_config)
|
||||||
|
|
||||||
# the part of the config that makes the evaluation pass
|
|
||||||
fs_config = dict(
|
|
||||||
fileSystems={
|
|
||||||
"/": dict(
|
|
||||||
device="/dev/fake_disk",
|
|
||||||
fsType="ext4",
|
|
||||||
),
|
|
||||||
},
|
|
||||||
boot=dict(
|
|
||||||
loader=dict(
|
|
||||||
grub=dict(
|
|
||||||
devices=["/dev/fake_disk"],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
# set some valid config
|
# set some valid config
|
||||||
config2 = dict(
|
config2 = dict(
|
||||||
clan=dict(),
|
clan=dict(),
|
||||||
@@ -149,7 +132,6 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest)
|
|||||||
enable=True,
|
enable=True,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
**fs_config,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response = api.put(
|
response = api.put(
|
||||||
@@ -214,7 +196,6 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest)
|
|||||||
"fake-flag": True,
|
"fake-flag": True,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
**fs_config,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# set the fake-module.fake-flag option to true
|
# set the fake-module.fake-flag option to true
|
||||||
@@ -236,17 +217,14 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest)
|
|||||||
"fake-flag": True,
|
"fake-flag": True,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
**fs_config,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove the import from the config
|
# remove the import from the config
|
||||||
config_with_empty_imports = dict(
|
|
||||||
clanImports=[],
|
|
||||||
**fs_config,
|
|
||||||
)
|
|
||||||
response = api.put(
|
response = api.put(
|
||||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||||
json=config_with_empty_imports,
|
json=dict(
|
||||||
|
clanImports=[],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@@ -256,7 +234,6 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest)
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"clanImports": ["fake-module"],
|
|
||||||
"clan": {},
|
"clan": {},
|
||||||
**config_with_empty_imports,
|
"clanImports": [],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user