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: I99492161d29254e48a0196b3b5cbdfa7c9dc1863
Signed-off-by: Juan Hernandez <[email protected]>
---
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/93/12793/1

diff --git a/packaging/fedora/setup/common_utils.py 
b/packaging/fedora/setup/common_utils.py
index 7acd19a..392e1a6 100755
--- a/packaging/fedora/setup/common_utils.py
+++ b/packaging/fedora/setup/common_utils.py
@@ -1308,15 +1308,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/12793
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I99492161d29254e48a0196b3b5cbdfa7c9dc1863
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to