Adam Litke has uploaded a new change for review. Change subject: tests: FakeStorageDomainCache ......................................................................
tests: FakeStorageDomainCache Change-Id: I7d6aade8ae6942d8c8e14a92dec682f957044746 Signed-off-by: Adam Litke <ali...@redhat.com> --- M tests/storagefakelib.py M tests/storagefakelibTests.py M tests/storagetestlib.py 3 files changed, 33 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/55/57055/1 diff --git a/tests/storagefakelib.py b/tests/storagefakelib.py index 8044195..e967e9a 100644 --- a/tests/storagefakelib.py +++ b/tests/storagefakelib.py @@ -286,3 +286,14 @@ @recorded def releaseResource(self, *args, **kwargs): pass + + +class FakeStorageDomainCache(object): + def __init__(self, domains): + self._domains = domains + + def produce(self, sd_id): + try: + return self._domains[sd_id] + except KeyError: + raise se.StorageDomainDoesNotExist(sd_id) diff --git a/tests/storagefakelibTests.py b/tests/storagefakelibTests.py index 898e69e..9165bf5 100644 --- a/tests/storagefakelibTests.py +++ b/tests/storagefakelibTests.py @@ -25,7 +25,7 @@ from testlib import VdsmTestCase, namedTemporaryDir from testlib import permutations, expandPermutations -from storagefakelib import FakeLVM, FakeResourceManager +from storagefakelib import FakeLVM, FakeResourceManager, FakeStorageDomainCache from storage import blockSD, blockVolume from storage import lvm as real_lvm @@ -358,3 +358,16 @@ self.assertEqual(expected_calls, rm.__calls__) expected_calls.append(('releaseResource', acquire_args, {})) self.assertEqual(expected_calls, rm.__calls__) + + +class FakeStorageDomainCacheTests(VdsmTestCase): + + def test_domain_does_not_exist(self): + sdc = FakeStorageDomainCache(dict()) + self.assertRaises(se.StorageDomainDoesNotExist, sdc.produce, 'foo') + + def test_produce(self): + # The cache just returns objects so we don't need to pass a domain + dom = object() + sdc = FakeStorageDomainCache(dict(foo=dom)) + self.assertEqual(dom, sdc.produce('foo')) diff --git a/tests/storagetestlib.py b/tests/storagetestlib.py index 1a3dfce..2d9fab2 100644 --- a/tests/storagetestlib.py +++ b/tests/storagetestlib.py @@ -21,7 +21,7 @@ from contextlib import contextmanager from testlib import make_file, namedTemporaryDir -from storagefakelib import FakeLVM +from storagefakelib import FakeLVM, FakeStorageDomainCache from monkeypatch import MonkeyPatchScope from vdsm import utils @@ -46,10 +46,11 @@ def fake_file_env(obj=None): with namedTemporaryDir() as tmpdir: sd_manifest = make_filesd_manifest(tmpdir) + fake_sdc = FakeStorageDomainCache({sd_manifest.sdUUID: sd_manifest}) with MonkeyPatchScope([ - [sd, 'storage_repository', tmpdir] + [sd, 'storage_repository', tmpdir], + [volume, 'sdCache', fake_sdc], ]): - yield FakeEnv(sd_manifest) @@ -64,7 +65,10 @@ (sd, 'storage_repository', tmpdir), ]): sd_manifest = make_blocksd_manifest(tmpdir, lvm) - yield FakeEnv(sd_manifest, lvm=lvm) + fake_sdc = FakeStorageDomainCache( + {sd_manifest.sdUUID: sd_manifest}) + with MonkeyPatchScope([[volume, 'sdCache', fake_sdc]]): + yield FakeEnv(sd_manifest, lvm=lvm) class FakeMetadata(dict): -- To view, visit https://gerrit.ovirt.org/57055 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7d6aade8ae6942d8c8e14a92dec682f957044746 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam Litke <ali...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches