Skip to content

Commit

Permalink
Fixes to use consistent configdb during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rdjeric-arista committed May 13, 2024
1 parent f04c25e commit 49590ab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
49 changes: 39 additions & 10 deletions pfc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tabulate import tabulate
from natsort import natsorted
from importlib import reload
from utilities_common import multi_asic as multi_asic_util

ALL_PRIORITIES = [str(x) for x in range(8)]
PRIORITY_STATUS = ['on', 'off']
Expand All @@ -21,12 +22,23 @@
pass

class Pfc(object):
def __init__(self, db=None):
self.db = None
self.cfgdb = db
self.multi_asic = multi_asic_util.MultiAsic()

def configPfcAsym(self, interface, pfc_asym):
"""
PFC handler to configure asymmentric PFC.
PFC handler to configure asymmetric PFC.
"""
configdb = ConfigDBConnector()
configdb.connect()

configdb = self.cfgdb
if configdb is None:
# Get the namespace list
namespaces = multi_asic.get_namespace_list()

configdb = ConfigDBConnector(namespace=namespaces[0])
configdb.connect()

configdb.mod_entry("PORT", interface, {'pfc_asym': pfc_asym})

Expand All @@ -39,8 +51,13 @@ def showPfcAsym(self, interface):
"""
header = ('Interface', 'Asymmetric')

configdb = ConfigDBConnector()
configdb.connect()
configdb = self.cfgdb
if configdb is None:
# Get the namespace list
namespaces = multi_asic.get_namespace_list()

configdb = ConfigDBConnector(namespace=namespaces[0])
configdb.connect()

if interface:
db_keys = configdb.keys(configdb.CONFIG_DB, 'PORT|{0}'.format(interface))
Expand All @@ -65,8 +82,13 @@ def showPfcAsym(self, interface):
click.echo()

def configPfcPrio(self, status, interface, priority):
configdb = ConfigDBConnector()
configdb.connect()
configdb = self.cfgdb
if configdb is None:
# Get the namespace list
namespaces = multi_asic.get_namespace_list()

configdb = ConfigDBConnector(namespace=namespaces[0])
configdb.connect()

if interface not in configdb.get_keys('PORT_QOS_MAP'):
click.echo('Cannot find interface {0}'.format(interface))
Expand Down Expand Up @@ -106,8 +128,13 @@ def showPfcPrio(self, interface):
header = ('Interface', 'Lossless priorities')
table = []

configdb = ConfigDBConnector()
configdb.connect()
configdb = self.cfgdb
if configdb is None:
# Get the namespace list
namespaces = multi_asic.get_namespace_list()

configdb = ConfigDBConnector(namespace=namespaces[0])
configdb.connect()

"""Get all the interfaces with QoS map information"""
intfs = configdb.get_keys('PORT_QOS_MAP')
Expand All @@ -132,8 +159,10 @@ def showPfcPrio(self, interface):
@click.group()
@click.pass_context
def cli(ctx):
# Use the db object if given as input.
db = None if ctx.obj is None else ctx.obj.cfgdb
"""PFC Command Line"""
ctx.obj = { 'pfc': Pfc() }
ctx.obj = { 'pfc': Pfc(db) }

@cli.group()
@click.pass_context
Expand Down
7 changes: 5 additions & 2 deletions tests/pfc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import pfc.main as pfc
from pfc_input.assert_show_output import *
from utilities_common.db import Db

from click.testing import CliRunner
from importlib import reload
Expand All @@ -20,7 +21,9 @@ def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "2"

def executor(self, command, args, expected_rc=0, expected_output=None, runner=CliRunner()):
result = runner.invoke(command, args)
db = Db()
obj = {'config_db':db.cfgdb}
result = runner.invoke(command, args, obj=db)
print(result.exit_code)
print(result.output)

Expand Down Expand Up @@ -76,4 +79,4 @@ def test_pfc_config_asymmetric(self):

def test_pfc_config_priority(self):
self.executor(pfc.cli, ['config', 'priority', 'on', 'Ethernet0', '5'],
expected_output=pfc_config_priority_on)
expected_output=pfc_config_priority_on)

0 comments on commit 49590ab

Please sign in to comment.