Change in vdsm[master]: vdsm: libvirt service was restarted everytime vdsm was resta...

ybronhei at redhat.com ybronhei at redhat.com
Mon Aug 20 08:21:22 UTC 2012


Yaniv Bronhaim has uploaded a new change for review.

Change subject: vdsm: libvirt service was restarted everytime vdsm was restarted (#734847)
......................................................................

vdsm: libvirt service was restarted everytime vdsm was restarted (#734847)

This fix included vdsmd log that follows the initialization process of vdsm
service.
I added node to fs that sign whether vdsm runs for first time,
if we are run for first time we process reconfiguration of libvirt. This
part includes reset of external services and libvirt service. We ensure
in this fix that this reset will happen only once.

reconfiguration of libvirt and external services can be only if we delete
the file that sign the first vdsm start.

Change-Id: I4f5207ac6ed7a9b01907b31d9ac7992aafb118ad
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
A .project
A .pydevproject
A 0001-WIP-report-another-unique-identity.patch
A a.sh
A conflicts_bs
M vdsm/vdsmd.init.in
6 files changed, 277 insertions(+), 39 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/31/7331/1

diff --git a/.project b/.project
new file mode 100644
index 0000000..7a5325e
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>upstream</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.python.pydev.pythonNature</nature>
+	</natures>
+</projectDescription>
diff --git a/.pydevproject b/.pydevproject
new file mode 100644
index 0000000..6e49f64
--- /dev/null
+++ b/.pydevproject
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?><pydev_project>
+<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
+<path>/upstream</path>
+</pydev_pathproperty>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
+</pydev_project>
diff --git a/0001-WIP-report-another-unique-identity.patch b/0001-WIP-report-another-unique-identity.patch
new file mode 100644
index 0000000..01de137
--- /dev/null
+++ b/0001-WIP-report-another-unique-identity.patch
@@ -0,0 +1,167 @@
+From 6a726bff7200cb35bf56e2a8bdc5ade7f5c1c250 Mon Sep 17 00:00:00 2001
+From: Dan Kenigsberg <danken at redhat.com>
+Date: Wed, 30 May 2012 01:10:56 +0300
+Subject: [PATCH] [WIP] report another unique identity
+
+ovirt-engine identifies each hypervisor node according to the uuid
+reported by getVdsCapabilities. That uuid is combined of the bios-stored
+host uuid + mac address of the first host nic. The contraction was
+required since plenty of hosts out there are sold with a non-unique uuid
+stored in their bios.
+
+However, that was a terribly wrong solution, as nics come and go, bond
+together or simply change their mac address. None of these changes
+should cause a change of the identity of the node.
+
+We cannot just ditch the old solution, since existing installations must
+keep reporting their old uuid. This patch suggests that on upgrade, vdsm
+would persist the funny uuid+mac reported by the old vdsm version. On
+fresh installation, a fresh uuid is generated and persisted.
+
+Known issues:
+- We must not persist the node uuid when creating ovirt-node image.
+  ovirt-node should persist its legacy/sane uuid during boot, based on
+  its being a fresh installation, or an upgrade.
+- Code untested, probably broken.
+
+Change-Id: I35462b23b0b61c2d555500a631eeea65f838f5ab
+Signed-off-by: Dan Kenigsberg <danken at redhat.com>
+---
+ vdsm.spec.in               | 12 ++++++++++++
+ vdsm/caps.py               |  3 +--
+ vdsm/libvirtvm.py          |  2 +-
+ vdsm/utils.py              |  7 ++++++-
+ vdsm_reg/vdsm-reg-setup.in |  7 ++-----
+ 5 files changed, 22 insertions(+), 9 deletions(-)
+
+diff --git a/vdsm.spec.in b/vdsm.spec.in
+index 3c75d08..8cd9507 100644
+--- a/vdsm.spec.in
++++ b/vdsm.spec.in
+@@ -83,6 +83,7 @@ Requires: %{name}-python = %{version}-%{release}
+ Requires: selinux-policy-targeted >= 3.7.19-80.el6
+ Requires: pyparted
+ Requires(post): /usr/sbin/saslpasswd2
++Requires(post): /usr/bin/uuidgen
+ 
+ %description
+ The VDSM service is required by a Virtualization Manager to manage the
+@@ -391,6 +392,17 @@ fi
+ exit 0
+ %endif
+ 
++UUIDFILE=/var/lib/vdsm/uuid
++if [ ! -f "$UUIDFILE" ]; then
++    if [ "$1" -eq 1 ] ; then
++        UUID=`/usr/bin/uuidgen`
++    else
++        cd /usr/share/vdsm
++        UUID=`/usr/bin/python -c 'from vdsm.utils import getLegacyHostUUID as u;print u()'`
++    fi
++    /bin/echo -n "$UUID" > "$UUIDFILE"
++fi
++
+ %preun
+ %if 0%{?rhel}
+ if [ "$1" -eq 0 ]
+diff --git a/vdsm/caps.py b/vdsm/caps.py
+index 5950ee9..b1e56a8 100644
+--- a/vdsm/caps.py
++++ b/vdsm/caps.py
+@@ -230,7 +230,7 @@ def get():
+         logging.debug('not reporting hooks', exc_info=True)
+ 
+     caps['operatingSystem'] = osversion()
+-    caps['uuid'] = utils.getHostUUID()
++    caps['uuid'] = utils.getVdsmUUID()
+     caps['packages2'] = _getKeyPackages()
+     caps['emulatedMachines'] = _getEmulatedMachines()
+     caps['ISCSIInitiatorName'] = _getIscsiIniName()
+@@ -307,4 +307,3 @@ def _getKeyPackages():
+                 logging.error('', exc_info=True)
+ 
+     return pkgs
+-
+diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
+index 84ffdd9..d5b489e 100644
+--- a/vdsm/libvirtvm.py
++++ b/vdsm/libvirtvm.py
+@@ -1175,7 +1175,7 @@ class LibvirtVm(vm.Vm):
+         domxml.appendSysinfo(
+             osname=caps.OSName.RHEVH,
+             osversion=osd.get('version', '') + '-' + osd.get('release', ''),
+-            hostUUID=utils.getHostUUID() )
++            hostUUID=utils.getVdsmUUID() )
+ 
+         domxml.appendClock()
+         domxml.appendFeatures()
+diff --git a/vdsm/utils.py b/vdsm/utils.py
+index 639299a..adb0c71 100644
+--- a/vdsm/utils.py
++++ b/vdsm/utils.py
+@@ -664,8 +664,9 @@ def tobool(s):
+         return False
+ 
+ 
++# obsolete. do not use in new code
+ __hostUUID = ''
+-def getHostUUID():
++def getLegacyHostUUID():
+     global __hostUUID
+     if __hostUUID:
+         return __hostUUID
+@@ -799,6 +800,10 @@ class memoized(object):
+         """Support instance methods."""
+         return functools.partial(self.__call__, obj)
+ 
++ at memoized
++def getVdsmUUID():
++    return file('/var/lib/vdsm/uuid'.read())
++
+ def validateMinimalKeySet(dictionary, reqParams):
+     if not all(key in dictionary for key in reqParams):
+         raise ValueError
+diff --git a/vdsm_reg/vdsm-reg-setup.in b/vdsm_reg/vdsm-reg-setup.in
+index 0f3e896..25e47e3 100644
+--- a/vdsm_reg/vdsm-reg-setup.in
++++ b/vdsm_reg/vdsm-reg-setup.in
+@@ -22,6 +22,7 @@ import ssl
+ from config import config
+ import deployUtil
+ import createDaemon
++from vdsm.utils import getVdsmUUID
+ 
+ TICKET_RETRIES=3
+ DEFAULT_CONFIG_FILE="/etc/vdsm-reg/vdsm-reg.conf"
+@@ -49,11 +50,9 @@ class Setup:
+         if self.vdcURL != "None":
+             self.ovirtURL = deployUtil.getMGTIP(self.vdsmDir, self.vdcName)
+             self.ovirtName = socket.getfqdn()
+-            self.ovirtUID = deployUtil.getHostID()
+         else:
+             self.ovirtURL = "None"
+             self.ovirtName = "None"
+-            self.ovirtUID = "None"
+ 
+         self.vdcPORT = config.get('vars', 'vdc_host_port')
+         self.vdcURI = config.get('vars', 'vdc_reg_uri')
+@@ -115,15 +114,13 @@ class Setup:
+         params = {
+                 'vds_ip': self.ovirtURL,
+                 'vds_name': self.ovirtName,
+-                'vds_unique_id': self.ovirtUID,
++                'vds_unique_id': getVdsmUUID(),
+                 'port': self.vdcRegPort,
+                 '__VIEWSTATE': '',
+                 'ticket': self.ticket if self.ticket else "",
+         }
+         strFullURI = self.vdcURI + '?' + urllib.urlencode(params)
+         logging.debug("registerVDS URI= %s\n", strFullURI)
+-        if self.ovirtUID == "None" and "localhost.localdomain" in self.ovirtName:
+-            logging.warn("WARNING! registering RHEV-H with no UUID and no unique host-name!")
+ 
+         fReturn = True
+         res = None
+-- 
+1.7.11.2
+
diff --git a/a.sh b/a.sh
new file mode 100755
index 0000000..312a5fe
--- /dev/null
+++ b/a.sh
@@ -0,0 +1,7 @@
+UUIDFILE=/var/lib/vdsm/uuid
+UUID=$(uuidgen)
+
+echo $UUID
+/bin/echo -n $UUID >> $UUIDFILE
+
+
diff --git a/conflicts_bs b/conflicts_bs
new file mode 100755
index 0000000..58c2c56
--- /dev/null
+++ b/conflicts_bs
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+
+for srv in "libvirt-guests"
+do
+	echo $srv
+done
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in
index d34b48d..15538de 100755
--- a/vdsm/vdsmd.init.in
+++ b/vdsm/vdsmd.init.in
@@ -25,6 +25,8 @@
 
 VDSM_BIN=@VDSMDIR@/vdsm
 CONF_FILE=@CONFDIR@/vdsm.conf
+INIT_LOG=@VDSMDIR@/vdsmd.log
+FIRST_TIME=@VDSMDIR@/first
 GETCONFITEM=@VDSMDIR@/get-conf-item
 prog=vdsm
 PIDFILE=@VDSMRUNDIR@/vdsmd.pid
@@ -122,14 +124,14 @@
         return 0
     else
         echo "conflicting vdsm and libvirt-qemu tls configuration."
-        echo "vdsm.conf with ssl=False requires the following changed: "
+        echo "vdsm.conf with ssl=False requires the following changes: "
         echo "libvirtd.conf: listen_tcp=1, auth_tcp=\"none\", "
         echo "qemu.conf: spice_tls=0."
         return 1
     fi
 }
 
