From 33944cf74e44723187de67aacdf96c4590127ea1 Mon Sep 17 00:00:00 2001 From: DavHau Date: Mon, 13 Nov 2023 20:50:11 +0700 Subject: [PATCH] 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 --- pkgs/clan-cli/clan_cli/config/machine.py | 2 +- pkgs/clan-cli/tests/test_machines_api.py | 45 ++++++------------------ 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/config/machine.py b/pkgs/clan-cli/clan_cli/config/machine.py index f6e2a049f..fca031e79 100644 --- a/pkgs/clan-cli/clan_cli/config/machine.py +++ b/pkgs/clan-cli/clan_cli/config/machine.py @@ -44,7 +44,7 @@ def verify_machine_config( "--show-trace", "--show-trace", "--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) diff --git a/pkgs/clan-cli/tests/test_machines_api.py b/pkgs/clan-cli/tests/test_machines_api.py index 35dbef09b..9e2812e1f 100644 --- a/pkgs/clan-cli/tests/test_machines_api.py +++ b/pkgs/clan-cli/tests/test_machines_api.py @@ -91,9 +91,12 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest) json_response = response.json() 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( clan=dict(), + foo=dict( + bar=True, + ), services=dict( nginx=dict( 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( f"/api/{test_flake_with_core.name}/machines/machine1/verify", json=invalid_config, ) assert response.status_code == 200 - assert ( - "The ‘fileSystems’ option does not specify your root" - in response.json()["error"] - ) + assert "error: The option `foo' does not exist" in response.json()["error"] - # set come invalid config (fileSystems missing) + # set come invalid config (foo option does not exist) response = api.put( f"/api/{test_flake_with_core.name}/machines/machine1/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.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 config2 = dict( clan=dict(), @@ -149,7 +132,6 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest) enable=True, ), ), - **fs_config, ) response = api.put( @@ -214,7 +196,6 @@ def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest) "fake-flag": True, }, }, - **fs_config, } # 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, }, }, - **fs_config, } # remove the import from the config - config_with_empty_imports = dict( - clanImports=[], - **fs_config, - ) response = api.put( f"/api/{test_flake_with_core.name}/machines/machine1/config", - json=config_with_empty_imports, + json=dict( + clanImports=[], + ), ) 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.json() == { - "clanImports": ["fake-module"], "clan": {}, - **config_with_empty_imports, + "clanImports": [], }