63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
import json
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
import controller
|
|
|
|
|
|
class ControllerTests(unittest.TestCase):
|
|
def test_runner_release_is_pinned(self):
|
|
self.assertEqual(controller.RUNNER_VERSION, "3.5.0")
|
|
self.assertEqual(len(controller.RUNNER_SHA256), 64)
|
|
|
|
def test_instance_spec_uses_pro6000_and_cuda_128(self):
|
|
spec = controller.instance_spec("image-test", 120, [])
|
|
self.assertEqual(spec["gpu_spec_uuid"], "pro6000-p")
|
|
self.assertEqual(spec["cuda_v_from"], 128)
|
|
self.assertNotIn("data_center_list", spec)
|
|
|
|
def test_instance_spec_preserves_data_center_preference(self):
|
|
spec = controller.instance_spec("image-test", 100, ["westDC3"])
|
|
self.assertEqual(spec["data_center_list"], ["westDC3"])
|
|
|
|
def test_instance_spec_rejects_missing_image(self):
|
|
with self.assertRaises(controller.ControllerError):
|
|
controller.instance_spec("", 120, [])
|
|
|
|
def test_runner_has_required_host_labels_and_no_docker(self):
|
|
rendered = controller.runner_yaml()
|
|
self.assertIn('"ubuntu-latest:host"', rendered)
|
|
self.assertIn('"ces-ci:host"', rendered)
|
|
self.assertIn('"gpu:host"', rendered)
|
|
self.assertIn('docker_host: "-"', rendered)
|
|
|
|
def test_state_is_private_and_round_trips(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
paths = controller.Paths(
|
|
root / "model",
|
|
"/model",
|
|
"/artifacts",
|
|
root / "artifacts",
|
|
root / "key",
|
|
root / "known_hosts",
|
|
root / "state.json",
|
|
root / "runner",
|
|
)
|
|
controller.write_state(paths, {"instance_uuid": "pro-test"})
|
|
self.assertEqual(controller.read_state(paths)["instance_uuid"], "pro-test")
|
|
self.assertEqual(os.stat(paths.state_file).st_mode & 0o777, 0o600)
|
|
|
|
def test_example_workflow_files_are_valid_json_free(self):
|
|
# Guards against accidentally treating workflow YAML as controller state.
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / "value.json"
|
|
path.write_text(json.dumps({"ok": True}), encoding="utf-8")
|
|
self.assertTrue(json.loads(path.read_text())["ok"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|