Yeela Kaplan has uploaded a new change for review. Change subject: hsm: Check image alignment using virt-alignment-scan ......................................................................
hsm: Check image alignment using virt-alignment-scan Change-Id: Ia925f5f138948acca623f6379b7b811474a43ffe Signed-off-by: Yeela Kaplan <[email protected]> --- M tests/alignmentScanTests.py M vdsm.spec.in M vdsm/alignmentScan.py M vdsm/storage/hsm.py 4 files changed, 44 insertions(+), 45 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/03/12003/1 diff --git a/tests/alignmentScanTests.py b/tests/alignmentScanTests.py index ba0097a..a69c8d4 100644 --- a/tests/alignmentScanTests.py +++ b/tests/alignmentScanTests.py @@ -19,10 +19,8 @@ # Refer to the README and COPYING files for full details of the license # -import os import tempfile from nose.tools import eq_, raises, assert_not_equals -from nose.plugins.skip import SkipTest from testrunner import VdsmTestCase as TestCaseBase from testValidation import slowtest from storage.misc import execCmd @@ -33,20 +31,13 @@ open(imagepath, "wb").truncate(4 * 1024 ** 3) cmd = ["/sbin/sfdisk", "-uS", "--force", imagepath] cmd_input = "128,,\n" if aligned else "1,,\n" - r, o, e = execCmd(cmd, data=cmd_input) - assert r == 0 - - -def validate_virtalignscan_installed(): - fpath = "/usr/bin/virt-alignment-scan" - if not (os.path.isfile(fpath) and os.access(fpath, os.X_OK)): - raise SkipTest('cannot execute %s' % fpath) + rc, out, err = execCmd(cmd, data=cmd_input) + assert rc == 0 class AlignmentScanTests(TestCaseBase): def test_help_response(self): - validate_virtalignscan_installed() retcode, out, err = runScanArgs("--help") eq_(retcode, 0) eq_(err, []) @@ -61,25 +52,20 @@ @raises(VirtAlignError) def test_bad_path(self): - validate_virtalignscan_installed() scanImage("nonexistent-image-name") @slowtest def test_nonaligned_image(self): - validate_virtalignscan_installed() with tempfile.NamedTemporaryFile() as img: mkimage(img.name, aligned=False) msg = scanImage(img.name) eq_(msg[0][0], '/dev/sda1') - eq_(msg[0][3], False) - eq_(msg[0][4], 'bad (alignment < 4K)') + eq_(msg[0][3], 'bad (alignment < 4K)') @slowtest def test_aligned_image(self): - validate_virtalignscan_installed() with tempfile.NamedTemporaryFile() as img: mkimage(img.name, aligned=True) msg = scanImage(img.name) eq_(msg[0][0], '/dev/sda1') - eq_(msg[0][3], True) - eq_(msg[0][4], 'ok') + eq_(msg[0][3], 'ok') diff --git a/vdsm.spec.in b/vdsm.spec.in index 5544e9d..d88a42e 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -77,6 +77,7 @@ Requires: nfs-utils Requires: python-pthreading Requires: m2crypto +Requires: libguestfs-tools-c Requires: %{name}-xmlrpc = %{version}-%{release} %ifarch x86_64 diff --git a/vdsm/alignmentScan.py b/vdsm/alignmentScan.py index 53d4ee3..ecbd1e3 100644 --- a/vdsm/alignmentScan.py +++ b/vdsm/alignmentScan.py @@ -20,12 +20,17 @@ from collections import namedtuple +from utils import CommandPath from storage.misc import execCmd ScanOutput = namedtuple( 'ScanOutput', - ['partition_name', 'partition_start_bytes', 'partition_alignment', - 'alignment_scan_result', 'alignment_scan_explanation']) + ['partitionName', 'partitionStartBytes', 'partitionAlignment', + 'alignmentScanResult']) + +_virtAlignmentScan = CommandPath("virt-alignment-scan", + "/usr/bin/virt-alignment-scan", # Fedora, EL6 + ) class VirtAlignError(Exception): @@ -33,38 +38,21 @@ def runScanArgs(*args): - cmd = ['/usr/bin/virt-alignment-scan'] + cmd = [_virtAlignmentScan.cmd] cmd.extend(args) return execCmd(cmd) def scanImage(image_path): image_path = image_path.strip() - retcode, out, err = runScanArgs('--add', image_path) - if retcode == 0: - pass - elif retcode == 1: + rc, out, err = runScanArgs('--add', image_path) + if rc == 1: raise VirtAlignError("An error scanning the disk image " "or guest:\n%s" % err) - elif retcode == 2: - # Successful exit, some partitions have alignment < 64K - # which can result in poor performance on high end network storage. - pass - elif retcode == 3: - # Successful exit, some partitions have alignment < 4K - # which can result in poor performance on most hypervisors. - pass - else: + elif rc not in [0, 2, 3]: raise VirtAlignError("Unexpected return code from " - "virt-alignment-scan: %d" % retcode) - out_list = [] + "virt-alignment-scan: %d" % rc) + outList = [] for line in out: - line = line.split(None, 3) - part_name = line[0] # the device and partition name (eg. "/dev/sda1") - part_start = int(line[1]) # the start of the partition in bytes - part_alignment = line[2] # in bytes or Kbytes (eg. 512 or "4K") - scan_result = (line[3] == "ok") # True if aligned, otherwise False - scan_explanation = line[3] # optional free-text explanation - out_list.append(ScanOutput(part_name, part_start, part_alignment, - scan_result, scan_explanation)) - return out_list + outList.append(ScanOutput(*line.split(None, 3))) + return outList diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py index 29980f3..b427dce 100644 --- a/vdsm/storage/hsm.py +++ b/vdsm/storage/hsm.py @@ -38,6 +38,7 @@ import stat from vdsm.config import config +import alignmentScan import sp import sd import blockSD @@ -1706,6 +1707,29 @@ imgUUID, ancestor, successor, misc.parseBool(postZero)) @public + def getImageAlignment(self, sdUUID, spUUID, imgUUID): + """ + Returns the alignment of the image + + :param spUUID: The UUID of the storage pool that contains the image. + :type spUUID: UUID + :param sdUUID: The UUID of the storage domain that contains the image. + :type sdUUID: UUID + :param imgUUID: The UUID of the image. + :type imgUUID: UUID + """ + img = self.prepareImage(sdUUID, spUUID, imgUUID) + try: + out = alignmentScan.scanImage(img['path']) + finally: + self.teardownImage(sdUUID, spUUID, imgUUID) + + aligning = {} + for line in out: + aligning[out[line][0]] = (out[line][3] == "ok") + return aligning + + @public def reconstructMaster(self, spUUID, poolName, masterDom, domDict, masterVersion, lockPolicy=None, lockRenewalIntervalSec=None, leaseTimeSec=None, -- To view, visit http://gerrit.ovirt.org/12003 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia925f5f138948acca623f6379b7b811474a43ffe Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yeela Kaplan <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
