Change in vdsm[master]: virt: Separate validation from getXML
nsoffer at redhat.com
nsoffer at redhat.com
Mon Apr 20 23:32:16 UTC 2015
Nir Soffer has uploaded a new change for review.
Change subject: virt: Separate validation from getXML
......................................................................
virt: Separate validation from getXML
Extract _validate() method and move the validation code into it, and add
missing tests for sgio and cow format.
Change-Id: I00916c13850e335fb13e74a13b52b71560bfb797
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/vmStorageTests.py
M vdsm/virt/vmdevices/storage.py
2 files changed, 27 insertions(+), 7 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/65/40065/1
diff --git a/tests/vmStorageTests.py b/tests/vmStorageTests.py
index 1d577c7..055d1c9 100644
--- a/tests/vmStorageTests.py
+++ b/tests/vmStorageTests.py
@@ -129,6 +129,22 @@
@expandPermutations
+class DriveValidation(VdsmTestCase):
+
+ @permutations([["disk"], ["cdrom"], ["floppy"]])
+ def test_sgio_without_lun(self, device):
+ self.check(device=device, sgio='unfiltered')
+
+ def test_cow_with_lun(self):
+ self.check(device='lun', format='cow')
+
+ def check(self, **kw):
+ conf = drive_config(**kw)
+ drive = Drive({}, self.log, **conf)
+ self.assertRaises(ValueError, drive.getXML)
+
+
+ at expandPermutations
class DriveExSharedStatusTests(VdsmTestCase):
def test_default_not_shared(self):
diff --git a/vdsm/virt/vmdevices/storage.py b/vdsm/virt/vmdevices/storage.py
index 5ace5cc..37ed8c9 100644
--- a/vdsm/virt/vmdevices/storage.py
+++ b/vdsm/virt/vmdevices/storage.py
@@ -323,6 +323,7 @@
<serial>54-a672-23e5b495a9ea</serial>
</disk>
"""
+ self._validate()
source = vmxml.Element('source')
if self.diskType == DISK_TYPE.BLOCK:
source.setAttrs(dev=self.path)
@@ -363,12 +364,6 @@
if hasattr(self, 'bootOrder'):
diskelem.appendChildWithArgs('boot', order=self.bootOrder)
- if self.device != 'lun' and hasattr(self, 'sgio'):
- raise ValueError("sgio attribute can be set only for LUN devices")
-
- if self.device == 'lun' and self.format == 'cow':
- raise ValueError("cow format is not supported for LUN devices")
-
if self.device == 'disk' or self.device == 'lun':
driverAttrs = {'name': 'qemu'}
if self.blockDev:
@@ -390,10 +385,19 @@
diskelem.appendChildWithArgs('driver', **driverAttrs)
if hasattr(self, 'specParams') and 'ioTune' in self.specParams:
- self._validateIoTuneParams(self.specParams['ioTune'])
iotune = vmxml.Element('iotune')
for key, value in self.specParams['ioTune'].iteritems():
iotune.appendChildWithArgs(key, text=str(value))
diskelem.appendChild(iotune)
return diskelem
+
+ def _validate(self):
+ if self.device != 'lun' and hasattr(self, 'sgio'):
+ raise ValueError("sgio attribute can be set only for LUN devices")
+
+ if self.device == 'lun' and self.format == 'cow':
+ raise ValueError("cow format is not supported for LUN devices")
+
+ if hasattr(self, 'specParams') and 'ioTune' in self.specParams:
+ self._validateIoTuneParams(self.specParams['ioTune'])
--
To view, visit https://gerrit.ovirt.org/40065
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I00916c13850e335fb13e74a13b52b71560bfb797
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>
More information about the vdsm-patches
mailing list