Nir Soffer has uploaded a new change for review.
Change subject: virt: Extract helpers for major XML elements ......................................................................
virt: Extract helpers for major XML elements
Now drive xml is built using small helper methods creating each of the elements. This is more maintainable and will allow creating drive replica xml without code duplication.
Change-Id: I6ef6a38d3abc14413f1001a8673f38fce8d828b7 Signed-off-by: Nir Soffer nsoffer@redhat.com --- M vdsm/virt/vmdevices/storage.py 1 file changed, 58 insertions(+), 45 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/40066/1
diff --git a/vdsm/virt/vmdevices/storage.py b/vdsm/virt/vmdevices/storage.py index 37ed8c9..799f66c 100644 --- a/vdsm/virt/vmdevices/storage.py +++ b/vdsm/virt/vmdevices/storage.py @@ -324,6 +324,35 @@ </disk> """ self._validate() + diskelem = self.createXmlElem('disk', self.diskType, + ['device', 'address', 'sgio']) + diskelem.setAttrs(snapshot='no') + + diskelem.appendChild(self._getSourceXML()) + diskelem.appendChild(self._getTargetXML()) + + if self.extSharedState == DRIVE_SHARED_TYPE.SHARED: + diskelem.appendChildWithArgs('shareable') + if hasattr(self, 'readonly') and utils.tobool(self.readonly): + diskelem.appendChildWithArgs('readonly') + elif self.device == 'floppy' and not hasattr(self, 'readonly'): + # floppies are used only internally for sysprep, so + # they are readonly unless explicitely stated otherwise + diskelem.appendChildWithArgs('readonly') + if hasattr(self, 'serial'): + diskelem.appendChildWithArgs('serial', text=self.serial) + if hasattr(self, 'bootOrder'): + diskelem.appendChildWithArgs('boot', order=self.bootOrder) + + if self.device == 'disk' or self.device == 'lun': + diskelem.appendChild(self._getDriverXML()) + + if hasattr(self, 'specParams') and 'ioTune' in self.specParams: + diskelem.appendChild(self._getIotuneXML()) + + return diskelem + + def _getSourceXML(self): source = vmxml.Element('source') if self.diskType == DISK_TYPE.BLOCK: source.setAttrs(dev=self.path) @@ -340,57 +369,41 @@ source.setAttrs(startupPolicy='optional') else: raise RuntimeError("Unsupported diskType %r", self.diskType) + return source
- diskelem = self.createXmlElem('disk', self.diskType, - ['device', 'address', 'sgio']) - diskelem.setAttrs(snapshot='no') - diskelem.appendChild(source) - - targetAttrs = {'dev': self.name} + def _getTargetXML(self): + target = vmxml.Element('target', dev=self.name) if self.iface: - targetAttrs['bus'] = self.iface - diskelem.appendChildWithArgs('target', **targetAttrs) + target.setAttrs(bus=self.iface) + return target
- if self.extSharedState == DRIVE_SHARED_TYPE.SHARED: - diskelem.appendChildWithArgs('shareable') - if hasattr(self, 'readonly') and utils.tobool(self.readonly): - diskelem.appendChildWithArgs('readonly') - elif self.device == 'floppy' and not hasattr(self, 'readonly'): - # floppies are used only internally for sysprep, so - # they are readonly unless explicitely stated otherwise - diskelem.appendChildWithArgs('readonly') - if hasattr(self, 'serial'): - diskelem.appendChildWithArgs('serial', text=self.serial) - if hasattr(self, 'bootOrder'): - diskelem.appendChildWithArgs('boot', order=self.bootOrder) + def _getDriverXML(self): + driver = vmxml.Element('driver') + driverAttrs = {'name': 'qemu'} + if self.blockDev: + driverAttrs['io'] = 'native' + else: + driverAttrs['io'] = 'threads' + if self.format == 'cow': + driverAttrs['type'] = 'qcow2' + elif self.format: + driverAttrs['type'] = 'raw'
- if self.device == 'disk' or self.device == 'lun': - driverAttrs = {'name': 'qemu'} - if self.blockDev: - driverAttrs['io'] = 'native' - else: - driverAttrs['io'] = 'threads' - if self.format == 'cow': - driverAttrs['type'] = 'qcow2' - elif self.format: - driverAttrs['type'] = 'raw' + driverAttrs['cache'] = self.cache
- driverAttrs['cache'] = self.cache + if (self.propagateErrors == 'on' or + utils.tobool(self.propagateErrors)): + driverAttrs['error_policy'] = 'enospace' + else: + driverAttrs['error_policy'] = 'stop' + driver.setAttrs(**driverAttrs) + return driver
- if (self.propagateErrors == 'on' or - utils.tobool(self.propagateErrors)): - driverAttrs['error_policy'] = 'enospace' - else: - driverAttrs['error_policy'] = 'stop' - diskelem.appendChildWithArgs('driver', **driverAttrs) - - if hasattr(self, 'specParams') and 'ioTune' in self.specParams: - iotune = vmxml.Element('iotune') - for key, value in self.specParams['ioTune'].iteritems(): - iotune.appendChildWithArgs(key, text=str(value)) - diskelem.appendChild(iotune) - - return diskelem + def _getIotuneXML(self): + iotune = vmxml.Element('iotune') + for key, value in self.specParams['ioTune'].iteritems(): + iotune.appendChildWithArgs(key, text=str(value)) + return iotune
def _validate(self): if self.device != 'lun' and hasattr(self, 'sgio'):
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 1:
Build Started (1/2) -> http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/18062/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 1:
Build Started (2/2) -> http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/17891/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 1:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/18062/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/17891/ : SUCCESS
Nir Soffer has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 1: Verified+1
Francesco Romani has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 1: Code-Review+1
nice refactoring
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 2:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 2:
Build Started (1/2) -> http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/17920/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 2:
Build Started (2/2) -> http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/18092/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 2:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/18092/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/17920/ : SUCCESS
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 3:
Build Started (1/2) -> http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18027/
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 3:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 3:
Build Started (2/2)
0 -> http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1256/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 3:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18027/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1256/ : 0
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 4:
Build Started (1/2) -> http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18135/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 4:
Build Started (2/2)
0 -> http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1365/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 4:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18135/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1365/ : 0
Nir Soffer has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 4: Verified+1
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 5:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 5:
Build Started (1/2) -> http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18179/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 5:
Build Started (2/2)
0 -> http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1409/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 5:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18179/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1409/ : 0
Adam Litke has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 5: Code-Review+2
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 6:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 6:
Build Started (1/2) -> http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18381/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 6:
Build Started (2/2) -> http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1611/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 6:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/18381/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/1611/ : SUCCESS
Federico Simoncelli has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 6: Code-Review+1
I haven't checked closely but it's just XML composition so it should be safe and any mistake easy to be caught in practice.
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 7:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Dan Kenigsberg has submitted this change and it was merged.
Change subject: virt: Extract helpers for major XML elements ......................................................................
virt: Extract helpers for major XML elements
Now drive xml is built using small helper methods creating each of the elements. This is more maintainable and will allow creating drive replica xml without code duplication.
Change-Id: I6ef6a38d3abc14413f1001a8673f38fce8d828b7 Signed-off-by: Nir Soffer nsoffer@redhat.com Reviewed-on: https://gerrit.ovirt.org/40066 Reviewed-by: Adam Litke alitke@redhat.com Reviewed-by: Federico Simoncelli fsimonce@redhat.com --- M vdsm/virt/vmdevices/storage.py 1 file changed, 61 insertions(+), 48 deletions(-)
Approvals: Adam Litke: Looks good to me, approved Nir Soffer: Verified Federico Simoncelli: Looks good to me, but someone else must approve
automation@ovirt.org has posted comments on this change.
Change subject: virt: Extract helpers for major XML elements ......................................................................
Patch Set 8:
* Update tracker::IGNORE, no Bug-Url found * Set MODIFIED::IGNORE, no Bug-Url found.
vdsm-patches@lists.fedorahosted.org