Blob Blame History Raw
From 23e6f2024c34fc6e1b3a67c416334bba2b55d5a9 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Thu, 31 Oct 2019 12:50:03 +0100
Subject: [PATCH] Fix expected cache pool name with newest LVM

LVM now adds "_cpool" suffix to attached pools.
---
 tests/lvm_dbus_tests.py | 17 ++++++++++++++++-
 tests/lvm_test.py       | 19 +++++++++++++++++--
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py
index 625a392..f2a17c9 100644
--- a/tests/lvm_dbus_tests.py
+++ b/tests/lvm_dbus_tests.py
@@ -6,6 +6,7 @@ import overrides_hack
 import six
 import re
 import subprocess
+from distutils.version import LooseVersion
 from itertools import chain
 
 from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, run_command, TestTags, tag_test
@@ -31,6 +32,13 @@ class LVMTestCase(unittest.TestCase):
             else:
                 BlockDev.reinit([cls.ps, cls.ps2], True, None)
 
+    def _get_lvm_version(self):
+        _ret, out, _err = run_command("lvm version")
+        m = re.search(r"LVM version:\s+([\d\.]+)", out)
+        if not m or len(m.groups()) != 1:
+            raise RuntimeError("Failed to determine LVM version from: %s" % out)
+        return LooseVersion(m.groups()[0])
+
 @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
 class LvmNoDevTestCase(LVMTestCase):
 
@@ -1291,7 +1299,14 @@ class LvmPVVGcachedLVpoolTestCase(LvmPVVGLVTestCase):
         succ = BlockDev.lvm_cache_attach("testVG", "testLV", "testCache", None)
         self.assertTrue(succ)
 
-        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), "testCache")
+        lvm_version = self._get_lvm_version()
+        if lvm_version < LooseVersion("2.03.06"):
+            cpool_name = "testCache"
+        else:
+            # since 2.03.06 LVM adds _cpool suffix to the cache pool after attaching it
+            cpool_name = "testCache_cpool"
+
+        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), cpool_name)
 
 @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
 class LvmPVVGcachedLVstatsTestCase(LvmPVVGLVTestCase):
diff --git a/tests/lvm_test.py b/tests/lvm_test.py
index 0b2c5ad..242ca94 100644
--- a/tests/lvm_test.py
+++ b/tests/lvm_test.py
@@ -6,8 +6,9 @@ import overrides_hack
 import six
 import re
 import subprocess
+from distutils.version import LooseVersion
 
-from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, skip_on, TestTags, tag_test
+from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, skip_on, TestTags, tag_test, run_command
 from gi.repository import BlockDev, GLib
 
 
@@ -25,6 +26,13 @@ class LVMTestCase(unittest.TestCase):
         else:
             BlockDev.reinit(cls.requested_plugins, True, None)
 
+    def _get_lvm_version(self):
+        _ret, out, _err = run_command("lvm version")
+        m = re.search(r"LVM version:\s+([\d\.]+)", out)
+        if not m or len(m.groups()) != 1:
+            raise RuntimeError("Failed to determine LVM version from: %s" % out)
+        return LooseVersion(m.groups()[0])
+
 
 class LvmNoDevTestCase(LVMTestCase):
     def __init__(self, *args, **kwargs):
@@ -1249,7 +1257,14 @@ class LvmPVVGcachedLVpoolTestCase(LvmPVVGLVTestCase):
         succ = BlockDev.lvm_cache_attach("testVG", "testLV", "testCache", None)
         self.assertTrue(succ)
 
-        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), "testCache")
+        lvm_version = self._get_lvm_version()
+        if lvm_version < LooseVersion("2.03.06"):
+            cpool_name = "testCache"
+        else:
+            # since 2.03.06 LVM adds _cpool suffix to the cache pool after attaching it
+            cpool_name = "testCache_cpool"
+
+        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), cpool_name)
 
 class LvmPVVGcachedLVstatsTestCase(LvmPVVGLVTestCase):
     @tag_test(TestTags.SLOW)
-- 
2.21.0