Skip to content

Provision the E2E NetBox with docker compose - #2565

Open
ideaship wants to merge 1 commit into
mainfrom
sonic-e2e-v2-compose
Open

Provision the E2E NetBox with docker compose#2565
ideaship wants to merge 1 commit into
mainfrom
sonic-e2e-v2-compose

Conversation

@ideaship

@ideaship ideaship commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Part of the series tracked in #2562, which explains the ordering and what each PR covers. Based on the preceding PR in the stack, so review only the top commits here.

The infrastructure: compose.yaml (Postgres, Valkey, NetBox), deploy_netbox.sh
to bring it up and mint an API token, sonic_golden_test.sh as the harness
entry point, and the make sonic-e2e* targets.

Two decisions worth knowing while reading it:

Only NETBOX_PORT is interpolated into the compose file. Compose
re-interpolates the whole file on every subcommand, not just up, so
${VAR:?} guards would break down, ps and logs too. The rest of the
configuration lives in the container environment instead.

Seeding runs serially by default (SEED_PARALLEL=1). Concurrent seeding
deadlocks intermittently on PostgreSQL KEY SHARE row locks on shared parent
dcim_device rows — object disjointness says nothing about lock contention.
The escape hatch is kept for anyone who wants to retry it.

The Ansible pins are installed at run time, not the .[ansible] extra. The
conductor import chain needs ansible-core, which the unit tests stub out in
conftest.py — so a venv that passes the unit suite does not necessarily
satisfy that import. Installing the extra would also reinstall the project on
every run, replacing a developer's editable install with a wheel built from the
checkout. It is not needed for currency either: generate.py runs as
python -m from the repo root, so osism is imported from the working tree
rather than site-packages. Installing requirements.ansible.txt directly avoids
both, and is 1.4s rather than 8.9s when already satisfied.

Still nothing to run: the fixtures and goldens arrive in the next PR.

@ideaship ideaship changed the title sonic e2e v2 compose Provision the E2E NetBox with docker compose Aug 5, 2026
@berendt
berendt force-pushed the sonic-e2e-v2-compose branch from df1acf4 to 29058cc Compare August 5, 2026 15:10
@ideaship
ideaship force-pushed the sonic-e2e-v2-compose branch from 29058cc to 0299da7 Compare August 5, 2026 19:51
Base automatically changed from sonic-e2e-v2-scripts to main August 6, 2026 10:56
@berendt
berendt force-pushed the sonic-e2e-v2-compose branch from 0299da7 to be5399c Compare August 6, 2026 10:56
@ideaship
ideaship marked this pull request as ready for review August 6, 2026 11:13
@ideaship ideaship moved this from New to Ready for review in Human Board Aug 6, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In tests/e2e/sonic_golden_test.sh the pipenv run pip install --quiet '.[ansible]' step will run on every invocation and can be both slow and mutate the developer environment unexpectedly; consider moving this into a dedicated setup step (e.g. a make target or CI job bootstrap) and failing fast if the extra is missing instead of installing it during the test run.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In tests/e2e/sonic_golden_test.sh the `pipenv run pip install --quiet '.[ansible]'` step will run on every invocation and can be both slow and mutate the developer environment unexpectedly; consider moving this into a dedicated setup step (e.g. a make target or CI job bootstrap) and failing fast if the extra is missing instead of installing it during the test run.

## Individual Comments

### Comment 1
<location path="Makefile" line_range="8-13" />
<code_context>
+# Full cycle: start the NetBox compose stack (an existing stack is reused
+# and left in place), seed, generate, compare against tests/e2e/golden/.
+sonic-e2e:
+	NETBOX_MANAGER_DIR=$(NETBOX_MANAGER_DIR) tests/e2e/sonic_golden_test.sh
+
+# Regenerate the golden files after an intentional generator change,
+# then review and commit the diff.
+sonic-e2e-regen:
+	NETBOX_MANAGER_DIR=$(NETBOX_MANAGER_DIR) tests/e2e/sonic_golden_test.sh --regenerate
+
+# Start the NetBox stack and leave it running for debugging. Export a
</code_context>
<issue_to_address>
**suggestion:** Quote NETBOX_MANAGER_DIR when exporting to avoid issues with spaces in the path

As written, these targets will fail if `NETBOX_MANAGER_DIR` contains spaces or shell-special characters because the variable expansion isn’t quoted. Please update the invocations to quote the assignment, e.g. `NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" tests/e2e/sonic_golden_test.sh` (or use `env NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" ...`) so directories with spaces work correctly.

Suggested implementation:

