77import subprocess
88import netaddr
99import re
10+ import syslog
1011
1112import sonic_platform
1213from swsssdk import ConfigDBConnector
1718import mlnx
1819
1920SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
21+ SYSLOG_IDENTIFIER = "config"
22+
23+ # ========================== Syslog wrappers ==========================
24+
25+ def log_debug (msg ):
26+ syslog .openlog (SYSLOG_IDENTIFIER )
27+ syslog .syslog (syslog .LOG_DEBUG , msg )
28+ syslog .closelog ()
29+
30+
31+ def log_info (msg ):
32+ syslog .openlog (SYSLOG_IDENTIFIER )
33+ syslog .syslog (syslog .LOG_INFO , msg )
34+ syslog .closelog ()
35+
36+
37+ def log_warning (msg ):
38+ syslog .openlog (SYSLOG_IDENTIFIER )
39+ syslog .syslog (syslog .LOG_WARNING , msg )
40+ syslog .closelog ()
41+
42+
43+ def log_error (msg ):
44+ syslog .openlog (SYSLOG_IDENTIFIER )
45+ syslog .syslog (syslog .LOG_ERR , msg )
46+ syslog .closelog ()
2047
2148#
2249# Helper functions
@@ -229,7 +256,11 @@ def _stop_services():
229256 'teamd' ,
230257 ]
231258 for service in services :
232- run_command ("systemctl stop %s" % service , display_cmd = True )
259+ try :
260+ run_command ("systemctl stop %s" % service , display_cmd = True )
261+ except SystemExit as e :
262+ log_error ("Stopping {} failed with error {}" .format (service , e ))
263+ raise
233264
234265def _restart_services ():
235266 services = [
@@ -246,8 +277,11 @@ def _restart_services():
246277 'dhcp_relay' ,
247278 ]
248279 for service in services :
249- run_command ("systemctl restart %s" % service , display_cmd = True )
250-
280+ try :
281+ run_command ("systemctl restart %s" % service , display_cmd = True )
282+ except SystemExit as e :
283+ log_error ("Restart {} failed with error {}" .format (service , e ))
284+ raise
251285
252286# This is our main entrypoint - the main 'config' command
253287@click .group ()
@@ -286,6 +320,8 @@ def reload(filename, yes, load_sysinfo):
286320 if not yes :
287321 click .confirm ('Clear current config and reload config from the file %s?' % filename , abort = True )
288322
323+ log_info ("'reload' executing..." )
324+
289325 if load_sysinfo :
290326 command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku" .format (SONIC_CFGGEN_PATH , filename )
291327 proc = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE )
@@ -340,6 +376,8 @@ def load_mgmt_config(filename):
340376 expose_value = False , prompt = 'Reload config from minigraph?' )
341377def load_minigraph ():
342378 """Reconfigure based on minigraph."""
379+ log_info ("'load_minigraph' executing..." )
380+
343381 #Stop services before config push
344382 _stop_services ()
345383
0 commit comments