WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Added unit test for the DevController subclasses.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Added unit test for the DevController subclasses.
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Nov 2005 16:16:07 +0000
Delivery-date: Mon, 21 Nov 2005 16:16:21 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Added unit test for the DevController subclasses., Xen patchbot -unstable <=