2
2
from datetime import timedelta
3
3
4
4
import pytest
5
- from databricks .sdk import AccountClient
5
+ from databricks .sdk import AccountClient , WorkspaceClient
6
6
from databricks .sdk .errors import NotFound
7
7
from databricks .sdk .retries import retried
8
8
from databricks .sdk .service .compute import DataSecurityMode , AwsAttributes
9
9
from databricks .sdk .service .catalog import Privilege , SecurableType , TableInfo , TableType
10
10
from databricks .sdk .service .iam import PermissionLevel
11
+
11
12
from databricks .labs .ucx .__about__ import __version__
12
13
13
14
from databricks .labs .ucx .config import WorkspaceConfig
@@ -650,7 +651,9 @@ def test_mapping_reverts_table(ws, sql_backend, runtime_ctx, make_catalog):
650
651
651
652
652
653
# @retried(on=[NotFound], timeout=timedelta(minutes=3))
653
- def test_migrate_managed_tables_with_acl (ws , sql_backend , runtime_ctx , make_catalog , make_user , env_or_skip ):
654
+ def test_migrate_managed_tables_with_acl (
655
+ ws : WorkspaceClient , sql_backend , runtime_ctx , make_catalog , make_user , env_or_skip
656
+ ) -> None :
654
657
src_schema = runtime_ctx .make_schema (catalog_name = "hive_metastore" )
655
658
src_managed_table = runtime_ctx .make_table (catalog_name = src_schema .catalog_name , schema_name = src_schema .name )
656
659
user = make_user ()
@@ -687,10 +690,11 @@ def test_migrate_managed_tables_with_acl(ws, sql_backend, runtime_ctx, make_cata
687
690
assert len (target_tables ) == 1
688
691
689
692
target_table_properties = ws .tables .get (f"{ dst_schema .full_name } .{ src_managed_table .name } " ).properties
693
+ assert target_table_properties
690
694
assert target_table_properties ["upgraded_from" ] == src_managed_table .full_name
691
695
assert target_table_properties [Table .UPGRADED_FROM_WS_PARAM ] == str (ws .get_workspace_id ())
692
696
693
- target_table_grants = ws .grants .get (SecurableType .TABLE , f"{ dst_schema .full_name } .{ src_managed_table .name } " )
697
+ target_table_grants = ws .grants .get (SecurableType .TABLE . value , f"{ dst_schema .full_name } .{ src_managed_table .name } " )
694
698
target_principals = [pa for pa in target_table_grants .privilege_assignments or [] if pa .principal == user .user_name ]
695
699
assert len (target_principals ) == 1 , f"Missing grant for user { user .user_name } "
696
700
assert target_principals [0 ].privileges == [Privilege .MODIFY , Privilege .SELECT ]
@@ -721,8 +725,8 @@ def test_migrate_managed_tables_with_acl(ws, sql_backend, runtime_ctx, make_cata
721
725
722
726
@retried (on = [NotFound ], timeout = timedelta (minutes = 3 ))
723
727
def test_migrate_external_tables_with_principal_acl_azure (
724
- ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , make_ucx_group
725
- ):
728
+ ws : WorkspaceClient , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , make_ucx_group
729
+ ) -> None :
726
730
if not ws .config .is_azure :
727
731
pytest .skip ("only works in azure test env" )
728
732
ctx , table_full_name , _ , _ = prepared_principal_acl
@@ -741,7 +745,8 @@ def test_migrate_external_tables_with_principal_acl_azure(
741
745
)
742
746
table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
743
747
744
- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
748
+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
749
+ assert target_table_grants .privilege_assignments is not None
745
750
match = False
746
751
for _ in target_table_grants .privilege_assignments :
747
752
if _ .principal == user_with_cluster_access .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
@@ -764,8 +769,8 @@ def test_migrate_external_tables_with_principal_acl_azure(
764
769
765
770
@retried (on = [NotFound ], timeout = timedelta (minutes = 3 ))
766
771
def test_migrate_external_tables_with_principal_acl_aws (
767
- ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , env_or_skip
768
- ):
772
+ ws : WorkspaceClient , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , env_or_skip
773
+ ) -> None :
769
774
ctx , table_full_name , _ , _ = prepared_principal_acl
770
775
ctx .with_dummy_resource_permission ()
771
776
cluster = make_cluster (
@@ -782,7 +787,8 @@ def test_migrate_external_tables_with_principal_acl_aws(
782
787
)
783
788
table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
784
789
785
- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
790
+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
791
+ assert target_table_grants .privilege_assignments is not None
786
792
match = False
787
793
for _ in target_table_grants .privilege_assignments :
788
794
if _ .principal == user .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
@@ -793,8 +799,12 @@ def test_migrate_external_tables_with_principal_acl_aws(
793
799
794
800
@retried (on = [NotFound ], timeout = timedelta (minutes = 3 ))
795
801
def test_migrate_external_tables_with_principal_acl_aws_warehouse (
796
- ws , make_user , prepared_principal_acl , make_warehouse_permissions , make_warehouse , env_or_skip
797
- ):
802
+ ws : WorkspaceClient ,
803
+ make_user ,
804
+ prepared_principal_acl ,
805
+ make_warehouse_permissions ,
806
+ make_warehouse ,
807
+ ) -> None :
798
808
if not ws .config .is_aws :
799
809
pytest .skip ("temporary: only works in aws test env" )
800
810
ctx , table_full_name , _ , _ = prepared_principal_acl
@@ -809,7 +819,8 @@ def test_migrate_external_tables_with_principal_acl_aws_warehouse(
809
819
)
810
820
table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
811
821
812
- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
822
+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
823
+ assert target_table_grants .privilege_assignments is not None
813
824
match = False
814
825
for _ in target_table_grants .privilege_assignments :
815
826
if _ .principal == user .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
@@ -879,8 +890,8 @@ def test_migrate_table_in_mount(
879
890
880
891
881
892
def test_migrate_external_tables_with_spn_azure (
882
- ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster
883
- ):
893
+ ws : WorkspaceClient , prepared_principal_acl , make_cluster_permissions , make_cluster
894
+ ) -> None :
884
895
if not ws .config .is_azure :
885
896
pytest .skip ("temporary: only works in azure test env" )
886
897
ctx , table_full_name , _ , _ = prepared_principal_acl
@@ -897,7 +908,8 @@ def test_migrate_external_tables_with_spn_azure(
897
908
)
898
909
table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
899
910
900
- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
911
+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
912
+ assert target_table_grants .privilege_assignments is not None
901
913
match = False
902
914
for _ in target_table_grants .privilege_assignments :
903
915
if _ .principal == spn_with_mount_access and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
0 commit comments