Change in vdsm[master]: Moving modprobe operations to separate module
ybronhei at redhat.com
ybronhei at redhat.com
Sun Nov 29 08:00:57 UTC 2015
Yaniv Bronhaim has uploaded a new change for review.
Change subject: Moving modprobe operations to separate module
......................................................................
Moving modprobe operations to separate module
that way we won't need to import utils each testValidation import
Change-Id: I62a36e3c6aa4aff90040ba671c29daaf10e4bb44
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
M debian/vdsm-python.install
M lib/vdsm/Makefile.am
A lib/vdsm/modprobe.py
M tests/functional/networkTests.py
M tests/functional/networkTestsOVS.py
M tests/netinfoTests.py
M tests/testValidation.py
M vdsm.spec.in
8 files changed, 78 insertions(+), 55 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/49/49349/1
diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install
index ce09700..841d8a8 100644
--- a/debian/vdsm-python.install
+++ b/debian/vdsm-python.install
@@ -50,6 +50,7 @@
./usr/lib/python2.7/dist-packages/vdsm/tool/upgrade.py
./usr/lib/python2.7/dist-packages/vdsm/tool/validate_ovirt_certs.py
./usr/lib/python2.7/dist-packages/vdsm/tool/vdsm-id.py
+./usr/lib/python2.7/dist-packages/vdsm/modprobe.py
./usr/lib/python2.7/dist-packages/vdsm/udevadm.py
./usr/lib/python2.7/dist-packages/vdsm/utils.py
./usr/lib/python2.7/dist-packages/vdsm/vdscli.py
diff --git a/lib/vdsm/Makefile.am b/lib/vdsm/Makefile.am
index 8a6b68b..64b3ea4 100644
--- a/lib/vdsm/Makefile.am
+++ b/lib/vdsm/Makefile.am
@@ -35,6 +35,7 @@
jsonrpcvdscli.py \
libvirtconnection.py \
m2cutils.py \
+ modprobe.py \
netconfpersistence.py \
netinfo.py \
password.py \
diff --git a/lib/vdsm/modprobe.py b/lib/vdsm/modprobe.py
new file mode 100644
index 0000000..82e2237
--- /dev/null
+++ b/lib/vdsm/modprobe.py
@@ -0,0 +1,70 @@
+#
+# Copyright 2015 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 os
+from functools import wraps
+
+from vdsm import utils
+
+modprobe = utils.CommandPath("modprobe",
+ "/sbin/modprobe", # EL6
+ "/usr/sbin/modprobe", # Fedora
+ )
+
+
+def RequireDummyMod(f):
+ """
+ Assumes root privileges to be used after
+ ValidateRunningAsRoot decoration.
+ """
+ @wraps(f)
+ def wrapper(*args, **kwargs):
+ if not os.path.exists('/sys/module/dummy'):
+ cmd_modprobe = [modprobe.cmd, "dummy"]
+ rc, out, err = utils.execCmd(cmd_modprobe, sudo=True)
+ return f(*args, **kwargs)
+ return wrapper
+
+
+def RequireBondingMod(f):
+ """
+ Assumes root privileges to be used after
+ ValidateRunningAsRoot decoration.
+ """
+ @wraps(f)
+ def wrapper(*args, **kwargs):
+ if not os.path.exists('/sys/module/bonding'):
+ cmd_modprobe = [modprobe.cmd, "bonding"]
+ rc, out, err = utils.execCmd(cmd_modprobe, sudo=True)
+ return f(*args, **kwargs)
+
+ return wrapper
+
+
+def RequireVethMod(f):
+ """
+ Assumes root privileges to be used after
+ ValidateRunningAsRoot decoration.
+ """
+ @wraps(f)
+ def wrapper(*args, **kwargs):
+ if not os.path.exists('/sys/module/veth'):
+ cmd_modprobe = [modprobe.cmd, "veth"]
+ rc, out, err = utils.execCmd(cmd_modprobe, sudo=True)
+ return f(*args, **kwargs)
+ return wrapper
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 7225790..45e7070 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -39,6 +39,7 @@
OPERSTATE_UP, NET_CONF_BACK_DIR)
from vdsm.netlink import monitor
from vdsm import sysctl
+from vdsm.modprobe import RequireDummyMod, RequireVethMod
from vdsm.utils import CommandPath, RollbackContext, execCmd, pgrep, running
from network import api, errors, sourceroute, tc
@@ -47,8 +48,7 @@
from hookValidation import ValidatesHook
from testlib import (VdsmTestCase as TestCaseBase, namedTemporaryDir,
expandPermutations, permutations)
-from testValidation import (brokentest, slowtest, RequireDummyMod,
- RequireVethMod, ValidateRunningAsRoot)
+from testValidation import brokentest, slowtest, ValidateRunningAsRoot
from nettestlib import Dummy, Tap, veth_pair
import dhcp
diff --git a/tests/functional/networkTestsOVS.py b/tests/functional/networkTestsOVS.py
index b8e915e..bb8b926 100644
--- a/tests/functional/networkTestsOVS.py
+++ b/tests/functional/networkTestsOVS.py
@@ -22,9 +22,9 @@
from vdsm.ipwrapper import linkSet, addrAdd
from vdsm.utils import RollbackContext
+from vdsm.modprobe import RequireVethMod
from nettestlib import veth_pair
-from testValidation import RequireVethMod
from testlib import expandPermutations, permutations
from networkTests import (setupModule, tearDownModule, NetworkTest, dummyIf,
diff --git a/tests/netinfoTests.py b/tests/netinfoTests.py
index 15573a0..92d7b09 100644
--- a/tests/netinfoTests.py
+++ b/tests/netinfoTests.py
@@ -30,13 +30,14 @@
from vdsm import netinfo
from vdsm.netinfo import OPERSTATE_UP
from vdsm.netlink import addr as nl_addr
+from vdsm.modprobe import RequireBondingMod
from vdsm.utils import random_iface_name
from ipwrapperTests import _fakeTypeDetection
from monkeypatch import MonkeyPatch, MonkeyPatchScope
from nettestlib import dummy_device, veth_pair
from testlib import VdsmTestCase as TestCaseBase, namedTemporaryDir
-from testValidation import ValidateRunningAsRoot, RequireBondingMod
+from testValidation import ValidateRunningAsRoot
from testValidation import brokentest
# speeds defined in ethtool
diff --git a/tests/testValidation.py b/tests/testValidation.py
index 3e5232e..736a9c0 100644
--- a/tests/testValidation.py
+++ b/tests/testValidation.py
@@ -24,14 +24,6 @@
from nose.plugins import Plugin
import subprocess
-from vdsm import utils
-
-
-modprobe = utils.CommandPath("modprobe",
- "/sbin/modprobe", # EL6
- "/usr/sbin/modprobe", # Fedora
- )
-
class SlowTestsPlugin(Plugin):
"""
@@ -115,49 +107,6 @@
return f(*args, **kwargs)
- return wrapper
-
-
-def RequireDummyMod(f):
- """
- Assumes root privileges to be used after
- ValidateRunningAsRoot decoration.
- """
- @wraps(f)
- def wrapper(*args, **kwargs):
- if not os.path.exists('/sys/module/dummy'):
- cmd_modprobe = [modprobe.cmd, "dummy"]
- rc, out, err = utils.execCmd(cmd_modprobe, sudo=True)
- return f(*args, **kwargs)
- return wrapper
-
-
-def RequireBondingMod(f):
- """
- Assumes root privileges to be used after
- ValidateRunningAsRoot decoration.
- """
- @wraps(f)
- def wrapper(*args, **kwargs):
- if not os.path.exists('/sys/module/bonding'):
- cmd_modprobe = [modprobe.cmd, "bonding"]
- rc, out, err = utils.execCmd(cmd_modprobe, sudo=True)
- return f(*args, **kwargs)
-
- return wrapper
-
-
-def RequireVethMod(f):
- """
- Assumes root privileges to be used after
- ValidateRunningAsRoot decoration.
- """
- @wraps(f)
- def wrapper(*args, **kwargs):
- if not os.path.exists('/sys/module/veth'):
- cmd_modprobe = [modprobe.cmd, "veth"]
- rc, out, err = utils.execCmd(cmd_modprobe, sudo=True)
- return f(*args, **kwargs)
return wrapper
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 6466988..3d22717 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1106,6 +1106,7 @@
%{python_sitelib}/%{vdsm_name}/pthread.py*
%{python_sitelib}/%{vdsm_name}/qemuimg.py*
%{python_sitelib}/%{vdsm_name}/response.py*
+%{python_sitelib}/%{vdsm_name}/modprobe.py*
%{python_sitelib}/%{vdsm_name}/netconfpersistence.py*
%{python_sitelib}/%{vdsm_name}/schedule.py*
%{python_sitelib}/%{vdsm_name}/sslcompat.py*
--
To view, visit https://gerrit.ovirt.org/49349
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I62a36e3c6aa4aff90040ba671c29daaf10e4bb44
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>
More information about the vdsm-patches
mailing list