diff --git a/generic_config_updater/services_validator.py b/generic_config_updater/services_validator.py index 25501f759f..029039d2f7 100644 --- a/generic_config_updater/services_validator.py +++ b/generic_config_updater/services_validator.py @@ -1,6 +1,6 @@ -import os import time from .gu_common import genericUpdaterLogging +from subprocess import call logger = genericUpdaterLogging.get_logger(title="Service Validator") @@ -17,16 +17,16 @@ def set_verbose(verbose=False): def _service_restart(svc_name): - rc = os.system(f"systemctl restart {svc_name}") + rc = call(['systemctl', 'restart', svc_name]) if rc != 0: # This failure is likely due to too many restarts # - rc = os.system(f"systemctl reset-failed {svc_name}") + rc = call(['systemctl', 'reset-failed', svc_name]) logger.log(logger.LOG_PRIORITY_ERROR, f"Service has been reset. rc={rc}; Try restart again...", print_to_console) - rc = os.system(f"systemctl restart {svc_name}") + rc = call(['systemctl', 'restart', svc_name]) if rc != 0: # Even with reset-failed, restart fails. # Give a pause before retry. @@ -35,7 +35,7 @@ def _service_restart(svc_name): f"Restart failed for {svc_name} rc={rc} after reset; Pause for 10s & retry", print_to_console) time.sleep(10) - rc = os.system(f"systemctl restart {svc_name}") + rc = call(['systemctl', 'restart', svc_name]) if rc == 0: logger.log(logger.LOG_PRIORITY_NOTICE, @@ -53,8 +53,8 @@ def rsyslog_validator(old_config, upd_config, keys): upd_syslog = upd_config.get("SYSLOG_SERVER", {}) if old_syslog != upd_syslog: - os.system("systemctl reset-failed rsyslog-config rsyslog") - rc = os.system("systemctl restart rsyslog-config") + call(['systemctl', 'reset-failed', 'rsyslog-config', 'rsyslog']) + rc = call(['systemctl', 'restart', 'rsyslog-config']) if rc != 0: return False return True @@ -122,7 +122,7 @@ def vlanintf_validator(old_config, upd_config, keys): deleted_keys = list(set(old_keys) - set(upd_keys)) for key in deleted_keys: iface, iface_ip = key - rc = os.system(f"ip neigh flush dev {iface} {iface_ip}") + rc = call(['ip', 'neigh', 'flush', 'dev', iface, iface_ip]) if rc: return False return True