Skip to content

Commit 64aa1b8

Browse files
author
maksymbelei95
authored
[show] Fix warnings, related to gearbox, while show commands execution (sonic-net#1343)
* Performing getting from APPL_DB of all the keys while checking readiness status of the gearbox to prevent warnings sending to syslog if there no records of PHYs of a gearbox in APPL_DB. * Moving of the gearbox readiness status checking procedure to separated function. Signed-off-by: Maksym Belei <Maksym_Belei@jabil.com>
1 parent ff226d0 commit 64aa1b8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

show/main.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import subprocess
44
import sys
5+
import re
56

67
import click
78
import netifaces
@@ -45,6 +46,8 @@
4546

4647
VLAN_SUB_INTERFACE_SEPARATOR = '.'
4748

49+
GEARBOX_TABLE_PHY_PATTERN = r"_GEARBOX_TABLE:phy:*"
50+
4851
# To be enhanced. Routing-stack information should be collected from a global
4952
# location (configdb?), so that we prevent the continous execution of this
5053
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.
@@ -119,7 +122,20 @@ def connect_config_db():
119122
config_db.connect()
120123
return config_db
121124

125+
def is_gearbox_configured():
126+
"""
127+
Checks whether Gearbox is configured or not
128+
"""
129+
app_db = SonicV2Connector()
130+
app_db.connect(app_db.APPL_DB)
122131

132+
keys = app_db.keys(app_db.APPL_DB, '*')
133+
134+
# If any _GEARBOX_TABLE:phy:* records present in APPL_DB, then the gearbox is configured
135+
if any(re.match(GEARBOX_TABLE_PHY_PATTERN, key) for key in keys):
136+
return True
137+
else:
138+
return False
123139

124140
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?'])
125141

@@ -160,10 +176,7 @@ def cli(ctx):
160176
cli.add_command(warm_restart.warm_restart)
161177

162178
# Add greabox commands only if GEARBOX is configured
163-
# TODO: Find a cleaner way to do this
164-
app_db = SonicV2Connector(host='127.0.0.1')
165-
app_db.connect(app_db.APPL_DB)
166-
if app_db.keys(app_db.APPL_DB, '_GEARBOX_TABLE:phy:*'):
179+
if is_gearbox_configured():
167180
cli.add_command(gearbox.gearbox)
168181

169182

0 commit comments

Comments
 (0)