With this patch all RPC calls at runtime of masterd will show up in the
lock monitor. There is a chicken-and-egg issue with initializing the
configuration with a context since the lock manager, containing the
monitor, requires the configuration. This is worked around by setting
the config's context only once the lock monitor is available.

Example:
rpc/node19.example.com/write_ssconf_files  Jq9/Job32/N_SET_PARAMjobqueue_update 
 Jq2/Job27/C_VERIFY_CONFIG

Signed-off-by: Michael Hanselmann <[email protected]>
---
 lib/config.py         |   15 +++++++++++----
 lib/rpc.py            |   10 ++++++++--
 lib/server/masterd.py |    2 ++
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/lib/config.py b/lib/config.py
index 7185d27..f7dbf4b 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -167,10 +167,17 @@ class ConfigWriter:
     self._cfg_id = None
     self._OpenConfig(accept_foreign)
 
-    resolver = compat.partial(rpc.NodeConfigResolver,
-                              self._UnlockedGetNodeInfo,
-                              self._UnlockedGetAllNodesInfo)
-    self._rpc = rpc.ConfigRunner(resolver)
+    self._resolver = compat.partial(rpc.NodeConfigResolver,
+                                    self._UnlockedGetNodeInfo,
+                                    self._UnlockedGetAllNodesInfo)
+    self.SetContext(None)
+    assert self._rpc
+
+  def SetContext(self, context):
+    """Set up RPC runner with L{server.masterd.GanetiContext}.
+
+    """
+    self._rpc = rpc.ConfigRunner(context, self._resolver)
 
   # this method needs to be static, so that we can call it on the class
   @staticmethod
diff --git a/lib/rpc.py b/lib/rpc.py
index 52e6db1..e66eaab 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -659,14 +659,20 @@ class ConfigRunner(_generated_rpc.RpcClientConfig):
   _PrepareFileUpload = \
     staticmethod(RpcRunner._PrepareFileUpload) # pylint: disable=W0212
 
-  def __init__(self, resolver):
+  def __init__(self, context, resolver):
     """Initializes this class.
 
     """
     _generated_rpc.RpcClientConfig.__init__(self)
 
+    if context:
+      lock_monitor_cb = context.glm.AddToLockMonitor
+    else:
+      lock_monitor_cb = None
+
     self._proc = _RpcProcessor(resolver,
-                               netutils.GetDaemonPort(constants.NODED))
+                               netutils.GetDaemonPort(constants.NODED),
+                               lock_monitor_cb=lock_monitor_cb)
 
   def _Call(self, node_list, procedure, timeout, args):
     """Entry point for automatically generated RPC wrappers.
diff --git a/lib/server/masterd.py b/lib/server/masterd.py
index cc86d8a..6c32a64 100644
--- a/lib/server/masterd.py
+++ b/lib/server/masterd.py
@@ -401,6 +401,8 @@ class GanetiContext(object):
                 self.cfg.GetNodeGroupList(),
                 self.cfg.GetInstanceList())
 
+    self.cfg.SetContext(self)
+
     # Job queue
     self.jobqueue = jqueue.JobQueue(self)
 
-- 
1.7.6

Reply via email to