Fix ProxmoxVE migration causing reauthentication (#167624)

This commit is contained in:
Tom
2026-04-08 13:22:25 +02:00
committed by GitHub
parent 726edf3a3b
commit e4aeee9d85
2 changed files with 35 additions and 0 deletions
@@ -189,6 +189,14 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ProxmoxConfigEntry) ->
# Migration for additional configuration options added to support API tokens
if entry.version < 3:
data = dict(entry.data)
# If CONF_REALM wasn't there yet, extract from username
if CONF_REALM not in data:
data[CONF_REALM] = DEFAULT_REALM
if "@" in data.get(CONF_USERNAME, ""):
username, realm = data[CONF_USERNAME].split("@", 1)
data[CONF_USERNAME] = username
data[CONF_REALM] = realm.lower()
realm = data[CONF_REALM].lower()
# If the realm is one of the base providers, set the provider to match the realm.
+27
View File
@@ -281,6 +281,33 @@ async def test_migration_v2_to_v3(
assert entry.data[CONF_REALM] == AUTH_PAM
async def test_migration_v2_to_v3_without_realm(
hass: HomeAssistant,
) -> None:
"""Test migration from version 2 to 3."""
entry = MockConfigEntry(
domain=DOMAIN,
version=2,
unique_id="1",
data={
CONF_HOST: "http://test_host",
CONF_PORT: 8006,
CONF_USERNAME: "test_user@pam",
CONF_PASSWORD: "test_password",
CONF_VERIFY_SSL: True,
},
)
entry.add_to_hass(hass)
assert entry.version == 2
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.version == 3
assert entry.data[CONF_AUTH_METHOD] == AUTH_PAM
assert entry.data[CONF_REALM] == AUTH_PAM
async def test_new_vm_creates_entity(
hass: HomeAssistant,
mock_proxmox_client: MagicMock,