Following issue #1194, this patch allows Ganeti to correctly parse drbd versions that also include a dash in their k-fix version component.
Signed-off-by: Federico Morg Pareschi <m...@google.com> --- lib/storage/drbd_info.py | 17 +++++++++++++++-- test/py/ganeti.storage.drbd_unittest.py | 10 ++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/storage/drbd_info.py b/lib/storage/drbd_info.py index 99605f1..469ed7f 100644 --- a/lib/storage/drbd_info.py +++ b/lib/storage/drbd_info.py @@ -164,13 +164,15 @@ class DRBD8Info(object): """ - _VERSION_RE = re.compile(r"^version: (\d+)\.(\d+)\.(\d+)(?:\.(\d+))?" + _VERSION_RE = re.compile(r"^version: (\d+)\.(\d+)\.(\d+)(?:[.-](\d+))?" r" \(api:(\d+)/proto:(\d+)(?:-(\d+))?\)") _VALID_LINE_RE = re.compile("^ *([0-9]+): cs:([^ ]+).*$") + _K_FIX_DASH_SEPARATOR_RE = re.compile(r"^version: (\d+)\.(\d+)\.(\d+)(?:-)") def __init__(self, lines): self._version = self._ParseVersion(lines) self._minors, self._line_per_minor = self._JoinLinesPerMinor(lines) + self._k_fix_separator = self._GetKFixSeparator(lines) def GetVersion(self): """Return the DRBD version. @@ -195,7 +197,7 @@ class DRBD8Info(object): retval = "%d.%d.%d" % \ (version["k_major"], version["k_minor"], version["k_point"]) if "k_fix" in version: - retval += ".%s" % version["k_fix"] + retval += "%s%s" % (self._k_fix_separator, version["k_fix"]) retval += " (api:%d/proto:%d" % (version["api"], version["proto"]) if "proto2" in version: @@ -240,6 +242,17 @@ class DRBD8Info(object): return retval + def _GetKFixSeparator(self, lines): + """Check, in case of a K-fix version, if the separator is a dash or dot.""" + + first_line = lines[0].strip() + match = self._K_FIX_DASH_SEPARATOR_RE.match(first_line) + if match is None: + return "." + else: + return "-" + + def _JoinLinesPerMinor(self, lines): """Transform the raw lines into a dictionary based on the minor. diff --git a/test/py/ganeti.storage.drbd_unittest.py b/test/py/ganeti.storage.drbd_unittest.py index 9a1894f..3ffdb74 100755 --- a/test/py/ganeti.storage.drbd_unittest.py +++ b/test/py/ganeti.storage.drbd_unittest.py @@ -50,6 +50,7 @@ class TestDRBD8(testutils.GanetiTestCase): "version: 8.0.12 (api:76/proto:86-91)", "version: 8.2.7 (api:88/proto:0-100)", "version: 8.3.7.49 (api:188/proto:13-191)", + "version: 8.4.8-1 (api:1/proto:86-101)", ] result = [ { @@ -83,6 +84,15 @@ class TestDRBD8(testutils.GanetiTestCase): "api": 188, "proto": 13, "proto2": "191", + }, + { + "k_major": 8, + "k_minor": 4, + "k_point": 8, + "k_fix": "1", + "api": 1, + "proto": 86, + "proto2": "101", } ] for d, r in zip(data, result): -- 2.8.0.rc3.226.g39d4020