Change in vdsm[master]: storage: add a context manager for the domainLock
gerrit-hooks has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 2: * Update tracker: IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3']) -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Adam Litke has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 1: (3 comments) https://gerrit.ovirt.org/#/c/50272/1/tests/manifest_tests.py File tests/manifest_tests.py: Line 170: acquired = manifest._lvTagMetaSlotLock.acquire(False) Line 171: self.assertFalse(acquired) Line 172: Line 173: Line 174: class FakeStorageDomainManifest(sd.StorageDomainManifest): > This is not really a fake object, but a subclass that good only for testing Done Line 175: def __init__(self): Line 176: pass Line 177: Line 178: @recorded Line 192: with manifest.domain_lock(1): Line 193: expected_calls.append(("acquireDomainLock", (1,), {})) Line 194: self.assertEqual(manifest.__calls__, expected_calls) Line 195: expected_calls.append(("releaseDomainLock", (), {})) Line 196: self.assertEqual(manifest.__calls__, expected_calls) > I would simplify like this - first, record another method: Done Line 197: Line 198: def test_domainlock_contextmanager_exception(self): Line 199: class InjectedFailure(Exception): Line 200: pass Line 207: self.assertEqual(manifest.__calls__, expected_calls) Line 208: raise InjectedFailure() Line 209: except InjectedFailure: Line 210: expected_calls.append(("releaseDomainLock", (), {})) Line 211: self.assertEqual(manifest.__calls__, expected_calls) > I would test it like this: Done -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: Yes ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Nir Soffer has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 2: Code-Review+1 (2 comments) Looks good, but we can simplify the failing test even more. https://gerrit.ovirt.org/#/c/50272/2/tests/manifest_tests.py File tests/manifest_tests.py: Line 191: def dummy(self): Line 192: pass Line 193: Line 194: def fail(self): Line 195: raise InjectedFailure() Thinking again, we don't need this - we can simply raise in the context manager. Line 196: Line 197: Line 198: class DomainLockTests(VdsmTestCase): Line 199: Line 213: try: Line 214: with manifest.domain_lock(1): Line 215: manifest.fail() Line 216: except InjectedFailure: Line 217: pass Better use self.assertRaises for this: with self.assertRaises(InjectedFailure): with manitsst.domain_lock(): raise InjectedFailure -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: Yes ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Adam Litke has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 3: Verified+1 -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
gerrit-hooks has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 3: * Update tracker: IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3']) -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Adam Litke has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 2: (2 comments) https://gerrit.ovirt.org/#/c/50272/2/tests/manifest_tests.py File tests/manifest_tests.py: Line 191: def dummy(self): Line 192: pass Line 193: Line 194: def fail(self): Line 195: raise InjectedFailure() > Thinking again, we don't need this - we can simply raise in the context man Done Line 196: Line 197: Line 198: class DomainLockTests(VdsmTestCase): Line 199: Line 213: try: Line 214: with manifest.domain_lock(1): Line 215: manifest.fail() Line 216: except InjectedFailure: Line 217: pass > Better use self.assertRaises for this: Done -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: Yes ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
gerrit-hooks has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 4: * Update tracker: IGNORE, no Bug-Url found * Set MODIFIED::IGNORE, no Bug-Url found. -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 4 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Nir Soffer has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 3: Continuous-Integration+1 -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Nir Soffer has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 3: Code-Review+2 -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Nir Soffer has submitted this change and it was merged. Change subject: storage: add a context manager for the domainLock .. storage: add a context manager for the domainLock Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Signed-off-by: Adam LitkeReviewed-on: https://gerrit.ovirt.org/50272 Reviewed-by: Nir Soffer Continuous-Integration: Nir Soffer --- M tests/manifest_tests.py M vdsm/storage/sd.py 2 files changed, 51 insertions(+), 1 deletion(-) Approvals: Nir Soffer: Looks good to me, approved; Passed CI tests Adam Litke: Verified -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 4 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam Litke Gerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Adam Litke has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 2: Verified+1 Verified with unit tests as before. -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Adam Litke has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 1: Verified+1 Verified by running unit tests. This is new code so there are not yet any users. -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Nir Soffer has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 1: Code-Review-1 (3 comments) Nice, the tests can be simplified. https://gerrit.ovirt.org/#/c/50272/1/tests/manifest_tests.py File tests/manifest_tests.py: Line 170: acquired = manifest._lvTagMetaSlotLock.acquire(False) Line 171: self.assertFalse(acquired) Line 172: Line 173: Line 174: class FakeStorageDomainManifest(sd.StorageDomainManifest): This is not really a fake object, but a subclass that good only for testing certain methods. I would call it TestingStorageDomainManifest Line 175: def __init__(self): Line 176: pass Line 177: Line 178: @recorded Line 192: with manifest.domain_lock(1): Line 193: expected_calls.append(("acquireDomainLock", (1,), {})) Line 194: self.assertEqual(manifest.__calls__, expected_calls) Line 195: expected_calls.append(("releaseDomainLock", (), {})) Line 196: self.assertEqual(manifest.__calls__, expected_calls) I would simplify like this - first, record another method: class FakeStorageDomainManifest(sd.StorageDomainManifest): ... @recorded def dummy(self): pass Now, lets call it with the context manager: with manifest.domain_lock(1): manifes.dummy() And verify that we got: [ ("acquireDomainLock", (1,), {}), ("dummy", (), {}), ("releaseDomainLock", (), {}), ] Line 197: Line 198: def test_domainlock_contextmanager_exception(self): Line 199: class InjectedFailure(Exception): Line 200: pass Line 207: self.assertEqual(manifest.__calls__, expected_calls) Line 208: raise InjectedFailure() Line 209: except InjectedFailure: Line 210: expected_calls.append(("releaseDomainLock", (), {})) Line 211: self.assertEqual(manifest.__calls__, expected_calls) I would test it like this: class FakeStorageDomainManifest(sd.StorageDomainManifest): ... def fail(self): raise ... Now, lets call it with the context manager: with manifest.domain_lock(1): manifes.fail() And verify that the exception was raised, and we recorded: [ ("acquireDomainLock", (1,), {}), ("releaseDomainLock", (), {}), ] -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: Adam Litke Gerrit-Reviewer: Ala Hino Gerrit-Reviewer: Daniel Erez Gerrit-Reviewer: Freddy Rolland Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Nir Soffer Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: Yes ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
Adam Litke has uploaded a new change for review. Change subject: storage: add a context manager for the domainLock .. storage: add a context manager for the domainLock Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Signed-off-by: Adam Litke--- M tests/manifest_tests.py M vdsm/storage/sd.py 2 files changed, 50 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/50272/1 diff --git a/tests/manifest_tests.py b/tests/manifest_tests.py index cfb5ee7..1e0e18a 100644 --- a/tests/manifest_tests.py +++ b/tests/manifest_tests.py @@ -20,7 +20,7 @@ import os import uuid -from testlib import VdsmTestCase, namedTemporaryDir, make_file +from testlib import VdsmTestCase, namedTemporaryDir, make_file, recorded from monkeypatch import MonkeyPatchScope from storagefakelib import FakeLVM from storagetestlib import make_filesd_manifest, make_blocksd, make_file_volume @@ -169,3 +169,43 @@ with manifest.acquireVolumeMetadataSlot(None, 1): acquired = manifest._lvTagMetaSlotLock.acquire(False) self.assertFalse(acquired) + + +class FakeStorageDomainManifest(sd.StorageDomainManifest): +def __init__(self): +pass + +@recorded +def acquireDomainLock(self, host_id): +pass + +@recorded +def releaseDomainLock(self): +pass + + +class FakeDomainManifestTests(VdsmTestCase): + +def test_domainlock_contextmanager(self): +expected_calls = [] +manifest = FakeStorageDomainManifest() +with manifest.domain_lock(1): +expected_calls.append(("acquireDomainLock", (1,), {})) +self.assertEqual(manifest.__calls__, expected_calls) +expected_calls.append(("releaseDomainLock", (), {})) +self.assertEqual(manifest.__calls__, expected_calls) + +def test_domainlock_contextmanager_exception(self): +class InjectedFailure(Exception): +pass + +expected_calls = [] +manifest = FakeStorageDomainManifest() +try: +with manifest.domain_lock(1): +expected_calls.append(("acquireDomainLock", (1,), {})) +self.assertEqual(manifest.__calls__, expected_calls) +raise InjectedFailure() +except InjectedFailure: +expected_calls.append(("releaseDomainLock", (), {})) +self.assertEqual(manifest.__calls__, expected_calls) diff --git a/vdsm/storage/sd.py b/vdsm/storage/sd.py index 68fa285..807d92a 100644 --- a/vdsm/storage/sd.py +++ b/vdsm/storage/sd.py @@ -24,6 +24,7 @@ import threading from collections import namedtuple import codecs +from contextlib import contextmanager import image import storage_exception as se @@ -422,6 +423,14 @@ def releaseDomainLock(self): self._domainLock.release() +@contextmanager +def domain_lock(self, host_id): +self.acquireDomainLock(host_id) +try: +yield +finally: +self.releaseDomainLock() + def inquireDomainLock(self): return self._domainLock.inquire() -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam Litke ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[master]: storage: add a context manager for the domainLock
gerrit-hooks has posted comments on this change. Change subject: storage: add a context manager for the domainLock .. Patch Set 1: * Update tracker: IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3']) -- To view, visit https://gerrit.ovirt.org/50272 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Id7b831d4fe5a67f6998f31978f2399fdebdb3ceb Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam LitkeGerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches