Skip to content

Commit 1bfafba

Browse files
m-nazeerSravaniMaddukurishivaboddulads952811Sonic Build
authored andcommitted
sync from broadcom_sonic_4.x_share to dell_sonic_4.x_share - 0629 (#129)
* [JIRA SONIC-59502] User name field in not applicable cases should be displayed as Not Applicable instead of empty. Change-Id: Ie96be7eacf13a9ebe4c9e95abbd6a88f1e47533f * [JIRA SONIC-60245] Field to display the operational value of the session timeout in the output of the show authentication clients. Change-Id: Ieddba8ac30568d55197fe1ce172b8cc208ffdc30 * [JIRA SONIC-56405] Added support for pac configuration over range of interfaces. Change-Id: I0ce68fc2497fcc45fcd0c15d6113542967d974c2 * [JIRA SONIC-61478] KLISH: add 50G AN support Signed-off-by: Dante Su <[email protected]> Change-Id: If6c05a49f18469858b66c58cd456e7b4f6a3c0e0 * [JIRA SONIC-61803] GetTablePattern ExistKeysPattern API in DB Layer - Added Statistics Change-Id: I3732e78e13881842e9394a571788abe3ab1ac337 * [JIRA SONIC-61314] go.sum update Change-Id: I7576ffc6933f9727747d3463b022c23ad7def609 * [JIRA SONIC-61807] - Model Identity as enumeration Used Enum to represent identities This will allow swagger ui to show drop-down in case of parameters. Change-Id: I8e438545d0b28c9c2ee545a2704366da512b5c74 * [JIRA SONIC-60508]: ospf neighbor details template fix Change-Id: Iee1dbdc72e02a6d23e0dfac71220843be3730ddd * [JIRA SONIC-61879] PAC - Added required changes for config knobs dymanic_vlan_enable, vlan_assign_enable. Change-Id: Ib38db8f2e9917b4261fc709e1548ea78f0196453 * [JIRA SONIC-61168] Klish support for ND config commands Change-Id: I7227cb99ecf82bddac169c3b544bd28758f40c3b * [JIRA SONIC-61223] With user added explicit snooping configuration on Vlan, actioner has called PATCH with default value for the no form of the user configuration, this has resulted in running configuration showing default value when there is no explicit configuration for the default - Fixed actioner script to trigger DELETE for the snooping configuration instead of PATCH with the default values. - Fix added in l2mcmgrd to fill snooping configuration IPC message by reading redisDB update instead of keeping separate local cache for snooping configurations which comes before snooping enable. Change-Id: I3ace4e6eca5cb7608d48bb9e3a11bb1c4976e4d9 * [JIRA SONIC-61948] - Using oc-yang for dhcp snooping trusted port configuration in Klish Change-Id: I33c811e9316b552b08cdbc12489c73806f4e3e95 * [JIRA SONIC-62134] - Corrected the sag xml order to come after vrf config Change-Id: I0d463d9d16e014d39b343d14d36ff801019017d4 * [JIRA SONIC-61997] using escap_chars option to skip '\' for special chars Change-Id: I3b654ea105931c0e3605b84ed5db560cb5e13e95 * [JIRA SONIC-62061] validating tag field of SNMP_SERVER_TARGET entry, before using it Change-Id: I504812121a85e83693d00dae76d5321583b1b7a0 * [JIRA SONIC-61168] Klish support for show command Change-Id: Ia2e6d4d8b8ae598af3cdcdbbb051bcddc8625bbc * [JIRA SONIC-62420] Added changes to not format debug logs until its enabled to speed up execuction of actioners for ACL and FBS Change-Id: Ibbad404d7f6890d03b99d63f26f9ddd36eab728d * [JIRA SONIC-61168] Klish support for modifying help string associated with config commands to make it more descriptive Change-Id: I9377ef77a093c3b0ed5269a1df874965ae6a3298 * [JIRA SONIC-60945] Show redirect ACL binding in show access-group CLI Change-Id: I56a2f7bce3a34eec51c4371210a4379ee8730589 * Fixing merge conflict Co-authored-by: Sravani Maddukuri <[email protected]> Co-authored-by: Shiva Kumar Boddula <[email protected]> Co-authored-by: Dante Su <[email protected]> Co-authored-by: Sonic Build <[email protected]> Co-authored-by: Arun Barboza <[email protected]> Co-authored-by: Sachin Holla <[email protected]> Co-authored-by: Faraaz <[email protected]> Co-authored-by: Ramachandran Sathianandan <[email protected]> Co-authored-by: sonicmergeuser <[email protected]> Co-authored-by: sudhanshukumar22 <[email protected]> Co-authored-by: Ashok Krishnegowda <[email protected]> Co-authored-by: Akhilesh Samineni <[email protected]> Co-authored-by: suresh-rupanagudi <[email protected]> Co-authored-by: Lakshmi Sruthy <[email protected]> Co-authored-by: Abhishek Dharwadkar <[email protected]> Co-authored-by: SONiC Syncbot <[email protected]>
1 parent be6381f commit 1bfafba

File tree

11 files changed

+547
-173
lines changed

11 files changed

+547
-173
lines changed

CLI/actioner/cli_log.py

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,83 @@
2020
import syslog
2121
import inspect
2222

23+
2324
syslog.openlog("sonic-cli")
24-
__enable_debug = False
25-
__enable_print = False
25+
__enable_debug = False
26+
__enable_print = False
27+
__enable_caller_name = False
2628

2729

28-
def log_debug(msg):
29-
if not isinstance(msg, str):
30-
msg = "{}".format(msg)
30+
class LogMessage:
31+
def __init__(self, level, msg, *args, **kwargs):
32+
self.level = level
33+
self.msg = msg
34+
self.args = args
35+
self.kwargs = kwargs
36+
self.fmt_msg = None
37+
self.caller = None
38+
if "_caller" in kwargs:
39+
self.caller = self.kwargs.pop("_caller")
40+
if not self.args and not self.kwargs:
41+
self.msg = "{}"
42+
self.args = [msg]
3143

32-
if __enable_debug:
33-
syslog.syslog(syslog.LOG_DEBUG, msg)
44+
def __str__(self):
45+
if self.fmt_msg is None:
46+
if self.caller:
47+
self.fmt_msg = str(self.caller) + " " + self.level + " :- " + self.fmt_msg
48+
else:
49+
self.fmt_msg = self.level + ": " + self.msg.format(*self.args, **self.kwargs)
3450

35-
if __enable_print:
51+
return self.fmt_msg
52+
53+
54+
def log_debug(msg, *args, **kwargs):
55+
if not __enable_debug and not __enable_print:
56+
return
57+
58+
if __enable_caller_name:
3659
caller_frame = inspect.stack()[1][0]
3760
frame_info = inspect.getframeinfo(caller_frame)
38-
for line in msg.split("\n"):
39-
print(("[{}:{}] DEBUG:: {}".format(frame_info.function,
40-
frame_info.lineno, line)))
61+
log_msg = LogMessage('DEBUG', msg, *args, _caller=LogMessage('[{}:{}]', frame_info.function, frame_info.lineno), **kwargs)
62+
else:
63+
log_msg = LogMessage('DEBUG', msg, *args, **kwargs)
4164

65+
if __enable_debug:
66+
syslog.syslog(syslog.LOG_DEBUG, str(log_msg))
4267

43-
def log_info(msg):
44-
if not isinstance(msg, str):
45-
msg = "{}".format(msg)
68+
if __enable_print:
69+
print(log_msg)
4670

47-
syslog.syslog(syslog.LOG_INFO, msg)
4871

49-
if __enable_print:
72+
def log_info(msg, *args, **kwargs):
73+
if not __enable_debug and not __enable_print:
74+
return
75+
76+
if __enable_caller_name:
5077
caller_frame = inspect.stack()[1][0]
5178
frame_info = inspect.getframeinfo(caller_frame)
52-
for line in msg.split("\n"):
53-
print(("[{}:{}] INFO:: {}".format(frame_info.function,
54-
frame_info.lineno, line)))
79+
log_msg = LogMessage('INFO', msg, *args, _caller=LogMessage('[{}:{}]', frame_info.function, frame_info.lineno), **kwargs)
80+
else:
81+
log_msg = LogMessage('INFO', msg, *args, **kwargs)
5582

83+
if __enable_debug:
84+
syslog.syslog(syslog.LOG_INFO, str(log_msg))
5685

57-
def log_error(msg):
58-
if not isinstance(msg, str):
59-
msg = "{}".format(msg)
86+
if __enable_print:
87+
print(log_msg)
6088

61-
syslog.syslog(syslog.LOG_ERR, msg)
6289

63-
if __enable_print:
90+
def log_error(msg, *args, **kwargs):
91+
if __enable_caller_name:
6492
caller_frame = inspect.stack()[1][0]
6593
frame_info = inspect.getframeinfo(caller_frame)
66-
for line in msg.split("\n"):
67-
print(("[{}:{}] ERROR:: {}".format(frame_info.function,
68-
frame_info.lineno, line)))
94+
log_msg = LogMessage('ERROR', msg, *args, _caller=LogMessage('[{}:{}]', frame_info.function, frame_info.lineno), **kwargs)
95+
else:
96+
log_msg = LogMessage('ERROR', msg, *args, **kwargs)
97+
98+
syslog.syslog(syslog.LOG_ERR, str(log_msg))
99+
100+
if __enable_print:
101+
print(log_msg)
102+

CLI/actioner/show_config_acl.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import cli_log as log
2525

2626
def __build_acl_config_cache(acl_type, acl_name, cache):
27-
log.log_debug("Building ACL Cache for {},{}".format(acl_type, acl_name))
27+
log.log_debug("Building ACL Cache for {},{}", acl_type, acl_name)
2828
if acl_name is not None:
2929
cache['_acl_cache_'] = dict()
3030
keypath = cc.Path('/restconf/data/openconfig-acl:acl/acl-sets/acl-set={name},{acl_type}', name=acl_name,
@@ -35,7 +35,7 @@ def __build_acl_config_cache(acl_type, acl_name, cache):
3535
acl_data = response.content['openconfig-acl:acl-set'][0]
3636
if 'config' in acl_data:
3737
cache['_acl_cache_'][(acl_type, acl_name)] = response.content['openconfig-acl:acl-set'][0]
38-
log.log_debug("ACL cache added for {},{}".format(acl_type, acl_name))
38+
log.log_debug("ACL cache added for {},{}", acl_type, acl_name)
3939
else:
4040
log.log_debug(response.error_message())
4141
elif '_acl_cache_' not in cache:
@@ -50,17 +50,17 @@ def __build_acl_config_cache(acl_type, acl_name, cache):
5050
oc_acl_type = acl_set['type'].split(':')[-1]
5151
if (acl_type and oc_acl_type == acl_type) or (acl_type is None):
5252
cache['_acl_cache_'][(oc_acl_type, acl_set['name'])] = acl_set
53-
log.log_debug("ACL cache added for {},{}".format(oc_acl_type, acl_set['name']))
53+
log.log_debug("ACL cache added for {},{}", oc_acl_type, acl_set['name'])
5454
else:
55-
log.log_debug("Not storing ACL {},{}".format(oc_acl_type, acl_set['name']))
55+
log.log_debug("Not storing ACL {},{}", oc_acl_type, acl_set['name'])
5656
else:
5757
log.log_debug(response.error_message())
5858
else:
5959
log.log_debug("ACL Cache already exists")
6060

6161

6262
def __build_acl_binding_cache(intf_type, ifname, cache):
63-
log.log_debug("ACL Interface {},{} specific show running".format(intf_type, ifname))
63+
log.log_debug("ACL Interface {},{} specific show running", intf_type, ifname)
6464
if ifname:
6565
keypath = cc.Path('/restconf/data/openconfig-acl:acl/interfaces/interface={intfname}', intfname=ifname)
6666
acl_client = cc.ApiClient()
@@ -69,7 +69,7 @@ def __build_acl_binding_cache(intf_type, ifname, cache):
6969
log.log_debug("Resp not success")
7070
return
7171
if 'openconfig-acl:interface' not in response.content:
72-
log.log_debug("'openconfig-acl:interface' not found in response {}".format(str(response.content)))
72+
log.log_debug("'openconfig-acl:interface' not found in response {}", response.content)
7373
return
7474
cache[ifname] = {'openconfig-acl:interface': response.content['openconfig-acl:interface'][0]}
7575
else:
@@ -81,14 +81,14 @@ def __build_acl_binding_cache(intf_type, ifname, cache):
8181
if (intf_type and intf_data['id'].startswith(intf_type)) or (intf_type is None):
8282
cache[intf_data['id']] = {'openconfig-acl:interface': intf_data}
8383
else:
84-
log.log_debug("Not storing cache for {}".format(intf_data['id']))
84+
log.log_debug("Not storing cache for {}", intf_data['id'])
8585
else:
8686
log.log_debug("Resp not success")
8787
return
8888

8989

9090
def __show_running_acl(in_acl_type, in_acl_name, cache):
91-
log.log_debug("Show running for ACL {},{}".format(in_acl_type, in_acl_name))
91+
log.log_debug("Show running for ACL {},{}", in_acl_type, in_acl_name)
9292
add_ex = False
9393
cmd_str = ''
9494
for (acl_type, acl_name), acl_set in cache['_acl_cache_'].items():
@@ -153,7 +153,7 @@ def __display_acl_bindings(data, direction, prefix):
153153

154154

155155
def __show_running_acl_binding(keypath, root, data, prefix):
156-
# log.log_debug("Show ACL binding for {},{},{},{}".format(keypath, root, data, prefix))
156+
log.log_debug("Show ACL binding for {},{},{},{}", keypath, root, data, prefix)
157157
cmd_str = ''
158158
if keypath:
159159
acl_client = cc.ApiClient()
@@ -163,7 +163,7 @@ def __show_running_acl_binding(keypath, root, data, prefix):
163163
log.log_debug("Resp not success")
164164
return ''
165165
if root not in response.content:
166-
log.log_debug("Root not found in response {}".format(str(response.content)))
166+
log.log_debug("Root not found in response {}", response.content)
167167
return ''
168168

169169
content = response.content
@@ -186,7 +186,7 @@ def __show_running_acl_binding(keypath, root, data, prefix):
186186

187187

188188
def show_running_acl_intf_bind_cb(render_tables):
189-
# log.log_debug("ACL binding callback for {}".format(str(render_tables)))
189+
log.log_debug("ACL binding callback for {}", render_tables)
190190
cmd_str = ''
191191
if render_tables['name'] in render_tables[__name__]:
192192
cmd_str = __show_running_acl_binding(None, 'openconfig-acl:interface',
@@ -195,21 +195,21 @@ def show_running_acl_intf_bind_cb(render_tables):
195195

196196

197197
def show_running_acl_global_bind_cb(render_tables):
198-
# log.log_debug("Show Global ACL bindings for {}".format(str(render_tables)))
198+
log.log_debug("Show Global ACL bindings for {}", render_tables)
199199
keypath = cc.Path('/restconf/data/openconfig-acl:acl/openconfig-acl-ext:global')
200200
cmd_str = __show_running_acl_binding(keypath, 'openconfig-acl-ext:global', None, '')
201201
return 'CB_SUCCESS', cmd_str, True
202202

203203

204204
def show_running_acl_ctrl_plane_bind_cb(render_tables):
205-
# log.log_debug("Show CtrlPlane ACL bindings for {}".format(str(render_tables)))
205+
log.log_debug("Show CtrlPlane ACL bindings for {}", render_tables)
206206
keypath = cc.Path('/restconf/data/openconfig-acl:acl/openconfig-acl-ext:control-plane')
207207
cmd_str = __show_running_acl_binding(keypath, 'openconfig-acl-ext:control-plane', None, ' ')
208208
return 'CB_SUCCESS', cmd_str, False
209209

210210

211211
def show_running_config_acl_start_callback(context, cache):
212-
log.log_debug("ACL Context={}".format(str(context)))
212+
log.log_debug("ACL Context={}", context)
213213
if context['view_name'] == '':
214214
log.log_debug("All ACLs and Interfaces config")
215215
__build_acl_config_cache(None, None, cache)
@@ -242,3 +242,4 @@ def show_running_config_acl_start_callback(context, cache):
242242

243243
def show_running_config_line_vty_view_cb(render_tables):
244244
return 'CB_SUCCESS', 'line vty', True
245+

0 commit comments

Comments
 (0)