Skip to content

Commit

Permalink
Merge pull request #1063 from dan1elt0m/fix-volumes-error
Browse files Browse the repository at this point in the history
Handle NotFound error
  • Loading branch information
dan1elt0m authored Dec 6, 2023
2 parents 80687fd + 239db47 commit b93972b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import List

from databricks.sdk.service.catalog import PermissionsList, PrivilegeAssignment, SecurableType
Expand All @@ -6,6 +7,8 @@
from databricks_cdk.resources.permissions.changes import get_permission_changes
from databricks_cdk.utils import CnfResponse, get_workspace_client

logger = logging.getLogger(__name__)


class VolumePermissionsProperties(BaseModel):
workspace_url: str
Expand All @@ -17,7 +20,7 @@ def create_or_update_volume_permissions(
properties: VolumePermissionsProperties,
) -> CnfResponse:
"""Create volume permissions on volume at databricks"""

logger.info(f"Creating volume permissions {properties.privilege_assignments} for volume {properties.volume_name}")
workspace_client = get_workspace_client(properties.workspace_url)
existing_grants: PermissionsList = workspace_client.grants.get(
securable_type=SecurableType.VOLUME, full_name=properties.volume_name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import logging
from typing import Optional

from databricks.sdk import WorkspaceClient
from databricks.sdk.errors import NotFound
from databricks.sdk.service.catalog import VolumeInfo, VolumeType
from pydantic import BaseModel

from databricks_cdk.utils import CnfResponse, get_workspace_client

logger = logging.getLogger(__name__)


class VolumeCreationError(Exception):
pass
Expand Down Expand Up @@ -99,5 +103,9 @@ def update_volume(
def delete_volume(properties: VolumeProperties, physical_resource_id: str) -> CnfResponse:
"""Delete a volume on databricks"""
workspace_client = get_workspace_client(properties.workspace_url)
workspace_client.volumes.delete(full_name_arg=properties.volume.full_name)
try:
workspace_client.volumes.delete(full_name_arg=properties.volume.full_name)
except NotFound:
logger.warning("Volume not found, never existed or already removed")

return CnfResponse(physical_resource_id=physical_resource_id)

0 comments on commit b93972b

Please sign in to comment.