Revision 5bb0a1cb

b/lib/backend.py
66 66
from ganeti import vcluster
67 67
from ganeti import ht
68 68
from ganeti.block.base import BlockDev
69
from ganeti.block.drbd_info import DRBD8Info
69 70
from ganeti import hooksmaster
70 71

  
71 72

  
......
830 831
    hyper = hypervisor.GetHypervisor(what[constants.NV_HVINFO])
831 832
    result[constants.NV_HVINFO] = hyper.GetNodeInfo()
832 833

  
834
  if constants.NV_DRBDVERSION in what and vm_capable:
835
    try:
836
      drbd_version = DRBD8Info.CreateFromFile().GetVersionString()
837
    except errors.BlockDeviceError, err:
838
      logging.warning("Can't get DRBD version", exc_info=True)
839
      drbd_version = str(err)
840
    result[constants.NV_DRBDVERSION] = drbd_version
841

  
833 842
  if constants.NV_DRBDLIST in what and vm_capable:
834 843
    try:
835 844
      used_minors = drbd.DRBD8.GetUsedDevs()
b/lib/block/drbd_info.py
149 149

  
150 150
  """
151 151

  
152
  _VERSION_RE = re.compile(r"^version: (\d+)\.(\d+)\.(\d+)(?:\.\d+)?"
152
  _VERSION_RE = re.compile(r"^version: (\d+)\.(\d+)\.(\d+)(?:\.(\d+))?"
153 153
                           r" \(api:(\d+)/proto:(\d+)(?:-(\d+))?\)")
154 154
  _VALID_LINE_RE = re.compile("^ *([0-9]+): cs:([^ ]+).*$")
155 155

  
......
164 164
      - k_major
165 165
      - k_minor
166 166
      - k_point
167
      - k_fix (only on some drbd versions)
167 168
      - api
168 169
      - proto
169 170
      - proto2 (only on drbd > 8.2.X)
......
171 172
    """
172 173
    return self._version
173 174

  
175
  def GetVersionString(self):
176
    """Return the DRBD version as a single string.
177

  
178
    """
179
    version = self.GetVersion()
180
    retval = "%d.%d.%d" % \
181
             (version["k_major"], version["k_minor"], version["k_point"])
182
    if "k_fix" in version:
183
      retval += ".%s" % version["k_fix"]
184

  
185
    retval += " (api:%d/proto:%d" % (version["api"], version["proto"])
186
    if "proto2" in version:
187
      retval += "-%s" % version["proto2"]
188
    retval += ")"
189
    return retval
190

  
174 191
  def GetMinors(self):
175 192
    """Return a list of minor for which information is available.
176 193

  
......
198 215
      "k_major": int(values[0]),
199 216
      "k_minor": int(values[1]),
200 217
      "k_point": int(values[2]),
201
      "api": int(values[3]),
202
      "proto": int(values[4]),
218
      "api": int(values[4]),
219
      "proto": int(values[5]),
203 220
      }
204
    if values[5] is not None:
205
      retval["proto2"] = values[5]
221
    if values[3] is not None:
222
      retval["k_fix"] = values[3]
223
    if values[6] is not None:
224
      retval["proto2"] = values[6]
206 225

  
207 226
    return retval
208 227

  
b/lib/constants.py
1669 1669
# Node verify constants
1670 1670
NV_BRIDGES = "bridges"
1671 1671
NV_DRBDHELPER = "drbd-helper"
1672
NV_DRBDVERSION = "drbd-version"
1672 1673
NV_DRBDLIST = "drbd-list"
1673 1674
NV_EXCLUSIVEPVS = "exclusive-pvs"
1674 1675
NV_FILELIST = "filelist"
b/test/py/ganeti.block.drbd_unittest.py
36 36
class TestDRBD8(testutils.GanetiTestCase):
37 37
  def testGetVersion(self):
38 38
    data = [
39
      ["version: 8.0.12 (api:76/proto:86-91)"],
40
      ["version: 8.2.7 (api:88/proto:0-100)"],
41
      ["version: 8.3.7.49 (api:188/proto:13-191)"],
39
      "version: 8.0.0 (api:76/proto:80)",
40
      "version: 8.0.12 (api:76/proto:86-91)",
41
      "version: 8.2.7 (api:88/proto:0-100)",
42
      "version: 8.3.7.49 (api:188/proto:13-191)",
42 43
    ]
43 44
    result = [
44 45
      {
45 46
        "k_major": 8,
46 47
        "k_minor": 0,
48
        "k_point": 0,
49
        "api": 76,
50
        "proto": 80,
51
      },
52
      {
53
        "k_major": 8,
54
        "k_minor": 0,
47 55
        "k_point": 12,
48 56
        "api": 76,
49 57
        "proto": 86,
......
61 69
        "k_major": 8,
62 70
        "k_minor": 3,
63 71
        "k_point": 7,
72
        "k_fix": "49",
64 73
        "api": 188,
65 74
        "proto": 13,
66 75
        "proto2": "191",
67 76
      }
68 77
    ]
69 78
    for d, r in zip(data, result):
70
      info = drbd.DRBD8Info.CreateFromLines(d)
79
      info = drbd.DRBD8Info.CreateFromLines([d])
71 80
      self.assertEqual(info.GetVersion(), r)
81
      self.assertEqual(info.GetVersionString(), d.replace("version: ", ""))
72 82

  
73 83

  
74 84
class TestDRBD8Runner(testutils.GanetiTestCase):

Also available in: Unified diff