Adam Litke has uploaded a new change for review.
Change subject: tests: Add tests for verify_untrusted_volume
......................................................................
tests: Add tests for verify_untrusted_volume
Add some tests to check that verify_untrusted_volume works as expected.
Tests are placed in a new storage_hsm_test module which can accomodate
tests for other HSM verbs.
Change-Id: I44d3bbe33430a34e3a3b985e1485c6d46ebdc3aa
Signed-off-by: Adam Litke <alitke(a)redhat.com>
---
M tests/Makefile.am
A tests/storage_hsm_test.py
M tests/storagetestlib.py
3 files changed, 84 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/60/60060/1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 874f75f..4ba4d10 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -121,6 +121,7 @@
storage_asyncevent_test.py \
storage_check_test.py \
storage_directio_test.py \
+ storage_hsm_test.py \
storage_monitor_test.py \
storage_rwlock_test.py \
storage_sdm_api_test.py \
diff --git a/tests/storage_hsm_test.py b/tests/storage_hsm_test.py
new file mode 100644
index 0000000..f2f2629
--- /dev/null
+++ b/tests/storage_hsm_test.py
@@ -0,0 +1,80 @@
+#
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import uuid
+from contextlib import contextmanager
+
+from testlib import VdsmTestCase
+from testlib import permutations, expandPermutations
+from storagetestlib import fake_file_env
+from storagetestlib import make_file_volume
+
+from vdsm import qemuimg
+from vdsm.storage import constants as sc
+from vdsm.storage import exception as se
+
+from storage.hsm import HSM
+
+
+class FakeHSM(HSM):
+ def __init__(self):
+ pass
+
+
+@expandPermutations
+class VerifyUntrustedVolumeTest(VdsmTestCase):
+ SIZE = 1024 * 1024
+
+ @permutations(((sc.RAW_FORMAT,), (sc.COW_FORMAT,)))
+ def test_ok(self, vol_fmt):
+ with self.fake_volume(vol_fmt) as vol:
+ qemu_fmt = sc.FMT2STR[vol_fmt]
+ qemuimg.create(vol.volumePath, size=self.SIZE, format=qemu_fmt)
+ hsm = FakeHSM()
+ self.assertNotRaises(hsm.verify_untrusted_volume,
+ 'sp', vol.sdUUID, vol.imgUUID, vol.volUUID)
+
+ def test_wrong_format_raises(self):
+ with self.fake_volume(sc.RAW_FORMAT) as vol:
+ qemu_fmt = qemuimg.FORMAT.QCOW2
+ qemuimg.create(vol.volumePath, size=self.SIZE, format=qemu_fmt)
+ hsm = FakeHSM()
+ self.assertRaises(se.ImageVerificationError,
+ hsm.verify_untrusted_volume,
+ 'sp', vol.sdUUID, vol.imgUUID, vol.volUUID)
+
+ def test_backingfile_raises(self):
+ with self.fake_volume(sc.COW_FORMAT) as vol:
+ qemu_fmt = qemuimg.FORMAT.QCOW2
+ qemuimg.create(vol.volumePath, size=self.SIZE, format=qemu_fmt,
+ backing='foo')
+ hsm = FakeHSM()
+ self.assertRaises(se.ImageVerificationError,
+ hsm.verify_untrusted_volume,
+ 'sp', vol.sdUUID, vol.imgUUID, vol.volUUID)
+
+ @contextmanager
+ def fake_volume(self, vol_fmt):
+ with fake_file_env() as env:
+ img_id = str(uuid.uuid4())
+ vol_id = str(uuid.uuid4())
+ make_file_volume(env.sd_manifest, self.SIZE, img_id, vol_id,
+ vol_format=vol_fmt)
+ yield env.sd_manifest.produceVolume(img_id, vol_id)
diff --git a/tests/storagetestlib.py b/tests/storagetestlib.py
index 35f59c4..245e776 100644
--- a/tests/storagetestlib.py
+++ b/tests/storagetestlib.py
@@ -29,6 +29,7 @@
from vdsm.storage import constants as sc
from storage import sd, blockSD, fileSD, image, blockVolume, volume
+from storage import hsm
from storage.sdm import volume_artifacts
@@ -52,6 +53,7 @@
with MonkeyPatchScope([
[sd, 'storage_repository', tmpdir],
[volume, 'sdCache', fake_sdc],
+ [hsm, 'sdCache', fake_sdc],
]):
fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest)
yield FakeEnv(sd_manifest)
@@ -68,6 +70,7 @@
(volume_artifacts, 'lvm', lvm),
(sd, 'storage_repository', tmpdir),
(volume, 'sdCache', fake_sdc),
+ (hsm, 'sdCache', fake_sdc),
]):
sd_manifest = make_blocksd_manifest(tmpdir, lvm)
fake_sdc.domains[sd_manifest.sdUUID] = FakeSD(sd_manifest)
--
To view, visit
https://gerrit.ovirt.org/60060
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I44d3bbe33430a34e3a3b985e1485c6d46ebdc3aa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>