Change in vdsm[master]: Add unit tests for unified network persistence

amuller at redhat.com amuller at redhat.com
Thu Nov 14 13:21:23 UTC 2013


Assaf Muller has uploaded a new change for review.

Change subject: Add unit tests for unified network persistence
......................................................................

Add unit tests for unified network persistence

Change-Id: I0221f2e0313a80d0ed5ce2d5406dc45f08ab26dd
Signed-off-by: Assaf Muller <amuller at redhat.com>
---
A tests/netconfpersistenceTests.py
1 file changed, 79 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/69/21269/1

diff --git a/tests/netconfpersistenceTests.py b/tests/netconfpersistenceTests.py
new file mode 100644
index 0000000..f9ce7e7
--- /dev/null
+++ b/tests/netconfpersistenceTests.py
@@ -0,0 +1,79 @@
+#
+# Copyright 2013 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
+#
+
+import json
+import os
+from shutil import rmtree
+import tempfile
+
+from testrunner import VdsmTestCase as TestCaseBase
+
+from vdsm.netconfpersistence import Config
+
+NETWORK = 'luke'
+NETWORK_ATTRIBUTES = {'bonding': 'bond0', 'bridged': 'true', 'vlan': '1'}
+BONDING = 'skywalker'
+BONDING_ATTRIBUTES = {'options': 'mode=4 miimon=100', 'nics': ['eth0', 'eth1']}
+
+
+class netConfPersistenceTests(TestCaseBase):
+    def __init__(self, *args, **kwargs):
+        TestCaseBase.__init__(self, *args, **kwargs)
+        self.tempdir = tempfile.mkdtemp()
+        os.mkdir(os.path.join(self.tempdir, 'nets'))
+        os.mkdir(os.path.join(self.tempdir, 'bonds'))
+
+    def __del__(self):
+        rmtree(self.tempdir)
+
+    def testInit(self):
+        try:
+            filePath = os.path.join(self.tempdir, 'nets', NETWORK)
+            with open(filePath, 'w') as networkFile:
+                json.dump(NETWORK_ATTRIBUTES, networkFile)
+
+            persistence = Config(self.tempdir + os.sep)
+            self.assertEqual(persistence.networks[NETWORK], NETWORK_ATTRIBUTES)
+        finally:
+            os.remove(filePath)
+
+    def testSetAndRemoveNetwork(self):
+        persistence = Config(self.tempdir + os.sep)
+        persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
+        self.assertEqual(persistence.networks[NETWORK], NETWORK_ATTRIBUTES)
+        persistence.removeNetwork(NETWORK)
+        self.assertTrue(persistence.networks.get(NETWORK) is None)
+
+    def testSetAndRemoveBonding(self):
+        persistence = Config(self.tempdir + os.sep)
+        persistence.setBonding(BONDING, BONDING_ATTRIBUTES)
+        self.assertEqual(persistence.bonds[BONDING], BONDING_ATTRIBUTES)
+        persistence.removeBonding(BONDING)
+        self.assertTrue(persistence.bonds.get(BONDING) is None)
+
+    def testSaveAndDelete(self):
+        persistence = Config(self.tempdir + os.sep)
+        persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
+        filePath = os.path.join(self.tempdir, 'nets', NETWORK)
+        self.assertFalse(os.path.exists(filePath))
+        persistence.save()
+        self.assertTrue(os.path.exists(filePath))
+        persistence.delete()
+        self.assertFalse(os.path.exists(filePath))


-- 
To view, visit http://gerrit.ovirt.org/21269
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0221f2e0313a80d0ed5ce2d5406dc45f08ab26dd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Assaf Muller <amuller at redhat.com>


More information about the vdsm-patches mailing list