Skip to content

Commit

Permalink
🧪 unit test: Add runninngconfig syslog test
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Fastiuk <yfastiuk@nvidia.com>
  • Loading branch information
fastiuk committed May 23, 2023
1 parent a91e18d commit a540fe5
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import show.main as show
from click.testing import CliRunner
from unittest import mock
from unittest.mock import call, MagicMock, patch
from unittest.mock import call, MagicMock, patch, mock_open

EXPECTED_BASE_COMMAND = 'sudo '

Expand Down Expand Up @@ -147,3 +147,28 @@ def test_show_version():
runner = CliRunner()
result = runner.invoke(show.cli.commands["version"])
assert "SONiC OS Version: 11" in result.output


class TestShowRunningconfiguration(object):
@classmethod
def setup_class(cls):
print('SETUP')
os.environ['UTILITIES_UNIT_TESTING'] = '1'

@patch('show.main.run_command')
@patch('builtins.open', mock_open(
read_data=open('tests/syslog_input/rsyslog.conf').read()))
def test_rc_syslog(self, mock_rc):
runner = CliRunner()

result = runner.invoke(
show.cli.commands['runningconfiguration'].commands['syslog'])
print(result.exit_code)
print(result.output)

assert result.exit_code == 0
assert '[1.1.1.1]' in result.output

@classmethod
def teardown_class(cls):
print('TEARDOWN')
77 changes: 77 additions & 0 deletions tests/syslog_input/rsyslog.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
###############################################################################
# Managed by Ansible
# file: ansible/roles/acs/templates/rsyslog.conf.j2
###############################################################################
#
# /etc/rsyslog.conf Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html


#################
#### MODULES ####
#################

$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog # provides kernel logging support
#$ModLoad immark # provides --MARK-- message capability

# provides UDP syslog reception
$ModLoad imudp
$UDPServerAddress 127.0.0.1 #bind to localhost before udp server run
$UDPServerRun 514

# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514


###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Define a custom template
$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
$ActionFileDefaultTemplate SONiCFileFormat

template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall time=\"%timereported\
:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\
:::date-second%\" fw=\"sonic\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n")

#Set remote syslog server
*.notice
action(type="omfwd" Target="1.1.1.1" Port="514" Protocol="udp" Device="eth0" Template="SONiCFileFormat")

#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

#
# Suppress duplicate messages and report "message repeated n times"
#
$RepeatedMsgReduction on

###############
#### RULES ####
###############

0 comments on commit a540fe5

Please sign in to comment.