From 9f3ac97059d3b565805a7b1d7e472d82a9782f22 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 19 Apr 2010 11:06:25 +0200 Subject: [PATCH] Fix changing the list of enabled hypervisors When enabling a new hypervisor, we must ensure that we have its parameters in the cluster (global) hvparams dictionary. Furthermore, we add a verify check for this case (this should be better replaced with an auto-fix?). Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/cmdlib.py | 14 +++++++++++++- lib/config.py | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 0b0559208..66cd41631 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 35d800c0a..aa479c096 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'" % -- GitLab