Skip to content

Commit 4ebd49b

Browse files
feat: test and sample unification (#640)
BREAKING CHANGE: requirement tests moved to KO tests Co-authored-by: kkania-splunk <[email protected]>
1 parent 50b681b commit 4ebd49b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1827
-241
lines changed

.github/workflows/build-test-release.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ on:
88
tags:
99
- "v[0-9]+.[0-9]+.[0-9]+"
1010
pull_request:
11-
branches: [main, develop]
11+
branches:
12+
- "**"
1213

1314
concurrency:
1415
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
@@ -191,14 +192,15 @@ jobs:
191192
- fossa-scan
192193
- compliance-copyrights
193194
- test-splunk-doc
194-
- test-splunk-unit
195+
# - test-splunk-unit
195196
- review_secrets
196197
- review-dog-misspell
197198
runs-on: ubuntu-latest
198199
strategy:
199200
fail-fast: false
200201
matrix:
201-
splunk-version: [8.1, 8.2]
202+
splunk-version: [8.2]
203+
# splunk-version: [8.1, 8.2]
202204
test-marker: [
203205
"splunk_connection_docker",
204206
"splunk_app_fiction",
@@ -208,10 +210,11 @@ jobs:
208210
"splunk_fiction_indextime",
209211
"splunk_fiction_indextime_broken",
210212
"splunk_setup_fixture",
211-
"splunk_app_requirements",
212-
"splunk_app_requirements_modinput",
213-
"splunk_app_requirements_uf",
214-
"splunk_app_requirements_scripted"
213+
# "splunk_app_requirements",
214+
# "splunk_app_requirements_modinput",
215+
# "splunk_app_requirements_uf",
216+
# "splunk_app_requirements_scripted",
217+
"splunk_app_req"
215218
]
216219
steps:
217220
- uses: actions/checkout@v3

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ docs/_build/
3030
!deps/build
3131
.vscode
3232
test_report.md
33-
.idea/
33+
.idea/
34+
.python-version

.licenserc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ header:
3131
- "tests/**"
3232
- ".*"
3333
- "pytest_splunk_addon/standard_lib/**/*.json"
34+
- "pytest_splunk_addon/standard_lib/**/*.xsd"
3435
- "MANIFEST.in"
3536
- "entrypoint.sh"
3637
- "pytest_splunk_addon/.ignore_splunk_internal_errors"

Dockerfile.uf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
ARG SPLUNK_VERSION=latest
17-
FROM splunk/universalforwarder:$SPLUNK_VERSION
18-
ARG SPLUNK_VERSION=latest
16+
ARG SPLUNK_VERSION=8.2.6
17+
FROM splunk/universalforwarder:8.2.6
18+
ARG SPLUNK_VERSION=8.2.6
1919
ARG SPLUNK_APP_ID=TA_UNKNOWN
2020
ARG SPLUNK_APP_PACKAGE=package
2121
RUN echo ${SPLUNK_VERSION} $SPLUNK_APP_PACKAGE
22-
COPY ${SPLUNK_APP_PACKAGE} /opt/splunkforwarder/etc/apps/${SPLUNK_APP_ID}
22+
COPY ${SPLUNK_APP_PACKAGE} /opt/splunkforwarder/etc/apps/${SPLUNK_APP_ID}

poetry.lock

Lines changed: 44 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ junitparser = "^2.2.0"
4646
addonfactory-splunk-conf-parser-lib = "^0.3.3"
4747
defusedxml = "^0.7.1"
4848
Faker = "^13.12.0"
49+
xmltodict = "^0.13.0"
50+
xmlschema = "^1.11.3"
4951

5052
[tool.poetry.extras]
5153
docker = ['lovely-pytest-docker']

pytest_splunk_addon/plugin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828

2929
def pytest_configure(config):
30-
global test_generator
3130
"""
3231
Setup configuration after command-line options are parsed
3332
"""
@@ -78,8 +77,6 @@ def pytest_configure(config):
7877
"markers",
7978
"splunk_searchtime_requirements: Test an requirement test only is mapped with only one data models",
8079
)
81-
if config.getoption("splunk_app", None):
82-
test_generator = AppTestGenerator(config)
8380

8481
cim_report = config.getoption("cim_report")
8582
if cim_report and not hasattr(config, "slaveinput"):
@@ -96,7 +93,7 @@ def pytest_unconfigure(config):
9693

9794

9895
def pytest_sessionstart(session):
99-
96+
global test_generator
10097
SampleXdistGenerator.event_path = session.config.getoption("event_path")
10198
SampleXdistGenerator.event_stored = False
10299
SampleXdistGenerator.tokenized_event_source = session.config.getoption(
@@ -114,6 +111,8 @@ def pytest_sessionstart(session):
114111
store_events = session.config.getoption("store_events")
115112
sample_generator = SampleXdistGenerator(app_path, config_path)
116113
sample_generator.get_samples(store_events)
114+
if session.config.getoption("splunk_app", None):
115+
test_generator = AppTestGenerator(session.config)
117116

118117

119118
def pytest_generate_tests(metafunc):

pytest_splunk_addon/splunk.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import logging
2424
import os
2525
import shutil
26+
from collections import defaultdict
27+
from itertools import chain
2628
from time import sleep
2729
import json
2830
import pytest
@@ -800,6 +802,60 @@ def file_system_prerequisite():
800802
os.mkdir(monitor_dir)
801803

802804

805+
@pytest.fixture(scope="session")
806+
def splunk_dm_recommended_fields(splunk_search_util):
807+
"""
808+
Returns function which gets recommended fields from Splunk for given datamodel
809+
810+
Note that data is being dynamically retrieved from Splunk. When CIM add-on version changes
811+
retrieved data may differ
812+
813+
Args:
814+
splunk_search_util: Other fixture preparing connection to Splunk Search.
815+
816+
"""
817+
recommended_fields = defaultdict(list)
818+
819+
def _find(name, dictionary):
820+
for key, value in dictionary.items():
821+
if key == name:
822+
yield value
823+
elif isinstance(value, dict):
824+
yield from _find(name, value)
825+
elif isinstance(value, list):
826+
for element in value:
827+
if isinstance(element, dict):
828+
yield from _find(name, element)
829+
830+
def update_recommended_fields(model, datasets):
831+
model_key = f"{model}:{':'.join(datasets)}".strip(":")
832+
if model_key not in recommended_fields:
833+
for cim_model in splunk_search_util.getFieldValuesList(
834+
f'| rest /servicesNS/-/-/data/models/{model} | fields "eai:data"'
835+
):
836+
model_definition = json.loads(cim_model["eai:data"])
837+
for object in model_definition["objects"]:
838+
object_name = object["objectName"]
839+
if (
840+
object["parentName"] == "BaseEvent"
841+
or object_name in datasets
842+
or object_name == model
843+
):
844+
for fields in chain(
845+
_find("fields", object), _find("outputFields", object)
846+
):
847+
for field in fields:
848+
recommended = field["comment"].get("recommended")
849+
if recommended:
850+
recommended_fields[model_key].append(
851+
field["fieldName"]
852+
)
853+
854+
return recommended_fields
855+
856+
return update_recommended_fields
857+
858+
803859
def is_responsive_uf(uf):
804860
"""
805861
Verify if the management port of Universal Forwarder is responsive or not

pytest_splunk_addon/standard_lib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434

3535
from .app_test_generator import AppTestGenerator
3636
from .addon_basic import Basic
37+
from .utilities import escape_char_event

pytest_splunk_addon/standard_lib/addon_requirements_basic.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)