Skip to content

Commit

Permalink
Merge branch '202305' into 202305
Browse files Browse the repository at this point in the history
  • Loading branch information
yxieca committed Dec 20, 2023
2 parents db82c24 + 61903ee commit 8b090df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 5 additions & 3 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ def set_level(lvl, log_to_syslog):
report_level = syslog.LOG_DEBUG


def print_message(lvl, *args):
def print_message(lvl, *args, write_to_stdout=True):
"""
print and log the message for given level.
:param lvl: Log level for this message as ERR/INFO/DEBUG
:param args: message as list of strings or convertible to string
:param write_to_stdout: print the message to stdout if set to true
:return None
"""
msg = ""
Expand All @@ -129,7 +130,8 @@ def print_message(lvl, *args):
break
msg += str(arg)[0:rem_len]

print(msg)
if write_to_stdout:
print(msg)
if write_to_syslog:
syslog.syslog(lvl, msg)

Expand Down Expand Up @@ -575,7 +577,7 @@ def mitigate_installed_not_offloaded_frr_routes(missed_frr_rt, rt_appl):
fvs = swsscommon.FieldValuePairs([('err_str', 'SWSS_RC_SUCCESS'), ('protocol', entry['protocol'])])
response_producer.send('SWSS_RC_SUCCESS', entry['prefix'], fvs)

print_message(syslog.LOG_ERR, f'Mitigated route {entry["prefix"]}')
print_message(syslog.LOG_ERR, f'Mitigated route {entry["prefix"]}', write_to_stdout=False)


def get_soc_ips(config_db):
Expand Down
13 changes: 11 additions & 2 deletions tests/route_check_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
from io import StringIO
import json
import os
import logging
Expand All @@ -7,7 +8,7 @@
import time
from sonic_py_common import device_info
from unittest.mock import MagicMock, patch
from tests.route_check_test_data import APPL_DB, ARGS, ASIC_DB, CONFIG_DB, DEFAULT_CONFIG_DB, DESCR, OP_DEL, OP_SET, PRE, RESULT, RET, TEST_DATA, UPD, FRR_ROUTES
from tests.route_check_test_data import APPL_DB, ARGS, ASIC_DB, CONFIG_DB, DEFAULT_CONFIG_DB, APPL_STATE_DB, DESCR, OP_DEL, OP_SET, PRE, RESULT, RET, TEST_DATA, UPD, FRR_ROUTES

import pytest

Expand Down Expand Up @@ -89,7 +90,7 @@ def hget(self, key, field):
return True, ret


db_conns = {"APPL_DB": APPL_DB, "ASIC_DB": ASIC_DB}
db_conns = {"APPL_DB": APPL_DB, "ASIC_DB": ASIC_DB, "APPL_STATE_DB": APPL_STATE_DB }
def conn_side_effect(arg, _):
return db_conns[arg]

Expand Down Expand Up @@ -321,3 +322,11 @@ def test_logging(self):
assert len(msg) == 5
msg = route_check.print_message(syslog.LOG_ERR, "a", "b", "c", "d", "e", "f")
assert len(msg) == 5

def test_mitigate_routes(self, mock_dbs):
missed_frr_rt = [ { 'prefix': '192.168.0.1', 'protocol': 'bgp' } ]
rt_appl = [ '192.168.0.1' ]
with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
route_check.mitigate_installed_not_offloaded_frr_routes(missed_frr_rt, rt_appl)
# Verify that the stdout are suppressed in this function
assert not mock_stdout.getvalue()
1 change: 1 addition & 0 deletions tests/route_check_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
APPL_DB = 0
ASIC_DB = 1
CONFIG_DB = 4
APPL_STATE_DB = 14
PRE = "pre-value"
UPD = "update"
FRR_ROUTES = "frr-routes"
Expand Down

0 comments on commit 8b090df

Please sign in to comment.