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@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)
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 1:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 2:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
Nir Soffer has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 2: Verified+1
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 3:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 4:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
Nir Soffer has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 4: Verified+1
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 5:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 6:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
Nir Soffer has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 6: Verified+1
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 7:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
Nir Soffer has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 7: Verified+1
Nir Soffer has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 7:
(1 comment)
https://gerrit.ovirt.org/#/c/64367/7/tests/storage_lvm_test.py File tests/storage_lvm_test.py:
Line 57: Line 58: class TestDeactivation(TestCaseBase): Line 59: Line 60: @ValidateRunningAsRoot Line 61: def test_deactivate_unused_ovirt_lvs(self): This test always fails in the ci, anyone has an idea why? maybe we need to filter out these tests on the ci, running inside mock.
On real system (fedora 24, rhel 7.3 configured as ovirt host), it works. Line 62: with fake_env() as env: Line 63: log.debug("Creating ovirt lvs") Line 64: run("pvcreate", "-ff", env.device) Line 65: run("vgcreate", "ovirt-vg", env.device)
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 8:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
Nir Soffer has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 8: Code-Review-1
(7 comments)
https://gerrit.ovirt.org/#/c/64367/8/tests/storage_lvm_test.py File tests/storage_lvm_test.py:
Line 56: Line 57: Line 58: class TestDeactivation(TestCaseBase): Line 59: Line 60: @ValidateRunningAsRoot Need to mark this broken_on_ci for now. Line 61: def test_deactivate_unused_ovirt_lvs(self): Line 62: with fake_env() as env: Line 63: log.debug("Creating ovirt lvs") Line 64: run("pvcreate", "-ff", env.device)
Line 60: @ValidateRunningAsRoot Line 61: def test_deactivate_unused_ovirt_lvs(self): Line 62: with fake_env() as env: Line 63: log.debug("Creating ovirt lvs") Line 64: run("pvcreate", "-ff", env.device) lvm commands should use global_filter limiting the operations to the test devices.
Maybe add helpers in the env:
env.create_pv(force=True, env.devices[0]) Line 65: run("vgcreate", "ovirt-vg", env.device) Line 66: run("vgchange", "--addtag", blockSD.STORAGE_DOMAIN_TAG) Line 67: run("lvcreate", "-n", "ovirt-lv-1", "-L", "128m", "ovirt-vg") Line 68: run("lvcreate", "-n", "ovirt-lv-2", "-L", "128m", "ovirt-vg")
Line 70: lvm.bootstrap() Line 71: # ovirt-lv must be inactive Line 72: self.assertEqual(self.find_active_lvs("ovirt-vg"), []) Line 73: finally: Line 74: run("vgchange", "-an", "ovirt-vg") The environment should keep created vgs and deactivate them. Line 75: Line 76: # TODO: do not modify vgs without STORAGE_DOMAIN_TAG Line 77: Line 78: def find_active_lvs(self, vgname):
Line 77: Line 78: def find_active_lvs(self, vgname): Line 79: out = run("lvs", "--noheadings", "-o", "name", Line 80: "--select", "lv_active=active", vgname)[0] Line 81: return [line.strip() for line in out.splitlines()] The environment should provide such helpers, so we can write:
active_lvs = env.list_lvs(where="ovirt-vg", select="lv_active=active", output="name") Line 82: Line 83: Line 84: def run(*cmd): Line 85: rc, out, err = commands.execCmd(cmd, raw=True)
Line 84: def run(*cmd): Line 85: rc, out, err = commands.execCmd(cmd, raw=True) Line 86: if rc != 0: Line 87: raise cmdutils.Error(cmd, rc, out, err) Line 88: return out, err Return out, err is interesting only on errors. Line 89: Line 90: Line 91: try: Line 92: run("systemctl", "status", "lvm2-lvmetad.socket")
Line 95: else: Line 96: using_lvmetad = True Line 97: Line 98: Line 99: Env = collections.namedtuple("Env", "tmpdir, device") Replace with real class that provide lvm helpers, using devices to add filter to lvm commands. Line 100: Line 101: Line 102: @contextmanager Line 103: def fake_env():
Line 108: backing_file = os.path.join(tmpdir, "backing_file") Line 109: with open(backing_file, "w") as f: Line 110: f.truncate(1024**3) Line 111: try: Line 112: with loop.Device(backing_file) as device: We need to support may devices for more interesting tests. Line 113: log.debug("Using loop device %s", device.path) Line 114: with MonkeyPatchScope([ Line 115: # Created during bootstrap. Line 116: (lvm, "VDSM_LVM_SYSTEM_DIR",
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 9:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
gerrit-hooks has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 10:
* #1374545::Update tracker: OK * Check Bug-Url::OK * Check Public Bug::#1374545::OK, public bug * Check Product::#1374545::OK, Correct product Red Hat Enterprise Virtualization Manager * Check TM::SKIP, not in a monitored branch (ovirt-3.6 ovirt-4.0) * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
Nir Soffer has posted comments on this change.
Change subject: guest-lvs: Add lvm bootstrap tests ......................................................................
Patch Set 10: Verified+1
vdsm-patches@lists.fedorahosted.org