Skip to content

Commit 76bdff9

Browse files
authored
Fixed config.yml upgrade from very old versions (#984)
1 parent 6ba71a1 commit 76bdff9

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/databricks/labs/ucx/config.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,11 @@ def replace_inventory_variable(self, text: str) -> str:
4141

4242
@classmethod
4343
def v1_migrate(cls, raw: dict) -> dict:
44-
stored_version = raw.pop("version", None)
45-
if stored_version == cls.__version__:
46-
return raw
47-
if stored_version == 1:
48-
raw["include_group_names"] = (
49-
raw.get("groups", {"selected": []})["selected"] if "selected" in raw["groups"] else None
50-
)
51-
raw["renamed_group_prefix"] = raw.get("groups", {"backup_group_prefix": "db-temp-"})["backup_group_prefix"]
52-
raw.pop("groups", None)
53-
return raw
54-
msg = f"Unknown config version: {stored_version}"
55-
raise ValueError(msg)
44+
# See https://github.com/databrickslabs/ucx/blob/v0.5.0/src/databricks/labs/ucx/config.py#L16-L32
45+
groups = raw.pop("groups", {})
46+
selected_groups = groups.get("selected", [])
47+
if selected_groups:
48+
raw["include_group_names"] = selected_groups
49+
raw["renamed_group_prefix"] = groups.get("backup_group_prefix", "db-temp-")
50+
raw["version"] = 2
51+
return raw

tests/unit/test_config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from databricks.labs.blueprint.installation import MockInstallation
2+
3+
from databricks.labs.ucx.config import WorkspaceConfig
4+
5+
6+
def test_v1_migrate_zeroconf():
7+
installation = MockInstallation(
8+
{'config.yml': {'inventory_database': 'x', 'groups': {}, 'connect': {'host': 'a', 'token': 'b'}}}
9+
)
10+
11+
workspace_config = installation.load(WorkspaceConfig)
12+
13+
assert workspace_config.renamed_group_prefix == 'db-temp-'
14+
15+
16+
def test_v1_migrate_some_conf():
17+
installation = MockInstallation(
18+
{
19+
'config.yml': {
20+
'inventory_database': 'x',
21+
'groups': {'selected': ['foo', 'bar'], 'backup_group_prefix': 'some-'},
22+
'connect': {'host': 'a', 'token': 'b'},
23+
}
24+
}
25+
)
26+
27+
workspace_config = installation.load(WorkspaceConfig)
28+
29+
assert workspace_config.renamed_group_prefix == 'some-'
30+
assert workspace_config.include_group_names == ['foo', 'bar']

0 commit comments

Comments
 (0)