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

Add volume test #10

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Changes from 1 commit
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
61 changes: 61 additions & 0 deletions src/sonic-eventd/tools/rsyslog_volume_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sys
import subprocess
import time
import logging
import argparse

logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers = [
logging.FileHandler("debug.log"),
logging.StreamHandler(sys.stdout)
]
)

def read_events_from_file(count):
logging.info("Reading from file generated by events_tool")
lines = 0
with open('STDOUT', 'r') as file:
zbud-msft marked this conversation as resolved.
Show resolved Hide resolved
lines = file.readlines()
logging.info("Should receive {} events and got {} events\n".format(count, len(lines)))
assert len(lines) == count

def start_tool():
logging.info("Starting events_tool\n")
proc = subprocess.Popen(["./events_tool", "-r"])
return proc

def run_test(file, count):
# log messages to see if events have been received
tool_proc = start_tool()

time.sleep(2) # buffer for events_tool to startup

log_messages_cnt = 0
logging.info("Generating logger messages\n")
zbud-msft marked this conversation as resolved.
Show resolved Hide resolved
with open(file, 'r') as infile:
lines = infile.readlines()
log_messages_cnt = len(lines)
for line in lines:
line.rstrip()
command = "logger -p local0.notice -t {}\n".format(line)
for _ in range(count):
subprocess.run(command, shell=True, stdout=subprocess.PIPE)

time.sleep(2) # some buffer for all events to be published to file
read_events_from_file(count * log_messages_cnt)
tool_proc.terminate()

def main():
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", nargs='?', const='', default='', help="File containing log messages to be generated and read by rsyslog_plugin")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set required = True, the python parser will fail on no arg.
Need not change.
More a tip.

parser.add_argument("-c", "--count", type=int, nargs='?', const=1, default=1, help="Count of times log message needs to be published down/up, default is 1")
args = parser.parse_args()
if(args.file == ''):
logging.error("Invalid logfile\n")
return
run_test(args.file, args.count)

if __name__ == "__main__":
main()