Change in vdsm[master]: vm: move device attached check to device itself
mmirecki at redhat.com
mmirecki at redhat.com
Sat Nov 21 13:28:15 UTC 2015
Marcin Mirecki has uploaded a new change for review.
Change subject: vm: move device attached check to device itself
......................................................................
vm: move device attached check to device itself
Moving the check for being attached to the device in question.
Change-Id: I4df478798bc774c1134ca36879abd809ea2b6380
Signed-off-by: Marcin Mirecki <mmirecki at redhat.com>
---
M tests/vmTests.py
M vdsm/virt/vm.py
M vdsm/virt/vmdevices/network.py
M vdsm/virt/vmdevices/storage.py
4 files changed, 11 insertions(+), 9 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/81/48881/1
diff --git a/tests/vmTests.py b/tests/vmTests.py
index 176a5cc..4a5a487 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -44,6 +44,8 @@
from vdsm import define
from vdsm import password
from vdsm import response
+from virt.vmdevices.storage import Drive
+from virt.vmdevices.storage import DISK_TYPE
from testlib import VdsmTestCase as TestCaseBase
from testlib import permutations, expandPermutations
from testlib import find_xml_element
@@ -1251,11 +1253,9 @@
self.assertFalse(response.is_error(testvm.acpiShutdown()))
def test_wait_for_device_removal(self):
- class Device(object):
- pass
- drive = Device()
+ drive = Drive({}, log=self.log, index=0, path='test_path', iface="")
drive.name = ''
- drive.xpath = "./devices/disk/source[@file='test_path']"
+ drive.diskType = DISK_TYPE.FILE
with fake.VM() as testvm:
testvm._dom = FakeVmDom(999)
testvm._hotunplug_timeout = 1
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 5f4bd57..567d300 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -2688,7 +2688,7 @@
with utils.stopwatch("Hotunplug device %s" % device.name):
deadline = (utils.monotonic_time() +
self._hotunplug_timeout)
- while self._is_device_attached(device):
+ while device.is_attached_to(ET.fromstring(self._dom.XMLDesc(0))):
self._wait_for_sleep()
if utils.monotonic_time() > deadline:
raise HotunplugTimeout("Timeout detaching device %s"
@@ -2696,10 +2696,6 @@
def _wait_for_sleep(self):
time.sleep(1)
-
- def _is_device_attached(self, device):
- root = ET.fromstring(self._dom.XMLDesc(0))
- return bool(root.findall(device.xpath))
def _readPauseCode(self):
state, reason = self._dom.state(0)
diff --git a/vdsm/virt/vmdevices/network.py b/vdsm/virt/vmdevices/network.py
index 76f70db..80c82b4 100644
--- a/vdsm/virt/vmdevices/network.py
+++ b/vdsm/virt/vmdevices/network.py
@@ -192,3 +192,6 @@
The path is relative to the root element
"""
return "./devices/interface/mac[@address='%s']" % self.macAddr
+
+ def is_attached_to(self, dom):
+ return bool(dom.findall(self.xpath))
diff --git a/vdsm/virt/vmdevices/storage.py b/vdsm/virt/vmdevices/storage.py
index ea4b223..eda6522 100644
--- a/vdsm/virt/vmdevices/storage.py
+++ b/vdsm/virt/vmdevices/storage.py
@@ -435,6 +435,9 @@
return "./devices/disk/source[@%s='%s']" \
% (source_key[self.diskType], self.path)
+ def is_attached_to(self, dom):
+ return bool(dom.findall(self.xpath))
+
def _getSourceXML(drive):
source = vmxml.Element('source')
--
To view, visit https://gerrit.ovirt.org/48881
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4df478798bc774c1134ca36879abd809ea2b6380
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Marcin Mirecki <mmirecki at redhat.com>
More information about the vdsm-patches
mailing list