Juan Hernandez has uploaded a new change for review.

Change subject: packaging: Use Id=... to check systemd services
......................................................................

packaging: Use Id=... to check systemd services

The services managed by systemd can have an unique identifier and then
several alternative names, or aliases. The NFS service, for example, has
"nfs-server" as identifier but it also has "nfs" and "nfs-server" as
aliases. These alternative names can be used for some operations, but
not for all of them, in particular the "systemctl enable ..." operation
requires the main name, it will not work with alternative names. This
meas that we need to make sure that the method that checks the
availability of services uses the main name, otherwise it can succeed
but then later the call to "systemctl enable" can fail.

Change-Id: I60ba0a5481f191c67eeb1fed6abd3f961cfbc8f4
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
(cherry picked from commit b2f6cbeac1cef232b560269faa50de4d030bb282)
---
M packaging/fedora/setup/common_utils.py
1 file changed, 14 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/63/12863/1

diff --git a/packaging/fedora/setup/common_utils.py 
b/packaging/fedora/setup/common_utils.py
index b6575d3..444cf20 100755
--- a/packaging/fedora/setup/common_utils.py
+++ b/packaging/fedora/setup/common_utils.py
@@ -1281,15 +1281,22 @@
     def available(self):
         logging.debug("checking if %s service is available", self.name)
 
-        # Checks if systemd service available
-        cmd = [
-            basedefs.EXEC_SYSTEMCTL,
-            "show",
-            "%s.service" % self.name
-        ]
+        # Checks if systemd service available. Note that in systemd a
+        # service can have several aliases, for example, the NFS service
+        # can be used with "nfs" or "nfs-server", but then only the
+        # main name can be used to manipulate the service with commands
+        # like "systemctl enable ...". So we need to check that we are
+        # using the main name, otherwise later methods will use the
+        # wrong name and fail.
         if os.path.exists(basedefs.EXEC_SYSTEMCTL):
+            cmd = [
+                basedefs.EXEC_SYSTEMCTL,
+                "show",
+                "%s.service" % self.name
+            ]
             out, rc = execCmd(cmdList=cmd)
-            sysd = "LoadState=loaded" in out
+            sysd = re.search(r"^Id=%s\.service$" % self.name, out, 
re.MULTILINE) is not None and \
+                   re.search(r"^LoadState=loaded$", out, re.MULTILINE) is not 
None
         else:
             sysd = False
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I60ba0a5481f191c67eeb1fed6abd3f961cfbc8f4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: engine_3.2
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to