Change in vdsm[ovirt-3.5]: patch to avoid using upstarts when libvirtd.upstart not exist

ybronhei at redhat.com ybronhei at redhat.com
Thu May 28 12:39:39 UTC 2015


Yaniv Bronhaim has uploaded a new change for review.

Change subject: patch to avoid using upstarts when libvirtd.upstart not exist
......................................................................

patch to avoid using upstarts when libvirtd.upstart not exist

This caused regression in ovirt-node which doesn't include
/usr/share/doc files from libvirt rpm and libvirtd.upstart is installed
as doc file.

Change-Id: I8c6daf8650927e05357a6f4e35312365b0138452
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
M lib/vdsm/tool/configurators/libvirt.py
1 file changed, 51 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/41573/1

diff --git a/lib/vdsm/tool/configurators/libvirt.py b/lib/vdsm/tool/configurators/libvirt.py
index 8dc9831..4cc83df 100644
--- a/lib/vdsm/tool/configurators/libvirt.py
+++ b/lib/vdsm/tool/configurators/libvirt.py
@@ -50,6 +50,8 @@
 
 class Libvirt(ModuleConfigure):
 
+    INITCTL = '/sbin/initctl'
+
     def getName(self):
         return 'libvirt'
 
@@ -60,7 +62,9 @@
         return ["vdsmd", "supervdsmd", "libvirtd"]
 
     def configure(self):
-        self._sysvToUpstart()
+        packaged = self._isUpstartAvailable()
+        if packaged is not None:
+            self._sysvToUpstart(packaged)
 
         if utils.isOvirtNode():
             if not os.path.exists(constants.P_VDSM_CERT):
@@ -101,12 +105,13 @@
         # disabled libvirtd's sysv service. If chkconfig returns 0, it means
         # that sysv would run libvirtd. If chkconfig returns 1 or does not
         # exist (el7, fedora, debian), all is well.
-        if hasattr(service, 'chkconfigList'):
-            try:
-                if service.chkconfigList('libvirtd'):
-                    ret = NOT_CONFIGURED
-            except service.ServiceNotExistError:
-                pass
+        if self._isUpstartAvailable() is not None:
+            if hasattr(service, 'chkconfigList'):
+                try:
+                    if service.chkconfigList('libvirtd'):
+                        ret = NOT_CONFIGURED
+                except service.ServiceNotExistError:
+                    pass
 
         if ret == NOT_SURE:
             sys.stdout.write("libvirt is already configured for vdsm\n")
@@ -130,12 +135,7 @@
             if cfile['persisted']
         ]
 
-    def _sysvToUpstart(self):
-        """
-        On RHEL 6, libvirtd can be started by either SysV init or Upstart.
-        We prefer upstart because it respawns libvirtd if libvirtd
-        crashed.
-        """
+    def _isUpstartAvailable(self):
         def iterateLibvirtFiles():
             ts = rpm.TransactionSet()
             for name in ['libvirt', 'libvirt-daemon']:
@@ -143,8 +143,27 @@
                     for filename in matches[rpm.RPMTAG_FILENAMES]:
                         yield filename
 
+        LIBVIRTD_UPSTART = 'libvirtd.upstart'
+        packaged = None
+        if os.path.isfile(self.INITCTL) and os.access(self.INITCTL, os.X_OK):
+            # libvirtd package does not provide libvirtd.upstart,
+            # this could happen in Ubuntu or other distro,
+            # so continue to use system default init mechanism
+            for fname in iterateLibvirtFiles():
+                if os.path.basename(fname) == LIBVIRTD_UPSTART:
+                    packaged = fname
+                    break
+
+        return packaged
+
+    def _sysvToUpstart(self, packaged):
+        """
+        On RHEL 6, libvirtd can be started by either SysV init or Upstart.
+        We prefer upstart because it respawns libvirtd if libvirtd
+        crashed.
+        """
         def reloadConfiguration():
-            rc, out, err = utils.execCmd((INITCTL,
+            rc, out, err = utils.execCmd((self.INITCTL,
                                           "reload-configuration"))
             if rc != 0:
                 sys.stdout.write(out)
@@ -152,41 +171,27 @@
                 raise InvalidRun(
                     "Failed to reload upstart configuration.")
 
-        INITCTL = '/sbin/initctl'
-        LIBVIRTD_UPSTART = 'libvirtd.upstart'
         TARGET = os.path.join(constants.SYSCONF_PATH, "init/libvirtd.conf")
+        if hasattr(service, '_chkconfigDisable'):
+            service._chkconfigDisable('libvirtd')
+        if not os.path.isfile(TARGET):
+            service.service_stop('libvirtd')
+        if (not os.path.isfile(TARGET) or
+                not filecmp.cmp(packaged, TARGET)):
+            oldmod = None
+            if os.path.isfile(TARGET):
+                oldmod = os.stat(TARGET).st_mode
 
-        if os.path.isfile(INITCTL) and os.access(INITCTL, os.X_OK):
-            # libvirtd package does not provide libvirtd.upstart,
-            # this could happen in Ubuntu or other distro,
-            # so continue to use system default init mechanism
-            packaged = ''
-            for fname in iterateLibvirtFiles():
-                if os.path.basename(fname) == LIBVIRTD_UPSTART:
-                    packaged = fname
-                    break
+            if utils.isOvirtNode():
+                NodeCfg().unpersist(TARGET)
+            shutil.copyfile(packaged, TARGET)
+            if utils.isOvirtNode():
+                NodeCfg().persist(TARGET)
 
-            if os.path.isfile(packaged):
-                if hasattr(service, '_chkconfigDisable'):
-                    service._chkconfigDisable('libvirtd')
-                if not os.path.isfile(TARGET):
-                    service.service_stop('libvirtd')
-                if (not os.path.isfile(TARGET) or
-                        not filecmp.cmp(packaged, TARGET)):
-                    oldmod = None
-                    if os.path.isfile(TARGET):
-                        oldmod = os.stat(TARGET).st_mode
-
-                    if utils.isOvirtNode():
-                        NodeCfg().unpersist(TARGET)
-                    shutil.copyfile(packaged, TARGET)
-                    if utils.isOvirtNode():
-                        NodeCfg().persist(TARGET)
-
-                    if (oldmod is not None and
-                            oldmod != os.stat(TARGET).st_mode):
-                        os.chmod(TARGET, oldmod)
-                    reloadConfiguration()
+            if (oldmod is not None and
+                    oldmod != os.stat(TARGET).st_mode):
+                os.chmod(TARGET, oldmod)
+            reloadConfiguration()
 
     def _isSslConflict(self):
         """


-- 
To view, visit https://gerrit.ovirt.org/41573
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8c6daf8650927e05357a6f4e35312365b0138452
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>


More information about the vdsm-patches mailing list