Wenyi Gao has uploaded a new change for review.

Change subject: Move load_needed_modules to vdsm-tool
......................................................................

Move load_needed_modules to vdsm-tool

Move load_needed_modules to vdsm-tool from vdsmd.init

Change-Id: Icdc8f9d07a7150c4a846228811d6c5dcb17fa358
Signed-off-by: Wenyi Gao <we...@linux.vnet.ibm.com>
---
M configure.ac
M vdsm-tool/Makefile.am
A vdsm-tool/load_needed_modules.py.in
M vdsm.spec.in
M vdsm/vdsmd.init.in
5 files changed, 63 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/87/7487/1

diff --git a/configure.ac b/configure.ac
index d4b6815..c50f42f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -149,6 +149,7 @@
 AC_PATH_PROG([MKFS_PATH], [mkfs], [/sbin/mkfs])
 AC_PATH_PROG([MKFS_MSDOS_PATH], [mkfs.msdos], [/sbin/mkfs.msdos])
 AC_PATH_PROG([MKISOFS_PATH], [mkisofs], [/usr/bin/mkisofs])
+AC_PATH_PROG([MODPROBE_PATH], [modprobe], [/sbin/modprobe])
 AC_PATH_PROG([MOUNT_PATH], [mount], [/bin/mount])
 AC_PATH_PROG([MULTIPATH_PATH], [multipath], [/sbin/multipath])
 AC_PATH_PROG([MV_PATH], [mv], [/bin/mv])
diff --git a/vdsm-tool/Makefile.am b/vdsm-tool/Makefile.am
index 6ec0198..95298e2 100644
--- a/vdsm-tool/Makefile.am
+++ b/vdsm-tool/Makefile.am
@@ -28,4 +28,5 @@
 dist_vdsmtool_DATA = \
        __init__.py \
        passwd.py \
-       validate_ovirt_certs.py
\ No newline at end of file
+       validate_ovirt_certs.py \
+       load_needed_modules.py
diff --git a/vdsm-tool/load_needed_modules.py.in 
b/vdsm-tool/load_needed_modules.py.in
new file mode 100644
index 0000000..80be9b1
--- /dev/null
+++ b/vdsm-tool/load_needed_modules.py.in
@@ -0,0 +1,58 @@
+# Copyright 2012 by IBM
+#
+# 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
+import subprocess
+from vdsm.tool import expose
+
+
+EX_MODPROBE = '@MODPROBE_PATH@'
+
+BOND = ['bond0', 'bond1', 'bond2', 'bond3', 'bond4']
+DEVS = '/sys/class/net/bonding_masters'
+
+
+def _exec_command(argv):
+    subprocess.Popen(argv, stdout=subprocess.PIPE,
+                     stderr=subprocess.PIPE).communicate()
+
+
+def _is_bond_dev_available(bond):
+    if os.path.exists(DEVS):
+        with open(DEVS, 'r') as f:
+            devs = f.read().strip('\n').split(' ')
+            if bond in devs:
+                return True
+    return False
+
+
+@expose('load-needed-modules')
+def load_needed_modules():
+    """
+    Load needed modules
+    """
+    _exec_command([EX_MODPROBE, 'tun'])
+    _exec_command([EX_MODPROBE, 'bonding'])
+
+    for bond in BOND:
+        if not _is_bond_dev_available(bond):
+            with open(DEVS, 'w') as f:
+                f.write('+%s\n' % bond)
+
+    _exec_command([EX_MODPROBE, '8021q'])
diff --git a/vdsm.spec.in b/vdsm.spec.in
index ce73f6e..5e68ce8 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -720,6 +720,7 @@
 %{python_sitearch}/%{vdsm_name}/tool/__init__.py*
 %{python_sitearch}/%{vdsm_name}/tool/passwd.py*
 %{python_sitearch}/%{vdsm_name}/tool/validate_ovirt_certs.py*
+%{python_sitearch}/%{vdsm_name}/tool/load_needed_modules.py*
 
 %files tests
 %doc %{_datadir}/%{vdsm_name}/tests/README
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in
index a57649f..3d6211b 100755
--- a/vdsm/vdsmd.init.in
+++ b/vdsm/vdsmd.init.in
@@ -198,32 +198,6 @@
     return 0
 }
 
-bond_dev_available() {
-    local BOND_DEVS=$(/bin/cat /sys/class/net/bonding_masters)
-    local x
-
-    [[ -z "$BOND_DEVS" ]] && return 1
-
-    for x in $BOND_DEVS; do
-        [[ "$x" == "$1" ]] && return 0
-    done
-
-    return 1
-}
-
-load_needed_modules() {
-    local b
-
-    /sbin/modprobe tun
-    /sbin/modprobe bonding
-    # RHEV-M currently assumes that all bonding devices pre-exist
-    for b in bond{0,1,2,3,4}; do
-        if ! bond_dev_available $b; then
-            echo +$b > /sys/class/net/bonding_masters 2>/dev/null
-        fi
-    done
-    /sbin/modprobe 8021q
-}
 
 test_already_running()
 {
@@ -472,7 +446,7 @@
     fi
 
     @VDSMDIR@/vdsm-restore-net-config
-    load_needed_modules
+    /usr/bin/vdsm-tool load_needed_modules
     mk_data_center
     mk_core_path
     mk_dom_backup


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icdc8f9d07a7150c4a846228811d6c5dcb17fa358
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Wenyi Gao <we...@linux.vnet.ibm.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to