Fix a node name vs. UUID bug in instance import
authorThomas Thrainer <thomasth@google.com>
Mon, 19 Aug 2013 12:10:18 +0000 (14:10 +0200)
committerThomas Thrainer <thomasth@google.com>
Mon, 19 Aug 2013 13:23:47 +0000 (15:23 +0200)
This patch fixes a bug where node names were incorrectly used as node
UUID's.

Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/cmdlib/instance.py

index 529a492..137f2af 100644 (file)
@@ -562,7 +562,7 @@ class LUInstanceCreate(LogicalUnit):
         if self.needed_locks[locking.LEVEL_NODE] is not locking.ALL_SET:
           self.needed_locks[locking.LEVEL_NODE].append(self.op.src_node_uuid)
         if not os.path.isabs(src_path):
-          self.op.src_path = src_path = \
+          self.op.src_path = \
             utils.PathJoin(pathutils.EXPORT_DIR, src_path)
 
     self.needed_locks[locking.LEVEL_NODE_RES] = \
@@ -670,13 +670,13 @@ class LUInstanceCreate(LogicalUnit):
       locked_nodes = self.owned_locks(locking.LEVEL_NODE)
       exp_list = self.rpc.call_export_list(locked_nodes)
       found = False
-      for node in exp_list:
-        if exp_list[node].fail_msg:
+      for node_uuid in exp_list:
+        if exp_list[node_uuid].fail_msg:
           continue
-        if self.op.src_path in exp_list[node].payload:
+        if self.op.src_path in exp_list[node_uuid].payload:
           found = True
-          self.op.src_node = node
-          self.op.src_node_uuid = self.cfg.GetNodeInfoByName(node).uuid
+          self.op.src_node = self.cfg.GetNodeInfo(node_uuid).name
+          self.op.src_node_uuid = node_uuid
           self.op.src_path = utils.PathJoin(pathutils.EXPORT_DIR,
                                             self.op.src_path)
           break
@@ -730,8 +730,10 @@ class LUInstanceCreate(LogicalUnit):
         if einfo.has_option(constants.INISECT_INS, "nic%d_mac" % idx):
           ndict = {}
           for name in list(constants.NICS_PARAMETERS) + ["ip", "mac"]:
-            v = einfo.get(constants.INISECT_INS, "nic%d_%s" % (idx, name))
-            ndict[name] = v
+            nic_param_name = "nic%d_%s" % (idx, name)
+            if einfo.has_option(constants.INISECT_INS, nic_param_name):
+              v = einfo.get(constants.INISECT_INS, nic_param_name)
+              ndict[name] = v
           nics.append(ndict)
         else:
           break