From 0802ecab3d72f9c52cf042ddbcd86e6beba7cd5d Mon Sep 17 00:00:00 2001
From: Andrey Gordeev <dreyou@gmail.com>
Date: Wed, 30 Jan 2013 11:46:33 +0400
Subject: [PATCH] CentOS 6.3 changes

---
 build-aux/pkg-version |    6 +++++-
 vds_bootstrap/setup   |    2 +-
 vdsm.spec.in          |   29 ++++++++++++++++++++++++++---
 vdsm/caps.py          |   15 +++++++++++++--
 vdsm/configNetwork.py |    5 +++++
 vdsm/storage/misc.py  |    2 +-
 vdsm/vdsmd.init.in    |    3 ++-
 7 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/build-aux/pkg-version b/build-aux/pkg-version
index 346ad23..9c410ff 100755
--- a/build-aux/pkg-version
+++ b/build-aux/pkg-version
@@ -32,7 +32,11 @@ if test "x$1" = "x--full"; then
 elif test "x$1" = "x--version"; then
     echo $PKG_VERSION | awk "$AWK_VERSION" | tr -cd '[:alnum:].'
 elif test "x$1" = "x--release"; then
-    echo $PKG_VERSION | awk "$AWK_RELEASE" | tr -cd '[:alnum:].'
+    if [ $LOCAL_BUILDID ]; then
+       echo $PKG_VERSION | awk "$AWK_RELEASE" | sed "s/git.*$/{$LOCAL_BUILDID}/" | tr -cd '[:alnum:].'
+    else
+       echo $PKG_VERSION | awk "$AWK_RELEASE" | tr -cd '[:alnum:].'
+    fi
 else
     echo "usage: $0 [--full|--version|--release]"
     exit 1
diff --git a/vds_bootstrap/setup b/vds_bootstrap/setup
index d372f57..1dfac01 100755
--- a/vds_bootstrap/setup
+++ b/vds_bootstrap/setup
@@ -29,7 +29,7 @@ import re
 import tempfile
 from time import strftime
 
-SUPPORTED_PLATFORMS = [ "RedHatEnterpriseServer", "Fedora" ]
+SUPPORTED_PLATFORMS = [ "RedHatEnterpriseServer", "Fedora", "CentOS", "Scientific", "Oracle" ]
 HYPERVISOR_PLATFORMS = [ "RedHatEnterpriseVirtualizationHypervisor", "RedHatEnterpriseHypervisor", "oVirtNodeHypervisor" ]
 HYPERVISOR_RELEASE_FILE = '/etc/rhev-hypervisor-release'
 REDHAT_RELEASE_FILE = '/etc/redhat-release'
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 7923a2d..b2dbccb 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -108,7 +108,8 @@ Requires: device-mapper-multipath >= 0.4.9-52
 Requires: e2fsprogs >= 1.41.12-11
 Requires: kernel >= 2.6.32-279.9.1
 Requires: sanlock >= 2.3-4, sanlock-python
-Requires: initscripts >= 9.03.31-2.el6_3.1
+#Requires: initscripts >= 9.03.31-2.el6_3.1
+Requires: initscripts >= 9.03.31-2
 Requires: mom >= 0.3.0
 Requires: selinux-policy-targeted >= 3.7.19-155
 Requires: lvm2 >= 2.02.95-10.el6_3.2
@@ -444,6 +445,8 @@ install -Dm 0644 vdsm/limits.conf \
 # Install the SysV init scripts
 install -Dm 0755 vdsm/vdsmd.init %{buildroot}%{_initrddir}/vdsmd
 install -Dm 0755 vdsm_reg/vdsm-reg.init %{buildroot}%{_initrddir}/vdsm-reg
+install -Dm 0644 vdsm/vdsm.conf.sample \
+                 %{buildroot}%{_sysconfdir}/vdsm/vdsm.conf
 
 # This is not commonplace, but we want /var/log/core to be a world-writable
 # dropbox for core dumps
@@ -488,6 +491,16 @@ export LC_ALL=C
 /usr/sbin/usermod -a -G %{qemu_group},%{vdsm_group} %{snlk_user}
 
 %post
