|
1 | 1 | from types import SimpleNamespace |
2 | 2 | from unittest.mock import MagicMock |
3 | 3 |
|
4 | | -from platform_api_python_client import CreateJobDeploymentRequest |
| 4 | +from platform_api_python_client import CreateJobDeploymentRequest, CreateHardwareInstanceRequest |
5 | 5 |
|
6 | 6 | from centml.sdk import ApiException |
7 | 7 | from centml.sdk.api import CentMLClient |
@@ -72,3 +72,50 @@ def test_create_job_delegates_to_platform_client(): |
72 | 72 |
|
73 | 73 | assert response is expected_response |
74 | 74 | api.create_job_deployment_deployments_job_post.assert_called_once_with(request) |
| 75 | + |
| 76 | + |
| 77 | +def test_get_hardware_instances_returns_results(): |
| 78 | + api = MagicMock() |
| 79 | + expected_results = [SimpleNamespace(id=1), SimpleNamespace(id=2)] |
| 80 | + api.get_hardware_instances_hardware_instances_get.return_value = SimpleNamespace(results=expected_results) |
| 81 | + client = CentMLClient(api) |
| 82 | + |
| 83 | + response = client.get_hardware_instances(cluster_id=5) |
| 84 | + |
| 85 | + assert response is expected_results |
| 86 | + api.get_hardware_instances_hardware_instances_get.assert_called_once_with(cluster_id=5) |
| 87 | + |
| 88 | + |
| 89 | +def test_create_hardware_instance_delegates_to_platform_client(): |
| 90 | + api = MagicMock() |
| 91 | + expected_response = MagicMock() |
| 92 | + api.create_hardware_instance_hardware_instances_post.return_value = expected_response |
| 93 | + request = CreateHardwareInstanceRequest( |
| 94 | + cluster_id=1, |
| 95 | + name="h100-test", |
| 96 | + gpu_type="H100", |
| 97 | + num_gpu=8, |
| 98 | + cpu=64000, |
| 99 | + memory=128000, |
| 100 | + accelerator_resource_key="nvidia.com/gpu", |
| 101 | + node_affinity_labels={"gpu": "h100"}, |
| 102 | + accelerator_memory=80000, |
| 103 | + ) |
| 104 | + client = CentMLClient(api) |
| 105 | + |
| 106 | + response = client.create_hardware_instance(request) |
| 107 | + |
| 108 | + assert response is expected_response |
| 109 | + api.create_hardware_instance_hardware_instances_post.assert_called_once_with(request) |
| 110 | + |
| 111 | + |
| 112 | +def test_delete_hardware_instance_delegates_to_platform_client(): |
| 113 | + api = MagicMock() |
| 114 | + expected_response = MagicMock() |
| 115 | + api.delete_hardware_instance_hardware_instances_hardware_instance_id_delete.return_value = expected_response |
| 116 | + client = CentMLClient(api) |
| 117 | + |
| 118 | + response = client.delete_hardware_instance(123) |
| 119 | + |
| 120 | + assert response is expected_response |
| 121 | + api.delete_hardware_instance_hardware_instances_hardware_instance_id_delete.assert_called_once_with(123) |
0 commit comments