-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR updates the doc for how_to_use section and add the documentation for requirement tests. ref: https://splunk.atlassian.net/browse/ADDON-73384
- Loading branch information
1 parent
a968cd1
commit 5cf1bd4
Showing
5 changed files
with
226 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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,28 +1,41 @@ | ||
# Overview | ||
|
||
pytest-splunk-addon is an open-source dynamic test plugin for Splunk Apps and Add-ons | ||
which allows the user to test knowledge objects, CIM compatibility and index time properties. | ||
pytest-splunk-addon is an open-source dynamic test plugin for Splunk [Apps](https://docs.splunk.com/Splexicon:App) and [Add-ons](https://docs.splunk.com/Splexicon:Addon) | ||
which allows the user to test [knowledge objects](https://docs.splunk.com/Splexicon:Knowledgeobject), [CIM](https://docs.splunk.com/Splexicon:CommonInformationModel) compatibility and [index time properties](https://docs.splunk.com/Splexicon:Indexedfield). | ||
|
||
## Prerequisites | ||
|
||
- Splunk App or Add-on package | ||
- Splunk instance with App or Add-on installed (Not required if using Docker) | ||
- Docker (Not required if using external Splunk instance) | ||
|
||
## Support | ||
|
||
- **Python**: 3.7 | ||
- **Platforms**: Linux, Windows and MacOS | ||
|
||
## Features | ||
|
||
- Generate tests for Splunk Knowledge objects in Splunk Technology Add-ons. | ||
- Generate tests for checking CIM compatibility in Splunk Technology Add-ons. | ||
- Generate tests for checking Splunk index-time properties in Splunk Technology Add-ons. | ||
- Validate your add-ons using Splunk + Docker. | ||
|
||
## Release notes | ||
|
||
Find details about all the releases [here](https://github.com/splunk/pytest-splunk-addon/releases). | ||
|
||
## Installation | ||
|
||
pytest-splunk-addon can be installed via pip from PyPI: | ||
|
||
```console | ||
pip3 install pytest-splunk-addon | ||
``` | ||
|
||
## Features | ||
|
||
The pytest-splunk-addon works by dynamically generating different types of tests for Splunk apps and add-ons by parsing their configuration files. Specifically, it looks at the .conf files in the provided Splunk app/add-on to create: | ||
|
||
1. [Knowledge Object Tests](./field_tests.md) | ||
|
||
2. [CIM Compatibility Tests](./cim_tests.md) | ||
|
||
3. [Index-Time Field Tests](./index_time_tests.md) | ||
|
||
4. [Requirement Tests](./requirement_tests.md) | ||
|
||
Refer to the [How to use](./how_to_use.md) section for detailed instructions on running the tests. | ||
|
||
## Release notes | ||
|
||
Find details about all the releases [here](https://github.com/splunk/pytest-splunk-addon/releases). |
This file contains 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,93 @@ | ||
# Requirement Tests | ||
|
||
## Overview | ||
|
||
- The tests are written with a purpose of testing the proper functioning of the fields extractions of the add-on. | ||
|
||
______________________________________________________________________ | ||
|
||
To generate only requirement tests, append the folowing marker to pytest command: | ||
|
||
```console | ||
-m splunk_requirements | ||
``` | ||
|
||
## Test Scenarios | ||
|
||
**1. Fields should be extracted as defined in the cim_fields and other_mappings.** | ||
|
||
```python | ||
test_requirements_fields[sample_name::<stanza>::host::<host>] | ||
``` | ||
|
||
Testcase verifies that fields are getting extracted with the values defined in the cim_fields and other_mappings in sample xml. | ||
Here <stanza> is the stanza name defined in the pytest-splunk-addon-data.conf and | ||
<host> is the host of the event | ||
|
||
**Workflow:** | ||
|
||
- Plugin gets the list of events and the fields defined under cim_fields and other_mappings for each event | ||
- For each event, plugin generates a search query to retrieve all the fields extracted by splunk. | ||
- For each event, all the fields defined in the cim_fields and other_mappings should be extracted with the values defined in sample xml. | ||
|
||
**2. Event should be mapped with the datamodel defined in the sample xml** | ||
|
||
```python | ||
test_datamodels[<datamodel>::sample_name::<stanza>::host::<host>] | ||
``` | ||
|
||
Testcase verifies that the event is mapped with the datamodel defined in the sample xml. | ||
Here <datamodel> is the name of the datamodel that the event should be mapped with, <stanza> is the stanza name defined in the pytest-splunk-addon-data.conf and <host> is the host of the event | ||
|
||
**Workflow:** | ||
|
||
- Plugin gets the events and its expected datamodel from the sample xml | ||
- Plugin generates a search query for that event and validates if the values of tags field are according to the datamodel defined in sample xml. | ||
|
||
**3. All the cim recommended field should be extracted** | ||
|
||
```python | ||
test_cim_fields_recommended[<datamodel>::sample_name::<stanza>::host::<host>] | ||
``` | ||
|
||
Testcase verifies that all the cim recommended fields of mapped datamodel are extracted for the event defined in the sample xml. | ||
Here <datamodel> is the name of the datamodel that the event should be mapped with, <stanza> is the stanza name defined in the pytest-splunk-addon-data.conf and <host> is the host of the event | ||
|
||
**Workflow:** | ||
|
||
- For each events, plugin gets the list of fields defined under cim_fields and missing_recommended_fields. | ||
- Field list retrieved from the sample xml should be equal to the list of recommended fields defined in the datamodel schema. | ||
|
||
## Testcase Troubleshooting | ||
|
||
In the case of test-case failure check if: | ||
|
||
- The add-on to be tested is installed on the Splunk instance. | ||
- Splunk licence has not expired. | ||
- Splunk instance is up and running. | ||
- Splunk instance's management port is accessible from the test machine. | ||
|
||
If all the above conditions are satisfied, further analysis of the test is required. | ||
For every test case failure, there is a defined structure for the stack trace. | ||
|
||
```text | ||
- test_requirements_fields | ||
AssertionError: <<error_message>> | ||
Field | Splunk Value | Expected Value | ||
------| ------------ | -------------- | ||
str | str | str | ||
Search = <Query> | ||
- test_datamodels | ||
AssertionError: <<error_message>> | ||
Expected datamodel | Expected tags | Found datamodel | Found tags | ||
-------------------| ------------- | --------------- | ---------- | ||
str | str | str | str | ||
Search = <Query> | ||
- test_cim_fields_recommended | ||
AssertionError: <<error_message>> | ||
Search = <Query> | ||
``` | ||
|
||
Get the search query from the stack trace and execute it on the Splunk instance and verify which specific event is causing failure. |
This file contains 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 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