# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 5b0a7cac1087f98f0a1b4f1c3aedac901bbad2ee
# Parent 2cfded7de82f43bde8cd74b390de1ca5fb476762
Added unit test for the DevController subclasses.
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
diff -r 2cfded7de82f -r 5b0a7cac1087 tools/python/setup.py
--- a/tools/python/setup.py Mon Nov 21 11:40:02 2005
+++ b/tools/python/setup.py Mon Nov 21 11:41:39 2005
@@ -45,6 +45,7 @@
'xen.sv',
'xen.xend.tests',
+ 'xen.xend.server.tests',
'xen.xm.tests'
],
ext_package = "xen.lowlevel",
diff -r 2cfded7de82f -r 5b0a7cac1087
tools/python/xen/xend/server/tests/__init__.py
--- /dev/null Mon Nov 21 11:40:02 2005
+++ b/tools/python/xen/xend/server/tests/__init__.py Mon Nov 21 11:41:39 2005
@@ -0,0 +1,1 @@
+
diff -r 2cfded7de82f -r 5b0a7cac1087
tools/python/xen/xend/server/tests/test_controllers.py
--- /dev/null Mon Nov 21 11:40:02 2005
+++ b/tools/python/xen/xend/server/tests/test_controllers.py Mon Nov 21
11:41:39 2005
@@ -0,0 +1,81 @@
+import os
+import re
+import unittest
+
+import xen.xend.XendRoot
+
+xen.xend.XendRoot.XendRoot.config_default = '/dev/null'
+
+from xen.xend.server import netif
+
+
+FAKE_DOMID = 42
+FAKE_DEVID = 63
+
+
+xroot = xen.xend.XendRoot.instance()
+
+
+class test_controllers(unittest.TestCase):
+
+ def testNetif(self):
+ controller = self.controllerInstance(netif.NetifController)
+
+ self.assertNetif(controller.getDeviceDetails(['vif']), None)
+ self.assertNetif(
+ controller.getDeviceDetails(
+ ['vif', ['mac', 'aa:bb:cc:dd:ee:ff']]),
+ 'aa:bb:cc:dd:ee:ff')
+
+
+ def assertNetif(self, results, expectedMac):
+
+ (devid, backdets, frontdets) = results
+
+ self.assertEqual(devid, FAKE_DEVID)
+
+ self.assertEqual(backdets['handle'], str(FAKE_DEVID))
+ self.assertEqual(backdets['script'],
+ os.path.join(xroot.network_script_dir,
+ xroot.get_vif_script()))
+ self.assertValidMac(backdets['mac'], expectedMac)
+
+ self.assertEqual(frontdets['handle'], str(FAKE_DEVID))
+ self.assertValidMac(frontdets['mac'], expectedMac)
+
+
+ MAC_REGEXP = re.compile('^' +
+ ':'.join([r'[0-9a-f][0-9a-f]'
+ for i in range(0, 6)]) +
+ '$')
+
+ def assertValidMac(self, mac, expected):
+ if expected:
+ self.assertEqual(mac, expected)
+ else:
+ self.assert_(self.MAC_REGEXP.match(mac))
+
+
+ def controllerInstance(self, cls):
+ """Allocate an instance of the given controller class, and override
+ methods as appropriate so that we can run tests without needing
+ Xenstored."""
+
+ result = cls(FakeXendDomainInfo())
+
+ result.allocateDeviceID = fakeID
+
+ return result
+
+
+class FakeXendDomainInfo:
+ def getDomainPath(self):
+ return "/test/fake/domain/%d/" % FAKE_DOMID
+
+
+def fakeID():
+ return FAKE_DEVID
+
+
+def test_suite():
+ return unittest.makeSuite(test_controllers)
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|