Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Sep 25, 2023
1 parent 596a878 commit 1d571d6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
9 changes: 3 additions & 6 deletions src/databricks/labs/ucx/account/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def configured_workspaces(self):
if self._cfg.include_workspace_names:
if workspace.workspace_name not in self._cfg.include_workspace_names:
logger.debug(
f"skipping {workspace.name} ({workspace.workspace_id} because its not explicitly included"
f"skipping {workspace.workspace_name} ({workspace.workspace_id} because "
f"its not explicitly included"
)
continue
yield workspace
Expand Down Expand Up @@ -150,7 +151,7 @@ def _azure_workspaces(self):
yield workspace


def main():
if __name__ == "__main__":
logger.setLevel("INFO")

config_file = Path.home() / ".ucx/config.yml"
Expand All @@ -176,7 +177,3 @@ def main():
f"metastore {metastore_id}, "
f"default catalog: {default_catalog}"
)


if __name__ == "__main__":
main()
15 changes: 9 additions & 6 deletions src/databricks/labs/ucx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,6 @@ def inner(x):

@dataclass
class AccountConfig(_Config["AccountConfig"]):
# Inventory database holds the working state of UCX within hive_metastore catalogs
# across all deployed workspaces. Once configured, it cannot be changed. In the rare
# circumstances when we need to change the database name, we have to destroy all
# databases with the previous name in each workspace and restart the assessment steps.
inventory_database: str

# At least account console hostname and Databricks Account ID are required for the wide
# account-level installation. These values we cannot determine automatically. For Azure,
# it is required to run `az login` before the setup. For AWS, administrators may need
Expand All @@ -179,6 +173,15 @@ class AccountConfig(_Config["AccountConfig"]):
# authentication of Databricks SDK for Python.
connect: ConnectConfig

# Inventory database holds the working state of UCX within hive_metastore catalogs
# across all deployed workspaces. Once configured, it cannot be changed. In the rare
# circumstances when we need to change the database name, we have to destroy all
# databases with the previous name in each workspace and restart the assessment steps.
inventory_database: str = "ucx"

# Migrate only specific set of Databricks Workspaces. All by default. Keep in mind,
# that the workspace name (what is seen in the Databricks Account Console) may be
# different from the deployment name (what is seen as part of the workspace URL).
include_workspace_names: list[str] = dataclasses.field(default_factory=list)
include_azure_subscription_ids: list[str] = dataclasses.field(default_factory=list)
include_azure_subscription_names: list[str] = dataclasses.field(default_factory=list)
Expand Down
36 changes: 34 additions & 2 deletions tests/unit/account/test_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_list_azure_workspaces(arm_requests):
"value": [
{"displayName": "first", "subscriptionId": "001", "tenantId": "xxx"},
{"displayName": "second", "subscriptionId": "002", "tenantId": "def_from_token"},
{"displayName": "third", "subscriptionId": "003", "tenantId": "def_from_token"},
]
},
"/subscriptions/002/providers/Microsoft.Databricks/workspaces": {
Expand All @@ -75,14 +76,29 @@ def test_list_azure_workspaces(arm_requests):
"workspaceUrl": "adb-123.10.azuredatabricks.net",
"workspaceId": "123",
},
}
},
{
"id": ".../resourceGroups/first-rg/...",
"name": "second-workspace",
"location": "eastus",
"sku": {"name": "premium"},
"properties": {
"provisioningState": "Succeeded",
"workspaceUrl": "adb-123.10.azuredatabricks.net",
"workspaceId": "123",
},
},
]
},
}
)

wrksp = Workspaces(
AccountConfig(connect=ConnectConfig(host="https://accounts.azuredatabricks.net"), inventory_database="ucx")
AccountConfig(
connect=ConnectConfig(host="https://accounts.azuredatabricks.net"),
include_workspace_names=["first-workspace"],
include_azure_subscription_names=["second"],
)
)

all_workspaces = list(wrksp.configured_workspaces())
Expand All @@ -99,3 +115,19 @@ def test_list_azure_workspaces(arm_requests):
custom_tags={"AzureResourceGroup": "first-rg", "AzureSubscription": "second", "AzureSubscriptionID": "002"},
)
] == all_workspaces


def test_client_for_workspace():
wrksp = Workspaces(
AccountConfig(
connect=ConnectConfig(
host="https://accounts.azuredatabricks.net",
azure_tenant_id="abc",
azure_client_id="bcd",
azure_client_secret="def",
)
)
)
specified_workspace_client = wrksp.client_for(Workspace(cloud="azure", deployment_name="adb-123.10"))
assert "azure-client-secret" == specified_workspace_client.config.auth_type
assert "https://adb-123.10.azuredatabricks.net" == specified_workspace_client.config.host

0 comments on commit 1d571d6

Please sign in to comment.