Skip to content

Commit

Permalink
Move integration test to correct place (#3253)
Browse files Browse the repository at this point in the history
Fixed #3247
  • Loading branch information
nfx authored Nov 18, 2024
1 parent 10796e0 commit 27e290e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 44 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ classifiers = [
"Topic :: Utilities",
]

dependencies = ["databricks-sdk~=0.36.0",
dependencies = ["databricks-sdk~=0.37.0",
"databricks-labs-lsql>=0.5,<0.15",
"databricks-labs-blueprint>=0.9.1,<0.10",
"PyYAML>=6.0.0,<7.0.0",
Expand Down Expand Up @@ -107,6 +107,7 @@ verify = ["black --check . --extend-exclude 'tests/unit/source_code/samples
lint = ["pylint --output-format=colorized -j 0 src tests"]
cmds = "python tests/integration/cmds.py"


[tool.pytest.ini_options]
# TODO: remove `-p no:warnings`
addopts = "--no-header -p no:warnings"
Expand Down
43 changes: 0 additions & 43 deletions tests/integration/install/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
)
from databricks.sdk.retries import retried
from databricks.sdk.service import compute
from databricks.sdk.service.iam import PermissionLevel

from databricks.labs.ucx.__about__ import __version__
from databricks.labs.ucx.config import WorkspaceConfig
from databricks.labs.ucx.install import WorkspaceInstaller
from databricks.labs.ucx.workspace_access.groups import MigratedGroup

from ..conftest import MockInstallationContext

Expand Down Expand Up @@ -90,47 +88,6 @@ def factory(
pending.remove()


def test_experimental_permissions_migration_for_group_with_same_name(
installation_ctx,
make_cluster_policy,
make_cluster_policy_permissions,
):
ws_group, acc_group = installation_ctx.make_ucx_group()
migrated_group = MigratedGroup.partial_info(ws_group, acc_group)
cluster_policy = make_cluster_policy()
make_cluster_policy_permissions(
object_id=cluster_policy.policy_id,
permission_level=PermissionLevel.CAN_USE,
group_name=migrated_group.name_in_workspace,
)

schema_a = installation_ctx.make_schema()
table_a = installation_ctx.make_table(schema_name=schema_a.name)
installation_ctx.make_grant(migrated_group.name_in_workspace, 'USAGE', schema_info=schema_a)
installation_ctx.make_grant(migrated_group.name_in_workspace, 'OWN', schema_info=schema_a)
installation_ctx.make_grant(migrated_group.name_in_workspace, 'SELECT', table_info=table_a)

installation_ctx.workspace_installation.run()

installation_ctx.deployed_workflows.run_workflow("migrate-groups")

object_permissions = installation_ctx.generic_permissions_support.load_as_dict(
"cluster-policies", cluster_policy.policy_id
)
new_schema_grants = installation_ctx.grants_crawler.for_schema_info(schema_a)

if {"USAGE", "OWN"} != new_schema_grants[migrated_group.name_in_account] or object_permissions[
migrated_group.name_in_account
] != PermissionLevel.CAN_USE:
installation_ctx.deployed_workflows.relay_logs("migrate-groups-experimental")
assert {"USAGE", "OWN"} == new_schema_grants[
migrated_group.name_in_account
], "Incorrect schema grants for migrated group"
assert (
object_permissions[migrated_group.name_in_account] == PermissionLevel.CAN_USE
), "Incorrect permissions for migrated group"


@retried(on=[NotFound, TimeoutError], timeout=timedelta(minutes=3))
def test_job_failure_propagates_correct_error_message_and_logs(ws, sql_backend, installation_ctx):
installation_ctx.workspace_installation.run()
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/workspace_access/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from databricks.sdk.service.iam import PermissionLevel
from databricks.sdk.service.workspace import AclPermission

from databricks.labs.ucx.workspace_access.groups import MigratedGroup


def test_running_real_migrate_groups_job(
installation_ctx,
Expand Down Expand Up @@ -94,3 +96,44 @@ def test_running_legacy_validate_groups_permissions_job(

# assert the job does not throw any exception
installation_ctx.deployed_workflows.run_workflow("validate-groups-permissions")


def test_permissions_migration_for_group_with_same_name(
installation_ctx,
make_cluster_policy,
make_cluster_policy_permissions,
):
ws_group, acc_group = installation_ctx.make_ucx_group()
migrated_group = MigratedGroup.partial_info(ws_group, acc_group)
cluster_policy = make_cluster_policy()
make_cluster_policy_permissions(
object_id=cluster_policy.policy_id,
permission_level=PermissionLevel.CAN_USE,
group_name=migrated_group.name_in_workspace,
)

schema_a = installation_ctx.make_schema()
table_a = installation_ctx.make_table(schema_name=schema_a.name)
installation_ctx.make_grant(migrated_group.name_in_workspace, 'USAGE', schema_info=schema_a)
installation_ctx.make_grant(migrated_group.name_in_workspace, 'OWN', schema_info=schema_a)
installation_ctx.make_grant(migrated_group.name_in_workspace, 'SELECT', table_info=table_a)

installation_ctx.workspace_installation.run()

installation_ctx.deployed_workflows.run_workflow("migrate-groups")

object_permissions = installation_ctx.generic_permissions_support.load_as_dict(
"cluster-policies", cluster_policy.policy_id
)
new_schema_grants = installation_ctx.grants_crawler.for_schema_info(schema_a)

if {"USAGE", "OWN"} != new_schema_grants[migrated_group.name_in_account] or object_permissions[
migrated_group.name_in_account
] != PermissionLevel.CAN_USE:
installation_ctx.deployed_workflows.relay_logs("migrate-groups")
assert {"USAGE", "OWN"} == new_schema_grants[
migrated_group.name_in_account
], "Incorrect schema grants for migrated group"
assert (
object_permissions[migrated_group.name_in_account] == PermissionLevel.CAN_USE
), "Incorrect permissions for migrated group"

0 comments on commit 27e290e

Please sign in to comment.