From 0debfb35b615fda35811e3b80e0537e70fd0d9b8 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 27 Oct 2009 14:09:07 -0400
Subject: [PATCH] config.Add{Node,Instance}: get the ec id

This is ok because adding a node or instance cannot happen in a query.

We get the ec id from the LU and pass it to _EnsureUUID, which will
then for now not use it.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 daemons/ganeti-masterd         |  4 ++--
 lib/cmdlib.py                  |  5 +++--
 lib/config.py                  | 11 ++++++-----
 test/ganeti.config_unittest.py |  2 +-
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/daemons/ganeti-masterd b/daemons/ganeti-masterd
index 46e857e51..9b0851fe1 100755
--- a/daemons/ganeti-masterd
+++ b/daemons/ganeti-masterd
@@ -365,12 +365,12 @@ class GanetiContext(object):
     assert self.__class__._instance is None, "Attempt to modify Ganeti Context"
     object.__setattr__(self, name, value)
 
-  def AddNode(self, node):
+  def AddNode(self, node, ec_id):
     """Adds a node to the configuration and lock manager.
 
     """
     # Add it to the configuration
-    self.cfg.AddNode(node)
+    self.cfg.AddNode(node, ec_id)
 
     # If preseeding fails it'll not be added
     self.jobqueue.AddNode(node)
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index c1a52ffeb..abf9e70aa 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -3037,7 +3037,7 @@ class LUAddNode(LogicalUnit):
                           " candidate status: %s" % msg)
     else:
       _RedistributeAncillaryFiles(self, additional_nodes=[node])
-      self.context.AddNode(new_node)
+      self.context.AddNode(new_node, self.proc.GetECId())
 
 
 class LUSetNodeParams(LogicalUnit):
@@ -6097,7 +6097,8 @@ class LUCreateInstance(LogicalUnit):
 
     feedback_fn("adding instance %s to cluster config" % instance)
 
-    self.cfg.AddInstance(iobj)
+    self.cfg.AddInstance(iobj, self.proc.GetECId())
+
     # Declare that we don't want to remove the instance lock anymore, as we've
     # added the instance to the config
     del self.remove_locks[locking.LEVEL_INSTANCE]
diff --git a/lib/config.py b/lib/config.py
index 665c15cb1..338c3216e 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -724,7 +724,7 @@ class ConfigWriter:
     return self._config_data.cluster.rsahostkeypub
 
   @locking.ssynchronized(_config_lock)
-  def AddInstance(self, instance):
+  def AddInstance(self, instance, ec_id):
     """Add an instance to the config.
 
     This should be used after creating a new instance.
@@ -747,7 +747,7 @@ class ConfigWriter:
                                         " MAC address '%s' already in use." %
                                         (instance.name, nic.mac))
 
-    self._EnsureUUID(instance)
+    self._EnsureUUID(instance, ec_id)
 
     instance.serial_no = 1
     instance.ctime = instance.mtime = time.time()
@@ -758,10 +758,11 @@ class ConfigWriter:
       self._temporary_macs.discard(nic.mac)
     self._WriteConfig()
 
-  def _EnsureUUID(self, item):
+  def _EnsureUUID(self, item, ec_id):
     """Ensures a given object has a valid UUID.
 
     @param item: the instance or node to be checked
+    @param ec_id: the execution context id for the uuid reservation
 
     """
     if not item.uuid:
@@ -907,7 +908,7 @@ class ConfigWriter:
     return my_dict
 
   @locking.ssynchronized(_config_lock)
-  def AddNode(self, node):
+  def AddNode(self, node, ec_id):
     """Add a node to the configuration.
 
     @type node: L{objects.Node}
@@ -916,7 +917,7 @@ class ConfigWriter:
     """
     logging.info("Adding node %s to configuration", node.name)
 
-    self._EnsureUUID(node)
+    self._EnsureUUID(node, ec_id)
 
     node.serial_no = 1
     node.ctime = node.mtime = time.time()
diff --git a/test/ganeti.config_unittest.py b/test/ganeti.config_unittest.py
index 77d7f395c..25fa7eda0 100755
--- a/test/ganeti.config_unittest.py
+++ b/test/ganeti.config_unittest.py
@@ -148,7 +148,7 @@ class TestConfigRunner(unittest.TestCase):
     self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance,
                           None)
 
-    cfg.AddInstance(inst)
+    cfg.AddInstance(inst, "my-job")
     instance = cfg.GetInstanceInfo(cfg.GetInstanceList()[0])
     # first pass, must not fail
     cfg.Update(instance, None)
-- 
GitLab