Nir Soffer has uploaded a new change for review.
Change subject: guest-lvs: Add lvm bootstrap tests
......................................................................
guest-lvs: Add lvm bootstrap tests
Add fake_env for creating lvm tests using loop devices instead of shared
storage, and start lvm.bootstrap tests.
The first test is verifying that unused ovirt lvs are deactivated.
Change-Id: I314544930aa28cf1d929a23842a7e011d461706d
Bug-Url:
https://bugzilla.redhat.com/1374545
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M tests/storage_lvm_test.py
1 file changed, 86 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/67/64367/1
diff --git a/tests/storage_lvm_test.py b/tests/storage_lvm_test.py
index 6792266..67ed799 100644
--- a/tests/storage_lvm_test.py
+++ b/tests/storage_lvm_test.py
@@ -19,9 +19,25 @@
# Refer to the README and COPYING files for full details of the license
#
-from testlib import VdsmTestCase as TestCaseBase
+import collections
+import os
+import logging
-import storage.lvm as lvm
+from contextlib import contextmanager
+
+from vdsm import commands
+from vdsm import cmdutils
+
+from storage import blockSD
+from storage import lvm
+
+import loop
+from monkeypatch import MonkeyPatchScope
+from testlib import VdsmTestCase as TestCaseBase
+from testlib import namedTemporaryDir
+from testValidation import ValidateRunningAsRoot
+
+log = logging.getLogger("test")
class LvmTests(TestCaseBase):
@@ -37,3 +53,71 @@
"\\\\x22\\\\x28|\', \'r|.*|\' ]"
)
self.assertEqual(expectedFilter, filter)
+
+
+class TestBootstrap(TestCaseBase):
+
+ @ValidateRunningAsRoot
+ def test_deactivate_unused_ovirt_lvs(self):
+ with fake_env() as env:
+ log.debug("Creating ovirt lvs")
+ run("pvcreate", "-ff", env.device)
+ run("vgcreate", "ovirt-vg", env.device)
+ run("vgchange", "--addtag", blockSD.STORAGE_DOMAIN_TAG)
+ run("lvcreate", "-n", "ovirt-lv-1",
"-L", "128m", "ovirt-vg")
+ run("lvcreate", "-n", "ovirt-lv-2",
"-L", "128m", "ovirt-vg")
+ try:
+ lvm.bootstrap()
+ # ovirt-lv must be inactive
+ self.check_no_active_lvs("ovirt-vg")
+ finally:
+ run("lvchange", "-an", "ovirt-vg")
+
+ # TODO: do not modify vgs without STORAGE_DOMAIN_TAG
+
+ def check_no_active_lvs(self, vgname):
+ out = run("lvs", "--noheadings", "-o",
"name",
+ "--select", "lv_active=active", vgname)[0]
+ lvs = [line.strip() for line in out.splitlines()]
+ self.assertEqual(lvs, [])
+
+
+Env = collections.namedtuple("Env", "tmpdir, device")
+
+
+@contextmanager
+def fake_env():
+ """
+ Create test environment for lvm tests.
+ """
+ with namedTemporaryDir() as tmpdir:
+ backing_file = os.path.join(tmpdir, "backing_file")
+ truncate(backing_file, 1024**3)
+ with loop.Device(backing_file) as device:
+ log.debug("Using loop device %s", device.path)
+ with MonkeyPatchScope([
+ # Created during bootstrap.
+ (lvm, "VDSM_LVM_SYSTEM_DIR", os.path.join(tmpdir,
"lvm")),
+ # Saved each time conf is changed.
+ (lvm, "VDSM_LVM_CONF", os.path.join(tmpdir, "lvm",
"lvm.conf")),
+ # Allow detection of test device, otherwise only
+ # /dev/mapper/guid devices are detected.
+ (lvm, "USER_DEV_LIST", [device.path]),
+ ]):
+ try:
+ yield Env(tmpdir, device.path)
+ finally:
+ # Update lvmetad to keep the environment sane
+ run("pvscan", "--cache")
+
+
+def run(*cmd):
+ rc, out, err = commands.execCmd(cmd, raw=True)
+ if rc != 0:
+ raise cmdutils.Error(cmd, rc, out, err)
+ return out, err
+
+
+def truncate(path, size):
+ with open(path, "w") as f:
+ f.truncate(size)
--
To view, visit
https://gerrit.ovirt.org/64367
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I314544930aa28cf1d929a23842a7e011d461706d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>