Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[watermarkstat][202205] Add new warning message for the 'q_shared_multi' counters #2406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions scripts/watermarkstat
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ try:
tests_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
import mock_tables.dbconnector
from mock_tables import dbconnector

if os.environ["WATERMARKSTAT_UNIT_TESTING"] == "1":
input_path = os.path.join(tests_path, "wm_input")
mock_db_path = os.path.join(input_path, "mock_db")

for mock_db in os.listdir(mock_db_path):
name, ext = os.path.splitext(mock_db)
if ext == ".json":
dbconnector.dedicated_dbs[name.upper()] = os.path.join(mock_db_path, name)
except KeyError:
pass

Expand Down Expand Up @@ -201,7 +209,7 @@ class Watermarkstat(object):

return pg_index

def build_header(self, wm_type):
def build_header(self, wm_type, counter_type):
if wm_type is None:
print("Header info is not available!", file=sys.stderr)
sys.exit(1)
Expand All @@ -220,8 +228,12 @@ class Watermarkstat(object):
min_idx = element_idx

if min_idx == sys.maxsize:
print("Object map is empty!", file=sys.stderr)
sys.exit(1)
if counter_type != 'q_shared_multi':
print("Object map is empty!", file=sys.stderr)
sys.exit(1)
else:
print("Object map from the COUNTERS_DB is empty because the multicast queues are not configured in the CONFIG_DB!")
sys.exit(0)

self.min_idx = min_idx
self.header_list += ["{}{}".format(wm_type["header_prefix"], idx) for idx in range(self.min_idx, max_idx + 1)]
Expand Down Expand Up @@ -261,7 +273,7 @@ class Watermarkstat(object):
data = STATUS_NA
table.append((buf_pool, data))
else:
self.build_header(type)
self.build_header(type, key)
# Get stat for each port
for port in natsorted(self.counter_port_name_map):
row_data = list()
Expand Down
13 changes: 13 additions & 0 deletions tests/watermarkstat_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import pytest

import show.main as show
from click.testing import CliRunner
Expand All @@ -13,6 +14,15 @@
sys.path.insert(0, modules_path)


@pytest.fixture(scope="function")
def q_multicast_wm_neg():
print("Setup watermarkstat sample data: no queue multicast watermark counters")
os.environ['WATERMARKSTAT_UNIT_TESTING'] = "1"
yield
del os.environ['WATERMARKSTAT_UNIT_TESTING']
print("Teardown watermarkstat sample data: no queue multicast watermark counters")


class TestWatermarkstat(object):
@classmethod
def setup_class(cls):
Expand All @@ -32,6 +42,9 @@ def test_show_queue_unicast_wm(self):
def test_show_queue_multicast_wm(self):
self.executor(testData['show_q_wm_multicast'])

def test_show_queue_multicast_wm_neg(self, q_multicast_wm_neg):
self.executor(testData['show_q_wm_multicast_neg'])

def test_show_queue_all_wm(self):
self.executor(testData['show_q_wm_all'])

Expand Down
Loading