Change in vdsm[master]: tests: Generalize sdm_indirection_tests

alitke at redhat.com alitke at redhat.com
Wed Sep 16 18:24:11 UTC 2015


Adam Litke has uploaded a new change for review.

Change subject: tests: Generalize sdm_indirection_tests
......................................................................

tests: Generalize sdm_indirection_tests

The infrastructure in sdm_indirection_tests is useful for testing the
other classes where there is indirection:

    Image -> ImageManifest
    Volume -> VolumeMetadata

In order to reuse this code we need to generalize two things:
1. The class doing the redirection is not necessarily a StorageDomain.
It can also be an Image or Volume.
2. Each class that redirects calls for SDM contains an instance of the
redirection target class.  For example, StorageDomains contain a field
'_manifest' which is a StorageDomainManifest instance.

The generalization can be done by extracting the general purpose bits
from DomainTestMixin into SDMIndirectionMixin.  When Image and Volume
support will be added to this module we can subclass
SDMIndirectionMixin as we are now doing for DomainTestMixin.

Change-Id: Icb68cb27d4e36c22f74a1cc445f38bea4d0ce4da
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M tests/sdm_indirection_tests.py
1 file changed, 35 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/59/46259/1

diff --git a/tests/sdm_indirection_tests.py b/tests/sdm_indirection_tests.py
index c2f10a4..7a8c81d 100644
--- a/tests/sdm_indirection_tests.py
+++ b/tests/sdm_indirection_tests.py
@@ -282,17 +282,27 @@
         self._manifest = self.manifestClass()
 
 
- at expandPermutations
-class DomainTestMixin(object):
-    # Must be implemented by the sub class
-    fakeDomClass = None
+class SDMIndirectionMixin(object):
+    # The class that will be initiating redirection of calls.  For example,
+    # we use a faked StorageDomain object as the source of redirection to
+    # StorageDomainManifest objects.
+    # This attribute must be specified by the child class.
+    indirectionSourceClass = None
+
+    # The name of the destination class instance in the source class.  For
+    # example, calls are redirected from StorageDomain objects to
+    # StorageDomainManifest objects and each StorageDomain contains an instance
+    # of StorageDomainManifest which is named '_manifest'.
+    # This attribute must be specified by the child class.
+    indirectionTargetName = None
 
     def setUp(self):
-        self.dom = self.fakeDomClass()
+        self.redirector = self.indirectionSourceClass()
 
     def _check(self, fn, args, result):
-        getattr(self.dom, fn)(*args)
-        self.assertEqual(self.dom._manifest.__recording__, result)
+        target = getattr(self.redirector, self.indirectionTargetName)
+        getattr(self.redirector, fn)(*args)
+        self.assertEqual(target.__recording__, result)
 
     def check_call(self, fn, nr_args=0):
         args = tuple(range(nr_args))
@@ -300,9 +310,14 @@
 
     def check_classmethod_call(self, fn, nr_args=0):
         args = tuple(range(nr_args))
-        getattr(self.dom, fn)(*args)
-        self.assertEquals(self.dom._manifest.get_classmethod_calls(),
-                          [(fn, args)])
+        target = getattr(self.redirector, self.indirectionTargetName)
+        getattr(self.redirector, fn)(*args)
+        self.assertEquals(target.get_classmethod_calls(), [(fn, args)])
+
+
+ at expandPermutations
+class DomainTestMixin(SDMIndirectionMixin):
+    indirectionTargetName = '_manifest'
 
     @permutations([
         ['sdUUID', 'a6ecac0a-5c6b-46d7-9ba5-df8b34df2d01'],
@@ -311,7 +326,7 @@
         ['mountpoint', '/a/b'],
     ])
     def test_property(self, prop, val):
-        self.assertEqual(getattr(self.dom, prop), val)
+        self.assertEqual(getattr(self.redirector, prop), val)
 
     def test_getrepopath(self):
         # The private method _getRepoPath in StorageDomain calls the public
@@ -371,17 +386,17 @@
 
 
 @expandPermutations
-class BlockTests(DomainTestMixin, VdsmTestCase):
-    fakeDomClass = FakeBlockStorageDomain
+class BlockDomainTests(DomainTestMixin, VdsmTestCase):
+    indirectionSourceClass = FakeBlockStorageDomain
 
     def test_block_properties(self):
-        self.assertEqual(512, self.dom.logBlkSize)
-        self.assertEqual(512, self.dom.phyBlkSize)
+        self.assertEqual(512, self.redirector.logBlkSize)
+        self.assertEqual(512, self.redirector.phyBlkSize)
 
     def test_acquirevolumemetadataslot(self):
-        with self.dom.acquireVolumeMetadataSlot(0, 1):
+        with self.redirector.acquireVolumeMetadataSlot(0, 1):
             result = [('acquireVolumeMetadataSlot', (0, 1), {})]
-            self.assertEqual(self.dom._manifest.__recording__, result)
+            self.assertEqual(self.redirector._manifest.__recording__, result)
 
     @permutations([
         ['extend', 2],
@@ -401,8 +416,8 @@
         self.check_classmethod_call(fn, nargs)
 
 
-class FileTests(DomainTestMixin, VdsmTestCase):
-    fakeDomClass = FakeFileStorageDomain
+class FileDomainTests(DomainTestMixin, VdsmTestCase):
+    indirectionSourceClass = FakeFileStorageDomain
 
     def test_getremotepath(self):
-        self.assertEqual('b', self.dom.getRemotePath())
+        self.assertEqual('b', self.redirector.getRemotePath())


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb68cb27d4e36c22f74a1cc445f38bea4d0ce4da
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