import json import time import pytest from vdsm.common import concurrent from vdsm.common.units import MiB from vdsm.storage import clusterlock from vdsm.storage import constants as sc from vdsm.storage import exception as se from vdsm.storage.compat import sanlock LS_NAME = b"sd-uuid" LS_PATH = "ids" LS_OFF = 0 HOST_ID = 1 LEASE = clusterlock.Lease("SDM", "leases", MiB) class FakePanic(Exception): pass @pytest.fixture def lock(monkeypatch): # Reset class attributes to keep tests isolated. monkeypatch.setattr(clusterlock.SANLock, "_process_fd", None) monkeypatch.setattr(clusterlock.SANLock, "_lease_count", 0) # Monkeypatch clusterlock.panic() to allow testing panic without killing # the tests process.
def getVolumeLease(self, imgUUID, volUUID): """ Return the volume lease (leasePath, leaseOffset) """ return clusterlock.Lease(None, None, None)
from __future__ import division import time import pytest from vdsm.common import concurrent from vdsm.storage import clusterlock from vdsm.storage import constants as sc from vdsm.storage import exception as se from vdsm.storage.compat import sanlock LS_NAME = b"sd-uuid" LS_PATH = "ids" LS_OFF = 0 HOST_ID = 1 LEASE = clusterlock.Lease("SDM", "leases", 1024**2) @pytest.fixture def lock(): sanlock = clusterlock.SANLock(LS_NAME.decode("utf-8"), LS_PATH, LEASE) sanlock.initLock(LEASE) return sanlock def test_acquire_host_id_sync(fake_sanlock, lock): lock.acquireHostId(HOST_ID, wait=True) acquired = fake_sanlock.inq_lockspace(LS_NAME, HOST_ID, LS_PATH, LS_OFF) assert acquired is True