Revision f6eaed12

b/lib/backend.py
437 437
  if constants.NV_DRBDLIST in what:
438 438
    try:
439 439
      used_minors = bdev.DRBD8.GetUsedDevs().keys()
440
    except errors.BlockDeviceError:
440
    except errors.BlockDeviceError, err:
441 441
      logging.warning("Can't get used minors list", exc_info=True)
442
      used_minors = []
442
      used_minors = str(err)
443 443
    result[constants.NV_DRBDLIST] = used_minors
444 444

  
445 445
  return result
b/lib/bdev.py
639 639
    """Return data from /proc/drbd.
640 640

  
641 641
    """
642
    stat = open(filename, "r")
643 642
    try:
644
      data = stat.read().splitlines()
645
    finally:
646
      stat.close()
643
      stat = open(filename, "r")
644
      try:
645
        data = stat.read().splitlines()
646
      finally:
647
        stat.close()
648
    except EnvironmentError, err:
649
      if err.errno == errno.ENOENT:
650
        _ThrowError("The file %s cannot be opened, check if the module"
651
                    " is loaded (%s)", filename, str(err))
652
      else:
653
        _ThrowError("Can't read the DRBD proc file %s: %s", filename, str(err))
647 654
    if not data:
648 655
      _ThrowError("Can't read any data from %s", filename)
649 656
    return data
b/lib/cmdlib.py
757 757

  
758 758
    # check used drbd list
759 759
    used_minors = node_result.get(constants.NV_DRBDLIST, [])
760
    for minor, (iname, must_exist) in drbd_map.items():
761
      if minor not in used_minors and must_exist:
762
        feedback_fn("  - ERROR: drbd minor %d of instance %s is not active" %
763
                    (minor, iname))
764
        bad = True
765
    for minor in used_minors:
766
      if minor not in drbd_map:
767
        feedback_fn("  - ERROR: unallocated drbd minor %d is in use" % minor)
768
        bad = True
760
    if not isinstance(used_minors, (tuple, list)):
761
      feedback_fn("  - ERROR: cannot parse drbd status file: %s" %
762
                  str(used_minors))
763
    else:
764
      for minor, (iname, must_exist) in drbd_map.items():
765
        if minor not in used_minors and must_exist:
766
          feedback_fn("  - ERROR: drbd minor %d of instance %s is not active" %
767
                      (minor, iname))
768
          bad = True
769
      for minor in used_minors:
770
        if minor not in drbd_map:
771
          feedback_fn("  - ERROR: unallocated drbd minor %d is in use" % minor)
772
          bad = True
769 773

  
770 774
    return bad
771 775

  
b/test/ganeti.bdev_unittest.py
106 106
    self.proc_data = bdev.DRBD8._GetProcData(filename=proc_data)
107 107
    self.mass_data = bdev.DRBD8._MassageProcData(self.proc_data)
108 108

  
109
  def testIOErrors(self):
110
    """Test handling of errors while reading the proc file."""
111
    temp_file = self._CreateTempFile()
112
    os.unlink(temp_file)
113
    self.failUnlessRaises(errors.BlockDeviceError,
114
                          bdev.DRBD8._GetProcData, filename=temp_file)
115

  
109 116
  def testMinorNotFound(self):
110 117
    """Test not-found-minor in /proc"""
111 118
    self.failUnless(9 not in self.mass_data)

Also available in: Unified diff