-
Notifications
You must be signed in to change notification settings - Fork 1k
Added loganalyzer for pytest #1048
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
228d59a
Added loganalyzer for pytest. Updated existed loganalyzer.
yvolynets-mlnx ec6f538
Added loganalyzer for pytest. Updated existed loganalyzer.
yvolynets-mlnx 8d9dd99
Added fixes based on comments
yvolynets-mlnx 0055f38
Update README.md
yvolynets-mlnx 4d95015
Update README.md
yvolynets-mlnx 6160828
Added minor fixes based on comments.
yvolynets-mlnx 6044095
Merge branch 'loganalyzer_dev' of https://github.com/yvolynets-mlnx/s…
yvolynets-mlnx 87bd46b
Added minor fix.
yvolynets-mlnx b96898e
Added 'disable_loganalyzer' marker
yvolynets-mlnx 78a71eb
Merge branch 'master' into loganalyzer_dev
neethajohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
ansible/roles/test/files/tools/loganalyzer/loganalyzer_common_match.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| r, "\.ERR", "\.WARN", "crash" | ||
| r, "kernel:.*Oops", "kernel:.*hung", "kernel.*oom\s" | ||
| r, "kernel:.*scheduling", "kernel:.*atomic", "kernel:.*panic" | ||
| r, "kernel:.*\serr", "kernel:.*allocation", "kernel:.*kill", | ||
| r, "kernel:.*kmemleak.*","kernel:.* Err:" | ||
| r, "kernel:.*\serr", "kernel:.*allocation", "kernel:.*kill" | ||
| r, "kernel:.*kmemleak.*", "kernel:.* Err:" | ||
| s, "ERR" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #### Loganalyzer API usage example | ||
|
|
||
| Below is described possibility of loganalyzer fixture/module usage. | ||
|
|
||
| ##### Loganalyzer fixture | ||
| In the root conftest there is implemented "loganalyzer" pytest fixture, which starts automatically for all test cases. | ||
| Fixture main flow: | ||
| - loganalyzer will add start marker before test case start | ||
| - loganalyzer will add stop marker after test case finish | ||
| - if loganalyzer analysis is not disabled for current test case it will analyze DUT syslog and display results. | ||
| If loganalyzer find specified messages which corresponds to defined regular expressions, it will display found messages and pytest will generate 'error'. | ||
|
|
||
| #### To skip loganalyzer analysis for: | ||
| - all test cases - use pytest command line option ```--disable_loganalyzer``` | ||
| - specific test case: mark test case with ```@pytest.mark.disable_loganalyzer``` decorator. Example is shown below. | ||
|
|
||
|
|
||
| #### Notes: | ||
| loganalyzer.init() - can be called several times without calling "loganalyzer.analyze(marker)" between calls. Each call return its unique marker, which is used for "analyze" phase - loganalyzer.analyze(marker). | ||
|
|
||
|
|
||
| ### Loganalyzer usage example | ||
|
|
||
| #### Example calling loganalyzer init/analyze methods automatically by using with statement | ||
| ```python | ||
| # Read existed common regular expressions located with legacy loganalyzer module | ||
| loganalyzer.load_common_config() | ||
| # Analyze syslog for code executed inside with statement | ||
| with loganalyzer as analyzer: | ||
| logging.debug("============== Test steps ===================") | ||
| # Add test code here ... | ||
| time.sleep(1) | ||
|
|
||
| # Separately analyze syslog for code executed inside each with statement | ||
| with loganalyzer as analyzer: | ||
| # Clear current regexp match list if there is a need to have clear configuration | ||
| loganalyzer.match_regex = [] | ||
| # Load regular expressions from the specified file | ||
| reg_exp = loganalyzer.parse_regexp_file(src=COMMON_MATCH) | ||
| # Extend currently configured match criteria (regular expressions) with data read from "COMMON_MATCH" file | ||
| loganalyzer.match_regex.extend(reg_exp) | ||
| # Add test code here ... | ||
| # Here will be executed syslog analysis on context manager __exit__ | ||
| time.sleep(1) | ||
| with loganalyzer as analyzer: | ||
| # Clear current regexp match list if there is a need to have clear configuration | ||
| loganalyzer.match_regex = [] | ||
| # Set match criteria (regular expression) to custom regexp - "test:.*Error" | ||
| loganalyzer.match_regex.extend(["test:.*Error"]) | ||
| # Add test code here ... | ||
| # Here will be executed syslog analysis on context manager __exit__ | ||
| time.sleep(1) | ||
| with loganalyzer as analyzer: | ||
| # Add test code here ... | ||
| # Here will be executed syslog analysis on context manager __exit__ | ||
| time.sleep(1) | ||
| ``` | ||
|
|
||
| #### Example calling loganalyzer init/analyze methods directly in test case | ||
| ```python | ||
| # Example 1 | ||
| # Read existed common regular expressions located with legacy loganalyzer module | ||
| loganalyzer.load_common_config() | ||
| # Add start marker to the DUT syslog | ||
| marker = loganalyzer.init() | ||
| # PERFORM TEST CASE STEPS ... | ||
| # Verify that error messages were not found in DUT syslog. Exception will be raised if in DUT syslog will be found messages which fits regexp defined in COMMON_MATCH | ||
| loganalyzer.analyze(marker) | ||
|
|
||
| # Example 2 | ||
| # Read existed common regular expressions located with legacy loganalyzer module | ||
| loganalyzer.load_common_config() | ||
| # Add start marker to the DUT syslog | ||
| marker = loganalyzer.init() | ||
| # PERFORM TEST CASE STEPS ... | ||
| # Get summary of analyzed DUT syslog | ||
| result = loganalyzer.analyze(marker, fail=False) | ||
| # Verify that specific amount of error messages found in syslog # Negative test case | ||
| assert result["total"]["match"] == 2, "Not found expected errors: {}".format(result) | ||
|
|
||
| # Example 3 | ||
| # Download extracted syslog file from DUT to the local host | ||
| loganalyzer.save_extracted_log(dest="/tmp/log/syslog") | ||
|
|
||
| # Example 4 | ||
| # Update previously configured marker | ||
| # Now start marker will have new prefix - test_bgp | ||
| loganalyzer.update_marker_prefix("test_bgp") | ||
|
|
||
| def get_platform_info(dut): | ||
| """ | ||
| Example callback which gets DUT platform information and returns obtained string | ||
| """ | ||
| return dut.command("show platform summary") | ||
|
|
||
| # Example 5 | ||
| # Execute specific function and analyze logs during function execution | ||
| run_cmd_result = loganalyzer.run_cmd(get_platform_info, ans_host) | ||
| # Process result of "get_platform_info" callback | ||
| assert all(item in run_cmd_result["stdout"] for item in ["Platform", "HwSKU", "ASIC"]) is True, "Unexpected output returned after command execution: {}".format(run_cmd_result) | ||
|
|
||
| # Example 6 | ||
| # Clear current regexp match list | ||
| loganalyzer.match_regex = [] | ||
| # Load regular expressions from the specified file defined in COMMON_MATCH variable | ||
| reg_exp = loganalyzer.parse_regexp_file(src=COMMON_MATCH) | ||
| # Extend currently configured match criteria (regular expressions) with data read from "COMMON_MATCH" file | ||
| loganalyzer.match_regex.extend(reg_exp) | ||
| marker = loganalyzer.init() | ||
| # PERFORM TEST CASE STEPS ... | ||
| # Verify that error messages were not found in DUT syslog. Exception will be raised if in DUT syslog will be found messages which fits regexp defined in COMMON_MATCH | ||
| loganalyzer.analyze(marker) | ||
|
|
||
| # Example 7 | ||
| loganalyzer.expect_regex = [] | ||
| # Add specific EXPECTED regular expression | ||
| # Means that in the DUT syslog loganalyzer will search for message which matches with "kernel:.*Oops" regular expression | ||
| # If such message will not be present in DUT syslog, it will raise exception | ||
| loganalyzer.expect_regex.append("kernel:.*Oops") | ||
| # Add start marker to the DUT syslog | ||
| marker = loganalyzer.init() | ||
| # PERFORM TEST CASE STEPS ... | ||
| # Verify that expected error messages WERE FOUND in DUT syslog. Exception will be raised if in DUT syslog will NOT be found messages which fits to "kernel:.*Oops" regular expression | ||
| loganalyzer.analyze(marker) | ||
|
|
||
| # Example 8 | ||
| loganalyzer.expect_regex = [] | ||
| # Add specific EXPECTED regular expression | ||
| # Means that in the DUT syslog loganalyzer will search for message which matches with "kernel:.*Oops" regular expression | ||
| # If such message will not be present in DUT syslog, it will raise exception | ||
| loganalyzer.expect_regex.append("kernel:.*Oops") | ||
| # PERFORM TEST CASE STEPS ... | ||
| # Verify that expected error messages WERE FOUND in DUT syslog. Exception will be raised if in DUT syslog will NOT be found messages which fits to "kernel:.*Oops" regular expression | ||
| loganalyzer.run_cmd(ans_host.command, "echo '---------- kernel: says Oops --------------' >> /var/log/syslog") | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.