Nir Soffer has posted comments on this change.
Change subject: tests: Add loop module
......................................................................
Patch Set 5: Code-Review-1
(6 comments)
Needs more work to be useful for more interesting lvm tests.
https://gerrit.ovirt.org/#/c/64329/5/tests/loop.py
File tests/loop.py:
Line 31:
Line 32: log = logging.getLogger("test")
Line 33:
Line 34:
Line 35: class Device(object):
Rename to open()?
with loop.open("backing_file"):
...
And maybe convert to function?
Line 36:
Line 37: def __init__(self, backing_file):
Line 38: self._backing_file = backing_file
Line 39: self._path = None
Line 39: self._path = None
Line 40:
Line 41: @property
Line 42: def path(self):
Line 43: return self._path
Can be returned by the context manager.
Line 44:
Line 45: @property
Line 46: def backing_file(self):
Line 47: return self._backing_file
Line 43: return self._path
Line 44:
Line 45: @property
Line 46: def backing_file(self):
Line 47: return self._backing_file
The caller have this value, we don't need to keep it.
Line 48:
Line 49: def __enter__(self):
Line 50: cmd = ["losetup", "--find", "--show",
self._backing_file]
Line 51: rc, out, err = commands.execCmd(cmd, raw=True)
Line 45: @property
Line 46: def backing_file(self):
Line 47: return self._backing_file
Line 48:
Line 49: def __enter__(self):
This can accept the backing file.
Extract create_device function, usable for code that need to create many devices.
Line 50: cmd = ["losetup", "--find", "--show",
self._backing_file]
Line 51: rc, out, err = commands.execCmd(cmd, raw=True)
Line 52: if rc != 0:
Line 53: raise cmdutils.Error(cmd, rc, out, err)
Line 51: rc, out, err = commands.execCmd(cmd, raw=True)
Line 52: if rc != 0:
Line 53: raise cmdutils.Error(cmd, rc, out, err)
Line 54: self._path = out.strip()
Line 55: return self
We can return path here instead of self.
Line 56:
Line 57: def __exit__(self, t, v, tb):
Line 58: cmd = ["losetup", "--detach", self._path]
Line 59: rc, out, err = commands.execCmd(cmd, raw=True)
Line 53: raise cmdutils.Error(cmd, rc, out, err)
Line 54: self._path = out.strip()
Line 55: return self
Line 56:
Line 57: def __exit__(self, t, v, tb):
Extract detach_device function, usable for code that created many devices and need to
detach them.
Line 58: cmd = ["losetup", "--detach", self._path]
Line 59: rc, out, err = commands.execCmd(cmd, raw=True)
Line 60: if rc != 0:
Line 61: if t is None:
--
To view, visit
https://gerrit.ovirt.org/64329
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I37184887930ad9ec1234036fdcdeb6cee8ccac42
Gerrit-PatchSet: 5
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: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani(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