Change in vdsm[master]: inject failures into create container
by alitke@redhat.com
Adam Litke has uploaded a new change for review.
Change subject: inject failures into create container
......................................................................
inject failures into create container
Change-Id: I1fb5f18be6434ee21ac7550fe14c166b5e82b11e
Signed-off-by: Adam Litke <alitke(a)redhat.com>
---
M vdsm/storage/sdm.py
1 file changed, 20 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/32/44832/1
diff --git a/vdsm/storage/sdm.py b/vdsm/storage/sdm.py
index 7a53e04..af4d479 100644
--- a/vdsm/storage/sdm.py
+++ b/vdsm/storage/sdm.py
@@ -31,6 +31,8 @@
from vdsm import qemuimg
+from misc import maybe_fail
+
log = logging.getLogger('sdm')
rmanager = rm.ResourceManager.getInstance()
@@ -43,40 +45,58 @@
def create_volume_container(dom_manifest, img_id, size, vol_format, disk_type,
vol_id, desc, src_img_id, src_vol_id):
+ maybe_fail(0.005)
hostId = get_domain_host_id(dom_manifest.sdUUID)
+ maybe_fail(0.02)
dom_manifest.acquireDomainLock(hostId)
imageResourcesNamespace = sd.getNamespace(dom_manifest.sdUUID,
IMAGE_NAMESPACE)
try:
+ maybe_fail(0.02)
with rmanager.acquireResource(imageResourcesNamespace, img_id,
rm.LockType.exclusive):
+ maybe_fail(0.02)
image_manifest = ImageManifest(dom_manifest.getRepoPath())
+ maybe_fail(0.02)
img_path = image_manifest.create_image_dir(dom_manifest.sdUUID,
img_id)
+ maybe_fail(0.02)
vol_parent_md = None
+ maybe_fail(0.02)
if src_vol_id != volume.BLANK_UUID:
+ maybe_fail(0.02)
# When the src_img_id isn't specified we assume it's the same
# as img_id
if src_img_id == volume.BLANK_UUID:
+ maybe_fail(0.02)
src_img_id = img_id
+ maybe_fail(0.02)
vol_parent_md = dom_manifest.produceVolume(src_img_id,
src_vol_id)
+ maybe_fail(0.02)
size = vol_parent_md.getSize()
+ maybe_fail(0.02)
dom_manifest.create_volume_artifacts(img_id, vol_id, size,
vol_format, disk_type,
desc, src_vol_id)
+ maybe_fail(0.02)
if src_vol_id != volume.BLANK_UUID:
+ maybe_fail(0.02)
_prepare_volume_for_parenthood(vol_parent_md, src_img_id,
src_vol_id, img_id, img_path)
+ maybe_fail(0.02)
# TODO: get actual size from create_volume_artifacts retval
size = volume.VolumeMetadata.adjust_new_volume_size(
dom_manifest, img_id, vol_id, size, vol_format)
+ maybe_fail(0.02)
vol_path = os.path.join(img_path, vol_id)
+ maybe_fail(0.02)
_initialize_volume_contents(img_id, vol_id, vol_path, vol_format,
size, vol_parent_md)
+ maybe_fail(0.02)
dom_manifest.commit_volume_artifacts(img_path, img_id, vol_id)
finally:
dom_manifest.releaseDomainLock()
--
To view, visit https://gerrit.ovirt.org/44832
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1fb5f18be6434ee21ac7550fe14c166b5e82b11e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: blockVolume: Add classmethod helper to clear a metadata slot
by alitke@redhat.com
Adam Litke has uploaded a new change for review.
Change subject: blockVolume: Add classmethod helper to clear a metadata slot
......................................................................
blockVolume: Add classmethod helper to clear a metadata slot
Change-Id: I338f3fe5f232b1e6e7e8a2474efabcf56333e1cc
Signed-off-by: Adam Litke <alitke(a)redhat.com>
---
M vdsm/storage/blockVolume.py
1 file changed, 7 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/33/44833/1
diff --git a/vdsm/storage/blockVolume.py b/vdsm/storage/blockVolume.py
index 79061e5..c6c3938 100644
--- a/vdsm/storage/blockVolume.py
+++ b/vdsm/storage/blockVolume.py
@@ -296,16 +296,17 @@
# tags
self.setMetaParam(volume.IMAGE, imgUUID)
- def removeMetadata(self, metaId):
- """
- Just wipe meta.
- """
+ @classmethod
+ def clearMetadataSlot(cls, metaId):
try:
- self._putMetadata(metaId, {"NONE": "#" * (sd.METASIZE - 10)})
+ cls._putMetadata(metaId, {"NONE": "#" * (sd.METASIZE - 10)})
except Exception as e:
- self.log.error(e, exc_info=True)
+ cls.log.exception(e)
raise se.VolumeMetadataWriteError("%s: %s" % (metaId, e))
+ def removeMetadata(self, metaId):
+ self.clearMetadataSlot(metaId)
+
@classmethod
def newVolumeLease(cls, metaId, sdUUID, volUUID):
cls.log.debug("Initializing volume lease volUUID=%s sdUUID=%s, "
--
To view, visit https://gerrit.ovirt.org/44833
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I338f3fe5f232b1e6e7e8a2474efabcf56333e1cc
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: vm: Cleaner vm stats thread initialization
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: vm: Cleaner vm stats thread initialization
......................................................................
vm: Cleaner vm stats thread initialization
The vm stats thread was initialized too late, leading to unneeded checks
and unclear try except blocks when trying to stop the thread.
This patch changes AdvancedStatsThread so it keeps a thread instance
instead of inheriting from Thread, and initialize it in Vm.__init__, so
it is always available when we access it.
Change-Id: I2917de42b76ee3dc8b27bdc23b33f3c984a7cc68
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M vdsm/virt/sampling.py
M vdsm/virt/vm.py
2 files changed, 11 insertions(+), 18 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/99/39299/1
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 3206b97..848bb36 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -401,7 +401,7 @@
return self._samples.last()
-class AdvancedStatsThread(threading.Thread):
+class AdvancedStatsThread(object):
"""
A thread that runs the registered AdvancedStatsFunction objects
for statistic and monitoring purpose.
@@ -412,9 +412,8 @@
"""
Initialize an AdvancedStatsThread object
"""
- threading.Thread.__init__(self)
self.daemon = daemon
-
+ self._thread = None
self._log = log
self._stopEvent = threading.Event()
self._contEvent = threading.Event()
@@ -426,7 +425,7 @@
"""
Register the functions listed as arguments
"""
- if self.isAlive():
+ if self._thread is not None:
raise RuntimeError("AdvancedStatsThread is started")
for statsFunction in args:
@@ -437,7 +436,9 @@
Start the execution of the thread and exit
"""
self._log.debug("Start statistics collection")
- threading.Thread.start(self)
+ self._thread = threading.Thread(target=self._run)
+ self._thread.daemon = self.daemon
+ self._thread.start()
def stop(self):
"""
@@ -464,7 +465,7 @@
def getLastSampleTime(self):
return self._statsTime
- def run(self):
+ def _run(self):
self._log.debug("Stats thread started")
self._contEvent.set()
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 28054bf..1bc04e7 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -779,7 +779,7 @@
self._initTimeRTC = long(self.conf.get('timeOffset', 0))
self._guestEvent = vmstatus.POWERING_UP
self._guestEventTime = 0
- self._vmStats = None
+ self._vmStats = VmStatsThread(self)
self._guestCpuRunning = False
self._guestCpuLock = threading.Lock()
self._startTime = time.time() - \
@@ -1269,7 +1269,7 @@
return
toSave = self.status()
toSave['startTime'] = self._startTime
- if self.lastStatus != vmstatus.DOWN and self._vmStats:
+ if self.lastStatus != vmstatus.DOWN:
guestInfo = self.guestAgent.getGuestInfo()
toSave['username'] = guestInfo['username']
toSave['guestIPs'] = guestInfo['guestIPs']
@@ -1758,7 +1758,7 @@
decStats = {}
try:
- if self._vmStats and self._vmStats.getLastSampleTime() is not None:
+ if self._vmStats.getLastSampleTime() is not None:
decStats = self._vmStats.get()
self._setUnresponsiveIfTimeout(
stats,
@@ -2001,19 +2001,11 @@
return domxml.toxml()
def startVmStats(self):
- self._vmStats = VmStatsThread(self)
self._vmStats.start()
self._guestEventTime = self._startTime
def stopVmStats(self):
- # this is less clean that it could be, but we can get here from
- # many flows and with various locks held
- # (_releaseLock, _shutdownLock)
- # _vmStats may be None already, and we're good with that.
- try:
- self._vmStats.stop()
- except AttributeError:
- pass
+ self._vmStats.stop()
@staticmethod
def _guestSockCleanup(sock):
--
To view, visit https://gerrit.ovirt.org/39299
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2917de42b76ee3dc8b27bdc23b33f3c984a7cc68
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: fix remove: iterate while del
by alitke@redhat.com
Adam Litke has uploaded a new change for review.
Change subject: fix remove: iterate while del
......................................................................
fix remove: iterate while del
Change-Id: I594c98cf54ed93d045b76df1c6faa5122277b19e
Signed-off-by: Adam Litke <alitke(a)redhat.com>
---
M vdsm/storage/blockSD.py
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/44572/1
diff --git a/vdsm/storage/blockSD.py b/vdsm/storage/blockSD.py
index 74bf82d..832fb8b 100644
--- a/vdsm/storage/blockSD.py
+++ b/vdsm/storage/blockSD.py
@@ -201,8 +201,8 @@
vols = _getVolsTree(sdUUID)
# Remove volumes awaiting garbage collection from the result
- for vol_id in vols.iterkeys():
- if vols[vol_id].garbage_meta_id is not None:
+ for vol_id, vol_info in vols.items():
+ if vol_info.garbage_meta_id is not None:
del vols[vol_id]
res = {}
--
To view, visit https://gerrit.ovirt.org/44572
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I594c98cf54ed93d045b76df1c6faa5122277b19e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: storage: Do not count garbage volumes as children
by alitke@redhat.com
Adam Litke has uploaded a new change for review.
Change subject: storage: Do not count garbage volumes as children
......................................................................
storage: Do not count garbage volumes as children
Change-Id: Ice3c70249cbc3577b239bd11d224955f2e29b211
Signed-off-by: Adam Litke <alitke(a)redhat.com>
---
M vdsm/storage/blockVolume.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/44573/1
diff --git a/vdsm/storage/blockVolume.py b/vdsm/storage/blockVolume.py
index 51f60ea..9baa3d2 100644
--- a/vdsm/storage/blockVolume.py
+++ b/vdsm/storage/blockVolume.py
@@ -184,7 +184,7 @@
lvs = lvm.lvsByTag(self.sdUUID,
"%s%s" % (TAG_PREFIX_PARENT, self.volUUID))
- return tuple(lv.name for lv in lvs if TAG_VOL_UNINIT not in lv.tags)
+ return tuple(lv.name for lv in lvs if TAG_VOL_GARBAGE not in lv.tags)
def getImage(self):
"""
--
To view, visit https://gerrit.ovirt.org/44573
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice3c70249cbc3577b239bd11d224955f2e29b211
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: storage: export volume lease state in getVolumeInfo
by alitke@redhat.com
Adam Litke has uploaded a new change for review.
Change subject: storage: export volume lease state in getVolumeInfo
......................................................................
storage: export volume lease state in getVolumeInfo
In order to support an entity-based polling methodology (ie. in the new
SDM verbs) we must know whether a volume is currently locked by a long
running operation. Extend the getVolumeInfo API to report whether the
lease is free or held.
Change-Id: I55f062a4be15593fdc98518fd0a113976cbe0ae7
Signed-off-by: Adam Litke <alitke(a)redhat.com>
---
M vdsm/rpc/vdsmapi-schema.json
M vdsm/storage/volume.py
2 files changed, 31 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/23/38623/1
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index 988ce64..cba1008 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -7897,6 +7897,19 @@
{'enum': 'VolumeStatus', 'data': ['OK', 'INVALID', 'ILLEGAL']}
##
+# @VolumeLeaseState:
+#
+# An enumeration of Volume lease states.
+#
+# @FREE: The lease is free
+#
+# @HELD: The lease is held
+#
+# Since: 4.10.0
+##
+{'enum': 'VolumeLeaseState', 'data': ['FREE', 'HELD']}
+
+##
# @VolumeInfo:
#
# Information about a Volume.
@@ -7937,6 +7950,8 @@
#
# @children: A list of decendent Volumes that depend on this Volume
#
+# @leaseState: #optional The state of the volume lease
+#
# Since: 4.10.0
##
{'type': 'VolumeInfo',
@@ -7946,7 +7961,8 @@
'description': 'str', 'pool': 'UUID', 'domain': 'UUID',
'image': 'UUID', 'ctime': 'int', '*mtime': 'uint',
'legality': 'VolumeLegality', 'apparentsize': 'uint',
- 'truesize': 'uint', 'status': 'VolumeStatus', 'children': ['UUID']}}
+ 'truesize': 'uint', 'status': 'VolumeStatus', 'children': ['UUID'],
+ '*leaseState': 'VolumeLeaseState'}}
##
# @Volume.getInfo:
diff --git a/vdsm/storage/volume.py b/vdsm/storage/volume.py
index 980b6e3..2e16efc 100644
--- a/vdsm/storage/volume.py
+++ b/vdsm/storage/volume.py
@@ -33,6 +33,7 @@
import fileUtils
import task
from threadLocal import vars
+from clusterlock import InquireNotSupportedError
import resourceFactories
import resourceManager as rm
rmanager = rm.ResourceManager.getInstance()
@@ -85,6 +86,10 @@
ILLEGAL_VOL = "ILLEGAL"
LEGAL_VOL = "LEGAL"
FAKE_VOL = "FAKE"
+
+# Volume lease states
+LEASE_FREE = "FREE"
+LEASE_HELD = "HELD"
log = logging.getLogger('Storage.Volume')
@@ -839,6 +844,11 @@
cls.createMetadata(metaId, meta)
return meta
+ def getLeaseState(self):
+ ver, owners = sdCache.produce(self.sdUUID).inquireVolumeLease(
+ self.imgUUID, self.volUUID)
+ return LEASE_HELD if owners else LEASE_FREE
+
def getInfo(self):
"""
Get volume info
@@ -857,6 +867,10 @@
info['apparentsize'] = str(vsize)
info['truesize'] = str(avsize)
info['status'] = "OK"
+ try:
+ info['leaseState'] = self.getLeaseState()
+ except InquireNotSupportedError:
+ pass
except se.StorageException as e:
self.log.debug("exception: %s:%s" % (str(e.message), str(e.value)))
info['apparentsize'] = "0"
--
To view, visit https://gerrit.ovirt.org/38623
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I55f062a4be15593fdc98518fd0a113976cbe0ae7
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: misc: remove cp parameter
by ykaplan@redhat.com
Yeela Kaplan has uploaded a new change for review.
Change subject: misc: remove cp parameter
......................................................................
misc: remove cp parameter
All usages of cp parameter have been extinguished.
Therefore, no longer needed.
Change-Id: I0906bfd7dfa128c323aa399810bbd75883618434
Signed-off-by: Yeela Kaplan <ykaplan(a)redhat.com>
---
M vdsm/storage/misc.py
1 file changed, 5 insertions(+), 13 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/13/45613/1
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index b14fd26..b0146c8 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -449,7 +449,7 @@
return n
-def rotateFiles(directory, prefixName, gen, cp=False, persist=False):
+def rotateFiles(directory, prefixName, gen, persist=False):
log.debug("dir: %s, prefixName: %s, versions: %s" %
(directory, prefixName, gen))
gen = int(gen)
@@ -477,24 +477,16 @@
for key in keys:
oldName = os.path.join(directory, fd[key]['old'])
newName = os.path.join(directory, fd[key]['new'])
- if utils.isOvirtNode() and persist and not cp:
+ if utils.isOvirtNode() and persist:
try:
utils.unpersist(oldName)
utils.unpersist(newName)
except:
pass
- try:
- if cp:
- execCmd([constants.EXT_CP, oldName, newName], sudo=True)
- if (utils.isOvirtNode() and
- persist and not os.path.exists(newName)):
- utils.persist(newName)
- else:
- os.rename(oldName, newName)
- except:
- pass
- if utils.isOvirtNode() and persist and not cp:
+ os.rename(oldName, newName)
+
+ if utils.isOvirtNode() and persist:
try:
utils.persist(newName)
except:
--
To view, visit https://gerrit.ovirt.org/45613
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0906bfd7dfa128c323aa399810bbd75883618434
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yeela Kaplan <ykaplan(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: freeze: Freeze guest even when creating memory snapshot
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: freeze: Freeze guest even when creating memory snapshot
......................................................................
freeze: Freeze guest even when creating memory snapshot
We used to skip freezing the guest if creating memory snapshot. This was
probably done because qemu is pausing the vm for creating memory
snapshot.
However, this is not consistent with snapshots of external disks such as
network disks, where we always freeze the vm before taking the snapshot.
Also, it is probably safer to freeze even when creating memory snapshot,
giving applications on the guest chance to pause in consistent state.
This patch removes the check for memory snapshot, and freeze the guest
unless it is already frozen.
Change-Id: I8aa7ac0dea8690ca33df8067f84734d788da8bf8
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M vdsm/virt/vm.py
1 file changed, 3 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/99/43299/1
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 332281b..ecbbe1d 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -3093,9 +3093,6 @@
else:
snapFlags |= libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY
- # When creating memory snapshot libvirt will pause the vm
- should_freeze = not (memoryParams or frozen)
-
snapxml = snap.toprettyxml()
# TODO: this is debug information. For 3.6.x we still need to
# see the XML even with 'info' as default level.
@@ -3109,7 +3106,7 @@
self.stopDisksStatsCollection()
try:
- if should_freeze:
+ if not frozen:
freezed = self.freeze()
try:
self._dom.snapshotCreateXML(snapxml, snapFlags)
@@ -3120,7 +3117,7 @@
# Must always thaw, even if freeze failed; in case the guest
# did freeze the filesystems, but failed to reply in time.
# Libvirt is using same logic (see src/qemu/qemu_driver.c).
- if should_freeze:
+ if not frozen:
self.thaw()
# We are padding the memory volume with block size of zeroes
@@ -3148,7 +3145,7 @@
# Returning quiesce to notify the manager whether the guest agent
# froze and flushed the filesystems or not.
return {'status': doneCode,
- 'quiesce': should_freeze and freezed["status"]["code"] == 0}
+ 'quiesce': not frozen and freezed["status"]["code"] == 0}
def diskReplicateStart(self, srcDisk, dstDisk):
try:
--
To view, visit https://gerrit.ovirt.org/43299
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8aa7ac0dea8690ca33df8067f84734d788da8bf8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 1 month
Change in vdsm[master]: log: Use INFO log level as default
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: log: Use INFO log level as default
......................................................................
log: Use INFO log level as default
The current logs are much too verbose which cause trouble for users, and
make us look unprofessional. Mature project should not use debug log by
default.
To debug issues that are not clear enough using INFO logs, the relevant
logger level can be modified on a user machine as needed.
Change-Id: I767dcd9bad7b9fbeebb438e9ef13cb0ec3f042ee
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M vdsm/logger.conf.in
1 file changed, 4 insertions(+), 4 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/04/32504/1
diff --git a/vdsm/logger.conf.in b/vdsm/logger.conf.in
index 64b154f..8e963dd 100644
--- a/vdsm/logger.conf.in
+++ b/vdsm/logger.conf.in
@@ -8,18 +8,18 @@
keys=long,simple,none,sysform
[logger_root]
-level=DEBUG
+level=INFO
handlers=syslog,logfile
propagate=0
[logger_vds]
-level=DEBUG
+level=INFO
handlers=syslog,logfile
qualname=vds
propagate=0
[logger_Storage]
-level=DEBUG
+level=INFO
handlers=logfile
qualname=Storage
propagate=0
@@ -31,7 +31,7 @@
propagate=1
[logger_connectivity]
-level=DEBUG
+level=INFO
handlers=connlogfile
qualname=connectivity
propagate=0
--
To view, visit http://gerrit.ovirt.org/32504
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I767dcd9bad7b9fbeebb438e9ef13cb0ec3f042ee
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 2 months
Change in vdsm[master]: tests: JsonRpcClient tests suite
by Piotr Kliczewski
Piotr Kliczewski has uploaded a new change for review.
Change subject: tests: JsonRpcClient tests suite
......................................................................
tests: JsonRpcClient tests suite
Signed-off-by: pkliczewski <piotr.kliczewski(a)gmail.com>
Change-Id: I48c209915f4047958fd9b7e5dd6a202ca14a50cb
---
M tests/Makefile.am
A tests/jsonrpcClientTests.py
M tests/stompAdapterTests.py
3 files changed, 159 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/82/43582/1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9a7f81f..a010bb3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,6 +57,7 @@
iproute2Tests.py \
ipwrapperTests.py \
iscsiTests.py \
+ jsonrpcClientTests.py \
jsonrpcServerTests.py \
libvirtconnectionTests.py \
lvmTests.py \
diff --git a/tests/jsonrpcClientTests.py b/tests/jsonrpcClientTests.py
new file mode 100644
index 0000000..5d4304f
--- /dev/null
+++ b/tests/jsonrpcClientTests.py
@@ -0,0 +1,148 @@
+#
+# Copyright 2015 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 Queue import Queue
+from threading import Event
+
+from testlib import VdsmTestCase as TestCaseBase
+from yajsonrpc.stompreactor import ClientRpcTransportAdapter
+from yajsonrpc import JsonRpcClient, JsonRpcRequest, JsonRpcResponse
+from yajsonrpc.stomp import Frame, Headers
+from vdsm.compat import json
+
+from stompAdapterTests import TestSubscription
+
+
+ID = 'e8a936a6-d886-4cfa-97b9-2d54209053ff'
+
+
+class TestClient(object):
+
+ def __init__(self):
+ self._queue = Queue()
+ self.closed = False
+
+ def send(self, data, destination, headers):
+ self._queue.put_nowait((data, destination, headers))
+
+ def pop_message(self):
+ return self._queue.get(True, 3)
+
+ @property
+ def has_outgoing_messages(self):
+ return (self._queue.qsize() > 0)
+
+ def close(self):
+ self.closed = True
+
+
+class JsonrpcClientTest(TestCaseBase):
+
+ def test_call(self):
+ subscription = TestSubscription('jms.topic.vdsm_responses',
+ 'ad052acb-a934-4e10-8ec3-00c7417ef8d1')
+ client = TestClient()
+ subscription.set_client(client)
+
+ json_client = JsonRpcClient(
+ ClientRpcTransportAdapter(subscription,
+ 'jms.topic.vdsm_requests',
+ client)
+ )
+
+ request = JsonRpcRequest('my_method', (), ID)
+ json_client.call(request, timeout=0)
+
+ self.assertTrue(client.has_outgoing_messages)
+ data, destination, headers = client.pop_message()
+
+ req = JsonRpcRequest.fromRawObject(json.loads(data)[0])
+ self.assertEquals(req.method, request.method)
+ self.assertEquals(req.id, request.id)
+
+ self.assertEquals('jms.topic.vdsm_requests', destination)
+
+ self.assertEquals(headers[Headers.CONTENT_TYPE], 'application/json')
+ self.assertEquals(headers[Headers.REPLY_TO],
+ 'jms.topic.vdsm_responses')
+
+ def test_async_call_with_response(self):
+ subscription = TestSubscription('jms.topic.vdsm_responses',
+ 'ad052acb-a934-4e10-8ec3-00c7417ef8d1')
+ client = TestClient()
+ subscription.set_client(client)
+
+ json_client = JsonRpcClient(
+ ClientRpcTransportAdapter(subscription,
+ 'jms.topic.vdsm_requests',
+ client)
+ )
+
+ request = JsonRpcRequest('my_method', (), ID)
+ call = json_client.call_async(request)
+
+ self.assertTrue(client.has_outgoing_messages)
+
+ response = JsonRpcResponse(result='my_response', reqId=ID)
+ subscription.process(Frame(body=response.encode()))
+
+ self.assertTrue(call.isSet())
+ self.assertEquals('my_response', call.responses[0].result)
+
+ def test_receive_event(self):
+ subscription = TestSubscription('jms.topic.vdsm_responses',
+ 'ad052acb-a934-4e10-8ec3-00c7417ef8d1')
+ client = TestClient()
+ subscription.set_client(client)
+ ev = Event()
+
+ json_client = JsonRpcClient(
+ ClientRpcTransportAdapter(subscription,
+ 'jms.topic.vdsm_requests',
+ client)
+ )
+
+ def callback(client, event, params):
+ self.assertEquals(event, 'localhost|component|operation|id')
+ self.assertEquals(params['my_property'], 'my_value')
+ ev.set()
+
+ json_client.registerEventCallback(callback)
+
+ event = JsonRpcRequest('localhost|component|operation|id',
+ {'my_property': 'my_value'})
+
+ subscription.process(Frame(body=event.encode()))
+ ev.wait(timeout=3)
+ self.assertTrue(ev.is_set())
+
+ def test_close(self):
+ subscription = TestSubscription('jms.topic.vdsm_responses',
+ 'ad052acb-a934-4e10-8ec3-00c7417ef8d1')
+ client = TestClient()
+
+ json_client = JsonRpcClient(
+ ClientRpcTransportAdapter(subscription,
+ 'jms.topic.vdsm_requests',
+ client)
+ )
+
+ json_client.close()
+ self.assertTrue(client.closed)
+ self.assertTrue(subscription.unsubscribed)
diff --git a/tests/stompAdapterTests.py b/tests/stompAdapterTests.py
index a0be47f..68fae77 100644
--- a/tests/stompAdapterTests.py
+++ b/tests/stompAdapterTests.py
@@ -60,6 +60,7 @@
def __init__(self, destination, id):
self._destination = destination
self._id = id
+ self.unsubscribed = False
def set_client(self, client):
self._client = TestConnection(client)
@@ -76,6 +77,15 @@
def client(self):
return self._client
+ def set_message_handler(self, message_handler):
+ self.handler = message_handler
+
+ def process(self, data):
+ self.handler(None, data)
+
+ def unsubscribe(self):
+ self.unsubscribed = True
+
class ConnectFrameTest(TestCaseBase):
--
To view, visit https://gerrit.ovirt.org/43582
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I48c209915f4047958fd9b7e5dd6a202ca14a50cb
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>
7 years, 2 months