77from databricks .sdk import WorkspaceClient
88from databricks .sdk .errors import NotFound
99from databricks .sdk .service import iam
10- from databricks .sdk .service .compute import ClusterSpec , Policy
10+ from databricks .sdk .service .compute import ClusterSpec , GetInstancePool , Policy
1111from databricks .sdk .service .jobs import Job , JobCluster , JobSettings
1212from databricks .sdk .service .sql import (
1313 EndpointConfPair ,
@@ -34,6 +34,7 @@ def common():
3434 {
3535 r".*We have identified one or more cluster.*" : "Yes" ,
3636 r".*Choose a cluster policy.*" : "0" ,
37+ r".*Instance pool id to be set in cluster policy.*" : "" ,
3738 }
3839 )
3940 return w , prompts
@@ -252,6 +253,7 @@ def test_cluster_policy_definition_azure_hms_warehouse():
252253 {
253254 r".*We have identified one or more cluster.*" : "No" ,
254255 r".*We have identified the workspace warehouse.*" : "Yes" ,
256+ r".*Instance pool id to be set in cluster policy.*" : "" ,
255257 }
256258 )
257259 policy_installer = ClusterPolicyInstaller (MockInstallation (), ws , prompts )
@@ -303,6 +305,7 @@ def test_cluster_policy_definition_aws_glue_warehouse():
303305 {
304306 r".*We have identified one or more cluster.*" : "No" ,
305307 r".*We have identified the workspace warehouse.*" : "Yes" ,
308+ r".*Instance pool id to be set in cluster policy.*" : "" ,
306309 }
307310 )
308311 policy_installer = ClusterPolicyInstaller (MockInstallation (), ws , prompts )
@@ -357,6 +360,7 @@ def test_cluster_policy_definition_gcp_hms_warehouse():
357360 {
358361 r".*We have identified one or more cluster.*" : "No" ,
359362 r".*We have identified the workspace warehouse.*" : "Yes" ,
363+ r".*Instance pool id to be set in cluster policy.*" : "" ,
360364 }
361365 )
362366 policy_installer = ClusterPolicyInstaller (MockInstallation (), ws , prompts )
@@ -414,3 +418,43 @@ def test_cluster_policy_definition_empty_config():
414418 definition = json .dumps (policy_definition_actual ),
415419 description = "Custom cluster policy for Unity Catalog Migration (UCX)" ,
416420 )
421+
422+
423+ def test_cluster_policy_instance_pool ():
424+ ws , prompts = common ()
425+ prompts = prompts .extend ({r".*Instance pool id to be set in cluster policy.*" : "instance_pool_1" })
426+
427+ ws .instance_pools .get .return_value = GetInstancePool ("instance_pool_1" )
428+ ws .cluster_policies .list .return_value = []
429+ ws .config .is_aws = True
430+ ws .config .is_azure = False
431+ ws .config .is_gcp = False
432+
433+ policy_installer = ClusterPolicyInstaller (MockInstallation (), ws , prompts )
434+ policy_installer .create ('ucx' )
435+
436+ policy_expected = {
437+ "spark_version" : {"type" : "fixed" , "value" : "14.2.x-scala2.12" },
438+ "instance_pool_id" : {"type" : "fixed" , "value" : "instance_pool_1" },
439+ "aws_attributes.availability" : {"type" : "fixed" , "value" : "ON_DEMAND" },
440+ }
441+ # test the instance pool is added to the cluster policy
442+ ws .cluster_policies .create .assert_called_with (
443+ name = "Unity Catalog Migration (ucx) ([email protected] )" ,
444+ definition = json .dumps (policy_expected ),
445+ description = "Custom cluster policy for Unity Catalog Migration (UCX)" ,
446+ )
447+
448+ # test the instance pool is not found
449+ ws .instance_pools .get .side_effect = NotFound ()
450+ policy_expected = {
451+ "spark_version" : {"type" : "fixed" , "value" : "14.2.x-scala2.12" },
452+ "node_type_id" : {"type" : "fixed" , "value" : "Standard_F4s" },
453+ "aws_attributes.availability" : {"type" : "fixed" , "value" : "ON_DEMAND" },
454+ }
455+ policy_installer .create ('ucx' )
456+ ws .cluster_policies .create .assert_called_with (
457+ name = "Unity Catalog Migration (ucx) ([email protected] )" ,
458+ definition = json .dumps (policy_expected ),
459+ description = "Custom cluster policy for Unity Catalog Migration (UCX)" ,
460+ )
0 commit comments