From 0389c42aadc7b929a1f984626a82f39c8481ed6d Mon Sep 17 00:00:00 2001 From: Stephen Shirley <diamond@google.com> Date: Fri, 28 Jan 2011 13:24:30 +0100 Subject: [PATCH] Prevent removal of last node group - Add check in ConfigWriter to prevent last node group from being removed - Tidy up error message a bit Signed-off-by: Stephen Shirley <diamond@google.com> Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/cmdlib.py | 6 +++--- lib/config.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 2aba26927..edc91358c 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -10359,9 +10359,9 @@ class LUGroupRemove(LogicalUnit): # Verify the cluster would not be left group-less. if len(self.cfg.GetNodeGroupList()) == 1: - raise errors.OpPrereqError("Group '%s' is the last group in the cluster," - " which cannot be left without at least one" - " group" % self.op.group_name, + raise errors.OpPrereqError("Group '%s' is the only group," + " cannot be removed" % + self.op.group_name, errors.ECODE_STATE) def BuildHooksEnv(self): diff --git a/lib/config.py b/lib/config.py index 76e6b59dd..6cec7c4ac 100644 --- a/lib/config.py +++ b/lib/config.py @@ -916,6 +916,9 @@ class ConfigWriter: if group_uuid not in self._config_data.nodegroups: raise errors.ConfigurationError("Unknown node group '%s'" % group_uuid) + assert len(self._config_data.nodegroups) != 1, \ + "Group '%s' is the only group, cannot be removed" % group_uuid + del self._config_data.nodegroups[group_uuid] self._config_data.cluster.serial_no += 1 self._WriteConfig() -- GitLab