+#Hack to guaranty enable softdog
+if [ -f /etc/sysconfig/modules/softdog.modules ]
+then
+    cp /etc/sysconfig/modules/softdog.modules /etc/vdsm/softdog.modules.prevdsm
+fi
+echo -e '#!/bin/sh\nmodprobe softdog\nexit 0' > /etc/sysconfig/modules/softdog.modules
+chmod +x /etc/sysconfig/modules/softdog.modules
+/sbin/chkconfig wdmd on
+/sbin/chkconfig sanlock on
+
 %{_bindir}/vdsm-tool sebool-config || :
 # set the vdsm "secret" password for libvirt
 %{_bindir}/vdsm-tool set-saslpasswd
@@ -551,6 +564,16 @@ exit 0
 %endif
 
 %postun
+#Remove sanlock hack
+if [ -f /etc/sysconfig/modules/softdog.modules ]
+then
+    cp /etc/sysconfig/modules/softdog.modules /etc/vdsm/softdog.modules.prevdsm
+fi
+echo -e '#!/bin/sh\nmodprobe softdog\nexit 0' > /etc/sysconfig/modules/softdog.modules
+chmod +x /etc/sysconfig/modules/softdog.modules
+/sbin/chkconfig wdmd on
+/sbin/chkconfig sanlock on
+
 %if 0%{?rhel}
 if [ "$1" -ge 1 ]; then
     /sbin/service vdsmd condrestart > /dev/null 2>&1
@@ -784,9 +807,9 @@ exit 0
 %files python
 %defattr(-, root, root, -)
 %{_bindir}/vdsm-tool
-%if !0%{?rhel}
+#%if !0%{?rhel}
 %config(noreplace) %{_sysconfdir}/%{vdsm_name}/vdsm.conf
-%endif
+#%endif
 %{python_sitearch}/%{vdsm_name}/__init__.py*
 %{python_sitearch}/%{vdsm_name}/config.py*
 %{python_sitearch}/%{vdsm_name}/constants.py*
diff --git a/vdsm/caps.py b/vdsm/caps.py
index a307200..ef64c8b 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -335,11 +335,22 @@ def _getKeyPackages():
         try:
             ts = rpm.TransactionSet()
 
+#            for pkg in KEY_PACKAGES:
+#                try:
+#                    mi = ts.dbMatch('name', pkg).next()
+#                except StopIteration:
+#                    logging.debug("rpm package %s not found", pkg)
+            if len(list(ts.dbMatch('name', 'qemu-kvm-rhev'))) != 0:
+                QEMU_RHEV = True
             for pkg in KEY_PACKAGES:
                 try:
-                    mi = ts.dbMatch('name', pkg).next()
+                    if (pkg == 'qemu-kvm' or pkg == 'qemu-img') and QEMU_RHEV:
+                        rpkg = pkg + '-rhev'
+                    else:
+                        rpkg = pkg
+                    mi = ts.dbMatch('name', rpkg).next()
                 except StopIteration:
-                    logging.debug("rpm package %s not found", pkg)
+                    logging.debug("rpm package %s not found", rpkg)
                 else:
                     pkgs[pkg] = {
                         'version': mi['version'],
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 5380f31..bcdd1da 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -885,6 +885,11 @@ def addNetwork(network, vlan=None, bonding=None, nics=None, ipaddr=None,
     _netinfo = netinfo.NetInfo()
     bridged = utils.tobool(bridged)
 
+    # Hack here, netmask may be not defined, if this happen,
+    # set netmask to 255.255.255.0
+    if not netmask:
+        netmask = "255.255.255.0"
+
     if mtu:
         mtu = int(mtu)
 
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index 533a3ac..cb4f30c 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -777,7 +777,7 @@ class RollbackContext(object):
 
         # re-raise the earliest exception
         if firstException is not None:
-            raise firstException, None, traceback
+            raise firstException(None, traceback)
 
     def defer(self, func, *args, **kwargs):
         self._finally.append((func, args, kwargs))
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in
index c8223d3..e4dd221 100755
--- a/vdsm/vdsmd.init.in
+++ b/vdsm/vdsmd.init.in
@@ -136,7 +136,8 @@ shutdown_conflicting_srv() {
 }
 
 libvirt_should_use_upstart() {
-    [[ -x /sbin/initctl ]]
+#    [[ -x /sbin/initctl ]]
+    [[ -x /sbin/foo ]]
 }
 
 start_needed_srv() {
-- 
1.7.1

