Revision 06009e27

b/daemons/ganeti-noded
476 476
    hr = backend.HooksRunner()
477 477
    return hr.RunHooks(hpath, phase, env)
478 478

  
479
  # test -----------------------
480

  
481
  @staticmethod
482
  def perspective_test_delay(params):
483
    """Run test delay.
484

  
485
    """
486
    duration = params[0]
487
    return utils.TestDelay(duration)
488

  
479 489

  
480 490
class MyRealm:
481 491
  """Simple realm that forwards all requests to a ServerObject.
b/lib/cmdlib.py
4542 4542
      raise errors.OpRetryError("There has been a modification to the"
4543 4543
                                " config file and the operation has been"
4544 4544
                                " aborted. Please retry.")
4545

  
4546
class LUTestDelay(NoHooksLU):
4547
  """Sleep for a specified amount of time.
4548

  
4549
  This LU sleeps on the master and/or nodes for a specified amoutn of
4550
  time.
4551

  
4552
  """
4553
  _OP_REQP = ["duration", "on_master", "on_nodes"]
4554

  
4555
  def CheckPrereq(self):
4556
    """Check prerequisites.
4557

  
4558
    This checks that we have a good list of nodes and/or the duration
4559
    is valid.
4560

  
4561
    """
4562

  
4563
    if self.op.on_nodes:
4564
      self.op.on_nodes = _GetWantedNodes(self, self.op.on_nodes)
4565

  
4566
  def Exec(self, feedback_fn):
4567
    """Do the actual sleep.
4568

  
4569
    """
4570
    if self.op.on_master:
4571
      if not utils.TestDelay(self.op.duration):
4572
        raise errors.OpExecError("Error during master delay test")
4573
    if self.op.on_nodes:
4574
      result = rpc.call_test_delay(self.op.on_nodes, self.op.duration)
4575
      if not result:
4576
        raise errors.OpExecError("Complete failure from rpc call")
4577
      for node, node_result in result.items():
4578
        if not node_result:
4579
          raise errors.OpExecError("Failure during rpc call to node %s,"
4580
                                   " result: %s" % (node, node_result))
b/lib/mcpu.py
85 85
    opcodes.OpSearchTags: cmdlib.LUSearchTags,
86 86
    opcodes.OpAddTags: cmdlib.LUAddTags,
87 87
    opcodes.OpDelTags: cmdlib.LUDelTags,
88
    # test lu
89
    opcodes.OpTestDelay: cmdlib.LUTestDelay,
88 90
    }
89 91

  
90 92
  def __init__(self, feedback=None):
b/lib/opcodes.py
310 310
  """Remove a list of tags from a given object."""
311 311
  OP_ID = "OP_TAGS_DEL"
312 312
  __slots__ = ["kind", "name", "tags"]
313

  
314

  
315
# Test opcodes
316
class OpTestDelay(OpCode):
317
  """Sleeps for a configured amount of time.
318

  
319
  This is used just for debugging and testing.
320

  
321
  Parameters:
322
    - duration: the time to sleep
323
    - on_master: if true, sleep on the master
324
    - on_nodes: list of nodes in which to sleep
325

  
326
  If the on_master parameter is true, it will execute a sleep on the
327
  master (before any node sleep).
328

  
329
  If the on_nodes list is not empty, it will sleep on those nodes
330
  (after the sleep on the master, if that is enabled).
331

  
332
  As an additional feature, the case of duration < 0 will be reported
333
  as an execution error, so this opcode can be used as a failure
334
  generator. The case of duration == 0 will not be treated specially.
335

  
336
  """
337
  OP_ID = "OP_TEST_DELAY"
338
  __slots__ = ["duration", "on_master", "on_nodes"]
b/lib/rpc.py
801 801
  c.connect_list(node_list)
802 802
  c.run()
803 803
  return c.getresult()
804

  
805

  
806
def call_test_delay(node_list, duration):
807
  """Sleep for a fixed time on given node(s).
808

  
809
  This is a multi-node call.
810

  
811
  """
812
  c = Client("test_delay", [duration])
813
  c.connect_list(node_list)
814
  c.run()
815
  return c.getresult()
b/lib/utils.py
1065 1065
  """
1066 1066
  mac_check = re.compile("^([0-9a-f]{2}(:|$)){6}$")
1067 1067
  return mac_check.match(mac) is not None
1068

  
1069

  
1070
def TestDelay(duration):
1071
  """Sleep for a fixed amount of time.
1072

  
1073
  """
1074
  if duration < 0:
1075
    return False
1076
  time.sleep(duration)
1077
  return True

Also available in: Unified diff