Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service validator vul #3717

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions generic_config_updater/services_validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import time
from .gu_common import genericUpdaterLogging
import subprocess

logger = genericUpdaterLogging.get_logger(title="Service Validator")

Expand All @@ -16,17 +16,25 @@ def set_verbose(verbose=False):
logger.set_min_log_priority_notice()


def run_command(cmd):
try:
subprocess.check_call(cmd)
except Exception as e:
return e.returncode
return 0


def _service_restart(svc_name):
rc = os.system(f"systemctl restart {svc_name}")
rc = run_command(['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 = run_command(['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 = run_command(['systemctl', 'restart', svc_name])
if rc != 0:
# Even with reset-failed, restart fails.
# Give a pause before retry.
Expand All @@ -35,7 +43,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 = run_command(['systemctl', 'restart', svc_name])

if rc == 0:
logger.log(logger.LOG_PRIORITY_NOTICE,
Expand All @@ -53,8 +61,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")
run_command(['systemctl', 'reset-failed', 'rsyslog-config', 'rsyslog'])
rc = run_command(['systemctl', 'restart', 'rsyslog-config'])
if rc != 0:
return False
return True
Expand Down Expand Up @@ -122,7 +130,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 = run_command(['ip', 'neigh', 'flush', 'dev', iface, iface_ip])
if rc:
return False
return True
Loading