URL: https://github.com/freeipa/freeipa/pull/3084
Author: flo-renaud
 Title: #3084: ipactl restart: fix wrong logic when checking service list
Action: opened

PR body:
"""
ipactl is building a list of currently running services from
the content of /var/run/ipa/services.list, and a list of expected services
from the services configured in LDAP.

Because CA and KRA both correspond to the same pki-tomcatd service, the
lists may contain duplicates. The code handling these duplicates is called
at the wrong place, and may result in a wrong list of services to
stop / restart / start.
The fix removes the duplicates before returning the lists, hence making sure
that there is no error when building the list of services to stop / restart
/ start.

Fixes: https://pagure.io/freeipa/issue/7927
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/3084/head:pr3084
git checkout pr3084
From d348ed8307c60a4c5b3d5472ea474d292133fe41 Mon Sep 17 00:00:00 2001
From: Florence Blanc-Renaud <f...@redhat.com>
Date: Fri, 26 Apr 2019 15:10:22 +0200
Subject: [PATCH] ipactl restart: fix wrong logic when checking service list

ipactl is building a list of currently running services from
the content of /var/run/ipa/services.list, and a list of expected services
from the services configured in LDAP.

Because CA and KRA both correspond to the same pki-tomcatd service, the
lists may contain duplicates. The code handling these duplicates is called
at the wrong place, and may result in a wrong list of services to
stop / restart / start.
The fix removes the duplicates before returning the lists, hence making sure
that there is no error when building the list of services to stop / restart
/ start.

Fixes: https://pagure.io/freeipa/issue/7927
---
 install/tools/ipactl.in | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/install/tools/ipactl.in b/install/tools/ipactl.in
index ff4e01d81b..52773e099e 100644
--- a/install/tools/ipactl.in
+++ b/install/tools/ipactl.in
@@ -237,7 +237,7 @@ def get_config(dirsrv):
     for order, svc in sorted(svc_list):
         if svc in service.SERVICE_LIST:
             ordered_list.append(service.SERVICE_LIST[svc].systemd_name)
-    return ordered_list
+    return deduplicate(ordered_list)
 
 def get_config_from_file():
 
@@ -263,7 +263,7 @@ def get_config_from_file():
         if svc in svc_list:
             ordered_list.append(svc)
 
-    return ordered_list
+    return deduplicate(ordered_list)
 
 
 def stop_services(svc_list):
@@ -325,7 +325,6 @@ def ipa_start(options):
         # no service to start
         return
 
-    svc_list = deduplicate(svc_list)
     for svc in svc_list:
         svchandle = services.service(svc, api=api)
         try:
@@ -365,7 +364,6 @@ def ipa_stop(options):
             finally:
                 raise IpactlError()
 
-    svc_list = deduplicate(svc_list)
     for svc in reversed(svc_list):
         svchandle = services.service(svc, api=api)
         try:
@@ -452,7 +450,6 @@ def ipa_restart(options):
 
     if len(old_svc_list) != 0:
         # we need to definitely stop some services
-        old_svc_list = deduplicate(old_svc_list)
         for svc in reversed(old_svc_list):
             svchandle = services.service(svc, api=api)
             try:
@@ -477,7 +474,6 @@ def ipa_restart(options):
 
     if len(svc_list) != 0:
         # there are services to restart
-        svc_list = deduplicate(svc_list)
         for svc in svc_list:
             svchandle = services.service(svc, api=api)
             try:
@@ -500,7 +496,6 @@ def ipa_restart(options):
 
     if len(new_svc_list) != 0:
         # we still need to start some services
-        new_svc_list = deduplicate(new_svc_list)
         for svc in new_svc_list:
             svchandle = services.service(svc, api=api)
             try:
@@ -552,7 +547,6 @@ def ipa_status(options):
     if len(svc_list) == 0:
         return
 
-    svc_list = deduplicate(svc_list)
     for svc in svc_list:
         svchandle = services.service(svc, api=api)
         try:
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to