Skip to content

Commit aff8185

Browse files
feat: sample unification (#693)
BREAKING CHANGE: sample and test unification
1 parent 50b681b commit aff8185

File tree

147 files changed

+8325
-11275
lines changed

Some content is hidden

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

147 files changed

+8325
-11275
lines changed

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

Lines changed: 6 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 }}
@@ -146,7 +147,7 @@ jobs:
146147
strategy:
147148
fail-fast: false
148149
matrix:
149-
splunk-version: ["8.1","8.2"]
150+
splunk-version: ["8.1", "9.0"]
150151
steps:
151152
- uses: actions/checkout@v3
152153
with:
@@ -198,7 +199,7 @@ jobs:
198199
strategy:
199200
fail-fast: false
200201
matrix:
201-
splunk-version: [8.1, 8.2]
202+
splunk-version: ["8.1", "9.0"]
202203
test-marker: [
203204
"splunk_connection_docker",
204205
"splunk_app_fiction",
@@ -208,10 +209,8 @@ jobs:
208209
"splunk_fiction_indextime",
209210
"splunk_fiction_indextime_broken",
210211
"splunk_setup_fixture",
211-
"splunk_app_requirements",
212-
"splunk_app_requirements_modinput",
213-
"splunk_app_requirements_uf",
214-
"splunk_app_requirements_scripted"
212+
"splunk_app_req",
213+
"splunk_app_req_broken",
215214
]
216215
steps:
217216
- uses: actions/checkout@v3

.github/workflows/exclude-patterns.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
.circleci/
33
deps/.*
44
.*\.lock
5-
tests/
5+
tests/
6+
NOTICE
7+
pytest_splunk_addon/standard_lib/CIM_Models/5.0.0/Ticket_Management.json

.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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
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+
# TODO: go back to latest version when fixed
17+
ARG SPLUNK_VERSION=8.2.6
18+
FROM splunk/universalforwarder:8.2.6
19+
ARG SPLUNK_VERSION=8.2.6
1920
ARG SPLUNK_APP_ID=TA_UNKNOWN
2021
ARG SPLUNK_APP_PACKAGE=package
2122
RUN echo ${SPLUNK_VERSION} $SPLUNK_APP_PACKAGE
22-
COPY ${SPLUNK_APP_PACKAGE} /opt/splunkforwarder/etc/apps/${SPLUNK_APP_ID}
23+
COPY ${SPLUNK_APP_PACKAGE} /opt/splunkforwarder/etc/apps/${SPLUNK_APP_ID}

NOTICE

Lines changed: 4162 additions & 2492 deletions
Large diffs are not rendered by default.

entrypoint.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export PATH="~/.pyenv/bin:$PATH"
66
eval "$(pyenv init -)"
77
pyenv install 3.7.8
88
pyenv local 3.7.8
9-
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
9+
curl -sSL https://install.python-poetry.org | python
10+
export PATH="/root/.local/bin:$PATH"
1011
source ~/.poetry/env
1112
sleep 15
1213
poetry install -E docker

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/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818

1919
__author__ = """Splunk Inc."""
2020
__email__ = "[email protected]"
21-
__version__ = "3.0.8"
21+
__version__ = "4.0.0-beta.5"

pytest_splunk_addon/plugin.py

