- Updated the project structure to store configuration files (.env, models.yaml, extensions.yaml) in the project root instead of the user's home directory. - Enhanced the setup process to automatically copy example files to the project root on first run. - Implemented a migration function to transfer legacy configuration files from the user's home directory to the new project structure. - Revised documentation to reflect changes in file locations and setup instructions. - Improved code readability and maintainability by refactoring path management functions.
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
from gpu_rent.config import load_config
|
|
from gpu_rent.paths import env_path, migrate_legacy_if_needed, models_manifest_path, runtime_dir
|
|
from gpu_rent.ssh_keys import ensure_ed25519, public_path
|
|
|
|
|
|
def test_load_config_missing_auth(monkeypatch, tmp_path):
|
|
monkeypatch.setenv("HOME", str(tmp_path))
|
|
monkeypatch.setenv("USERPROFILE", str(tmp_path))
|
|
for key in (
|
|
"OS_AUTH_URL",
|
|
"OS_USER_DOMAIN_NAME",
|
|
"OS_USERNAME",
|
|
"OS_PASSWORD",
|
|
"OS_PROJECT_ID",
|
|
"OS_REGION_NAME",
|
|
"GPU_RENT_AZ",
|
|
):
|
|
monkeypatch.delenv(key, raising=False)
|
|
cfg = load_config(require_auth=False)
|
|
assert not cfg.auth_ok
|
|
assert "OS_USERNAME" in cfg.missing
|
|
assert cfg.data_volume_size_gb == 100
|
|
assert cfg.models_manifest == models_manifest_path()
|
|
assert runtime_dir() == tmp_path / ".gpu-rent"
|
|
assert env_path() == tmp_path / ".env"
|
|
|
|
|
|
def test_migrate_legacy_user_home(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HOME", str(tmp_path / "user"))
|
|
monkeypatch.setenv("USERPROFILE", str(tmp_path / "user"))
|
|
proj = tmp_path / "proj"
|
|
proj.mkdir()
|
|
monkeypatch.chdir(proj)
|
|
legacy = tmp_path / "user" / ".gpu-rent"
|
|
legacy.mkdir(parents=True)
|
|
(legacy / "models.yaml").write_text("checkpoint:\n - version_id: 1\n", encoding="utf-8")
|
|
(legacy / ".env").write_text("OS_USERNAME=x\n", encoding="utf-8")
|
|
notes = migrate_legacy_if_needed()
|
|
assert notes
|
|
assert (proj / "models.yaml").is_file()
|
|
assert (proj / ".env").is_file()
|
|
|
|
|
|
def test_ssh_key_generate(tmp_path):
|
|
private = tmp_path / "id_ed25519"
|
|
got, pub = ensure_ed25519(private)
|
|
assert got == private
|
|
assert pub == public_path(private)
|
|
assert private.is_file()
|
|
assert pub.is_file()
|
|
text = pub.read_text(encoding="utf-8")
|
|
assert text.startswith("ssh-ed25519")
|
|
ensure_ed25519(private)
|
|
assert private.read_bytes()
|