Skip to content
Closed
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
21 changes: 20 additions & 1 deletion tests/syslog/test_syslog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import pytest
import json

from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import wait_until
Expand Down Expand Up @@ -42,9 +43,25 @@ def config_dut(tbinfo, duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]
logger.info("Configuring the DUT")
local_syslog_srv_ip = tbinfo["ptf_ip"]
logger.info("test_syslog_srv_ip %s", local_syslog_srv_ip)

# Add static route to PTF docker for rsyslog to work
logger.info("Adding static route to PTF")
config_file_object = duthost.shell("cat /etc/sonic/config_db.json")
if config_file_object["rc"]:
assert("Failed to open config file on '/etc/sonic/config_db.json'")
config_file_content = config_file_object["stdout"]
mgmt_interface_data = json.loads(config_file_content)["MGMT_INTERFACE"]
for key, value in mgmt_interface_data.iteritems():
if key.count('.') == 3:
gw = value["gwaddr"]
break
if not gw:
assert("No IPv4 default GW found for eth0")
duthost.shell("sudo ip route add {}/32 via {} dev eth0".format(local_syslog_srv_ip, gw))
logger.debug("Added new route to PTF with command: sudo ip route add {}/32 via {} dev eth0".format(local_syslog_srv_ip, gw))

# Add Rsyslog destination for testing
logger.info("test_syslog_srv_ip %s", local_syslog_srv_ip)
duthost.shell("sudo config syslog add {}".format(local_syslog_srv_ip))
logger.debug("Added new rsyslog server IP {}".format(local_syslog_srv_ip))

Expand All @@ -53,6 +70,8 @@ def config_dut(tbinfo, duthosts, rand_one_dut_hostname):
# Remove the syslog configuration
duthost.shell("sudo config syslog del {}".format(local_syslog_srv_ip))

# Remove static route to PTF docker
duthost.shell("sudo ip route del {}/32 via {} dev eth0".format(local_syslog_srv_ip, gw))

def test_syslog(duthosts, rand_one_dut_hostname, ptfhost, config_dut):
duthost = duthosts[rand_one_dut_hostname]
Expand Down