From e0ef03fa03ba25f07d8daf67bb2ec7440086d9f1 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 3 Oct 2023 12:50:47 +0200 Subject: [PATCH] API: Added test for inspect_flake --- pkgs/clan-cli/clan_cli/secrets/generate.py | 5 +++++ pkgs/clan-cli/clan_cli/secrets/upload.py | 5 +++++ pkgs/clan-cli/tests/test_flake_api.py | 25 ++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/secrets/generate.py b/pkgs/clan-cli/clan_cli/secrets/generate.py index 9e47c93cf..77d13ca41 100644 --- a/pkgs/clan-cli/clan_cli/secrets/generate.py +++ b/pkgs/clan-cli/clan_cli/secrets/generate.py @@ -1,4 +1,5 @@ import argparse +import logging import os import shlex import subprocess @@ -9,6 +10,8 @@ from clan_cli.errors import ClanError from ..dirs import get_clan_flake_toplevel, module_root from ..nix import nix_build, nix_config +log = logging.getLogger(__name__) + def build_generate_script(machine: str, clan_dir: Path) -> str: config = nix_config() @@ -39,6 +42,8 @@ def run_generate_secrets(secret_generator_script: str, clan_dir: Path) -> None: ) if proc.returncode != 0: + log.error("stdout: %s", proc.stdout) + log.error("stderr: %s", proc.stderr) raise ClanError("failed to generate secrets") else: print("successfully generated secrets") diff --git a/pkgs/clan-cli/clan_cli/secrets/upload.py b/pkgs/clan-cli/clan_cli/secrets/upload.py index 44aac77b5..8491b12a9 100644 --- a/pkgs/clan-cli/clan_cli/secrets/upload.py +++ b/pkgs/clan-cli/clan_cli/secrets/upload.py @@ -1,5 +1,6 @@ import argparse import json +import logging import os import shlex import subprocess @@ -11,6 +12,8 @@ from ..errors import ClanError from ..nix import nix_build, nix_config, nix_shell from ..ssh import parse_deployment_address +log = logging.getLogger(__name__) + def build_upload_script(machine: str, clan_dir: Path) -> str: config = nix_config() @@ -67,6 +70,8 @@ def run_upload_secrets( ) if proc.returncode != 0: + log.error("Stdout: %s", proc.stdout) + log.error("Stderr: %s", proc.stderr) raise ClanError("failed to upload secrets") h = parse_deployment_address(flake_attr, target) diff --git a/pkgs/clan-cli/tests/test_flake_api.py b/pkgs/clan-cli/tests/test_flake_api.py index 767af4f7b..c760f7194 100644 --- a/pkgs/clan-cli/tests/test_flake_api.py +++ b/pkgs/clan-cli/tests/test_flake_api.py @@ -1,11 +1,11 @@ from pathlib import Path - +import json import pytest from api import TestClient @pytest.mark.impure -def test_inspect(api: TestClient, test_flake_with_core: Path) -> None: +def test_inspect_attrs(api: TestClient, test_flake_with_core: Path) -> None: params = {"url": str(test_flake_with_core)} response = api.get( "/api/flake/attrs", @@ -15,3 +15,24 @@ def test_inspect(api: TestClient, test_flake_with_core: Path) -> None: data = response.json() print("Data: ", data) assert data.get("flake_attrs") == ["vm1"] + + + +@pytest.mark.impure +def test_inspect_flake(api: TestClient, test_flake_with_core: Path) -> None: + params = {"url": str(test_flake_with_core)} + response = api.get( + "/api/flake", + params=params, + ) + assert response.status_code == 200, "Failed to inspect vm" + data = response.json() + print("Data: ", json.dumps(data, indent=2)) + assert data.get("content") is not None + actions = data.get("actions") + assert actions is not None + assert len(actions) == 2 + assert actions[0].get("id") == "vms/inspect" + assert actions[0].get("uri") == "api/vms/inspect" + assert actions[1].get("id") == "vms/create" + assert actions[1].get("uri") == "api/vms/create" \ No newline at end of file