7
7
import subprocess
8
8
import netaddr
9
9
import re
10
+ import syslog
10
11
11
12
import sonic_platform
12
13
from swsssdk import ConfigDBConnector
17
18
import mlnx
18
19
19
20
SONIC_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 ()
20
47
21
48
#
22
49
# Helper functions
@@ -229,7 +256,11 @@ def _stop_services():
229
256
'teamd' ,
230
257
]
231
258
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
233
264
234
265
def _restart_services ():
235
266
services = [
@@ -246,8 +277,11 @@ def _restart_services():
246
277
'dhcp_relay' ,
247
278
]
248
279
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
251
285
252
286
# This is our main entrypoint - the main 'config' command
253
287
@click .group ()
@@ -286,6 +320,8 @@ def reload(filename, yes, load_sysinfo):
286
320
if not yes :
287
321
click .confirm ('Clear current config and reload config from the file %s?' % filename , abort = True )
288
322
323
+ log_info ("'reload' executing..." )
324
+
289
325
if load_sysinfo :
290
326
command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku" .format (SONIC_CFGGEN_PATH , filename )
291
327
proc = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE )
@@ -340,6 +376,8 @@ def load_mgmt_config(filename):
340
376
expose_value = False , prompt = 'Reload config from minigraph?' )
341
377
def load_minigraph ():
342
378
"""Reconfigure based on minigraph."""
379
+ log_info ("'load_minigraph' executing..." )
380
+
343
381
#Stop services before config push
344
382
_stop_services ()
345
383
0 commit comments