Revision f4bc1f2c tools/lvmstrap

b/tools/lvmstrap
190 190

  
191 191
  osname, nodename, release, version, arch = os.uname()
192 192
  if osname != 'Linux':
193
    raise PrereqError("This tool only runs on Linux "
194
                      "(detected OS: %s)." % osname)
193
    raise PrereqError("This tool only runs on Linux"
194
                      " (detected OS: %s)." % osname)
195 195

  
196 196
  if not release.startswith("2.6."):
197
    raise PrereqError("Wrong major kernel version (detected %s, needs "
198
                      "2.6.*)" % release)
197
    raise PrereqError("Wrong major kernel version (detected %s, needs"
198
                      " 2.6.*)" % release)
199 199

  
200 200
  if not os.path.ismount("/sys"):
201
    raise PrereqError("Can't find a filesystem mounted at /sys. "
202
                      "Please mount /sys.")
201
    raise PrereqError("Can't find a filesystem mounted at /sys."
202
                      " Please mount /sys.")
203 203

  
204 204
  if not os.path.isdir("/sys/block"):
205
    raise SysconfigError("Can't find /sys/block directory. Has the "
206
                         "layout of /sys changed?")
205
    raise SysconfigError("Can't find /sys/block directory. Has the"
206
                         " layout of /sys changed?")
207 207

  
208 208
  if not os.path.ismount("/proc"):
209
    raise PrereqError("Can't find a filesystem mounted at /proc. "
210
                      "Please mount /proc.")
209
    raise PrereqError("Can't find a filesystem mounted at /proc."
210
                      " Please mount /proc.")
211 211

  
212 212
  if not os.path.exists("/proc/mounts"):
213 213
    raise SysconfigError("Can't find /proc/mounts")
......
228 228
      vg_free: The available space in the volume group
229 229
  """
230 230

  
231
  result = ExecCommand("vgs --nohead -o lv_count,vg_size,"
232
                       "vg_free --nosuffix --units g "
233
                       "--ignorelockingfailure %s" % vgname)
231
  result = ExecCommand("vgs --nohead -o lv_count,vg_size,vg_free"
232
                       " --nosuffix --units g"
233
                       " --ignorelockingfailure %s" % vgname)
234 234
  if not result.failed:
235 235
    try:
236 236
      lv_count, vg_size, vg_free = result.stdout.strip().split()
......
272 272
      break
273 273
    time.sleep(0.250)
274 274
  else:
275
    raise SysconfigError("the device file %s does not exist, but the block "
276
                         "device exists in the /sys/block tree" % path)
275
    raise SysconfigError("the device file %s does not exist, but the block"
276
                         " device exists in the /sys/block tree" % path)
277 277
  rdev = os.stat(path).st_rdev
278 278
  if devnum != rdev:
279
    raise SysconfigError("For device %s, the major:minor in /dev is %04x "
280
                         "while the major:minor in sysfs is %s" %
279
    raise SysconfigError("For device %s, the major:minor in /dev is %04x"
280
                         " while the major:minor in sysfs is %s" %
281 281
                         (path, rdev, devnum))
282 282

  
283 283

  
......
546 546
  """
547 547

  
548 548
  if not CheckReread(name):
549
    raise OperationalError("CRITICAL: disk %s you selected seems to be in "
550
                           "use. ABORTING!" % name)
549
    raise OperationalError("CRITICAL: disk %s you selected seems to be in"
550
                           " use. ABORTING!" % name)
551 551

  
552 552
  fd = os.open("/dev/%s" % name, os.O_RDWR | os.O_SYNC)
553 553
  olddata = os.read(fd, 512)
554 554
  if len(olddata) != 512:
