Revision 41be279f qa/qa_config.py

b/qa/qa_config.py
553 553
  return GetConfig().IsTemplateSupported(templ)
554 554

  
555 555

  
556
def _NodeSortKey(node):
557
  """Returns sort key for a node.
558

  
559
  @type node: L{_QaNode}
560

  
561
  """
562
  return (node.use_count, utils.NiceSortKey(node.primary))
563

  
564

  
556 565
def AcquireNode(exclude=None, _cfg=None):
557 566
  """Returns the least used node.
558 567

  
......
578 587
  if not nodes:
579 588
    raise qa_error.OutOfNodesError("No nodes left")
580 589

  
581
  # Get node with least number of uses
582
  # TODO: Switch to computing sort key instead of comparing directly
583
  def compare(a, b):
584
    result = cmp(a.use_count, b.use_count)
585
    if result == 0:
586
      result = cmp(a.primary, b.primary)
587
    return result
588

  
589
  nodes.sort(cmp=compare)
590

  
591
  return nodes[0].Use()
590
  # Return node with least number of uses
591
  return sorted(nodes, key=_NodeSortKey)[0].Use()
592 592

  
593 593

  
594 594
def AcquireManyNodes(num, exclude=None):

Also available in: Unified diff