Assaf Muller has uploaded a new change for review.

Change subject: Functional Tests [1/3]: Added module for dummy nics
......................................................................

Functional Tests [1/3]: Added module for dummy nics

Added setLinkUpDummy, setLinkDownDummy, setIPDummy
These methods will be used in an upcoming test

Change-Id: I1c7ed4110cd8d45a3fb7a9cc2cd2dc07004e96b9
Signed-off-by: Assaf Muller <[email protected]>
---
M tests/functional/Makefile.am
A tests/functional/dummyUtils.py
M tests/functional/networkTests.py
M tests/functional/utils.py
4 files changed, 105 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/39/18039/1

diff --git a/tests/functional/Makefile.am b/tests/functional/Makefile.am
index 50e643a..b59c5e1 100644
--- a/tests/functional/Makefile.am
+++ b/tests/functional/Makefile.am
@@ -21,6 +21,7 @@
 vdsmfunctestsdir = ${vdsmtestsdir}/functional
 
 dist_vdsmfunctests_PYTHON = \
+    dummyUtils.py \
        momTests.py \
        networkTests.py \
        sosPluginTests.py \
diff --git a/tests/functional/dummyUtils.py b/tests/functional/dummyUtils.py
new file mode 100644
index 0000000..60cf394
--- /dev/null
+++ b/tests/functional/dummyUtils.py
@@ -0,0 +1,102 @@
+#
+# 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 random
+from contextlib import contextmanager
+
+from nose.plugins.skip import SkipTest
+from vdsm import utils
+
+from utils import ip
+from utils import SUCCESS
+
+
+def create():
+    """
+    Creates a dummy interface, in a fixed number of attempts (100).
+    The dummy interface created has a pseudo-random name (e.g. dummy_85
+    in the format dummy_Number). Assumes root privileges.
+    """
+
+    rc = -1
+    for i in random.sample(xrange(100), 100):
+        dummy_name = 'dummy_%s' % i
+        ip_add_dummy = [ip.cmd, 'link', 'add', dummy_name,
+                        'type', 'dummy']
+        rc, out, err = utils.execCmd(ip_add_dummy, sudo=True)
+        if rc == SUCCESS:
+            return dummy_name
+
+    if rc != SUCCESS:
+        raise SkipTest('Failed to load a dummy interface')
+
+
+def remove(dummyName):
+    """
+    Removes dummy interface dummyName. Assumes root privileges.
+    """
+
+    ip_rm_dummy = [ip.cmd, 'link', 'delete',
+                   dummyName, 'type', 'dummy']
+    rc, out, err = utils.execCmd(ip_rm_dummy, sudo=True)
+    if rc != SUCCESS:
+        raise SkipTest("Unable to delete dummy interface:"
+                       " %s see %s %s" % (dummyName, out, err))
+
+
+def setIP(dummyName, ipaddr):
+    setDeviceIP = [ip.cmd, 'address', 'add', ipaddr, 'dev', dummyName]
+    rc, _, _ = utils.execCmd(setDeviceIP, sudo=True)
+    if rc == SUCCESS:
+        return
+
+    raise SkipTest('Failed to set device ip')
+
+
+def setLinkUp(dummyName):
+    _setLinkState(dummyName, 'up')
+
+
+def setLinkDown(dummyName):
+    _setLinkState(dummyName, 'down')
+
+
+def _setLinkState(dummyName, state):
+    activateDevice = [ip.cmd, 'link', 'set', 'dev', dummyName, state]
+    rc, _, _ = utils.execCmd(activateDevice, sudo=True)
+    if rc == SUCCESS:
+        return
+
+    raise SkipTest('Failed to bring device %s' % state)
+
+
+@contextmanager
+def dummyIf(num):
+    """
+    Manages a list of num dummy interfaces. Assumes root privileges.
+    """
+
+    dummies = []
+    try:
+        dummies = [create() for _ in range(num)]
+        yield dummies
+    except Exception:
+        raise
+    finally:
+        for dummy in dummies:
+            remove(dummy)
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 9e35120..5fbbc73 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -22,7 +22,8 @@
                         expandPermutations, permutations)
 from testValidation import RequireDummyMod, ValidateRunningAsRoot
 
-from utils import cleanupNet, dummyIf, restoreNetConfig, SUCCESS, VdsProxy
+from utils import cleanupNet, restoreNetConfig, SUCCESS, VdsProxy
+from dummyUtils import dummyIf
 
 
 NETWORK_NAME = 'test-network'
diff --git a/tests/functional/utils.py b/tests/functional/utils.py
index 1b8cdd3..a88d998 100644
--- a/tests/functional/utils.py
+++ b/tests/functional/utils.py
@@ -19,11 +19,8 @@
 from collections import namedtuple
 from contextlib import contextmanager
 from functools import wraps
-import random
 import time
 import threading
-
-from nose.plugins.skip import SkipTest
 
 from vdsm import netinfo
 from vdsm import vdscli
@@ -44,57 +41,6 @@
                             "/sbin/service",      # EL6
                             "/usr/sbin/service",  # Fedora
                             )
-
-
-def createDummy():
-    """
-    Creates a dummy interface, in a fixed number of attempts (100).
-    The dummy interface created has a pseudo-random name (e.g. dummy_85
-    in the format dummy_Number). Assumes root privileges.
-    """
-
-    rc = -1
-    dummy_name = None
-    for i in random.sample(xrange(100), 100):
-        dummy_name = 'dummy_%s' % i
-        ip_add_dummy = [ip.cmd, 'link', 'add', dummy_name,
-                        'type', 'dummy']
-        rc, out, err = utils.execCmd(ip_add_dummy, sudo=True)
-        if rc == SUCCESS:
-            return dummy_name
-
-    if rc != SUCCESS:
-        raise SkipTest('Failed to load a dummy interface')
-
-
-def removeDummy(dummyName):
-    """
-    Removes dummy interface dummyName. Assumes root privileges.
-    """
-
-    ip_rm_dummy = [ip.cmd, 'link', 'delete',
-                   dummyName, 'type', 'dummy']
-    rc, out, err = utils.execCmd(ip_rm_dummy, sudo=True)
-    if rc != SUCCESS:
-        raise SkipTest("Unable to delete dummy interface:"
-                       " %s see %s %s" % (dummyName, out, err))
-
-
-@contextmanager
-def dummyIf(num):
-    """
-    Manages a list of num dummy interfaces. Assumes root privileges.
-    """
-
-    dummies = []
-    try:
-        dummies = [createDummy() for _ in range(num)]
-        yield dummies
-    except Exception:
-        raise
-    finally:
-        for dummy in dummies:
-            removeDummy(dummy)
 
 
 def cleanupNet(func):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c7ed4110cd8d45a3fb7a9cc2cd2dc07004e96b9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Assaf Muller <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to