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

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