Change in vdsm[master]: tests: v2v: let the fake use VMs, not specs
fromani at redhat.com
fromani at redhat.com
Fri Nov 20 09:17:58 UTC 2015
Francesco Romani has uploaded a new change for review.
Change subject: tests: v2v: let the fake use VMs, not specs
......................................................................
tests: v2v: let the fake use VMs, not specs
Simplify the faking in v2vtests in two ways:
- make the vm specs an instance attribute, not
a local variable. This way it is way less clumsy
to check that a VM matches the spec (e.g. mac from UUID).
Furthermore, we should not recreate the same data on
each function call
- make the fake deal with VM, not create the VM internally
using the given specs. This is more flexible.
The improvements on this patch are small, but this patch
mostly paves the road for the next one, which want to add
a new test.
Change-Id: I3ddb451c21a96b5dd8391e5625bc313f20395dd4
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/v2vTests.py
1 file changed, 17 insertions(+), 17 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/54/48854/1
diff --git a/tests/v2vTests.py b/tests/v2vTests.py
index f9308f5..386d192 100644
--- a/tests/v2vTests.py
+++ b/tests/v2vTests.py
@@ -97,17 +97,14 @@
# FIXME: extend vmfakelib allowing to set predefined domain in Connection class
class LibvirtMock(object):
- def __init__(self,
- vmspecs=(
- VmSpec("RHEL", "564d7cb4-8e3d-06ec-ce82-7b2b13c6a611"),
- )):
- self._vmspecs = vmspecs
+ def __init__(self, vms):
+ self._vms = vms
def close(self):
pass
def listAllDomains(self):
- return [VmMock(*spec) for spec in self._vmspecs]
+ return self._vms
def storageVolLookupByPath(self, name):
return LibvirtMock.Volume()
@@ -153,27 +150,29 @@
class v2vTests(TestCaseBase):
+ _VM_SPECS = (
+ VmSpec("RHEL_0", str(uuid.uuid4())),
+ VmSpec("RHEL_1", str(uuid.uuid4())),
+ VmSpec("RHEL_2", str(uuid.uuid4()))
+ )
+
+ _VMS = [VmMock(*spec) for spec in _VM_SPECS]
+
def testGetExternalVMs(self):
if not v2v.supported():
raise SkipTest('v2v is not supported current os version')
- vmspecs = (
- VmSpec("RHEL_0", str(uuid.uuid4())),
- VmSpec("RHEL_1", str(uuid.uuid4())),
- VmSpec("RHEL_2", str(uuid.uuid4()))
- )
-
def _connect(uri, username, passwd):
- return LibvirtMock(vmspecs=vmspecs)
+ return LibvirtMock(vms=self._VMS)
with MonkeyPatchScope([(libvirtconnection, 'open_connection',
_connect)]):
vms = v2v.get_external_vms('esx://mydomain', 'user',
ProtectedPassword('password'))['vmList']
- self.assertEqual(len(vms), len(vmspecs))
+ self.assertEqual(len(vms), len(self._VM_SPECS))
- for vm, spec in zip(vms, vmspecs):
+ for vm, spec in zip(vms, self._VM_SPECS):
self._assertVmMatchesSpec(vm, spec)
self._assertVmDisksMatchSpec(vm, spec)
@@ -230,7 +229,8 @@
def internal_error(name):
raise fake.Error(libvirt.VIR_ERR_INTERNAL_ERROR)
- mock = LibvirtMock()
+ # we need a sequence of just one vm
+ mock = LibvirtMock(vms=self._VMS[:1])
mock.storageVolLookupByPath = internal_error
def _connect(uri, username, passwd):
@@ -241,7 +241,7 @@
vms = v2v.get_external_vms('esx://mydomain', 'user',
ProtectedPassword('password'))['vmList']
self.assertEquals(len(vms), 1)
- self._assertVmMatchesSpec(vms[0], mock._vmspecs[0])
+ self._assertVmMatchesSpec(vms[0], self._VM_SPECS[0])
for disk in vms[0]['disks']:
self.assertNotIn('capacity', disk)
self.assertNotIn('allocation', disk)
--
To view, visit https://gerrit.ovirt.org/48854
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ddb451c21a96b5dd8391e5625bc313f20395dd4
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