Revision a619a1dd tools/burnin

b/tools/burnin
36 36
from ganeti import cli
37 37
from ganeti import errors
38 38
from ganeti import utils
39
from ganeti import ssconf
40

  
41
from ganeti.confd import client as confd_client
39 42

  
40 43

  
41 44
USAGE = ("\tburnin -o OS_NAME [options...] instance_name ...")
......
164 167
  cli.cli_option("--no-nics", dest="nics",
165 168
                 help="No network interfaces", action="store_const",
166 169
                 const=[], default=[{}]),
170
  cli.cli_option("--no-confd", dest="do_confd_tests",
171
                 help="Skip confd queries",
172
                 action="store_false", default=True),
167 173
  cli.cli_option("--rename", dest="rename", default=None,
168 174
                 help=("Give one unused instance name which is taken"
169 175
                       " to start the renaming sequence"),
......
260 266
    self.hvp = self.bep = None
261 267
    self.ParseOptions()
262 268
    self.cl = cli.GetClient()
269
    self.ss = ssconf.SimpleStore()
263 270
    self.GetState()
264 271

  
265 272
  def ClearFeedbackBuf(self):
......
839 846
      Log("removing last NIC", indent=2)
840 847
      self.ExecOrQueue(instance, op_add, op_rem)
841 848

  
849
  def ConfdCallback(self, reply):
850
    """Callback for confd queries"""
851
    if reply.type == confd_client.UPCALL_REPLY:
852
      if reply.server_reply.status != constants.CONFD_REPL_STATUS_OK:
853
        Err("Query %s gave non-ok status %s: %s" % (reply.orig_request,
854
                                                    reply.server_reply.status,
855
                                                    reply.server_reply))
856
      if reply.orig_request.type == constants.CONFD_REQ_PING:
857
        Log("Ping: OK", indent=1)
858
      elif reply.orig_request.type == constants.CONFD_REQ_CLUSTER_MASTER:
859
        if reply.server_reply.answer == self.cluster_info["master"]:
860
          Log("Master: OK", indent=1)
861
        else:
862
          Err("Master: wrong: %s" % reply.server_reply.answer)
863
      elif reply.orig_request.type == constants.CONFD_REQ_NODE_ROLE_BYNAME:
864
        if reply.server_reply.answer == constants.CONFD_NODE_ROLE_MASTER:
865
          Log("Node role for master: OK", indent=1)
866
        else:
867
          Err("Node role for master: wrong: %s" % reply.server_reply.answer)
868

  
869
  def DoConfdRequestReply(self, req):
870
    self.confd_counting_callback.RegisterQuery(req.rsalt)
871
    self.confd_client.SendRequest(req, async=False)
872
    while not self.confd_counting_callback.AllAnswered():
873
      if not self.confd_client.ReceiveReply():
874
        Err("Did not receive all expected confd replies")
875
        break
876

  
877
  def BurnConfd(self):
878
    """Run confd queries for our instances.
879

  
880
    The following confd queries are tested:
881
    - CONFD_REQ_PING: simple ping
882
    - CONFD_REQ_CLUSTER_MASTER: cluster master
883
    - CONFD_REQ_NODE_ROLE_BYNAME: node role, for the master
884

  
885
    """
886
    Log("Checking confd results")
887

  
888
    hmac_key = utils.ReadFile(constants.CONFD_HMAC_KEY)
889
    mc_file = self.ss.KeyToFilename(constants.SS_MASTER_CANDIDATES_IPS)
890
    mc_list = utils.ReadFile(mc_file).splitlines()
891
    filter_callback = confd_client.ConfdFilterCallback(self.ConfdCallback)
892
    counting_callback = confd_client.ConfdCountingCallback(filter_callback)
893
    self.confd_counting_callback = counting_callback
894

  
895
    self.confd_client = confd_client.ConfdClient(hmac_key, mc_list,
896
                                                 counting_callback)
897

  
898
    req = confd_client.ConfdClientRequest(type=constants.CONFD_REQ_PING)
899
    self.DoConfdRequestReply(req)
900

  
901
    req = confd_client.ConfdClientRequest(
902
      type=constants.CONFD_REQ_CLUSTER_MASTER)
903
    self.DoConfdRequestReply(req)
904

  
905
    req = confd_client.ConfdClientRequest(
906
        type=constants.CONFD_REQ_NODE_ROLE_BYNAME,
907
        query=self.cluster_info["master"])
908
    self.DoConfdRequestReply(req)
909

  
842 910
  def _CheckInstanceAlive(self, instance):
843 911
    """Check if an instance is alive by doing http checks.
844 912

  
......
936 1004
      if opts.rename:
937 1005
        self.BurnRename()
938 1006

  
1007
      if opts.do_confd_tests:
1008
        self.BurnConfd()
1009

  
939 1010
      if opts.do_startstop:
940 1011
        self.BurnStopStart()
941 1012

  

Also available in: Unified diff