From 1c901d13c01540c7af61db0f21143b7f6de7c34b Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 1 Jul 2008 10:43:32 +0000
Subject: [PATCH] Processor: pass context in and use it.

The processor used to create a new ConfigWriter when it was initialized.
We now have one in the context, so we'll just recycle it. First of all
we'll pass the context in when creating a new Processor object, then
we'll just use context.cfg, which is granted to be initialized, wherever
we used self.cfg, and stop checking whether the config is already
initialized or not.

In the future the Processor will be able to use the context also to
acquire the BGL for LUs that require it, and to push the context down to
LUs that don't in order for them to manage their own locking.

Reviewed-by: iustinp
---
 daemons/ganeti-masterd |  2 +-
 lib/mcpu.py            | 17 +++++------------
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/daemons/ganeti-masterd b/daemons/ganeti-masterd
index 885db2fcb..e04201347 100755
--- a/daemons/ganeti-masterd
+++ b/daemons/ganeti-masterd
@@ -289,7 +289,7 @@ def PoolWorker(worker_id, incoming_queue, context):
     print "worker %s processing job %s" % (worker_id, item.data.job_id)
     #utils.Lock('cmd')
     try:
-      proc = mcpu.Processor(feedback=lambda x: None)
+      proc = mcpu.Processor(context, feedback=lambda x: None)
       try:
         JobRunner(proc, item, context)
       except errors.GenericError, err:
diff --git a/lib/mcpu.py b/lib/mcpu.py
index fff38e7fb..4e9659d0b 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -89,14 +89,14 @@ class Processor(object):
     opcodes.OpTestAllocator: cmdlib.LUTestAllocator,
     }
 
-  def __init__(self, feedback=None):
+  def __init__(self, context, feedback=None):
     """Constructor for Processor
 
     Args:
      - feedback_fn: the feedback function (taking one string) to be run when
                     interesting events are happening
     """
-    self.cfg = None
+    self.context = context
     self._feedback_fn = feedback
 
   def ExecOpCode(self, op):
@@ -119,13 +119,8 @@ class Processor(object):
     else:
       sstore = ssconf.SimpleStore()
 
-    if self.cfg is None:
-      self.cfg = config.ConfigWriter()
-    if self.cfg is not None:
-      write_count = self.cfg.write_count
-    else:
-      write_count = 0
-    lu = lu_class(self, op, self.cfg, sstore)
+    write_count = self.context.cfg.write_count
+    lu = lu_class(self, op, self.context.cfg, sstore)
     lu.CheckPrereq()
     hm = HooksMaster(rpc.call_hooks_runner, self, lu)
     h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
@@ -168,10 +163,8 @@ class Processor(object):
     else:
       sstore = ssconf.SimpleStore()
 
-    if self.cfg is None:
-      self.cfg = config.ConfigWriter()
     #do_hooks = lu_class.HPATH is not None
-    lu = lu_class(self, op, self.cfg, sstore)
+    lu = lu_class(self, op, self.context.cfg, sstore)
     lu.CheckPrereq()
     #if do_hooks:
     #  hm = HooksMaster(rpc.call_hooks_runner, self, lu)
-- 
GitLab