From 37a978e753a01f76b9b2efde4cdb9ebd2acf37b7 Mon Sep 17 00:00:00 2001
From: Helga Velroyen <helgav@google.com>
Date: Wed, 30 Jan 2013 17:12:26 +0100
Subject: [PATCH] Force conflicts check in LUNetworkDisconnect

Until now if one disconnects a network with --no-conflicts-check
and then remove it, there is a possibility to leave instances with NICs
referencing non-existing networks. This causes network queries,
instance removal and modification to fail.

This patch allows a network to be disconnected from a nodegroup,
only if instances residing in the nodegroup do not have NICs attached
to the network. Otherwise OpPrereqError is raised. The
--no-conflicts-check option is removed from the gnt-network disconnect
command as well.

This is a cherry-pick of commit 6bb939a.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
---
 lib/client/gnt_network.py |  5 ++---
 lib/cmdlib.py             | 10 ++++------
 lib/opcodes.py            |  1 -
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/lib/client/gnt_network.py b/lib/client/gnt_network.py
index 2407f392f..b2d6360e6 100644
--- a/lib/client/gnt_network.py
+++ b/lib/client/gnt_network.py
@@ -143,8 +143,7 @@ def DisconnectNetwork(opts, args):
   # TODO: Change logic to support "--submit"
   for group in groups:
     op = opcodes.OpNetworkDisconnect(group_name=group,
-                                     network_name=network,
-                                     conflicts_check=opts.conflicts_check)
+                                     network_name=network)
     SubmitOpCode(op, opts=opts, cl=cl)
 
 
@@ -344,7 +343,7 @@ commands = {
   "disconnect": (
     DisconnectNetwork,
     [ArgNetwork(min=1, max=1), ArgGroup()],
-    [NOCONFLICTSCHECK_OPT, PRIORITY_OPT],
+    [PRIORITY_OPT],
     "<network_name> [<node_group>...]",
     "Unmap a given network from a specified node group"),
   "remove": (
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index cf5bd152e..6e2b8a87c 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -16790,9 +16790,8 @@ class LUNetworkDisconnect(LogicalUnit):
 
       # Lock instances optimistically, needs verification once group lock has
       # been acquired
-      if self.op.conflicts_check:
-        self.needed_locks[locking.LEVEL_INSTANCE] = \
-          self.cfg.GetNodeGroupInstances(self.group_uuid)
+      self.needed_locks[locking.LEVEL_INSTANCE] = \
+        self.cfg.GetNodeGroupInstances(self.group_uuid)
 
   def BuildHooksEnv(self):
     ret = {
@@ -16817,9 +16816,8 @@ class LUNetworkDisconnect(LogicalUnit):
       self.connected = False
       return
 
-    if self.op.conflicts_check:
-      _NetworkConflictCheck(self, lambda nic: nic.network == self.network_name,
-                            "disconnect from")
+    _NetworkConflictCheck(self, lambda nic: nic.network == self.network_name,
+                          "disconnect from")
 
   def Exec(self, feedback_fn):
     if not self.connected:
diff --git a/lib/opcodes.py b/lib/opcodes.py
index f30ec4104..dc27e632b 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -2138,7 +2138,6 @@ class OpNetworkDisconnect(OpCode):
   OP_PARAMS = [
     _PGroupName,
     _PNetworkName,
-    ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IPs"),
     ]
   OP_RESULT = ht.TNone
 
-- 
GitLab