diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 0b0559208532a853659eb5911dcd3b97817d032f..66cd4163142628d31de9c62fd58050a8cf7a07ff 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2369,7 +2369,7 @@ class LUSetClusterParams(LogicalUnit): "\n".join(nic_errors)) # hypervisor list/parameters - self.new_hvparams = objects.FillDict(cluster.hvparams, {}) + self.new_hvparams = new_hvp = objects.FillDict(cluster.hvparams, {}) if self.op.hvparams: if not isinstance(self.op.hvparams, dict): raise errors.OpPrereqError("Invalid 'hvparams' parameter on input", @@ -2399,6 +2399,7 @@ class LUSetClusterParams(LogicalUnit): else: self.new_os_hvp[os_name][hv_name].update(hv_dict) + # changes to the hypervisor list if self.op.enabled_hypervisors is not None: self.hv_list = self.op.enabled_hypervisors if not self.hv_list: @@ -2411,6 +2412,16 @@ class LUSetClusterParams(LogicalUnit): " entries: %s" % utils.CommaJoin(invalid_hvs), errors.ECODE_INVAL) + for hv in self.hv_list: + # if the hypervisor doesn't already exist in the cluster + # hvparams, we initialize it to empty, and then (in both + # cases) we make sure to fill the defaults, as we might not + # have a complete defaults list if the hypervisor wasn't + # enabled before + if hv not in new_hvp: + new_hvp[hv] = {} + new_hvp[hv] = objects.FillDict(constants.HVC_DEFAULTS[hv], new_hvp[hv]) + utils.ForceDictType(new_hvp[hv], constants.HVS_PARAMETER_TYPES) else: self.hv_list = cluster.enabled_hypervisors @@ -2458,6 +2469,7 @@ class LUSetClusterParams(LogicalUnit): if self.op.os_hvp: self.cluster.os_hvp = self.new_os_hvp if self.op.enabled_hypervisors is not None: + self.cluster.hvparams = self.new_hvparams self.cluster.enabled_hypervisors = self.op.enabled_hypervisors if self.op.beparams: self.cluster.beparams[constants.PP_DEFAULT] = self.new_beparams diff --git a/lib/config.py b/lib/config.py index 35d800c0a8bca634eecb3118ffe3f797d0a0e99d..aa479c0967b4b2fbe477959e67a4b3f64f7c313b 100644 --- a/lib/config.py +++ b/lib/config.py @@ -364,6 +364,11 @@ class ConfigWriter: if invalid_hvs: result.append("enabled hypervisors contains invalid entries: %s" % invalid_hvs) + missing_hvp = (set(data.cluster.enabled_hypervisors) - + set(data.cluster.hvparams.keys())) + if missing_hvp: + result.append("hypervisor parameters missing for the enabled" + " hypervisor(s) %s" % utils.CommaJoin(missing_hvp)) if data.cluster.master_node not in data.nodes: result.append("cluster has invalid primary node '%s'" %