Petr Horáček has uploaded a new change for review.

Change subject: net tests: separate ifcfg and libvirt unit tests
......................................................................

net tests: separate ifcfg and libvirt unit tests

Change-Id: Ieca34a3f361586346d76ec22b11554c4a7c6e84d
---
M tests/network/conf_test.py
A tests/network/libvirt_test.py
2 files changed, 68 insertions(+), 38 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/90/65090/1

diff --git a/tests/network/conf_test.py b/tests/network/conf_test.py
index d94b5e6..e648c43 100644
--- a/tests/network/conf_test.py
+++ b/tests/network/conf_test.py
@@ -23,11 +23,9 @@
 from __future__ import absolute_import
 import os
 import pwd
-import re
 import shutil
 import subprocess
 import tempfile
-import xml.etree.ElementTree as ET
 
 from vdsm.network import libvirt
 from vdsm.network.configurators import ifcfg
@@ -64,19 +62,6 @@
                 with open(fn) as f:
                     restoredContent = f.read()
                 self.assertEqual(content, restoredContent)
-
-    def assertEqualXml(self, a, b, msg=None):
-        """
-        Compare two xml strings for equality.
-        """
-
-        aXml = ET.tostring(ET.fromstring(a))
-        bXml = ET.tostring(ET.fromstring(b))
-
-        aXmlNrml = re.sub('>\s*\n\s*<', '><', aXml).strip()
-        bXmlNrml = re.sub('>\s*\n\s*<', '><', bXml).strip()
-
-        self.assertEqual(aXmlNrml, bXmlNrml, msg)
 
     def setUp(self):
         self._tempdir = tempfile.mkdtemp()
@@ -134,26 +119,3 @@
             self._cw.restorePersistentBackup()
 
             self._assertFilesRestored()
-
-    def testCreateNetXmlBridged(self):
-        expectedDoc = """<network>
-                           <name>vdsm-awesome_net</name>
-                           <forward mode='bridge'/>
-                           <bridge name='awesome_net'/>
-                         </network>"""
-        actualDoc = libvirt.createNetworkDef('awesome_net', bridged=True)
-
-        self.assertEqualXml(expectedDoc, actualDoc)
-
-    def testCreateNetXml(self):
-        iface = "dummy"
-        expectedDoc = ("""<network>
-                            <name>vdsm-awesome_net</name>
-                            <forward mode='passthrough'>
-                            <interface dev='%s'/>
-                            </forward>
-                          </network>""" % iface)
-        actualDoc = libvirt.createNetworkDef('awesome_net', bridged=False,
-                                             iface=iface)
-
-        self.assertEqualXml(expectedDoc, actualDoc)
diff --git a/tests/network/libvirt_test.py b/tests/network/libvirt_test.py
new file mode 100644
index 0000000..95cc240
--- /dev/null
+++ b/tests/network/libvirt_test.py
@@ -0,0 +1,68 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301  USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from __future__ import absolute_import
+
+import re
+import xml.etree.ElementTree as ET
+
+from vdsm.network import libvirt
+
+from nose.plugins.attrib import attr
+from testlib import VdsmTestCase as TestCaseBase
+
+
+@attr(type='unit')
+class LibvirtTests(TestCaseBase):
+
+    def assertEqualXml(self, a, b, msg=None):
+        """
+        Compare two xml strings for equality.
+        """
+
+        aXml = ET.tostring(ET.fromstring(a))
+        bXml = ET.tostring(ET.fromstring(b))
+
+        aXmlNrml = re.sub('>\s*\n\s*<', '><', aXml).strip()
+        bXmlNrml = re.sub('>\s*\n\s*<', '><', bXml).strip()
+
+        self.assertEqual(aXmlNrml, bXmlNrml, msg)
+
+    def testCreateNetXmlBridged(self):
+        expectedDoc = """<network>
+                           <name>vdsm-awesome_net</name>
+                           <forward mode='bridge'/>
+                           <bridge name='awesome_net'/>
+                         </network>"""
+        actualDoc = libvirt.createNetworkDef('awesome_net', bridged=True)
+
+        self.assertEqualXml(expectedDoc, actualDoc)
+
+    def testCreateNetXml(self):
+        iface = "dummy"
+        expectedDoc = ("""<network>
+                            <name>vdsm-awesome_net</name>
+                            <forward mode='passthrough'>
+                            <interface dev='%s'/>
+                            </forward>
+                          </network>""" % iface)
+        actualDoc = libvirt.createNetworkDef('awesome_net', bridged=False,
+                                             iface=iface)
+
+        self.assertEqualXml(expectedDoc, actualDoc)


-- 
To view, visit https://gerrit.ovirt.org/65090
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieca34a3f361586346d76ec22b11554c4a7c6e84d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phora...@redhat.com>
_______________________________________________
vdsm-patches mailing list -- vdsm-patches@lists.fedorahosted.org
To unsubscribe send an email to vdsm-patches-le...@lists.fedorahosted.org

Reply via email to