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

[Beats][pytest] Asserting if filebeat logs include errors #20999

Merged
merged 6 commits into from
Oct 6, 2020
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
Prev Previous commit
Next Next commit
changing errors from string to array and adding more specific errors …
…to ensure no false positives
  • Loading branch information
P1llus committed Sep 6, 2020
commit ba59d5a92c53570d5e5bb6be342142fb3609f76f
11 changes: 7 additions & 4 deletions filebeat/tests/system/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ def run_on_file(self, module, fileset, test_file, cfgfile):
bufsize=0).wait()
output.close()
P1llus marked this conversation as resolved.
Show resolved Hide resolved

# List of errors to check in filebeat output logs
errors = ["Error loading pipeline for fileset"]
P1llus marked this conversation as resolved.
Show resolved Hide resolved
# Checks if the output of filebeat includes errors
contains_error, error_line = file_contains(os.path.join(output_path, "output.log"), "ERROR")
contains_error, error_line = file_contains(os.path.join(output_path, "output.log"), errors)
assert contains_error is False, "Error found in log:{}".format(error_line)

# Ensure file is actually closed to ensure large amount of file handlers is not spawning
Expand Down Expand Up @@ -305,11 +307,12 @@ def delete_key(obj, key):
del obj[key]


def file_contains(filepath, string):
def file_contains(filepath, strings):
with open(filepath, 'r') as file:
for line in file:
if string in line:
return True, line
for string in strings:
if string in line:
return True, line
return False, None


Expand Down