Revision c70481ab tools/burnin

b/tools/burnin
259 259

  
260 260
    return wrapper
261 261

  
262
  def _DoBatch(retry):
263
    """Decorator for possible batch operations.
264

  
265
    Must come after the _DoCheckInstances decorator (if any).
266

  
267
    @param retry: whether this is a retryable batch, will be
268
        passed to StartBatch
269

  
270
    """
271
    def wrap(fn):
272
      def batched(self, *args, **kwargs):
273
        self.StartBatch(retry)
274
        val = fn(self, *args, **kwargs)
275
        self.CommitQueue()
276
        return val
277
      return batched
278

  
279
    return wrap
280

  
262 281
  def ParseOptions(self):
263 282
    """Parses the command line options.
264 283

  
......
428 447
      Err("OS '%s' not found" % self.opts.os)
429 448

  
430 449
  @_DoCheckInstances
450
  @_DoBatch(False)
431 451
  def BurnCreateInstances(self):
432 452
    """Create the given instances.
433 453

  
434 454
    """
435
    self.StartBatch(False)
436 455
    self.to_rem = []
437 456
    mytor = izip(cycle(self.nodes),
438 457
                 islice(cycle(self.nodes), 1, None),
......
474 493
      self.ExecOrQueue(instance, op)
475 494
      self.to_rem.append(instance)
476 495

  
477
    self.CommitQueue()
478

  
496
  @_DoBatch(False)
479 497
  def BurnGrowDisks(self):
480 498
    """Grow both the os and the swap disks by the requested amount, if any."""
481 499
    Log("Growing disks")
482
    self.StartBatch(False)
483 500
    for instance in self.instances:
484 501
      Log("instance %s" % instance, indent=1)
485 502
      for idx, growth in enumerate(self.disk_growth):
......
488 505
                                  amount=growth, wait_for_sync=True)
489 506
          Log("increase disk/%s by %s MB" % (idx, growth), indent=2)
490 507
          self.ExecOrQueue(instance, op)
491
    self.CommitQueue()
492 508

  
509
  @_DoBatch(True)
493 510
  def BurnReplaceDisks1D8(self):
494 511
    """Replace disks on primary and secondary for drbd8."""
495 512
    Log("Replacing disks on the same nodes")
496
    self.StartBatch(True)
497 513
    for instance in self.instances:
498 514
      Log("instance %s" % instance, indent=1)
499 515
      ops = []
......
504 520
        Log("run %s" % mode, indent=2)
505 521
        ops.append(op)
506 522
      self.ExecOrQueue(instance, *ops)
507
    self.CommitQueue()
508 523

  
524
  @_DoBatch(True)
509 525
  def BurnReplaceDisks2(self):
510 526
    """Replace secondary node."""
511 527
    Log("Changing the secondary node")
512
    self.StartBatch(True)
513 528
    mode = constants.REPLACE_DISK_CHG
514 529

  
515 530
    mytor = izip(islice(cycle(self.nodes), 2, None),
......
528 543
                                  disks=[i for i in range(self.disk_count)])
529 544
      Log("run %s %s" % (mode, msg), indent=2)
530 545
      self.ExecOrQueue(instance, op)
531
    self.CommitQueue()
532 546

  
533 547
  @_DoCheckInstances
548
  @_DoBatch(False)
534 549
  def BurnFailover(self):
535 550
    """Failover the instances."""
536 551
    Log("Failing over instances")
537
    self.StartBatch(False)
538 552
    for instance in self.instances:
539 553
      Log("instance %s" % instance, indent=1)
540 554
      op = opcodes.OpFailoverInstance(instance_name=instance,
541 555
                                      ignore_consistency=False)
542 556

  
543 557
      self.ExecOrQueue(instance, op)
544
    self.CommitQueue()
545 558

  
559
  @_DoBatch(False)
546 560
  def BurnMigrate(self):
547 561
    """Migrate the instances."""
548 562
    Log("Migrating instances")
549
    self.StartBatch(False)
550 563
    for instance in self.instances:
551 564
      Log("instance %s" % instance, indent=1)
552 565
      op1 = opcodes.OpMigrateInstance(instance_name=instance, live=True,
......
556 569
                                      cleanup=True)
557 570
      Log("migration and migration cleanup", indent=2)
558 571
      self.ExecOrQueue(instance, op1, op2)
559
    self.CommitQueue()
560 572

  
561 573
  @_DoCheckInstances
574
  @_DoBatch(False)
562 575
  def BurnImportExport(self):
563 576
    """Export the instance, delete it, and import it back.