Lines changed: 19 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
"""
@@ -41,13 +40,25 @@ def pytest_configure(config):
4140
"markers",
4241
"splunk_searchtime_fields_positive: Test search time fields positive scenarios only",
4342
)
43+
config.addinivalue_line(
44+
"markers",
45+
"splunk_requirements: Tests that cover old requirement tests",
46+
)
47+
config.addinivalue_line(
48+
"markers",
49+
"splunk_searchtime_fields_requirements: Test checking fields from cim_fields",
50+
)
4451
config.addinivalue_line(
4552
"markers",
4653
"splunk_searchtime_fields_negative: Test search time fields negative scenarios only",
4754
)
4855
config.addinivalue_line(
4956
"markers", "splunk_searchtime_fields_tags: Test search time tags only"
5057
)
58+
config.addinivalue_line(
59+
"markers",
60+
"splunk_searchtime_fields_datamodels: Test checking datamodel defined in model",
61+
)
5162
config.addinivalue_line(
5263
"markers",
5364
"splunk_searchtime_fields_eventtypes: Test search time eventtypes only",
@@ -78,8 +89,10 @@ def pytest_configure(config):
7889
"markers",
7990
"splunk_searchtime_requirements: Test an requirement test only is mapped with only one data models",
8091
)
81-
if config.getoption("splunk_app", None):
82-
test_generator = AppTestGenerator(config)
92+
config.addinivalue_line(
93+
"markers",
94+
"splunk_requirements_unit: Test checking if all fields for datamodel are defined in cim_fields and missing_recommended_fields",
95+
)
8396

8497
cim_report = config.getoption("cim_report")
8598
if cim_report and not hasattr(config, "slaveinput"):
@@ -96,7 +109,7 @@ def pytest_unconfigure(config):
96109

97110

98111
def pytest_sessionstart(session):
99-
112+
global test_generator
100113
SampleXdistGenerator.event_path = session.config.getoption("event_path")
101114
SampleXdistGenerator.event_stored = False
102115
SampleXdistGenerator.tokenized_event_source = session.config.getoption(
@@ -114,6 +127,8 @@ def pytest_sessionstart(session):
114127
store_events = session.config.getoption("store_events")
115128
sample_generator = SampleXdistGenerator(app_path, config_path)
116129
sample_generator.get_samples(store_events)
130+
if session.config.getoption("splunk_app", None):
131+
test_generator = AppTestGenerator(session.config)
117132

118133

119134
def pytest_generate_tests(metafunc):

pytest_splunk_addon/splunk.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import logging
2424
import os
2525
import shutil
26+
from collections import defaultdict
2627
from time import sleep
2728
import json
2829
import pytest
@@ -32,6 +33,7 @@
3233
from .helmut.splunk.cloud import CloudSplunk
3334
from .helmut_lib.SearchUtil import SearchUtil
3435
from .standard_lib.event_ingestors import IngestorHelper
36+
from .standard_lib.CIM_Models.datamodel_definition import datamodels
3537
import configparser
3638
from filelock import FileLock
3739

@@ -265,13 +267,6 @@ def pytest_addoption(parser):
265267
dest="ignore_errors_not_related_to_addon",
266268
help=("Path to file where list of errors not related to addon are suppressed."),
267269
)
268-
group.addoption(
269-
"--requirement-test",
270-
action="store",
271-
dest="requirement_test",
272-
default="None",
273-
help="Default None, path to --requirement-test files if requirement tests need to be run",
274-
)
275270
group.addoption(
276271
"--splunk-uf-host",
277272
action="store",
@@ -733,7 +728,6 @@ def splunk_ingest_data(request, splunk_hec_uri, sc4s, uf, splunk_events_cleanup)
733728
):
734729
addon_path = request.config.getoption("splunk_app")
735730
config_path = request.config.getoption("splunk_data_generator")
736-
run_requirement_test = request.config.getoption("requirement_test")
737731
ingest_meta_data = {
738732
"uf_host": uf.get("uf_host"),
739733
"uf_port": uf.get("uf_port"),
@@ -752,7 +746,6 @@ def splunk_ingest_data(request, splunk_hec_uri, sc4s, uf, splunk_events_cleanup)
752746
config_path,
753747
thread_count,
754748
store_events,
755-
run_requirement_test,
756749
)
757750
sleep(50)
758751
if "PYTEST_XDIST_WORKER" in os.environ:
@@ -800,6 +793,38 @@ def file_system_prerequisite():
800793
os.mkdir(monitor_dir)
801794

802795

796+
@pytest.fixture(scope="session")
797+
def splunk_dm_recommended_fields():
798+
"""
799+
Returns function which gets recommended fields from Splunk for given datamodel
800+
801+
Note that data is being dynamically retrieved from Splunk. When CIM add-on version changes
802+
retrieved data may differ
803+
"""
804+
recommended_fields = defaultdict(list)
805+
806+
def update_recommended_fields(model, datasets, cim_version):
807+
model_key = f"{cim_version}:{model}:{':'.join(datasets)}".strip(":")
808+
809+
if model_key not in recommended_fields:
810+
LOGGER.info(f"Fetching {model_key} definition")
811+
datamodel_per_cim = datamodels.get(cim_version) or datamodels["latest"]
812+
datamodel = datamodel_per_cim[model]
813+
for object_name, value in datamodel.items():
814+
if (
815+
object_name == "BaseEvent"
816+
or object_name in datasets
817+
or object_name == model
818+
):
819+
recommended_fields[model_key] += value
820+
821+
if not recommended_fields.get(model_key) or []:
822+
raise ValueError(f"Model {model_key} definition was not fetched")
823+
return recommended_fields
824+
825+
return update_recommended_fields
826+
827+
803828
def is_responsive_uf(uf):
804829
"""
805830
Verify if the management port of Universal Forwarder is responsive or not

0 commit comments

Comments
 (0)