[hypervisor] prevent unsetting unconfigured values

Unsetting unconfigured values result in a snap error and will delay the
hypervisor configuration. When an unset value is detected, only set it
when the new value is not null.

Closes-Bug: #2065864
Change-Id: Id07f70276dab87326d2f2f024a938cc4b35b8cbd
This commit is contained in:
Guillaume Boutry
2024-05-29 09:41:38 +02:00
parent 9663868d14
commit d68e9c757c

View File

@@ -361,7 +361,10 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
# Trying to retrieve an unset parameter results in a snapError
# so assume the snap.SnapError means there is missing config
# that needs setting.
new_settings[k] = snap_data[k]
# Setting a value to None will unset the value from the snap,
# which will fail if the value was never set.
if snap_data[k] is not None:
new_settings[k] = snap_data[k]
if new_settings:
logger.debug(f"Applying new snap settings {new_settings}")
hypervisor.set(new_settings, typed=True)