Change in vdsm[master]: tests: basic scaffolding tests gor getUnderlying*
fromani at redhat.com
fromani at redhat.com
Fri Mar 20 12:01:14 UTC 2015
Francesco Romani has uploaded a new change for review.
Change subject: tests: basic scaffolding tests gor getUnderlying*
......................................................................
tests: basic scaffolding tests gor getUnderlying*
We want to refactor and cleanup Vm.getUnderlying*
and move this code where really belongs, vmdevices classes.
We have good intentions and a plan which is mostly code moving and
includes adding more unit tests and good coverage, but we are
also dealing with a big chunk of code which is very poorly covered
by tests.
To bootstrap the process and to have a decent hope which nothing
obvious breaks, add unit test to exercise the basic flow.
This test *is* fragile and the code *has* many flows and quirks,
so this must be intended as temporary scaffolding to provide
only very minimal safety.
Change-Id: I7609d346d7cef41286674e4b1443856ab088bc4c
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M Makefile.am
M tests/Makefile.am
M tests/deviceTests.py
3 files changed, 55 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/76/38976/1
diff --git a/Makefile.am b/Makefile.am
index 34885a1..0520da5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -75,6 +75,7 @@
config.py \
constants.py \
crossImportsTests.py \
+ deviceTestsData.py \
vdsm.py \
$(NULL)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 39bad01..29910a9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -32,6 +32,7 @@
configNetworkTests.py \
cpuProfileTests.py \
deviceTests.py \
+ deviceTestsData.py \
domainDescriptorTests.py \
executorTests.py \
fileSDTests.py \
diff --git a/tests/deviceTests.py b/tests/deviceTests.py
index 2e69b40..c05ef14 100644
--- a/tests/deviceTests.py
+++ b/tests/deviceTests.py
@@ -20,12 +20,15 @@
from vdsm import libvirtconnection
from virt import vmdevices
-from virt.vmdevices import hwclass
+from virt.vmdevices import hwclass, hwtree
from virt.domain_descriptor import DomainDescriptor
from monkeypatch import MonkeyPatchScope
from testlib import permutations, expandPermutations
+from testlib import VdsmTestCase as TestCaseBase
from testlib import XMLTestCase
import vmfakelib as fake
+
+import deviceTestsData as testdata
@expandPermutations
@@ -460,3 +463,52 @@
if graph.device == 'spice':
self.assertXMLEqual(graph.getSpiceVmcChannelsXML().toxml(),
spiceChannelXML)
+
+
+class VmDeviceUpdateTests(TestCaseBase):
+
+ def test_get_underlying_update_config_alias_address(self):
+ with fake.VM(testdata.VM_CONF_BASE) as testvm:
+ testvm._dom = fake.Domain(xml=testdata.DOMAIN_XML_LIVE)
+
+ self._setupDevices(testvm)
+
+ self._assertDeviceConfUpdated(testvm.conf['devices'],
+ testdata.VM_CONF_LIVE['devices'])
+
+ def _setupDevices(self, testvm):
+ devices = testvm.buildConfDevices()
+ testvm._updateDevices(devices)
+ testvm._devices = hwtree.build(devices, testvm.conf, testvm.log)
+
+ testvm._updateDomainDescriptor()
+ testvm._getUnderlyingVmDevicesInfo()
+
+ def _assertDeviceConfUpdated(self, built_devices, expected_devices):
+ for built_dev in built_devices:
+ # drives require more care, not yet in scope
+ if built_dev['type'] == hwclass.DISK:
+ continue
+
+ found = False
+ if 'alias' in built_dev:
+ for expected_dev in expected_devices:
+ # we deal with list of dicts, we must
+ # match by alias. We implicitely validate
+ # the alias being correct, this way.
+ if 'alias' in expected_dev and (
+ expected_dev['alias'] == built_dev['alias']):
+ if ('address' in built_dev and
+ 'address' in expected_dev):
+ self.assertEqual(built_dev['address'],
+ expected_dev['address'])
+ else:
+ # cope with video device oddity.
+ # TODO: is this correct?
+ self.assertEqual(built_dev, expected_dev)
+ found = True
+
+ # graphics device needs special care, and we can deal with that.
+ if not found and built_dev['type'] != hwclass.GRAPHICS:
+ raise AssertionError(
+ 'device %s built but not expected' % str(built_dev))
--
To view, visit https://gerrit.ovirt.org/38976
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7609d346d7cef41286674e4b1443856ab088bc4c
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