-shutdown_conflicting_srv() {
+restart_conflicting_srv() {    
     local srv
 
     for srv in $CONFLICTING_SERVICES
@@ -140,31 +142,32 @@
             if [ "$srv" == "libvirt-guests" ]; then
                 /bin/rm -f /var/lock/subsys/libvirt-guests
             else
-                /sbin/service $srv stop
+                /sbin/service $srv restart
             fi
         fi
     done
     return 0
 }
 
-upstart_libvirt() {
-    [[ -x /sbin/initctl ]]
+is_libvirt_active() {
+    pgrep libvirt > /dev/null
 }
 
 start_needed_srv() {
+    echo "starting needed services" >> $INIT_LOG
     local srv
     local ret_val
 
     for srv in $NEEDED_SERVICES
     do
-        if ! /sbin/service $srv status > /dev/null 2>&1;
+        if ! /sbin/service $srv status > /dev/null 2>&1; # Verify that status is inactive
         then
-            echo "Starting $srv..."
+            echo "Starting $srv..." >> $INIT_LOG
             /sbin/service $srv start
             ret_val=$?
             if [ $ret_val -ne 0 ]
             then
-                log_failure_msg "$prog: Dependent $srv failed to start"
+                log_failure_msg "$prog: Dependent $srv failed to start"                
                 return $ret_val
             fi
         fi
@@ -177,7 +180,8 @@
     if ! LC_ALL=C /sbin/ifconfig lo | /bin/grep -q UP;
     then
         log_failure_msg "VDSMD: lo interface is down, can't run !"
-        echo "VDSMD: lo interface is down, can't run !" > /dev/kmsg
+        echo "VDSMD: lo interface is down, can't run !" >> /dev/kmsg
+        echo "VDSMD: lo interface is down, can't run !" >> $INIT_LOG
         return 1
     fi
     return 0
@@ -299,11 +303,12 @@
        grep -q "$by_vdsm_vers" $lconf && grep -q "$by_vdsm_vers" $qconf && \
        grep -q "$by_vdsm_vers" $ldconf && grep -q "$by_vdsm_vers" $qlconf
     then
+        echo "no reconfigure proccedded" >> $INIT_LOG
         log_success_msg $"$prog: libvirt already configured for vdsm "
         return 0
     fi
 
-    echo $"Configuring libvirt for vdsm..."
+    echo $"Configuring libvirt for vdsm..." >> $INIT_LOG
 
     # Remove a previous configuration (if present)
     remove_vdsm_conf $lconf $qconf $ldconf $qlconf
@@ -388,14 +393,12 @@
     restorecon "$llogr"
 
     ovirt_store_config "$lconf" "$qconf" "$ldconf" "$llogr"
-
-    /sbin/initctl restart libvirtd 2>/dev/null || :
 }
-
 
 RETVAL=0
 
 reconfigure() {
+    echo $"start reconfigure" >> $INIT_LOG
     local args="$@"
     case $# in
         0)
@@ -409,23 +412,26 @@
     configure_libvirt $args
 }
 
-stop_libvirtd_sysv() {
-    # stop libvirt SysV service if we intend to configure upstart
-
-    if upstart_libvirt; then
+restart_libvirtd_sysv() {    
+    if is_libvirt_active; then
+        echo $"restarting libvirt.." >> $INIT_LOG
         /sbin/chkconfig libvirtd off
-        /sbin/service libvirtd stop
+        /sbin/service libvirtd restart
     fi
 }
 
-start_libvirtd() {
+start_libvirtd() {                    
     local packaged target
     local startout
 
-    if ! upstart_libvirt; then
+    if [ ! is_libvirt_active ]; then
+        echo $"starting libvirt" >> $INIT_LOG
         /sbin/service libvirtd start
+        return    
+    else
+        echo $"libvirt already runs" >> $INIT_LOG
         return
-    fi
+    fi 
 
     packaged=`/bin/rpm -ql libvirt libvirt-daemon | \
               /bin/grep libvirtd.upstart | /usr/bin/tail -1`
@@ -436,8 +442,8 @@
         /bin/cp -p "$packaged" "$target" || return 1
         /sbin/initctl reload-configuration
     fi
-
-    startout=`/sbin/initctl start libvirtd 2>&1`
+    
+    startout=`/sbin/service start libvirtd 2>&1`
     if [[ "$?" -eq 0 || "$startout" =~ .*already\ running.* ]];
     then
         return 0
@@ -447,28 +453,50 @@
     fi
 }
 
+restart_ext_services() {                    
+    echo "restarting external services and libvirt." >> $INIT_LOG
+                   
+    # stopping related services                                                
+    restart_conflicting_srv && restart_libvirtd_sysv
+    
+    ret_val=$?
+    if [ $ret_val -ne 0 ]; then
+        log_failure_msg "$prog: failed to reconfigure libvirt"
+        echo "error stopping ext srvs" >> $INIT_LOG
+        return $ret_val
+    fi                       
+}
+
 start() {
     local ret_val
     python @VDSMDIR@/hooks.pyc before_vdsm_start
 
-    shutdown_conflicting_srv && stop_libvirtd_sysv
-
-    reconfigure noforce
-    ret_val=$?
-    if [ $ret_val -ne 0 ]
-    then
-        log_failure_msg "$prog: failed to reconfigure libvirt"
-        return $ret_val
+    # external to vdsm: 
+    # if run for first time, the INIT_LOG is not exist.
+    if [[ ! -e $FIRST_TIME ]]; then
+        echo "running for first time, initialize external services" >> $INIT_LOG        
+        echo "running for first time, initialize external services"
+        
+        # sign the first time file. as long as this file exist, the reconfigure won't happened
+        echo "1" >> $FIRST_TIME
+         
+        reconfigure force  # run reconfiguration for libvirt      
+        restart_ext_services # This restarting all services. During normal start we don't want it.            
+    else
+        echo "starting normally.." >> $INIT_LOG
+        start_needed_srv && start_libvirtd                        
     fi
-
-    start_needed_srv && start_libvirtd
+    
     ret_val=$?
-    if [ $ret_val -ne 0 ]
-    then
+    if [ $ret_val -ne 0 ]; then
        log_failure_msg "$prog: one of the dependent services did not start, error code $ret_val"
+       echo "error starting ext srvs" >> $INIT_LOG
        return $ret_val
-    fi
-
+    fi  
+        
+    echo "starting up.." >> $INIT_LOG                
+    
+    # internal to vdsm:
     @VDSMDIR@/vdsm-restore-net-config
     load_needed_modules
     mk_data_center
@@ -490,6 +518,7 @@
     fi
 
     echo $"Starting up vdsm daemon: "
+    echo $"Starting up vdsm daemon" >> $INIT_LOG
     local vdsm_nice=`$GETCONFITEM $CONF_FILE vars vdsm_nice -5`
 
     LIBVIRT_LOG_FILTERS=`$GETCONFITEM $CONF_FILE vars libvirt_log_filters "1:libvirt 1:remote"` \
@@ -502,6 +531,7 @@
 
 stop() {
     echo $"Shutting down vdsm daemon: "
+    echo $"Shutting down vdsm daemon" >> $INIT_LOG
     if killproc -p $RESPAWNPIDFILE; then
         log_success_msg $"$prog watchdog stop"
     fi
@@ -559,9 +589,11 @@
 	RETVAL=$?
 	;;
     reconfigure)
-        # Jump over 'reconfigure'
+        # Jump over 'reconfigure' - not exist in systemctl
         shift 1
-        reconfigure "$@"
+        #reconfigure force
+        #restart_ext_services
+        #start
 	RETVAL=$?
     ;;
      *)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f5207ac6ed7a9b01907b31d9ac7992aafb118ad
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