Commit 72737a7f authored by Iustin Pop's avatar Iustin Pop
Browse files

Convert rpc module to RpcRunner

This big patch changes the call model used in internode-rpc from
standalong function calls in the rpc module to via a RpcRunner class,
that holds all the methods. This can be used in the future to enable
smarter processing in the RPC layer itself (some quick examples are not
setting the DiskID from cmdlib code, but only once in each rpc call,

There are a few RPC calls that are made outside of the LU code, and
these calls are left as staticmethods, so they can be used without a
class instance (which requires a ConfigWriter instance).

Reviewed-by: imsnah
parent b9bddb6b
......@@ -381,7 +381,7 @@ def CheckAgreement():
# either single node cluster, or a misconfiguration, but I won't
# break any other node, so I can proceed
return True
results = rpc.call_master_info(node_list)
results = rpc.RpcRunner.call_master_info(node_list)
if not isinstance(results, dict):
# this should not happen (unless internal error in rpc)
logging.critical("Can't complete rpc call, aborting master startup")
......@@ -445,7 +445,7 @@ def main():
# activate ip
master_node = ssconf.SimpleConfigReader().GetMasterNode()
if not rpc.call_node_start_master(master_node, False):
if not rpc.RpcRunner.call_node_start_master(master_node, False):
logging.error("Can't activate master IP address")
......@@ -38,6 +38,7 @@ from ganeti import constants
from ganeti import objects
from ganeti import ssconf
from ganeti.rpc import RpcRunner
def _InitSSHSetup(node):
"""Setup the SSH configuration for the cluster.
......@@ -236,7 +237,7 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
# start the master ip
# TODO: Review rpc call from bootstrap
rpc.call_node_start_master(, True)
RpcRunner.call_node_start_master(, True)
def InitConfig(version, cluster_config, master_node_config,
......@@ -281,9 +282,9 @@ def FinalizeClusterDestroy(master):
begun in cmdlib.LUDestroyOpcode.
if not rpc.call_node_stop_master(master, True):
if not RpcRunner.call_node_stop_master(master, True):
logging.warning("Could not disable the master role")
if not rpc.call_node_leave_cluster(master):
if not RpcRunner.call_node_leave_cluster(master):
logging.warning("Could not shutdown the node daemon and cleanup the node")
......@@ -365,7 +366,7 @@ def MasterFailover():"setting master to %s, old master: %s", new_master, old_master)
if not rpc.call_node_stop_master(old_master, True):
if not RpcRunner.call_node_stop_master(old_master, True):
logging.error("could disable the master role on the old master"
" %s, please disable manually", old_master)
......@@ -374,12 +375,12 @@ def MasterFailover():
# Here we have a phase where no master should be running
if not rpc.call_upload_file(cfg.GetNodeList(),
if not RpcRunner.call_upload_file(cfg.GetNodeList(),
logging.error("could not distribute the new simple store master file"
" to the other nodes, please check.")
if not rpc.call_node_start_master(new_master, True):
if not RpcRunner.call_node_start_master(new_master, True):
logging.error("could not start the master role on the new master"
" %s, please check", new_master)
rcode = 1
This diff is collapsed.
......@@ -821,7 +821,7 @@ class ConfigWriter:
except ValueError:
result = rpc.call_upload_file(nodelist, self._cfg_file)
result = rpc.RpcRunner.call_upload_file(nodelist, self._cfg_file)
for node in nodelist:
if not result[node]:
logging.error("copy of file %s to node %s failed",
......@@ -45,6 +45,7 @@ from ganeti import utils
from ganeti import jstore
from ganeti import rpc
from ganeti.rpc import RpcRunner
......@@ -404,7 +405,7 @@ class JobQueue(object):
assert node_name != self._my_hostname
# Clean queue directory on added node
# Upload the whole queue excluding archived jobs
files = [self._GetJobPath(job_id) for job_id in self._GetJobIDsUnlocked()]
......@@ -420,7 +421,7 @@ class JobQueue(object):
result = rpc.call_jobqueue_update([node_name], file_name, content)
result = RpcRunner.call_jobqueue_update([node_name], file_name, content)
if not result[node_name]:
logging.error("Failed to upload %s to %s", file_name, node_name)
......@@ -459,14 +460,14 @@ class JobQueue(object):
utils.WriteFile(file_name, data=data)
result = rpc.call_jobqueue_update(self._nodes, file_name, data)
result = RpcRunner.call_jobqueue_update(self._nodes, file_name, data)
self._CheckRpcResult(result, self._nodes,
"Updating %s" % file_name)
def _RenameFileUnlocked(self, old, new):
os.rename(old, new)
result = rpc.call_jobqueue_rename(self._nodes, old, new)
result = RpcRunner.call_jobqueue_rename(self._nodes, old, new)
self._CheckRpcResult(result, self._nodes,
"Moving %s to %s" % (old, new))
......@@ -97,6 +97,7 @@ class Processor(object):
self.context = context
self._feedback_fn = None
self.exclusive_BGL = False
self.rpc = rpc.RpcRunner(context.cfg)
def _ExecLU(self, lu):
"""Logical Unit execution sequence.
......@@ -104,7 +105,7 @@ class Processor(object):
write_count = self.context.cfg.write_count
hm = HooksMaster(rpc.call_hooks_runner, self, lu)
hm = HooksMaster(self.rpc.call_hooks_runner, self, lu)
h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
lu.HooksCallBack(constants.HOOKS_PHASE_PRE, h_results,
self._feedback_fn, None)
......@@ -202,7 +203,7 @@ class Processor(object):
shared=not lu_class.REQ_BGL)
self.exclusive_BGL = lu_class.REQ_BGL
lu = lu_class(self, op, self.context)
lu = lu_class(self, op, self.context, self.rpc)
assert lu.needed_locks is not None, "needed_locks not set by LU"
result = self._LockAndExecLU(lu, locking.LEVEL_INSTANCE)
This diff is collapsed.
......@@ -228,7 +228,9 @@ class TestHooksMaster(unittest.TestCase):
def setUp(self):
self.op = opcodes.OpCode()
self.context = FakeContext() = FakeLU(None, self.op, self.context)
# WARNING: here we pass None as RpcRunner instance since we know
# our usage via HooksMaster will not use lu.rpc = FakeLU(None, self.op, self.context, None)
def testTotalFalse(self):
"""Test complete rpc failure"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment