Skip to content

Commit

Permalink
[show] Fix warnings, related to gearbox, while show commands execution (
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
maksymbelei95 authored Jan 26, 2021
1 parent ff226d0 commit 64aa1b8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
import sys
import re

import click
import netifaces
Expand Down Expand Up @@ -45,6 +46,8 @@

VLAN_SUB_INTERFACE_SEPARATOR = '.'

GEARBOX_TABLE_PHY_PATTERN = r"_GEARBOX_TABLE:phy:*"

# To be enhanced. Routing-stack information should be collected from a global
# location (configdb?), so that we prevent the continous execution of this
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.
Expand Down Expand Up @@ -119,7 +122,20 @@ def connect_config_db():
config_db.connect()
return config_db

def is_gearbox_configured():
"""
Checks whether Gearbox is configured or not
"""
app_db = SonicV2Connector()
app_db.connect(app_db.APPL_DB)

keys = app_db.keys(app_db.APPL_DB, '*')

# If any _GEARBOX_TABLE:phy:* records present in APPL_DB, then the gearbox is configured
if any(re.match(GEARBOX_TABLE_PHY_PATTERN, key) for key in keys):
return True
else:
return False

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

Expand Down Expand Up @@ -160,10 +176,7 @@ def cli(ctx):
cli.add_command(warm_restart.warm_restart)

# Add greabox commands only if GEARBOX is configured
# TODO: Find a cleaner way to do this
app_db = SonicV2Connector(host='127.0.0.1')
app_db.connect(app_db.APPL_DB)
if app_db.keys(app_db.APPL_DB, '_GEARBOX_TABLE:phy:*'):
if is_gearbox_configured():
cli.add_command(gearbox.gearbox)


Expand Down

0 comments on commit 64aa1b8

Please sign in to comment.