555
    raise OperationalError("CRITICAL: Can't read partition table information "
556
                           "from /dev/%s (needed 512 bytes, got %d" %
555
    raise OperationalError("CRITICAL: Can't read partition table information"
556
                           " from /dev/%s (needed 512 bytes, got %d" %
557 557
                           (name, len(olddata)))
558 558
  newdata = "\0" * 512
559 559
  os.lseek(fd, 0, 0)
......
561 561
  os.close(fd)
562 562
  if bytes_written != 512:
563 563
    raise OperationalError("CRITICAL: Can't write partition table information"
564
                           " to /dev/%s (tried to write 512 bytes, written "
565
                           "%d. I don't know how to cleanup. Sorry." %
564
                           " to /dev/%s (tried to write 512 bytes, written"
565
                           " %d. I don't know how to cleanup. Sorry." %
566 566
                           (name, bytes_written))
567 567

  
568 568
  if not CheckReread(name):
569 569
    fd = os.open("/dev/%s" % name, os.O_RDWR | os.O_SYNC)
570 570
    os.write(fd, olddata)
571 571
    os.close(fd)
572
    raise OperationalError("CRITICAL: disk %s which I have just wiped cannot "
573
                           "reread partition table. Most likely, it is "
574
                           "in use. You have to clean after this yourself. "
575
                           "I tried to restore the old partition table, "
576
                           "but I cannot guarantee nothing has broken." %
572
    raise OperationalError("CRITICAL: disk %s which I have just wiped cannot"
573
                           " reread partition table. Most likely, it is"
574
                           " in use. You have to clean after this yourself."
575
                           " I tried to restore the old partition table,"
576
                           " but I cannot guarantee nothing has broken." %
577 577
                           name)
578 578

  
579 579

  
......
589 589
  result = ExecCommand(
590 590
    'echo ,,8e, | sfdisk /dev/%s' % name)
591 591
  if result.failed:
592
    raise OperationalError("CRITICAL: disk %s which I have just partitioned "
593
                           "cannot reread its partition table, or there "
594
                           "is some other sfdisk error. Likely, it is in "
595
                           "use. You have to clean this yourself. Error "
596
                           "message from sfdisk: %s" %
592
    raise OperationalError("CRITICAL: disk %s which I have just partitioned"
593
                           " cannot reread its partition table, or there"
594
                           " is some other sfdisk error. Likely, it is in"
595
                           " use. You have to clean this yourself. Error"
596
                           " message from sfdisk: %s" %
597 597
                           (name, result.output))
598 598

  
599 599

  
......
609 609
  """
610 610
  result = ExecCommand("pvcreate -yff /dev/%s1 " % name)
611 611
  if result.failed:
612
    raise OperationalError("I cannot create a physical volume on "
613
                           "partition /dev/%s1. Error message: %s. "
614
                           "Please clean up yourself." %
612
    raise OperationalError("I cannot create a physical volume on"
613
                           " partition /dev/%s1. Error message: %s."
614
                           " Please clean up yourself." %
615 615
                           (name, result.output))
616 616

  
617 617

  
......
628 628
  pnames = ["'/dev/%s1'" % disk for disk in disks]
629 629
  result = ExecCommand("vgcreate -s 64MB '%s' %s" % (vgname, " ".join(pnames)))
630 630
  if result.failed:
631
    raise OperationalError("I cannot create the volume group %s from "
632
                           "disks %s. Error message: %s. Please clean up "
633
                           "yourself." %
631
    raise OperationalError("I cannot create the volume group %s from"
632
                           " disks %s. Error message: %s. Please clean up"
633
                           " yourself." %
634 634
                           (vgname, " ".join(disks), result.output))
635 635

  
636 636

  
......
651 651

  
652 652
  sysdisks = GetDiskList()
653 653
  if not sysdisks:
654
    raise PrereqError("no disks found (I looked for "
655
                      "non-removable block devices).")
654
    raise PrereqError("no disks found (I looked for"
655
                      " non-removable block devices).")
656 656
  sysd_free = []
657 657
  sysd_used = []
658 658
  for name, size, dev, part, used in sysdisks:
......
678 678

  
679 679
  return disklist
680 680

  
681

  
681 682
def BootStrap():
682 683
  """Actual main routine."""
683 684

  
......
711 712
  status, lv_count, size, free = CheckVGExists(vgname)
712 713
  if status:
713 714
    print "Done! %s: size %s GiB, disks: %s" % (vgname, size,
714
                                                ",".join(disklist))
715
                                              ",".join(disklist))
715 716
  else:
716
    raise OperationalError("Although everything seemed ok, the volume "
717
                           "group did not get created.")
717
    raise OperationalError("Although everything seemed ok, the volume"
718
                           " group did not get created.")
718 719

  
719 720

  
720 721
def main():
......
727 728
    BootStrap()
728 729
  except PrereqError, err:
729 730
    print >> sys.stderr, "The prerequisites for running this tool are not met."
730
    print >> sys.stderr, ("Please make sure you followed all the steps in "
731
                          "the build document.")
731
    print >> sys.stderr, ("Please make sure you followed all the steps in"
732
                          " the build document.")
732 733
    print >> sys.stderr, "Description: %s" % str(err)
733 734
    sys.exit(1)
734 735
  except SysconfigError, err:
735
    print >> sys.stderr, ("This system's configuration seems wrong, at "
736
                          "least is not what I expect.")
737
    print >> sys.stderr, ("Please check that the installation didn't fail "
738
                          "at some step.")
736
    print >> sys.stderr, ("This system's configuration seems wrong, at"
737
                          " least is not what I expect.")
738
    print >> sys.stderr, ("Please check that the installation didn't fail"
739
                          " at some step.")
739 740
    print >> sys.stderr, "Description: %s" % str(err)
740 741
    sys.exit(1)
741 742
  except ParameterError, err:
742
    print >> sys.stderr, ("Some parameters you gave to the program or the "
743
                          "invocation is wrong. ")
743
    print >> sys.stderr, ("Some parameters you gave to the program or the"
744
                          " invocation is wrong. ")
744 745
    print >> sys.stderr, "Description: %s" % str(err)
745 746
    Usage()
746 747
  except OperationalError, err:
747
    print >> sys.stderr, ("A serious error has happened while modifying "
748
                          "the system's configuration.")
749
    print >> sys.stderr, ("Please review the error message below and make "
750
                          "sure you clean up yourself.")
751
    print >> sys.stderr, ("It is most likely that the system configuration "
752
                          "has been partially altered.")
748
    print >> sys.stderr, ("A serious error has happened while modifying"
749
                          " the system's configuration.")
750
    print >> sys.stderr, ("Please review the error message below and make"
751
                          " sure you clean up yourself.")
752
    print >> sys.stderr, ("It is most likely that the system configuration"
753
                          " has been partially altered.")
753 754
    print >> sys.stderr, str(err)
754 755
    sys.exit(1)
755 756
  except ProgrammingError, err:
756
    print >> sys.stderr, ("Internal application error. Please signal this "
757
                          "to xencluster-team.")
757
    print >> sys.stderr, ("Internal application error. Please signal this"
758
                          " to xencluster-team.")
758 759
    print >> sys.stderr, "Error description: %s" % str(err)
759 760
    sys.exit(1)
760 761
  except Error, err:

Also available in: Unified diff