def test_batch_compute_nodes(self, batch_pool, **kwargs): client = self.create_sharedkey_client(**kwargs) # Test List Compute Nodes nodes = list(client.compute_node.list(batch_pool.name)) self.assertEqual(len(nodes), 2) while self.is_live and any( [n for n in nodes if n.state != models.ComputeNodeState.idle]): time.sleep(10) nodes = list(client.compute_node.list(batch_pool.name)) # Test Get Compute Node node = client.compute_node.get(batch_pool.name, nodes[0].id) self.assertIsInstance(node, models.ComputeNode) self.assertEqual(node.scheduling_state, models.SchedulingState.enabled) self.assertTrue(node.is_dedicated) self.assertIsNotNone(node.node_agent_info) self.assertIsNotNone(node.node_agent_info.version) # Test Upload Log config = models.UploadBatchServiceLogsConfiguration( container_url= "https://test.blob.core.windows.net:443/test-container", start_time=datetime.datetime.utcnow() - datetime.timedelta(minutes=6)) result = client.compute_node.upload_batch_service_logs( batch_pool.name, nodes[0].id, config) self.assertIsNotNone(result) self.assertTrue(result.number_of_files_uploaded > 0) self.assertIsNotNone(result.virtual_directory_name) # Test Disable Scheduling response = client.compute_node.disable_scheduling( batch_pool.name, nodes[0].id) self.assertIsNone(response) # Test Enable Scheduling response = client.compute_node.enable_scheduling( batch_pool.name, nodes[0].id) self.assertIsNone(response) # Test Reboot Node response = client.compute_node.reboot( batch_pool.name, nodes[0].id, node_reboot_option=models.ComputeNodeRebootOption.terminate) self.assertIsNone(response) # Test Reimage Node self.assertBatchError( 'OperationNotValidOnNode', client.compute_node.reimage, batch_pool.name, nodes[1].id, node_reimage_option=models.ComputeNodeReimageOption.terminate) # Test Remove Nodes options = models.NodeRemoveParameter(node_list=[n.id for n in nodes]) response = client.pool.remove_nodes(batch_pool.name, options) self.assertIsNone(response)
def remove_compute_nodes(self, pool_id, compute_node_ids): client = self._get_batch_client() pool = self.get_pool(pool_id) if not pool: return None remove_param = batchmodels.NodeRemoveParameter( node_list=compute_node_ids, node_deallocation_option=batchmodels.ComputeNodeDeallocationOption. terminate) client.pool.remove_nodes(pool_id, remove_param)
def remove_node_from_pool(self, node_id): print(f"Attempting to remove node: {node_id}") try: self.client.pool.remove_nodes( pool_id=self.pool_id, node_remove_parameter=batchmodels.NodeRemoveParameter( node_list=[node_id], node_deallocation_option=batchmodels. ComputeNodeDeallocationOption.terminate)) return True except BatchErrorException as e: print( f"Something went wrong when attempting to remove a node! ID: {node_id} \n{e}" ) return False except Exception as e: print( f"Something went wrong when attempting to remove a node! ID: {node_id} \n{e}" ) return False
def test_batch_compute_nodes(self, batch_pool, **kwargs): client = self.create_sharedkey_client(**kwargs) # Test List Compute Nodes nodes = list(client.compute_node.list(batch_pool.name)) self.assertEqual(len(nodes), 2) while self.is_live and any([n for n in nodes if n.state != models.ComputeNodeState.idle]): time.sleep(10) nodes = list(client.compute_node.list(batch_pool.name)) # Test Get Compute Node node = client.compute_node.get(batch_pool.name, nodes[0].id) self.assertIsInstance(node, models.ComputeNode) self.assertEqual(node.scheduling_state, models.SchedulingState.enabled) self.assertTrue(node.is_dedicated) # Test Disable Scheduling response = client.compute_node.disable_scheduling(batch_pool.name, nodes[0].id) self.assertIsNone(response) # Test Enable Scheduling response = client.compute_node.enable_scheduling(batch_pool.name, nodes[0].id) self.assertIsNone(response) # Test Reboot Node response = client.compute_node.reboot( batch_pool.name, nodes[0].id, node_reboot_option=models.ComputeNodeRebootOption.terminate) self.assertIsNone(response) # Test Reimage Node response = client.compute_node.reimage( batch_pool.name, nodes[1].id, node_reimage_option=models.ComputeNodeReimageOption.terminate) self.assertIsNone(response) # Test Remove Nodes options = models.NodeRemoveParameter([n.id for n in nodes]) response = client.pool.remove_nodes(batch_pool.name, options) self.assertIsNone(response)