Skip to main content

SPL2 Testing Framework

Project description

SPL2 Testing Framework

Overview

The SPL2 Testing Framework enables running SPL2 tests both locally ( or on any Splunk instance with SPL2 orchestrator), remotely (using external cloud environments) or using cli.

  • For Cloud: It uses the Search Service API.
  • For Splunk: It uses the Splunk Search API (with SPL2 support)
  • For cli - it uses the internal spl2-processor-cli library. This option is not available for public usage, as spl2-processor-cli is a Splunk internal tool.

Prerequisites

1. Install Python and Poetry

  1. Ensure python3.x is available
  2. Install testing framework:
    • Install poetry and execute the command poetry install to create a virtual environment and install required dependencies.
    • OR
    • Install the library using pip: pip install spl2-testing-framework

2. Set configuration. It may be done in spl2_test_config.json file or environment variables

Note: setting configuration is necessary for running tests using splunk or cloud environment. For running tests using cli no configuration is required. The only requirement is to have this library installed, as described below

spl2_test_config.json - local file present in the current working directory (the directory from where tests are executed)

Configuration for running tests using cloud search client (Ingest processor)
  • cloud_instance - address of Cloud host where the tests can be executed
    • e.g.: staging.scs.splunk.com
  • tenant - tenant to use for testing
    • e.g.: spl2-content
  • bearer_token - token used for authentication. To obtain the token, go to: https://console.[cloud_instance]/[tenant]/settings
Configuration for running tests using splunk search client (Splunk instance)
  • host - address of Splunk host where the tests can be executed
    • e.g.: localhost or https://10.202.35.219
  • port - port of Splunk host where the tests can be executed
    • usually 8089, but can be different
  • user - user to authenticate
  • password - password to authenticate

The same configuration can be done using environment variables(however, spl2_test_config.json has higher priority):

cloud search client
  • SPL2_TF_CLOUD_INSTANCE => cloud_instance
  • SPL2_TF_TENANT => tenant
  • SPL2_TF_BEARER_TOKEN => bearer_token
splunk search client
  • SPL2_TF_HOST => host
  • SPL2_TF_PORT => port
  • SPL2_TF_USER => user
  • SPL2_TF_PASSWORD => password

3. Installing spl2-processor-cli (Splunk internal tool)

spl2-processor-cli can be installed using brew:

brew install spl2-processor-cli

Before installation, it may be necessary to authenticate to artifactory by running:

okta-artifactory-login -t generic

Running tests

To run tests, execute the command:

spl2_tests_run [cli|splunk|cloud]

In the directory where the tests are located. Test discovery is recursive, so it's possible to run tests even from the root directory of the project.

It is possible to pass more options to the command, which works also with pytest, e.g.:

  • -k "filter" - to run only tests which name contains "filter"
  • -v[vv] - to see more verbose output
  • -n [auto|<number>] - to run tests in parallel
    • auto - to use all available cores,
    • <number> - to use specific number of cores
    • however, it's recommended to run tests in parallel on cli mostly, as running on splunk or cloud doesn't give significant performance improvement
  • -x - to stop on first failure
  • -pdb - to enter debugger on failure
  • ... and much more, whatever is supported by pytest

Additionally, the following options are supported:

  • --ignore_empty_strings - to ignore empty strings in the results
  • --ignore_additional_fields_in_actual - to ignore fields present in actual results but not in expected results (useful when actual results contain extra fields that should not affect comparison)
  • --create_comparison_sheet - to create a comparison sheet in comparison_box_test folder using actual and expected outputs (works only when running box tests)

Note: The pytest.ini.sample file allows you to define command parameters. Just update the configurations, rename the file by removing the .sample extension, and execute the command.

Run tests in IDE [PyCharm]

It's also possible to run tests in PyCharm. To do this, it's necessary to set Run Configurations

Sample configuration which may be used:

  • Run configuration
    • Type: Python test
    • Module: spl2_testing_framework.test_runner
    • Parameters: --type [cli | splunk | cloud] --test_dir /tests/resources -o log_cli=true --log-cli-level=INFO --verbose
    • If test dir is not specified, current working directory will be used
    • If necessary another pytest options can be added

Note: It's necessary to set "pytest" as default test runner in PyCharm settings

Executing a spl2 file

This framework also supports executing a single spl2 file and prints the results in command line as well as a log file. This will help developers to get the results of the spl2 pipeline as and when they are developing the pipeline.

It requires 3 additional parameters:

  • --template_file
  • --sample_file
  • --sample_delimiter

It will execute the template_file provided in the --template_file parameter. It will read samples if --sample_file parameter is provided and will separate the samples by using --sample_delimiter. If --sample_file is not provided, then it will look for the samples in the respective module.json file corresponding to the template_file.

To run a single spl2 file, execute the command:

single_spl2_file_run [cli|splunk|cloud]

It is possible to pass more options to the command, which works also with pytest, e.g.:

  • --test_dir - Path in which the template file and module.json are available. If not provided, it will look for the current directory for the template file and module.json file

  • --template_file - The spl2 template file to execute

  • --sample_file - A file containing all the samples required for the template file. If not provided, it will look for the samples in module.json file of the corresponding template file

  • --sample_delimiter - Separator for separating the samples provided in the sample file. If not provided, it will use newline as a default separator.

  • --limit_tests - Limit number of tests to execute from the unit, sample file or module.json. If not provided, all will be executed. This can be used for quick testing of spl2 files during development.

  • ... and much more, whatever is supported by pytest

Note: The pytest.ini.sample file allows you to define command parameters. Just update the configurations, rename the file by removing the .sample extension, and execute the command.

Performance check

It is possible to measure execution time of spl2 pipeline, or even do more advanced time checks using flag:

  • --performance_check=time - to run basic time measurements - time of execution of spl2 pipeline will be printed to stdout
  • --performance_check=detailed_time - to do more advanced time checks which injects more timestamps into spl2 pipeline.

Running detailed_time check creates text file with spl2 pipeline code with injected timestamps after every command ("|") Content of this file will also be printed to stdout.

This checks can be applied only to box tests, as assertions which are used in unit tests may impact spl2 pipeline performance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spl2_testing_framework-1.4.0.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spl2_testing_framework-1.4.0-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file spl2_testing_framework-1.4.0.tar.gz.

File metadata

  • Download URL: spl2_testing_framework-1.4.0.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.7.17 Linux/6.8.0-1044-azure

File hashes

Hashes for spl2_testing_framework-1.4.0.tar.gz
Algorithm Hash digest
SHA256 562a6fdc498ab282ea88678a48042f79ad01d8d29d90b099c3db1bedd80bcde3
MD5 85bf745a46c172aff3b642441a19c03a
BLAKE2b-256 3aa21f2292edade927e54699ecf107cdc204ed067da656b2ba72b1cad07c8ae0

See more details on using hashes here.

File details

Details for the file spl2_testing_framework-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spl2_testing_framework-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de289976f6a658d5c61d03ceb6c1feae132f9baac4f2324ebf97bf9987d6d382
MD5 106180937b22641836e6df55a957c95f
BLAKE2b-256 a8d4b26fff7e33484413d50b2020901060a3fe60b9cb0efd3827481cd87a4ae7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page