Blame SOURCES/0007-fix-expected-cache-pool-name-with-newest-LVM.patch

60ab0d
From 23e6f2024c34fc6e1b3a67c416334bba2b55d5a9 Mon Sep 17 00:00:00 2001
60ab0d
From: Vojtech Trefny <vtrefny@redhat.com>
60ab0d
Date: Thu, 31 Oct 2019 12:50:03 +0100
60ab0d
Subject: [PATCH] Fix expected cache pool name with newest LVM
60ab0d
60ab0d
LVM now adds "_cpool" suffix to attached pools.
60ab0d
---
60ab0d
 tests/lvm_dbus_tests.py | 17 ++++++++++++++++-
60ab0d
 tests/lvm_test.py       | 19 +++++++++++++++++--
60ab0d
 2 files changed, 33 insertions(+), 3 deletions(-)
60ab0d
60ab0d
diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py
60ab0d
index 625a392..f2a17c9 100644
60ab0d
--- a/tests/lvm_dbus_tests.py
60ab0d
+++ b/tests/lvm_dbus_tests.py
60ab0d
@@ -6,6 +6,7 @@ import overrides_hack
60ab0d
 import six
60ab0d
 import re
60ab0d
 import subprocess
60ab0d
+from distutils.version import LooseVersion
60ab0d
 from itertools import chain
60ab0d
 
60ab0d
 from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, run_command, TestTags, tag_test
60ab0d
@@ -31,6 +32,13 @@ class LVMTestCase(unittest.TestCase):
60ab0d
             else:
60ab0d
                 BlockDev.reinit([cls.ps, cls.ps2], True, None)
60ab0d
 
60ab0d
+    def _get_lvm_version(self):
60ab0d
+        _ret, out, _err = run_command("lvm version")
60ab0d
+        m = re.search(r"LVM version:\s+([\d\.]+)", out)
60ab0d
+        if not m or len(m.groups()) != 1:
60ab0d
+            raise RuntimeError("Failed to determine LVM version from: %s" % out)
60ab0d
+        return LooseVersion(m.groups()[0])
60ab0d
+
60ab0d
 @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
60ab0d
 class LvmNoDevTestCase(LVMTestCase):
60ab0d
 
60ab0d
@@ -1291,7 +1299,14 @@ class LvmPVVGcachedLVpoolTestCase(LvmPVVGLVTestCase):
60ab0d
         succ = BlockDev.lvm_cache_attach("testVG", "testLV", "testCache", None)
60ab0d
         self.assertTrue(succ)
60ab0d
 
60ab0d
-        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), "testCache")
60ab0d
+        lvm_version = self._get_lvm_version()
60ab0d
+        if lvm_version < LooseVersion("2.03.06"):
60ab0d
+            cpool_name = "testCache"
60ab0d
+        else:
60ab0d
+            # since 2.03.06 LVM adds _cpool suffix to the cache pool after attaching it
60ab0d
+            cpool_name = "testCache_cpool"
60ab0d
+
60ab0d
+        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), cpool_name)
60ab0d
 
60ab0d
 @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
60ab0d
 class LvmPVVGcachedLVstatsTestCase(LvmPVVGLVTestCase):
60ab0d
diff --git a/tests/lvm_test.py b/tests/lvm_test.py
60ab0d
index 0b2c5ad..242ca94 100644
60ab0d
--- a/tests/lvm_test.py
60ab0d
+++ b/tests/lvm_test.py
60ab0d
@@ -6,8 +6,9 @@ import overrides_hack
60ab0d
 import six
60ab0d
 import re
60ab0d
 import subprocess
60ab0d
+from distutils.version import LooseVersion
60ab0d
 
60ab0d
-from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, skip_on, TestTags, tag_test
60ab0d
+from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, skip_on, TestTags, tag_test, run_command
60ab0d
 from gi.repository import BlockDev, GLib
60ab0d
 
60ab0d
 
60ab0d
@@ -25,6 +26,13 @@ class LVMTestCase(unittest.TestCase):
60ab0d
         else:
60ab0d
             BlockDev.reinit(cls.requested_plugins, True, None)
60ab0d
 
60ab0d
+    def _get_lvm_version(self):
60ab0d
+        _ret, out, _err = run_command("lvm version")
60ab0d
+        m = re.search(r"LVM version:\s+([\d\.]+)", out)
60ab0d
+        if not m or len(m.groups()) != 1:
60ab0d
+            raise RuntimeError("Failed to determine LVM version from: %s" % out)
60ab0d
+        return LooseVersion(m.groups()[0])
60ab0d
+
60ab0d
 
60ab0d
 class LvmNoDevTestCase(LVMTestCase):
60ab0d
     def __init__(self, *args, **kwargs):
60ab0d
@@ -1249,7 +1257,14 @@ class LvmPVVGcachedLVpoolTestCase(LvmPVVGLVTestCase):
60ab0d
         succ = BlockDev.lvm_cache_attach("testVG", "testLV", "testCache", None)
60ab0d
         self.assertTrue(succ)
60ab0d
 
60ab0d
-        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), "testCache")
60ab0d
+        lvm_version = self._get_lvm_version()
60ab0d
+        if lvm_version < LooseVersion("2.03.06"):
60ab0d
+            cpool_name = "testCache"
60ab0d
+        else:
60ab0d
+            # since 2.03.06 LVM adds _cpool suffix to the cache pool after attaching it
60ab0d
+            cpool_name = "testCache_cpool"
60ab0d
+
60ab0d
+        self.assertEqual(BlockDev.lvm_cache_pool_name("testVG", "testLV"), cpool_name)
60ab0d
 
60ab0d
 class LvmPVVGcachedLVstatsTestCase(LvmPVVGLVTestCase):
60ab0d
     @tag_test(TestTags.SLOW)
60ab0d
-- 
60ab0d
2.21.0
60ab0d