github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/python/tests/integration/sdk/test_cluster_ops.py (about) 1 # 2 # Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. 3 # 4 5 # Default provider is AIS, so all Cloud-related tests are skipped. 6 7 import unittest 8 9 from aistore.sdk import Client 10 from aistore.sdk.const import ACT_COPY_OBJECTS 11 from aistore.sdk.types import ClusterPerformance 12 from tests.integration import CLUSTER_ENDPOINT 13 from tests.utils import random_string 14 15 16 class TestClusterOps(unittest.TestCase): # pylint: disable=unused-variable 17 def setUp(self) -> None: 18 self.client = Client(CLUSTER_ENDPOINT) 19 self.cluster = self.client.cluster() 20 21 def test_health_success(self): 22 self.assertTrue(self.cluster.is_ready()) 23 24 def test_health_failure(self): 25 # url not existing or URL down 26 self.assertFalse(Client("http://localhost:1234").cluster().is_ready()) 27 28 def test_cluster_map(self): 29 smap = self.cluster.get_info() 30 31 self.assertIsNotNone(smap) 32 self.assertIsNotNone(smap.proxy_si) 33 self.assertNotEqual(len(smap.pmap), 0) 34 self.assertNotEqual(len(smap.tmap), 0) 35 self.assertNotEqual(smap.version, 0) 36 self.assertIsNot(smap.uuid, "") 37 38 def _check_jobs_in_result(self, expected_jobs, res, missing_jobs=None): 39 job_ids = [job.uuid for job in res] 40 for job in expected_jobs: 41 self.assertTrue(job in job_ids) 42 if not missing_jobs: 43 return 44 for job in missing_jobs: 45 self.assertFalse(job in job_ids) 46 47 def test_list_jobs_status(self): 48 job_kind = "lru" 49 50 job_1_id = self.client.job(job_kind=job_kind).start() 51 job_2_id = self.client.job(job_kind=job_kind).start() 52 job_3_id = self.client.job(job_kind="cleanup").start() 53 54 self._check_jobs_in_result( 55 [job_1_id, job_2_id], self.cluster.list_jobs_status() 56 ) 57 self._check_jobs_in_result( 58 [job_1_id, job_2_id], 59 self.cluster.list_jobs_status(job_kind=job_kind), 60 [job_3_id], 61 ) 62 63 def test_list_running_jobs(self): 64 # First generate a multi-obj copy job that will stay "running" (but idle) long enough to query 65 bck_name = random_string() 66 new_bck_name = random_string() 67 obj_name = random_string() 68 bck = self.client.bucket(bck_name).create() 69 new_bck = self.client.bucket(new_bck_name).create() 70 try: 71 bck.object(obj_name).put_content("any content") 72 idle_job = bck.objects(obj_names=[obj_name]).copy(to_bck=new_bck) 73 74 expected_res = f"{ACT_COPY_OBJECTS}[{idle_job}]" 75 self.assertIn(expected_res, self.client.cluster().list_running_jobs()) 76 self.assertIn( 77 expected_res, 78 self.cluster.list_running_jobs(job_kind=ACT_COPY_OBJECTS), 79 ) 80 self.assertNotIn( 81 expected_res, self.cluster.list_running_jobs(job_kind="lru") 82 ) 83 finally: 84 bck.delete() 85 new_bck.delete() 86 87 def test_get_performance(self): 88 smap = self.cluster.get_info() 89 performance = self.cluster.get_performance() 90 91 self.assertIsInstance(performance, ClusterPerformance) 92 93 num_targets_in_smap = len(smap.tmap) 94 95 self.assertEqual(num_targets_in_smap, len(performance.throughput)) 96 self.assertEqual(num_targets_in_smap, len(performance.latency)) 97 self.assertEqual(num_targets_in_smap, len(performance.counters)) 98 99 for target_id in smap.tmap: 100 self.assertIn(target_id, performance.throughput) 101 self.assertIn(target_id, performance.latency) 102 self.assertIn(target_id, performance.counters)