Change in vdsm[master]: vm: use the new response handling
fromani at redhat.com
fromani at redhat.com
Wed Mar 16 09:48:03 UTC 2016
Francesco Romani has uploaded a new change for review.
Change subject: vm: use the new response handling
......................................................................
vm: use the new response handling
Let's start using the new api.method
decoratore to handle exceptions and response
from few methods already in need of some
refactoring and cleanup.
Change-Id: Ib594a5cc6cd8945c24cfcb3704ad92d02102993b
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/vm.py
1 file changed, 19 insertions(+), 31 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/99/54799/1
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index f1b2a95..17cacfe 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -39,6 +39,7 @@
from vdsm import concurrent
from vdsm import constants
from vdsm import cpuarch
+from vdsm import exception
from vdsm import host
from vdsm import hooks
from vdsm import hostdev
@@ -54,6 +55,7 @@
from vdsm.define import ERROR, NORMAL, doneCode, errCode
from vdsm.logUtils import SimpleLogAdapter
from vdsm.netinfo import DUMMY_BRIDGE
+from vdsm.virt import api
from vdsm.virt import guestagent
from vdsm.virt import sampling
from vdsm.virt import vmchannels
@@ -2560,6 +2562,7 @@
return tunables
+ @api.method
def setIoTune(self, tunables):
for io_tune_change in tunables:
device_name = io_tune_change.get('name', None)
@@ -2570,8 +2573,7 @@
found_device = self._findDeviceByNameOrPath(device_name,
device_path)
if found_device is None:
- return response.error(
- 'updateIoTuneErr',
+ raise exception.UpdateIOTuneError(
"Device {} not found".format(device_name))
# Merge the update with current values
@@ -2587,8 +2589,7 @@
try:
found_device._validateIoTuneParams(io_tune)
except ValueError:
- return self._reportException(key='updateIoTuneErr',
- msg='Invalid ioTune value')
+ raise exception.UpdateIOTuneError('Invalid ioTune value')
try:
self._dom.setBlockIoTune(found_device.name, io_tune,
@@ -2596,9 +2597,9 @@
except libvirt.libvirtError as e:
self.log.exception("setVmIoTune failed")
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
- return response.error('noVM')
+ raise exception.NoSuchVM()
else:
- return response.error('updateIoTuneErr', e.message)
+ raise exception.UpdateIOTuneError(e.message)
# Update both the ioTune arguments and device xml DOM
# so we are still up-to-date
@@ -2618,8 +2619,6 @@
self.log.info("New device XML for %s: %s",
found_device.name, xml)
found_device._deviceXML = xml
-
- return {'status': doneCode}
def _createTransientDisk(self, diskParams):
if (diskParams.get('shared', None) !=
@@ -3967,20 +3966,20 @@
else:
return response.success()
+ @api.method
def setBalloonTarget(self, target):
if not self._dom.connected:
- return response.error('balloonErr')
+ raise exception.BalloonError()
try:
target = int(target)
self._dom.setMemory(target)
except ValueError:
- return self._reportException(
- key='balloonErr', msg='an integer is required for target')
+ raise exception.BalloonError('an integer is required for target')
except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
- return self._reportException(key='noVM')
- return self._reportException(key='balloonErr', msg=e.message)
+ raise exception.NoSuchVM()
+ raise exception.BalloonError(e.message)
else:
for dev in self.conf['devices']:
if dev['type'] == hwclass.BALLOON and \
@@ -3988,28 +3987,27 @@
dev['target'] = target
# persist the target value to make it consistent after recovery
self.saveState()
- return {'status': doneCode}
+ @api.method
def setCpuTuneQuota(self, quota):
try:
self._dom.setSchedulerParameters({'vcpu_quota': int(quota)})
except ValueError:
- return response.error('cpuTuneErr',
- 'an integer is required for period')
+ raise exception.CpuTuneError('an integer is required for quota')
except libvirt.libvirtError as e:
- return self._reportException(key='cpuTuneErr', msg=e.message)
+ raise exception.CpuTuneError(e.message)
else:
# libvirt may change the value we set, so we must get fresh data
return self._updateVcpuTuneInfo()
+ @api.method
def setCpuTunePeriod(self, period):
try:
self._dom.setSchedulerParameters({'vcpu_period': int(period)})
except ValueError:
- return response.error('cpuTuneErr',
- 'an integer is required for period')
+ raise exception.CpuTuneError('an integer is required for period')
except libvirt.libvirtError as e:
- return self._reportException(key='cpuTuneErr', msg=e.message)
+ raise exception.CpuTuneError(e.message)
else:
# libvirt may change the value we set, so we must get fresh data
return self._updateVcpuTuneInfo()
@@ -4018,17 +4016,7 @@
try:
self._vcpuTuneInfo = self._dom.schedulerParameters()
except libvirt.libvirtError as e:
- return self._reportException(key='cpuTuneErr', msg=e.message)
- else:
- return {'status': doneCode}
-
- def _reportException(self, key, msg=None):
- """
- Convert an exception to an error status.
- This method should be called only within exception-handling context.
- """
- self.log.exception("Operation failed")
- return response.error(key, msg)
+ raise exception.CpuTuneError(e.message)
def _getUnderlyingUnknownDeviceInfo(self):
"""
--
To view, visit https://gerrit.ovirt.org/54799
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib594a5cc6cd8945c24cfcb3704ad92d02102993b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list