Adam Litke has uploaded a new change for review. Change subject: storage: Add support for guarded to Volume Leases ......................................................................
storage: Add support for guarded to Volume Leases Support the use of volume leases with the guarded utilities by creating a VolumeLease class that conforms to the guarded.AbstractLock semantics. Change-Id: I53c3dc65975c236545d15b8e8be62403c29c7f9f Signed-off-by: Adam Litke <ali...@redhat.com> --- M lib/vdsm/storage/constants.py M tests/Makefile.am A tests/storage_volume_test.py M vdsm/storage/volume.py 4 files changed, 129 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/49/63549/1 diff --git a/lib/vdsm/storage/constants.py b/lib/vdsm/storage/constants.py index 7705c06..4c00a5b 100644 --- a/lib/vdsm/storage/constants.py +++ b/lib/vdsm/storage/constants.py @@ -28,6 +28,7 @@ IMAGE_NAMESPACE = '01_img' VOLUME_NAMESPACE = '02_vol' LVM_ACTIVATION_NAMESPACE = '03_lvm' +VOLUME_LEASE_NAMESPACE = "04_lease" SECTOR_SIZE = 512 VG_EXTENT_SIZE_MB = 128 diff --git a/tests/Makefile.am b/tests/Makefile.am index eb8a25e..ae671c9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -130,6 +130,7 @@ storage_sdm_api_test.py \ storage_sdm_copy_data_test.py \ storage_sdm_create_volume_test.py \ + storage_volume_test.py \ storage_volume_artifacts_test.py \ storage_volume_metadata_test.py \ tasksetTests.py \ @@ -232,6 +233,7 @@ storage_sdm_api_test.py \ storage_sdm_create_volume_test.py \ storage_sdm_copy_data_test.py \ + storage_volume_test.py \ storage_volume_artifacts_test.py \ storage_volume_metadata_test.py \ storagefakelibTests.py \ diff --git a/tests/storage_volume_test.py b/tests/storage_volume_test.py new file mode 100644 index 0000000..79cae70 --- /dev/null +++ b/tests/storage_volume_test.py @@ -0,0 +1,94 @@ +# +# 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 +# + +from __future__ import absolute_import + +from monkeypatch import MonkeyPatchScope +from storagefakelib import FakeStorageDomainCache +from storagetestlib import FakeSD +from testlib import expandPermutations, permutations +from testlib import recorded +from testlib import VdsmTestCase + +from vdsm.storage import constants as sc + +from storage import resourceManager as rm +from storage import sd +from storage import volume + +HOST_ID = 1 + + +class FakeSDManifest(object): + @recorded + def acquireVolumeLease(self, hostId, imgUUID, volUUID): + pass + + @recorded + def releaseVolumeLease(self, imgUUID, volUUID): + pass + + +@expandPermutations +class VolumeLeaseTest(VdsmTestCase): + + def test_properties(self): + a = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') + self.assertEqual(sd.getNamespace(sc.VOLUME_LEASE_NAMESPACE, 'dom'), + a.ns) + self.assertEqual('vol', a.name) + self.assertEqual(rm.LockType.exclusive, a.mode) + + @permutations(( + (('domA', 'img', 'vol'), ('domB', 'img', 'vol')), + (('dom', 'img', 'volA'), ('dom', 'img', 'volB')), + )) + def test_less_than(self, a, b): + b = volume.VolumeLease(HOST_ID, *b) + a = volume.VolumeLease(HOST_ID, *a) + self.assertLess(a, b) + + def test_equality(self): + a = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') + b = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') + self.assertEqual(a, b) + + def test_equality_different_image(self): + a = volume.VolumeLease(HOST_ID, 'dom', 'img1', 'vol') + b = volume.VolumeLease(HOST_ID, 'dom', 'img2', 'vol') + self.assertEqual(a, b) + + def test_equality_different_host_id(self): + a = volume.VolumeLease(0, 'dom', 'img', 'vol') + b = volume.VolumeLease(1, 'dom', 'img', 'vol') + self.assertEqual(a, b) + + def test_acquire_release(self): + sdcache = FakeStorageDomainCache() + manifest = FakeSDManifest() + sdcache.domains['dom'] = FakeSD(manifest) + expected = [('acquireVolumeLease', (HOST_ID, 'img', 'vol'), {}), + ('releaseVolumeLease', ('img', 'vol'), {})] + with MonkeyPatchScope([(volume, 'sdCache', sdcache)]): + lock = volume.VolumeLease(HOST_ID, 'dom', 'img', 'vol') + lock.acquire() + self.assertEqual(expected[:1], manifest.__calls__) + lock.release() + self.assertEqual(expected, manifest.__calls__) diff --git a/vdsm/storage/volume.py b/vdsm/storage/volume.py index 47847aa..f02be02 100644 --- a/vdsm/storage/volume.py +++ b/vdsm/storage/volume.py @@ -28,6 +28,7 @@ from vdsm.storage import constants as sc from vdsm.storage import exception as se from vdsm.storage import fileUtils +from vdsm.storage import guarded from vdsm.storage import misc from vdsm.storage.misc import deprecated from vdsm.storage.threadlocal import vars @@ -1182,3 +1183,34 @@ @classmethod def getImageVolumes(cls, repoPath, sdUUID, imgUUID): return cls.manifestClass.getImageVolumes(repoPath, sdUUID, imgUUID) + + +class VolumeLease(guarded.AbstractLock): + """ + Extend AbstractLock so Volume Leases may be used with guarded utilities. + """ + def __init__(self, host_id, sd_id, img_id, vol_id): + self._host_id = host_id + self._sd_id = sd_id + self._img_id = img_id + self._vol_id = vol_id + + @property + def ns(self): + return sd.getNamespace(sc.VOLUME_LEASE_NAMESPACE, self._sd_id) + + @property + def name(self): + return self._vol_id + + @property + def mode(self): + return rm.LockType.exclusive # All volume leases are exclusive + + def acquire(self): + dom = sdCache.produce_manifest(self._sd_id) + dom.acquireVolumeLease(self._host_id, self._img_id, self._vol_id) + + def release(self): + dom = sdCache.produce_manifest(self._sd_id) + dom.releaseVolumeLease(self._img_id, self._vol_id) -- To view, visit https://gerrit.ovirt.org/63549 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I53c3dc65975c236545d15b8e8be62403c29c7f9f 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/admin/lists/vdsm-patches@lists.fedorahosted.org