Improve error handling in netmask change
authorAndrea Spadaccini <spadaccio@google.com>
Fri, 4 Nov 2011 16:35:16 +0000 (16:35 +0000)
committerAndrea Spadaccini <spadaccio@google.com>
Mon, 7 Nov 2011 14:32:22 +0000 (14:32 +0000)
- check if the master IP with the old netmask is up before attempting to
  change the netmask (to avoid a failed change netmask resulting in an
  undesired activation of the master IP);
- improve error messages of the backend function;
- in case of error, report the problem but otherwise change the cluster
  master_netmask parameter;
- remove duplicate error feedback.

Signed-off-by: Andrea Spadaccini <spadaccio@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/backend.py
lib/cmdlib.py

index 9c3f094..fcf455f 100644 (file)
@@ -428,19 +428,23 @@ def ChangeMasterNetmask(old_netmask, netmask, master_ip, master_netdev):
   if old_netmask == netmask:
     return
 
+  if not netutils.IPAddress.Own(master_ip):
+    _Fail("The master IP address is not up, not attempting to change its"
+          " netmask")
+
   result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "add",
                          "%s/%s" % (master_ip, netmask),
                          "dev", master_netdev, "label",
                          "%s:0" % master_netdev])
   if result.failed:
-    _Fail("Could not change the master IP netmask")
+    _Fail("Could not set the new netmask on the master IP address")
 
   result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "del",
                          "%s/%s" % (master_ip, old_netmask),
                          "dev", master_netdev, "label",
                          "%s:0" % master_netdev])
   if result.failed:
-    _Fail("Could not change the master IP netmask")
+    _Fail("Could not bring down the master IP address with the old netmask")
 
 
 def EtcHostsModify(mode, host, ip):
index d147c43..8ea7c34 100644 (file)
@@ -3727,10 +3727,9 @@ class LUClusterSetParams(LogicalUnit):
                                                         master_params.netdev)
       if result.fail_msg:
         msg = "Could not change the master IP netmask: %s" % result.fail_msg
-        self.LogWarning(msg)
         feedback_fn(msg)
-      else:
-        self.cluster.master_netmask = self.op.master_netmask
+
+      self.cluster.master_netmask = self.op.master_netmask
 
     self.cfg.Update(self.cluster, feedback_fn)