Change in vdsm[master]: tests: Create storagetestutils module
nsoffer at redhat.com
nsoffer at redhat.com
Tue Jul 14 22:29:18 UTC 2015
Nir Soffer has posted comments on this change.
Change subject: tests: Create storagetestutils module
......................................................................
Patch Set 2: Code-Review-1
(10 comments)
https://gerrit.ovirt.org/#/c/43547/2/tests/storagetestlib.py
File tests/storagetestlib.py:
Line 22:
Line 23: from storage import sd, blockSD, fileSD
Line 24:
Line 25:
Line 26: NR_PVS = 5 # The number of fake PVs we use to make a fake VG
Why do we need this? I think an optional parameter in make vg is nicer.
Line 27: MDSIZE = 524288 # The size (in bytes) of fake metadata files
Line 28:
Line 29:
Line 30: class FakeMetadata(dict):
Line 32: def transaction(self):
Line 33: yield
Line 34:
Line 35:
Line 36: def make_blocksd_manifest(tmpdir=None, metadata=None):
Lets add the uuid as optional parameter, so code that like to create sds with know uuid can do this.
Line 37: sduuid = str(uuid.uuid4())
Line 38: if metadata is None:
Line 39: metadata = FakeMetadata()
Line 40: manifest = blockSD.BlockStorageDomainManifest(sduuid, metadata)
Line 43: os.makedirs(os.path.join(manifest.domaindir, sduuid, sd.DOMAIN_IMAGES))
Line 44: return manifest
Line 45:
Line 46:
Line 47: def get_device_list(count):
Rename to get_random_devices?
Line 48: return ['/dev/mapper/{0}'.format(os.urandom(16).encode('hex'))
Line 49: for _ in range(count)]
Line 50:
Line 51:
Line 51:
Line 52: def make_vg(fake_lvm, manifest, devices=None):
Line 53: vg_name = manifest.sdUUID
Line 54: if devices is None:
Line 55: devices = get_device_list(NR_PVS)
Lets add NR_PVS as optional parameter - pv_count=5
Line 56: fake_lvm.createVG(vg_name, devices, blockSD.STORAGE_UNREADY_DOMAIN_TAG,
Line 57: blockSD.VG_METADATASIZE)
Line 58: fake_lvm.createLV(vg_name, sd.METADATA, blockSD.SD_METADATA_SIZE)
Line 59:
Line 63: return vg_name
Line 64:
Line 65:
Line 66: def get_metafile_path(domaindir):
Line 67: return os.path.join(domaindir, sd.DOMAIN_META_DATA, sd.METADATA)
Can we move this into the real code? sd.py? fileSD.py?
Line 68:
Line 69:
Line 70: def make_filesd_manifest(tmpdir, metadata=None):
Line 71: sduuid = str(uuid.uuid4())
Line 77: os.makedirs(os.path.join(manifest.domaindir, sduuid, sd.DOMAIN_IMAGES))
Line 78: return manifest
Line 79:
Line 80:
Line 81: def make_fake_metafile(metafile):
This seems like a generic utility that belong in testlib.py, named make_file(path).
Line 82: os.makedirs(os.path.dirname(metafile))
Line 83: with open(metafile, "w") as f:
Line 84: f.truncate(0)
Line 85:
Line 78: return manifest
Line 79:
Line 80:
Line 81: def make_fake_metafile(metafile):
Line 82: os.makedirs(os.path.dirname(metafile))
This should handle the case where the directory exists, to make it more general.
Line 83: with open(metafile, "w") as f:
Line 84: f.truncate(0)
Line 85:
Line 86:
Line 80:
Line 81: def make_fake_metafile(metafile):
Line 82: os.makedirs(os.path.dirname(metafile))
Line 83: with open(metafile, "w") as f:
Line 84: f.truncate(0)
Better truncate to given size, default to 0?
Line 85:
Line 86:
Line 87: def make_file_volume(domaindir, size, imguuid=None, voluuid=None):
Line 88: imguuid = imguuid or str(uuid.uuid4())
Line 92: mdfiles = [volpath + '.meta', volpath + '.lease']
Line 93: if not os.path.exists(imgpath):
Line 94: os.makedirs(imgpath)
Line 95: with open(volpath, "w") as f:
Line 96: f.truncate(size)
This is same as make_fake_metafaile - lets reuse our utilities.
Line 97: for mdfile in mdfiles:
Line 98: with open(mdfile, "w") as f:
Line 99: f.truncate(0)
Line 100: return imguuid, voluuid
Line 95: with open(volpath, "w") as f:
Line 96: f.truncate(size)
Line 97: for mdfile in mdfiles:
Line 98: with open(mdfile, "w") as f:
Line 99: f.truncate(0)
This is same as make_fake_metafaile - lets reuse our utilities.
Line 100: return imguuid, voluuid
--
To view, visit https://gerrit.ovirt.org/43547
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I713e19473b45bc05da5a1c888a034306144228c5
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke at redhat.com>
Gerrit-Reviewer: Adam Litke <alitke at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: automation at ovirt.org
Gerrit-HasComments: Yes
More information about the vdsm-patches
mailing list