Change in vdsm[master]: tests: Test storagetestlib FakeEnv functions

alitke at redhat.com alitke at redhat.com
Fri Apr 8 21:02:49 UTC 2016


Adam Litke has uploaded a new change for review.

Change subject: tests: Test storagetestlib FakeEnv functions
......................................................................

tests: Test storagetestlib FakeEnv functions

The storagetestlib module provides functionality to create fake file and
block storage environments which help to unit test storage code.  As
this code has gotten more complex we need to test that it is actually
working correctly itself.

The new storagetestlibTests module tests both file and block
environments.  We check that the temporary directory housing the fake
environment has the correct layout and that metadata for the domain and
volumes 'persists' to the storage.

Change-Id: I65ab8c6419dfa1181efff2a533c00589ba5b8263
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M tests/Makefile.am
A tests/storagetestlibTests.py
2 files changed, 145 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/89/55889/1

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1fda1ce..ee7fb85 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -139,6 +139,7 @@
 	storageMailboxTests.py \
 	storageMonitorTests.py \
 	storageServerTests.py \
+	storagetestlibTests.py \
 	storage_sdm_api_test.py \
 	storage_sdm_create_volume_test.py \
 	storage_volume_artifacts_test.py \
diff --git a/tests/storagetestlibTests.py b/tests/storagetestlibTests.py
new file mode 100644
index 0000000..4393e0a
--- /dev/null
+++ b/tests/storagetestlibTests.py
@@ -0,0 +1,144 @@
+# 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 os
+import uuid
+
+from testlib import VdsmTestCase
+from testlib import TEMPDIR
+from storagetestlib import fake_block_env
+from storagetestlib import fake_file_env
+from storagetestlib import make_block_volume
+from storagetestlib import make_file_volume
+
+from storage import blockSD, fileSD, fileVolume, sd, volume
+
+from vdsm.storage import constants
+
+
+MB = 1048576
+
+
+class FakeFileEnvTests(VdsmTestCase):
+
+    def test_no_fakelvm(self):
+        with fake_file_env() as env:
+            self.assertFalse(hasattr(env, 'lvm'))
+
+    def test_repopath_location(self):
+        with fake_file_env() as env:
+            self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
+
+    def test_domain_structure(self):
+        with fake_file_env() as env:
+            self.assertTrue(os.path.exists(env.sd_manifest.metafile))
+            images_dir = os.path.dirname(env.sd_manifest.getImagePath('foo'))
+            self.assertTrue(os.path.exists(images_dir))
+
+    def test_volume_structure(self):
+        with fake_file_env() as env:
+            img_id, vol_id = make_file_volume(env.sd_manifest.domaindir, 0)
+            image_dir = env.sd_manifest.getImagePath(img_id)
+            files = (vol_id, vol_id + constants.LEASE_FILEEXT,
+                     vol_id + fileVolume.META_FILEEXT)
+            for f in files:
+                path = os.path.join(image_dir, f)
+                self.assertTrue(os.path.exists(path))
+
+    def test_domain_metadata_io(self):
+        with fake_file_env() as env:
+            set_domain_metaparams(env.sd_manifest,
+                                  {sd.DMDK_DESCRIPTION: 'foo'})
+            self.assertEqual('foo',
+                             env.sd_manifest.getMetaParam(sd.DMDK_DESCRIPTION))
+
+            # Test that metadata is persisted to our temporary storage area
+            domain_dir = env.sd_manifest.domaindir
+            manifest = fileSD.FileStorageDomainManifest(domain_dir)
+            self.assertEqual('foo', manifest.getMetaParam(sd.DMDK_DESCRIPTION))
+
+    def test_volume_metadata_io(self):
+        with fake_file_env() as env:
+            size = 1 * MB
+            img_id, vol_id = make_file_volume(env.sd_manifest.domaindir, size)
+            vol = env.sd_manifest.produceVolume(img_id, vol_id)
+            vol.setDescription('foo')
+            self.assertEqual('foo', vol.getDescription())
+
+            # Test that metadata is persisted to our temporary storage area
+            vol = env.sd_manifest.produceVolume(img_id, vol_id)
+            self.assertEqual('foo', vol.getDescription())
+
+
+class FakeBlockEnvTests(VdsmTestCase):
+
+    def test_repopath_location(self):
+        with fake_block_env() as env:
+            self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
+
+    def test_domain_structure(self):
+        with fake_block_env() as env:
+            vg_name = env.sd_manifest.sdUUID
+            md_path = env.lvm.lvPath(vg_name, sd.METADATA)
+            self.assertTrue(os.path.exists(md_path))
+
+            # Check that the domain's special LVs can be found via LVM
+            special_lvs = sd.SPECIAL_VOLUME_SIZES_MIB.keys() + [sd.METADATA]
+            for lv in special_lvs:
+                self.assertEqual(lv, env.lvm.getLV(vg_name, lv).name)
+
+            images_dir = os.path.join(env.sd_manifest.domaindir, vg_name,
+                                      sd.DOMAIN_IMAGES)
+            self.assertTrue(os.path.exists(images_dir))
+
+    def test_volume_metadata_io(self):
+        with fake_block_env() as env:
+            sd_id = env.sd_manifest.sdUUID
+            img_id = str(uuid.uuid4())
+            vol_id = str(uuid.uuid4())
+            size = 1 * MB
+            make_block_volume(env.lvm, env.sd_manifest, size, img_id, vol_id)
+
+            self.assertEqual(vol_id, env.lvm.getLV(sd_id, vol_id).name)
+            vol = env.sd_manifest.produceVolume(img_id, vol_id)
+            self.assertEqual(size / volume.BLOCK_SIZE, vol.getSize())
+            vol.setDescription('foo')
+            self.assertEqual('foo', vol.getDescription())
+
+            # Test that metadata is persisted to our temporary storage area
+            vol = env.sd_manifest.produceVolume(img_id, vol_id)
+            self.assertEqual('foo', vol.getDescription())
+
+    def test_domain_metadata_io(self):
+        with fake_block_env() as env:
+            set_domain_metaparams(env.sd_manifest,
+                                  {sd.DMDK_DESCRIPTION: 'foo'})
+            self.assertEqual('foo',
+                             env.sd_manifest.getMetaParam(sd.DMDK_DESCRIPTION))
+
+            # Test that metadata is persisted to our temporary storage area
+            sd_id = env.sd_manifest.sdUUID
+            manifest = blockSD.BlockStorageDomainManifest(sd_id)
+            self.assertEqual('foo', manifest.getMetaParam(sd.DMDK_DESCRIPTION))
+
+
+def set_domain_metaparams(manifest, params):
+    # XXX: Replace calls to this function with the proper manifest APIs once
+    # the set* methods are moved from StorageDomain to StorageDomainManifest.
+    manifest._metadata.update(params)


-- 
To view, visit https://gerrit.ovirt.org/55889
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I65ab8c6419dfa1181efff2a533c00589ba5b8263
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke at redhat.com>


More information about the vdsm-patches mailing list