Skip to content

Commit fbb8f6e

Browse files
feat!: separate CIM data models into standalone splunk-cim-models package [BREAKING] (#949)
## ⚠️ Breaking Change `splunk-cim-models` is **no longer a runtime dependency** of PSA. It is now a **dev-only dependency** (used only for PSA's own tests). **Add-ons must declare `splunk-cim-models` in their own dependencies** to control CIM version independently — this is the core purpose of the separation. ## Summary - Extract CIM version definitions, 23 data model JSON schemas, `CommonFields.json`, and `DatamodelSchema.json` into a new standalone [`splunk-cim-models`](https://github.com/splunk/psa-cim-models) package - Update PSA to import CIM data from `splunk_cim_models` instead of internal modules - Keep backward-compat stub in `CIM_Models/datamodel_definition.py` with deprecation warning - `splunk-cim-models` declared as **dev dependency** — add-ons own their CIM version ## Motivation Every CIM version bump (4.18 → 5.x → 6.x) currently forces a full PSA release even though only data changes. Separating CIM data into its own package enables: - Independent CIM version releases without touching PSA - Add-ons can pin/control CIM version in their own dependencies - Cleaner separation of test framework logic vs. CIM data ## psa-cim-models Package - Repo: https://github.com/splunk/psa-cim-models (internal) - Branch `v1`: CIM v5.5.2 era models (for add-ons still on PSA 5.x) - Branch `v2`: CIM v6.4.0 era models (for PSA 6.x add-ons) ## Add-on Validation Both add-ons use **PSA `feat/cim-separation`** but differ only in CIM version — proving the decoupling works: | Add-on | PSA branch | CIM models | |--------|-----------|------------| | [splunk-add-on-for-microsoft-office-365](https://github.com/splunk/splunk-add-on-for-microsoft-office-365/actions/runs/22655199998) | feat/cim-separation | psa-cim-models@v1 (CIM v5) | | [splunk-add-on-for-box](https://github.com/splunk/splunk-add-on-for-box/actions/runs/22655202302) | feat/cim-separation | psa-cim-models@v2 (CIM v6) | ## Jira https://splunk.atlassian.net/browse/ADDON-85727 BREAKING CHANGE: splunk-cim-models is no longer a runtime dependency of PSA. Add-ons must declare it in their own dependencies to control CIM version independently.
1 parent b95ed65 commit fbb8f6e

18 files changed

Lines changed: 760 additions & 2518 deletions

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ jobs:
7474
submodules: true
7575
- name: Install dependencies
7676
run: |
77+
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf https://github.com
78+
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf ssh://git@github.com
7779
curl -sSL https://install.python-poetry.org | python3 - --version 1.5.1
7880
poetry install
7981
poetry run pytest -v tests/unit
@@ -99,6 +101,8 @@ jobs:
99101
run: |
100102
mkdir test-results-${{ matrix.splunk.version }}
101103
- name: Test
104+
env:
105+
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
102106
run: |
103107
export SPLUNK_APP_PACKAGE=./tests/e2e/addons/TA_fiction_indextime
104108
export SPLUNK_ADDON=TA_fiction_indextime
@@ -159,14 +163,105 @@ jobs:
159163
with:
160164
python-version: 3.7
161165
- run: |
166+
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf https://github.com
167+
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf ssh://git@github.com
162168
curl -sSL https://install.python-poetry.org | python3 - --version 1.5.1
163169
poetry install
164170
poetry run pytest -v --splunk-version=${{ matrix.splunk.version }} -m docker -m ${{ matrix.test-marker }} tests/e2e
171+
env:
172+
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
173+
174+
# ---------------------------------------------------------------------------
175+
# Validate PSA against multiple splunk-cim-models package versions.
176+
#
177+
# Matrix axes:
178+
# splunk – every supported Splunk version (from meta job)
179+
# cim-models – every package git ref listed below
180+
#
181+
# How to add a new CIM models release:
182+
# 1. Append a new entry to the cim-models list with the git ref (branch
183+
# or tag) and a short human-readable label.
184+
# 2. The matrix will automatically run the splunk_cim_model e2e test
185+
# for each (Splunk version, CIM models version) combination.
186+
#
187+
# Only the splunk_cim_model marker is used here because the other CIM
188+
# e2e markers (splunk_app_cim_fiction, splunk_app_cim_broken) always pass
189+
# --splunk-dm-path with custom fiction models and are therefore unaffected
190+
# by the installed splunk-cim-models version.
191+
# ---------------------------------------------------------------------------
192+
test-cim-models-versions:
193+
needs:
194+
- meta
195+
- pre-commit
196+
- fossa-scan
197+
- compliance-copyrights
198+
- test-splunk-unit
199+
runs-on: ubuntu-22.04
200+
strategy:
201+
fail-fast: false
202+
matrix:
203+
splunk: ${{ fromJson(needs.meta.outputs.matrix_supportedSplunk) }}
204+
cim-models:
205+
- ref: "v1"
206+
label: "1.x"
207+
- ref: "v2"
208+
label: "2.x"
209+
# Add future releases here, e.g.:
210+
# - ref: "v3"
211+
# label: "3.x"
212+
name: "CIM models ${{ matrix.cim-models.label }} / Splunk ${{ matrix.splunk.version }}"
213+
steps:
214+
- uses: actions/checkout@v4
215+
with:
216+
submodules: true
217+
- uses: actions/setup-python@v5
218+
with:
219+
python-version: "3.7"
220+
- name: Install PSA with CIM models ${{ matrix.cim-models.label }}
221+
env:
222+
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
223+
run: |
224+
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf https://github.com
225+
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf ssh://git@github.com
226+
curl -sSL https://install.python-poetry.org | python3 - --version 1.5.1
227+
poetry install
228+
# Override the dev-dependency CIM models with the matrix version.
229+
# Using pip inside the Poetry venv so the pytester subprocess sees
230+
# the same environment.
231+
poetry run pip install \
232+
"git+https://github.com/splunk/psa-cim-models.git@${{ matrix.cim-models.ref }}"
233+
- name: Verify splunk-cim-models ${{ matrix.cim-models.label }}
234+
run: |
235+
poetry run python - <<'EOF'
236+
import splunk_cim_models as scm
237+
print("DATA_MODELS_PATH:", scm.DATA_MODELS_PATH)
238+
print("CIM versions available:", list(scm.datamodels.keys()))
239+
EOF
240+
- name: Run CIM compatibility e2e tests
241+
env:
242+
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
243+
run: |
244+
# splunk_app_cim_fiction uses --splunk-dm-path with local fiction
245+
# data models, so expected test outcomes are identical across all
246+
# splunk-cim-models versions. It still exercises all PSA import
247+
# paths (COMMON_FIELDS_PATH, DATAMODEL_SCHEMA_PATH, datamodels) so
248+
# an incompatible package version will surface as a collection or
249+
# runtime error rather than a wrong-field assertion.
250+
#
251+
# splunk_cim_model (real Change/Network_Traffic models) is left to
252+
# test-splunk-matrix, which always uses the default v2 dev
253+
# dependency and asserts version-specific field outcomes.
254+
poetry run pytest -v \
255+
--splunk-version=${{ matrix.splunk.version }} \
256+
-m docker \
257+
-m splunk_app_cim_fiction \
258+
tests/e2e
165259
166260
publish:
167261
needs:
168262
- test-splunk-external
169263
- test-splunk-matrix
264+
- test-cim-models-versions
170265
runs-on: ubuntu-22.04
171266
steps:
172267
- uses: actions/checkout@v4

.licenserc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ header:
3838
- "pytest_splunk_addon/.ignore_splunk_internal_errors"
3939
- "pytest_splunk_addon/docker_class.py"
4040
- "deps"
41+
- "splunk-cim-models/**"

docker-compose-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ services:
3232
- sc4s
3333
volumes:
3434
- results:/work/test-results
35+
environment:
36+
- GH_TOKEN
3537

3638
sc4s:
3739
image: ghcr.io/splunk/splunk-connect-for-syslog/container2:latest

docs/cim_tests.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@
22

33
## Overview
44

5-
The CIM tests are written with a purpose of testing the compatibility of the add-on with CIM Data Models (Based on Splunk_SA_CIM 4.15.0).
5+
The CIM tests are written with a purpose of testing the compatibility of the add-on with CIM Data Models.
66
An add-on is said to be CIM compatible if it fulfils the following two criteria:
77

8-
1. The add-on extracts all the fields with valid values, which are marked as required by the [Data Model Definitions](https://github.com/splunk/pytest-splunk-addon/tree/main/pytest_splunk_addon/standard_lib/data_models).
8+
1. The add-on extracts all the fields with valid values, which are marked as required by the [Data Model Definitions](https://github.com/splunk/psa-cim-models).
99
2. Any event for the add-on is not mapped with more than one data model.
1010

11+
## CIM Data Models Package (`splunk-cim-models`)
12+
13+
CIM data model definitions are provided by the separate
14+
[`splunk-cim-models`](https://github.com/splunk/psa-cim-models) package.
15+
This lets you update or pin CIM definitions independently of `pytest-splunk-addon` itself.
16+
17+
**Install for CIM testing:**
18+
19+
```console
20+
pip install splunk-cim-models
21+
```
22+
23+
Or, during development, install the latest from the repository:
24+
25+
```console
26+
pip install git+https://github.com/splunk/psa-cim-models.git@v2
27+
```
28+
29+
The package exposes:
30+
31+
| Symbol | Description |
32+
|---|---|
33+
| `DATA_MODELS_PATH` | Path to the directory containing the built-in CIM JSON data model files |
34+
| `COMMON_FIELDS_PATH` | Path to `CommonFields.json` (fields forbidden in props/search) |
35+
| `DATAMODEL_SCHEMA_PATH` | Path to `DatamodelSchema.json` (JSON schema for validating custom data model files) |
36+
| `datamodels` | Dict mapping CIM version strings to recommended fields per model |
37+
38+
If `splunk-cim-models` is not installed, any test run that exercises CIM functionality
39+
will raise an `ImportError` with a message pointing to the package.
40+
1141
______________________________________________________________________
1242

1343
To generate test cases only for CIM compatibility, append the following marker to pytest command:
@@ -30,7 +60,7 @@ To generate test cases only for CIM compatibility, append the following marker t
3060
**Workflow:**
3161

3262
- Plugin parses tags.conf to get a list of tags for each eventtype.
33-
- Plugin parses all the [supported datamodels](https://github.com/splunk/pytest-splunk-addon/tree/main/pytest_splunk_addon/standard_lib/data_models).
63+
- Plugin parses all the [supported datamodels](https://github.com/splunk/psa-cim-models).
3464
- Then it gets a list of the datasets mapped with an eventtype.
3565
- Generates test case for each eventtype.
3666

@@ -79,11 +109,11 @@ To generate test cases only for CIM compatibility, append the following marker t
79109

80110
**Workflow:**
81111

82-
- Plugin collects the list of not_allowed_in_search fields from mapped datasets and [CommonFields.json](https://github.com/splunk/pytest-splunk-addon/blob/main/pytest_splunk_addon/standard_lib/cim_tests/CommonFields.json).
112+
- Plugin collects the list of not_allowed_in_search fields from mapped datasets and [CommonFields.json](https://github.com/splunk/psa-cim-models/blob/v2/splunk_cim_models/CommonFields.json).
83113
- Using search query the test case verifies if not_allowed_in_search fields are populated in search or not.
84114

85115
> **_NOTE:_**
86-
[CommonFields.json](https://github.com/splunk/pytest-splunk-addon/blob/main/pytest_splunk_addon/standard_lib/cim_tests/CommonFields.json) contains fields which are automatically provided by asset and identity correlation features of applications like Splunk Enterprise Security.
116+
[CommonFields.json](https://github.com/splunk/psa-cim-models/blob/v2/splunk_cim_models/CommonFields.json) contains fields which are automatically provided by asset and identity correlation features of applications like Splunk Enterprise Security.
87117

88118

89119
**4. Testcase for all not_allowed_in_props fields**

docs/contributing.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,42 @@ To install currently checked out version of pytest-splunk-addon use:
1818
$ poetry install
1919
```
2020

21+
This installs `splunk-cim-models` automatically as a dev dependency (from the `v2` branch of
22+
[psa-cim-models](https://github.com/splunk/psa-cim-models)). In CI or when installing from
23+
PyPI, install `splunk-cim-models` separately before running CIM tests:
24+
25+
```
26+
$ pip install splunk-cim-models
27+
```
28+
29+
### Working with `splunk-cim-models`
30+
31+
CIM data model definitions live in the separate
32+
[`splunk-cim-models`](https://github.com/splunk/psa-cim-models) package.
33+
PSA imports four symbols from it:
34+
35+
| Symbol | Used by |
36+
|---|---|
37+
| `DATA_MODELS_PATH` | `app_test_generator.py` — default path for `--splunk_dm_path` |
38+
| `COMMON_FIELDS_PATH` | `cim_tests/test_generator.py` — fields forbidden in props/search |
39+
| `DATAMODEL_SCHEMA_PATH` | `cim_tests/json_schema.py` — JSON schema for custom data models |
40+
| `datamodels` | `splunk.py` — CIM version → recommended fields map |
41+
42+
To update CIM definitions locally without waiting for a `splunk-cim-models` release:
43+
44+
```bash
45+
# Edit files under splunk-cim-models/ then reinstall editable
46+
pip install -e path/to/psa-cim-models/
47+
48+
# Verify
49+
python -c "from splunk_cim_models import datamodels; print(list(datamodels.keys()))"
50+
```
51+
52+
After editing, run the unit tests to confirm nothing is broken:
53+
54+
```bash
55+
poetry run pytest -v tests/unit
56+
```
2157

2258
### Unit tests
2359

docs/how_to_use.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,12 @@ def splunk_setup(splunk):
460460

461461
How can this be achieved :
462462

463-
- Make json representation of the data models, which satisfies this [DataModelSchema](https://github.com/splunk/pytest-splunk-addon/blob/main/pytest_splunk_addon/cim_tests/DatamodelSchema.json).
464-
- Provide the path to the directory having all the data models by adding `--splunk_dm_path path_to_dir` to the pytest command
465-
- The test cases will now be generated for the data models provided to the plugin and not for the [default data models](https://github.com/splunk/pytest-splunk-addon/tree/main/pytest_splunk_addon/data_models).
463+
- Make json representation of the data models, which satisfies the [DatamodelSchema](https://github.com/splunk/psa-cim-models/blob/v2/splunk_cim_models/DatamodelSchema.json) provided by the `splunk-cim-models` package.
464+
- Provide the path to the directory having all the data models by adding `--splunk_dm_path path_to_dir` to the pytest command.
465+
- The test cases will now be generated for the data models provided to the plugin and not for the [default data models](https://github.com/splunk/psa-cim-models/tree/v2/splunk_cim_models/data_models) bundled in `splunk-cim-models`.
466+
467+
> **_NOTE:_** CIM data model definitions are provided by the [`splunk-cim-models`](https://github.com/splunk/psa-cim-models) package. Install it separately before running CIM tests:
468+
>
469+
> ```console
470+
> pip install splunk-cim-models
471+
> ```

docs/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ which allows the user to test [knowledge objects](https://docs.splunk.com/Splexi
88
- Splunk App or Add-on package
99
- Splunk instance with App or Add-on installed (Not required if using Docker)
1010
- Docker (Not required if using external Splunk instance)
11+
- [`splunk-cim-models`](https://github.com/splunk/psa-cim-models) — required for [CIM Compatibility Tests](./cim_tests.md) (not installed automatically)
1112

1213
## Support
1314

@@ -22,6 +23,17 @@ pytest-splunk-addon can be installed via pip from PyPI:
2223
pip3 install pytest-splunk-addon
2324
```
2425

26+
To run **CIM compatibility tests** you also need the CIM data models package:
27+
28+
```console
29+
pip3 install splunk-cim-models
30+
```
31+
32+
`splunk-cim-models` is versioned independently of `pytest-splunk-addon` so that CIM
33+
definitions can be updated without a full PSA release. See the
34+
[CIM Compatibility Tests](./cim_tests.md) page for details on how the two packages
35+
interact and how to pin or override data model definitions.
36+
2537
## Features
2638

2739
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:

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ pyenv local 3.7.8
99
curl -sSL https://install.python-poetry.org | python - --version 1.5.1
1010
export PATH="/root/.local/bin:$PATH"
1111
source ~/.poetry/env
12+
if [ -n "$GH_TOKEN" ]; then
13+
git config --global --add url."https://$GH_TOKEN@github.com".insteadOf https://github.com
14+
git config --global --add url."https://$GH_TOKEN@github.com".insteadOf ssh://git@github.com
15+
fi
1216
sleep 15
1317
poetry install
1418
exec poetry run pytest -vv $@

0 commit comments

Comments
 (0)