564 577

  
565 578
    """
566 579
    Log("Exporting and re-importing instances")
567
    self.StartBatch(False)
568 580
    mytor = izip(cycle(self.nodes),
569 581
                 islice(cycle(self.nodes), 1, None),
570 582
                 islice(cycle(self.nodes), 2, None),
......
624 636
      Log("remove export", indent=2)
625 637
      self.ExecOrQueue(instance, exp_op, rem_op, imp_op, erem_op)
626 638

  
627
    self.CommitQueue()
628

  
629 639
  def StopInstanceOp(self, instance):
630 640
    """Stop given instance."""
631 641
    return opcodes.OpShutdownInstance(instance_name=instance)
......
640 650
                                    new_name=instance_new)
641 651

  
642 652
  @_DoCheckInstances
653
  @_DoBatch(True)
643 654
  def BurnStopStart(self):
644 655
    """Stop/start the instances."""
645 656
    Log("Stopping and starting instances")
646
    self.StartBatch(True)
647 657
    for instance in self.instances:
648 658
      Log("instance %s" % instance, indent=1)
649 659
      op1 = self.StopInstanceOp(instance)
650 660
      op2 = self.StartInstanceOp(instance)
651 661
      self.ExecOrQueue(instance, op1, op2)
652 662

  
653
    self.CommitQueue()
654

  
663
  @_DoBatch(False)
655 664
  def BurnRemove(self):
656 665
    """Remove the instances."""
657
    self.StartBatch(False)
658 666
    Log("Removing instances")
659 667
    for instance in self.to_rem:
660 668
      Log("instance %s" % instance, indent=1)
......
662 670
                                    ignore_failures=True)
663 671
      self.ExecOrQueue(instance, op)
664 672

  
665
    self.CommitQueue()
666

  
667 673
  def BurnRename(self):
668 674
    """Rename the instances.
669 675

  
......
687 693
      self._CheckInstanceAlive(instance)
688 694

  
689 695
  @_DoCheckInstances
696
  @_DoBatch(True)
690 697
  def BurnReinstall(self):
691 698
    """Reinstall the instances."""
692 699
    Log("Reinstalling instances")
693
    self.StartBatch(True)
694 700
    for instance in self.instances:
695 701
      Log("instance %s" % instance, indent=1)
696 702
      op1 = self.StopInstanceOp(instance)
......
702 708
      op4 = self.StartInstanceOp(instance)
703 709
      self.ExecOrQueue(instance, op1, op2, op3, op4)
704 710

  
705
    self.CommitQueue()
706

  
707 711
  @_DoCheckInstances
712
  @_DoBatch(True)
708 713
  def BurnReboot(self):
709 714
    """Reboot the instances."""
710 715
    Log("Rebooting instances")
711
    self.StartBatch(True)
712 716
    for instance in self.instances:
713 717
      Log("instance %s" % instance, indent=1)
714 718
      ops = []
......
720 724
        ops.append(op)
721 725
      self.ExecOrQueue(instance, *ops)
722 726

  
723
    self.CommitQueue()
724

  
725 727
  @_DoCheckInstances
728
  @_DoBatch(True)
726 729
  def BurnActivateDisks(self):
727 730
    """Activate and deactivate disks of the instances."""
728 731
    Log("Activating/deactivating disks")
729
    self.StartBatch(True)
730 732
    for instance in self.instances:
731 733
      Log("instance %s" % instance, indent=1)
732 734
      op_start = self.StartInstanceOp(instance)
......
737 739
      Log("activate disks when offline", indent=2)
738 740
      Log("deactivate disks (when offline)", indent=2)
739 741
      self.ExecOrQueue(instance, op_act, op_stop, op_act, op_deact, op_start)
740
    self.CommitQueue()
741 742

  
742 743
  @_DoCheckInstances
744
  @_DoBatch(False)
743 745
  def BurnAddRemoveDisks(self):
744 746
    """Add and remove an extra disk for the instances."""
745 747
    Log("Adding and removing disks")
746
    self.StartBatch(False)
747 748
    for instance in self.instances:
748 749
      Log("instance %s" % instance, indent=1)
749 750
      op_add = opcodes.OpSetInstanceParams(\
......
756 757
      Log("adding a disk", indent=2)
757 758
      Log("removing last disk", indent=2)
758 759
      self.ExecOrQueue(instance, op_add, op_stop, op_rem, op_start)
759
    self.CommitQueue()
760 760

  
761
  @_DoBatch(False)
761 762
  def BurnAddRemoveNICs(self):
762 763
    """Add and remove an extra NIC for the instances."""
763 764
    Log("Adding and removing NICs")
764
    self.StartBatch(False)
765 765
    for instance in self.instances:
766 766
      Log("instance %s" % instance, indent=1)
767 767
      op_add = opcodes.OpSetInstanceParams(\
......
771 771
      Log("adding a NIC", indent=2)
772 772
      Log("removing last NIC", indent=2)
773 773
      self.ExecOrQueue(instance, op_add, op_rem)
774
    self.CommitQueue()
775 774

  
776 775
  def _CheckInstanceAlive(self, instance):
777 776
    """Check if an instance is alive by doing http checks.

Also available in: Unified diff