From e244090bd691d375394bb65dca21475225dfdbed Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sun, 31 May 2020 22:58:18 +0000 Subject: [PATCH 1/2] [hostcfgd] Get service enable/disable feature working --- files/image_config/hostcfgd/hostcfgd | 67 +++++++++++++++------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/files/image_config/hostcfgd/hostcfgd b/files/image_config/hostcfgd/hostcfgd index edbbacca86c2..08bf2500182d 100755 --- a/files/image_config/hostcfgd/hostcfgd +++ b/files/image_config/hostcfgd/hostcfgd @@ -268,38 +268,41 @@ class HostConfigDaemon: if not key: syslog.syslog(syslog.LOG_WARNING, "FEATURE key is missing") return - status = status_data[key]['status'] - if not status: - syslog.syslog(syslog.LOG_WARNING, "status is missing for {}".format(key)) - return - if status == "enabled": - start_cmds=[] - start_cmds.append("sudo systemctl enable {}".format(key)) - start_cmds.append("sudo systemctl start {}".format(key)) - for cmd in start_cmds: - syslog.syslog(syslog.LOG_INFO, "Running cmd - {}".format(cmd)) - try: - subprocess.check_call(cmd, shell=True) - except subprocess.CalledProcessError as err: - syslog.syslog(syslog.LOG_ERR, "{} - failed: return code - {}, output:\n{}" - .format(err.cmd, err.returncode, err.output)) - return - syslog.syslog(syslog.LOG_INFO, "Feature '{}' is enabled and started".format(key)) - elif status == "disabled": - stop_cmds=[] - stop_cmds.append("sudo systemctl stop {}".format(key)) - stop_cmds.append("sudo systemctl disable {}".format(key)) - for cmd in stop_cmds: - syslog.syslog(syslog.LOG_INFO, "Running cmd - {}".format(cmd)) - try: - subprocess.check_call(cmd, shell=True) - except subprocess.CalledProcessError as err: - syslog.syslog(syslog.LOG_ERR, "{} - failed: return code - {}, output:\n{}" - .format(err.cmd, err.returncode, err.output)) - return - syslog.syslog(syslog.LOG_INFO, "Feature '{}' is stopped and disabled".format(key)) - else: - syslog.syslog(syslog.LOG_ERR, "Unexpected status value '{}' for '{}'".format(status, key)) + + status = status_data[key]['status'] + if not status: + syslog.syslog(syslog.LOG_WARNING, "status is missing for {}".format(key)) + return + if status == "enabled": + start_cmds=[] + start_cmds.append("sudo systemctl unmask {}.service".format(key)) + start_cmds.append("sudo systemctl enable {}.service".format(key)) + start_cmds.append("sudo systemctl start {}.service".format(key)) + for cmd in start_cmds: + syslog.syslog(syslog.LOG_INFO, "Running cmd - {}".format(cmd)) + try: + subprocess.check_call(cmd, shell=True) + except subprocess.CalledProcessError as err: + syslog.syslog(syslog.LOG_ERR, "{} - failed: return code - {}, output:\n{}" + .format(err.cmd, err.returncode, err.output)) + return + syslog.syslog(syslog.LOG_INFO, "Feature '{}' is enabled and started".format(key)) + elif status == "disabled": + stop_cmds=[] + stop_cmds.append("sudo systemctl stop {}.service".format(key)) + stop_cmds.append("sudo systemctl disable {}.service".format(key)) + stop_cmds.append("sudo systemctl mask {}.service".format(key)) + for cmd in stop_cmds: + syslog.syslog(syslog.LOG_INFO, "Running cmd - {}".format(cmd)) + try: + subprocess.check_call(cmd, shell=True) + except subprocess.CalledProcessError as err: + syslog.syslog(syslog.LOG_ERR, "{} - failed: return code - {}, output:\n{}" + .format(err.cmd, err.returncode, err.output)) + return + syslog.syslog(syslog.LOG_INFO, "Feature '{}' is stopped and disabled".format(key)) + else: + syslog.syslog(syslog.LOG_ERR, "Unexpected status value '{}' for '{}'".format(status, key)) def start(self): self.config_db.subscribe('AAA', lambda table, key, data: self.aaa_handler(key, data)) From c20964ef23b92b9e9ed8795498fb273a0f5fcc15 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 1 Jun 2020 22:12:32 +0000 Subject: [PATCH 2/2] continue rather than return --- files/image_config/hostcfgd/hostcfgd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/image_config/hostcfgd/hostcfgd b/files/image_config/hostcfgd/hostcfgd index 08bf2500182d..6d4615d85823 100755 --- a/files/image_config/hostcfgd/hostcfgd +++ b/files/image_config/hostcfgd/hostcfgd @@ -267,12 +267,12 @@ class HostConfigDaemon: for key in status_data.keys(): if not key: syslog.syslog(syslog.LOG_WARNING, "FEATURE key is missing") - return + continue status = status_data[key]['status'] if not status: syslog.syslog(syslog.LOG_WARNING, "status is missing for {}".format(key)) - return + continue if status == "enabled": start_cmds=[] start_cmds.append("sudo systemctl unmask {}.service".format(key)) @@ -285,7 +285,7 @@ class HostConfigDaemon: except subprocess.CalledProcessError as err: syslog.syslog(syslog.LOG_ERR, "{} - failed: return code - {}, output:\n{}" .format(err.cmd, err.returncode, err.output)) - return + continue syslog.syslog(syslog.LOG_INFO, "Feature '{}' is enabled and started".format(key)) elif status == "disabled": stop_cmds=[] @@ -299,7 +299,7 @@ class HostConfigDaemon: except subprocess.CalledProcessError as err: syslog.syslog(syslog.LOG_ERR, "{} - failed: return code - {}, output:\n{}" .format(err.cmd, err.returncode, err.output)) - return + continue syslog.syslog(syslog.LOG_INFO, "Feature '{}' is stopped and disabled".format(key)) else: syslog.syslog(syslog.LOG_ERR, "Unexpected status value '{}' for '{}'".format(status, key))