```
sonic-e2e:
	NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" tests/e2e/sonic_golden_test.sh

```

```
sonic-e2e-regen:
	NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" tests/e2e/sonic_golden_test.sh --regenerate

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread Makefile Outdated
Comment on lines +8 to +13
NETBOX_MANAGER_DIR=$(NETBOX_MANAGER_DIR) tests/e2e/sonic_golden_test.sh

# Regenerate the golden files after an intentional generator change,
# then review and commit the diff.
sonic-e2e-regen:
NETBOX_MANAGER_DIR=$(NETBOX_MANAGER_DIR) tests/e2e/sonic_golden_test.sh --regenerate

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Quote NETBOX_MANAGER_DIR when exporting to avoid issues with spaces in the path

As written, these targets will fail if NETBOX_MANAGER_DIR contains spaces or shell-special characters because the variable expansion isn’t quoted. Please update the invocations to quote the assignment, e.g. NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" tests/e2e/sonic_golden_test.sh (or use env NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" ...) so directories with spaces work correctly.

Suggested implementation:

sonic-e2e:
	NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" tests/e2e/sonic_golden_test.sh

sonic-e2e-regen:
	NETBOX_MANAGER_DIR="$(NETBOX_MANAGER_DIR)" tests/e2e/sonic_golden_test.sh --regenerate

@ideaship
ideaship marked this pull request as draft August 6, 2026 12:09
@ideaship
ideaship force-pushed the sonic-e2e-v2-compose branch from be5399c to a75a30d Compare August 6, 2026 12:10
Add the infrastructure side of the SONiC config-generation E2E
golden test: tests/e2e/compose.yaml, tests/e2e/deploy_netbox.sh and
tests/e2e/sonic_golden_test.sh, plus the Makefile target and
.gitignore entry that drive them.

compose.yaml defines three services (NetBox, its Postgres database
and Redis) -- no Kubernetes, so there is no kind/kubectl dependency
and no cluster bring-up latency. NetBox is configured entirely
through the environment variables its own baked-in configuration.py
already reads; nothing is templated or mounted over it.
API_TOKEN_PEPPERS is deliberately left unset so that a plain v1 API
token can be minted for the test run instead of the peppered v2
format. NETBOX_PORT is the only variable interpolated into the
compose file, because compose re-interpolates the whole file on
every subcommand (up, ps, down, ...): keeping the rest of the
configuration in the container environment avoids re-resolving values
on each invocation.

deploy_netbox.sh brings the stack up, waits for the healthchecks and
mints/prints the API token. sonic_golden_test.sh is the harness
entrypoint: it provisions NetBox via deploy_netbox.sh, then seeds it
by installing netbox-manager into a dedicated venv (so its package
pins never mutate this project's venv) and running it against the
fixtures under tests/e2e/scenario/ -- netbox-manager's own bundled
example/ data is not used. Concurrent seeding is disabled by default
(SEED_PARALLEL=1) because seeding files in the same numeric group
take KEY SHARE locks on shared parent dcim_device rows and can
deadlock; the script documents the observed error and the condition
that still causes it (200-fabric.yml cabling both leaves to a shared
spine). Finally it runs sync_sonic() via generate.py and compares the
result against tests/e2e/golden/.

make sonic-e2e wires the above together; make sonic-e2e-regen adds
--regenerate to rewrite the goldens.

--regenerate refuses to run against a reused stack (CREATED_STACK==0)
unless ALLOW_WARM_REGEN=1 is set: applying the fixtures as an UPDATE
over whatever is already in a reused database can produce goldens a
fresh stack -- the only kind CI ever uses -- would not reproduce, and
nothing would otherwise say so. sonic_golden_test.sh also now accepts
--allow-coverage-loss and forwards it to tests.e2e.compare, so an
intentional fixture removal can get a green regen without editing the
script by hand.

Phase 3 installs requirements.ansible.txt rather than the project's
".[ansible]" extra.  The conductor import chain needs ansible-core,
which the unit tests stub out in conftest.py, so a venv that runs the
unit suite does not necessarily satisfy it.  Installing the extra would
also reinstall the project on every run, replacing an editable install
with a wheel built from the checkout -- and it is not needed for
currency either, since generate.py runs as python -m from the repo root
and therefore imports osism from the working tree, not site-packages.

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Roger Luethi <luethi@osism.tech>
@ideaship
ideaship force-pushed the sonic-e2e-v2-compose branch from a75a30d to 8b78556 Compare August 6, 2026 12:19
@ideaship
ideaship marked this pull request as ready for review August 6, 2026 12:24

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

2 participants