Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip filesinrepos to true if false #42

Merged
merged 11 commits into from
Feb 13, 2024
14 changes: 13 additions & 1 deletion src/databricks/labs/blueprint/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ def upload(self, filename: str, raw: bytes):
try:
logger.debug(f"Uploading: {dst}")
attempt()
except NotFound:
except NotFound as error:
if error.error_code == "FEATURE_DISABLED":
self._enable_files_in_repos()
parent_folder = os.path.dirname(dst)
logger.debug(f"Creating missing folders: {parent_folder}")
self._ws.workspace.mkdirs(parent_folder)
Expand Down Expand Up @@ -669,6 +671,16 @@ def _load_csv(raw: BinaryIO) -> list[Json]:
out.append(row)
return out

def _enable_files_in_repos(self):
# check if "enableWorkspaceFilesystem" is set to false
workspace_file_system = self._ws.workspace_conf.get_status("enableWorkspaceFilesystem")

logger.debug("Checking Files In Repos configuration")

if workspace_file_system["enableWorkspaceFilesystem"] == "false":
logger.debug("enableWorkspaceFilesystem is False, enabling the config")
self._ws.workspace_conf.set_status({"enableWorkspaceFilesystem": "true"})


class MockInstallation(Installation):
"""Install state testing toolbelt
Expand Down
31 changes: 30 additions & 1 deletion tests/unit/test_installation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io
from dataclasses import dataclass
from unittest.mock import create_autospec
from unittest.mock import MagicMock, create_autospec

import pytest
import yaml
Expand Down Expand Up @@ -327,3 +327,32 @@ def test_migrations_broken():

with pytest.raises(IllegalState):
installation.load(BrokenConfig)


def test_enable_files_in_repos():
ws = create_autospec(WorkspaceClient)
ws.current_user.me().user_name = "foo"
installation = Installation(ws, "ucx")
ws.workspace_conf.set_status = MagicMock()

# enableWorkspaceFilesystem is true
ws.workspace_conf.get_status.return_value = {"enableWorkspaceFilesystem": "true"}
installation._enable_files_in_repos()
pritishpai marked this conversation as resolved.
Show resolved Hide resolved
ws.workspace_conf.set_status.assert_not_called()

# enableWorkspaceFilesystem is false
ws.workspace_conf.get_status.return_value = {"enableWorkspaceFilesystem": "false"}
installation._enable_files_in_repos()
ws.workspace_conf.set_status.assert_called_once()
ws.workspace_conf.set_status.assert_called_with({"enableWorkspaceFilesystem": "true"})


def test_upload_feature_disabled_failure():
ws = create_autospec(WorkspaceClient)
ws.current_user.me().user_name = "foo"
ws.workspace.upload.side_effect = [NotFound(error_code="FEATURE_DISABLED"), None]
installation = Installation(ws, "blueprint")

installation.save(WorkspaceConfig(inventory_database="some_blueprint"))

ws.workspace.mkdirs.assert_called_with("/Users/foo/.blueprint")
Loading