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",
--
To view, visit
https://gerrit.ovirt.org/64367
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I314544930aa28cf1d929a23842a7e011d461706d
Gerrit-PatchSet: 8
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Adam Litke <alitke(a)redhat.com>
Gerrit-Reviewer: Ala Hino <ahino(a)redhat.com>
Gerrit-Reviewer: Allon Mureinik <amureini(a)redhat.com>
Gerrit-Reviewer: Fabian Deutsch <fabiand(a)redhat.com>
Gerrit-Reviewer: Freddy Rolland <frolland(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>
Gerrit-HasComments: Yes