def test_cluster_with_cloud_provider_with_minimum_node_pool_properties_list( self, ) -> None: formatter = ClustersFormatter() clusters = [ _Cluster( name="default", status="deployed", cloud_provider=_CloudProvider( type="on_prem", region=None, zones=[], node_pools=[ self._create_node_pool(is_scalable=False), self._create_node_pool(is_scalable=False, is_gpu=True), ], storage=None, ), ) ] expected_out = textwrap.dedent(f"""\ \x1b[1mdefault:\x1b[0m \x1b[1mStatus: \x1b[0mDeployed \x1b[1mNode pools:\x1b[0m Machine CPU Memory GPU Size n1-highmem-8 7.0 45.0G 2 n1-highmem-8 7.0 45.0G 1 x nvidia-tesla-k80 2""" # noqa: E501, ignore line length ) assert "\n".join(formatter(clusters)) == expected_out
def test_cluster_with_cloud_provider_with_maximum_node_pool_properties_list( self, ) -> None: formatter = ClustersFormatter() clusters = [ _Cluster( name="default", status="deployed", cloud_provider=_CloudProvider( type="gcp", region="us-central1", zones=[], node_pools=[ self._create_node_pool(is_preemptible=True, is_tpu_enabled=True, has_idle=True), self._create_node_pool(), ], storage=None, ), ) ] expected_out = textwrap.dedent(f"""\ \x1b[1mdefault:\x1b[0m \x1b[1mStatus: \x1b[0mDeployed \x1b[1mCloud: \x1b[0mgcp \x1b[1mRegion: \x1b[0mus-central1 \x1b[1mNode pools:\x1b[0m Machine CPU Memory Preemptible GPU TPU Min Max Idle n1-highmem-8 7.0 45.0G √ √ 1 2 1 n1-highmem-8 7.0 45.0G × × 1 2 0""" ) assert "\n".join(formatter(clusters)) == expected_out
def test_cluster_with_on_prem_cloud_provider_list(self) -> None: formatter = ClustersFormatter() clusters = [ _Cluster( name="on-prem", status="deployed", cloud_provider=_CloudProvider( type="on_prem", region=None, zones=[], node_pools=[], storage=None, ), ), ] expected_out = textwrap.dedent("""\ \x1b[1mon-prem:\x1b[0m \x1b[1mStatus: \x1b[0mDeployed""") assert "\n".join(formatter(clusters)) == expected_out
def test_cluster_with_cloud_provider_storage_list(self) -> None: formatter = ClustersFormatter() clusters = [ _Cluster( name="default", status="deployed", cloud_provider=_CloudProvider( type="gcp", region="us-central1", zones=["us-central1-a", "us-central1-c"], node_pools=[], storage=_Storage(description="Filestore"), ), ) ] expected_out = textwrap.dedent("""\ \x1b[1mdefault:\x1b[0m \x1b[1mStatus: \x1b[0mDeployed \x1b[1mCloud: \x1b[0mgcp \x1b[1mRegion: \x1b[0mus-central1 \x1b[1mZones: \x1b[0mus-central1-a, us-central1-c \x1b[1mStorage: \x1b[0mFilestore""") assert "\n".join(formatter(clusters)) == expected_out
async def test_list_clusters_with_cloud_provider( aiohttp_server: _TestServerFactory, make_client: _MakeClient) -> None: async def handle_list_clusters(request: web.Request) -> web.StreamResponse: assert request.query["include"] == "cloud_provider_infra" data = [ { "name": "default", "status": "deployed", "cloud_provider": { "type": "gcp", "region": "us-central1", "zone": "us-central1-a", "node_pools": [ { "machine_type": "n1-highmem-8", "min_size": 1, "max_size": 2, "idle_size": 1, "available_cpu": 7, "available_memory_mb": 46080, "gpu": 1, "gpu_model": "nvidia-tesla-k80", "is_tpu_enabled": True, "is_preemptible": True, }, { "machine_type": "n1-highmem-8", "min_size": 1, "max_size": 2, "available_cpu": 7, "available_memory_mb": 46080, }, ], "storage": { "description": "Filestore" }, }, }, { "name": "on-prem", "status": "deployed", "cloud_provider": { "type": "on_prem", "node_pools": [ { "min_size": 2, "max_size": 2, "machine_type": "n1-highmem-8", "available_cpu": 7, "available_memory_mb": 46080, }, ], "storage": { "description": "NFS" }, }, }, { "name": "other1", "status": "deployed", "cloud_provider": { "type": "gcp", "region": "us-central1", "zones": ["us-central1-a", "us-central1-c"], }, }, { "name": "other2", "status": "deployed", "cloud_provider": { "type": "aws", "region": "us-central1" }, }, ] return web.json_response(data) app = web.Application() app.router.add_get("/api/v1/clusters", handle_list_clusters) srv = await aiohttp_server(app) async with make_client(srv.make_url("/api/v1")) as client: clusters = await client._admin.list_clusters() assert clusters == { "default": _Cluster( name="default", status="deployed", cloud_provider=_CloudProvider( type="gcp", region="us-central1", zones=["us-central1-a"], node_pools=[ _NodePool( min_size=1, max_size=2, idle_size=1, machine_type="n1-highmem-8", available_cpu=7.0, available_memory_mb=46080, gpu=1, gpu_model="nvidia-tesla-k80", is_tpu_enabled=True, is_preemptible=True, ), _NodePool( min_size=1, max_size=2, machine_type="n1-highmem-8", available_cpu=7.0, available_memory_mb=46080, ), ], storage=_Storage(description="Filestore"), ), ), "on-prem": _Cluster( name="on-prem", status="deployed", cloud_provider=_CloudProvider( type="on_prem", region=None, zones=[], node_pools=[ _NodePool( min_size=2, max_size=2, machine_type="n1-highmem-8", available_cpu=7.0, available_memory_mb=46080, ), ], storage=_Storage(description="NFS"), ), ), "other1": _Cluster( name="other1", status="deployed", cloud_provider=_CloudProvider( type="gcp", region="us-central1", zones=["us-central1-a", "us-central1-c"], node_pools=[], storage=None, ), ), "other2": _Cluster( name="other2", status="deployed", cloud_provider=_CloudProvider( type="aws", region="us-central1", zones=[], node_pools=[], storage=None, ), ), }