From 5b349fd13f72e50b8b4b2d8579cee5177658ee7b Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 18 Mar 2010 16:56:08 +0100 Subject: [PATCH] Abstract the confd client creation Most creation of confd clients will do the same steps: read MC file, parse it, read HMAC key, etc. We abstract this functionality so that we don't duplicate the code. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/confd/client.py | 18 ++++++++++++++++++ tools/burnin | 8 +------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/confd/client.py b/lib/confd/client.py index efcb68d33..dfbc65063 100644 --- a/lib/confd/client.py +++ b/lib/confd/client.py @@ -60,6 +60,7 @@ from ganeti import serializer from ganeti import daemon # contains AsyncUDPSocket from ganeti import errors from ganeti import confd +from ganeti import ssconf class ConfdAsyncUDPClient(daemon.AsyncUDPSocket): @@ -494,3 +495,20 @@ class ConfdCountingCallback: elif up.type == UPCALL_EXPIRE: self._HandleExpire(up) self._callback(up) + +def GetConfdClient(callback): + """Return a client configured using the given callback. + + This is handy to abstract the MC list and HMAC key reading. + + @attention: This should only be called on nodes which are part of a + cluster, since it depends on a valid (ganeti) data directory; + for code running outside of a cluster, you need to create the + client manually + + """ + ss = ssconf.SimpleStore() + mc_file = ss.KeyToFilename(constants.SS_MASTER_CANDIDATES_IPS) + mc_list = utils.ReadFile(mc_file).splitlines() + hmac_key = utils.ReadFile(constants.CONFD_HMAC_KEY) + return ConfdClient(hmac_key, mc_list, callback) diff --git a/tools/burnin b/tools/burnin index a7ca79a8c..5ab5e87cc 100755 --- a/tools/burnin +++ b/tools/burnin @@ -36,7 +36,6 @@ from ganeti import constants from ganeti import cli from ganeti import errors from ganeti import utils -from ganeti import ssconf from ganeti.confd import client as confd_client @@ -266,7 +265,6 @@ class Burner(object): self.hvp = self.bep = None self.ParseOptions() self.cl = cli.GetClient() - self.ss = ssconf.SimpleStore() self.GetState() def ClearFeedbackBuf(self): @@ -885,15 +883,11 @@ class Burner(object): """ Log("Checking confd results") - hmac_key = utils.ReadFile(constants.CONFD_HMAC_KEY) - mc_file = self.ss.KeyToFilename(constants.SS_MASTER_CANDIDATES_IPS) - mc_list = utils.ReadFile(mc_file).splitlines() filter_callback = confd_client.ConfdFilterCallback(self.ConfdCallback) counting_callback = confd_client.ConfdCountingCallback(filter_callback) self.confd_counting_callback = counting_callback - self.confd_client = confd_client.ConfdClient(hmac_key, mc_list, - counting_callback) + self.confd_client = confd_client.GetConfdClient(counting_callback) req = confd_client.ConfdClientRequest(type=constants.CONFD_REQ_PING) self.DoConfdRequestReply(req) -- GitLab