Skip to content

testing (3/4): Add gNMI integration tests with envtest - #409

Open
nikatza wants to merge 3 commits into
mainfrom
refactor-tests-3
Open

testing (3/4): Add gNMI integration tests with envtest#409
nikatza wants to merge 3 commits into
mainfrom
refactor-tests-3

Conversation

@nikatza

@nikatza nikatza commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This PR introduces envtest-based gNMI integration tests for the OpenConfig provider, enabling faster validation of the Kubernetes resources to gNMI sequence without requiring a full cluster deployment.

The test architecture uses a per-process gNMI server design that enables parallel test execution with Ginkgo's --procs flag. Each process creates its own suite-level server in BeforeSuite and shares it across tests running serially within that process.

@nikatza
nikatza force-pushed the refactor-tests-3 branch from 78654a7 to d200e98 Compare June 16, 2026 22:11
@nikatza nikatza changed the title e2e-tests (3/4): Add test resources for NXOS e2e-tests (3/4): Add envtest mode for faster in-process e2e testing Jun 17, 2026
@nikatza
nikatza force-pushed the refactor-tests-2 branch from 82d714b to 829e761 Compare June 17, 2026 23:40
@nikatza
nikatza force-pushed the refactor-tests-3 branch from d200e98 to 823e208 Compare June 17, 2026 23:40
@github-actions github-actions Bot added size/XL and removed size/XXL labels Jun 17, 2026
@nikatza
nikatza force-pushed the refactor-tests-3 branch from 823e208 to f735c68 Compare June 17, 2026 23:45
@nikatza
nikatza force-pushed the refactor-tests-2 branch 2 times, most recently from be16d2f to e20ae93 Compare June 18, 2026 07:59
@nikatza
nikatza force-pushed the refactor-tests-3 branch 2 times, most recently from 51d400f to ace1a56 Compare June 18, 2026 08:15
@nikatza
nikatza force-pushed the refactor-tests-2 branch from 8b82070 to e0403cc Compare June 18, 2026 08:54
@nikatza
nikatza force-pushed the refactor-tests-3 branch from ace1a56 to bce5bb0 Compare June 18, 2026 08:54
@nikatza
nikatza changed the base branch from refactor-tests-2 to refactor-tests-1 July 14, 2026 12:20
@nikatza
nikatza force-pushed the refactor-tests-3 branch from bce5bb0 to 2cf82d6 Compare July 14, 2026 17:16
@github-actions github-actions Bot added size/XXL and removed size/XL labels Jul 14, 2026
@nikatza nikatza changed the title e2e-tests (3/4): Add envtest mode for faster in-process e2e testing e2e-tests (3/4): Add gNMI integration tests with envtest Jul 14, 2026
@nikatza
nikatza force-pushed the refactor-tests-3 branch 2 times, most recently from dd3f643 to 5b100a6 Compare July 15, 2026 08:53
@nikatza
nikatza force-pushed the refactor-tests-1 branch 5 times, most recently from f81d9b2 to 47fda5a Compare July 15, 2026 14:22
Base automatically changed from refactor-tests-1 to main July 15, 2026 15:34
@nikatza
nikatza force-pushed the refactor-tests-3 branch 3 times, most recently from 268ae9b to 625b160 Compare July 16, 2026 13:23
@nikatza
nikatza force-pushed the refactor-tests-3 branch 12 times, most recently from a6bf5d6 to b92a3b7 Compare July 27, 2026 10:20
@nikatza
nikatza marked this pull request as draft July 27, 2026 11:48
@nikatza
nikatza force-pushed the refactor-tests-3 branch 3 times, most recently from 78a7329 to 88ddff7 Compare July 27, 2026 12:26
@nikatza
nikatza marked this pull request as ready for review July 27, 2026 12:31
@nikatza
nikatza force-pushed the refactor-tests-3 branch 4 times, most recently from b93b249 to 8aff030 Compare July 27, 2026 13:27
@nikatza
nikatza force-pushed the refactor-tests-3 branch from 8aff030 to 6cf3d85 Compare July 28, 2026 07:54
Comment thread .github/workflows/test-gnmi.yaml Outdated
Comment on lines +35 to +36
- name: Install ginkgo
run: go install github.com/onsi/ginkgo/v2/ginkgo@latest

@felix-kaestner felix-kaestner Aug 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- name: Install ginkgo
run: go install github.com/onsi/ginkgo/v2/ginkgo@latest

The Makefile target for test-gnmi should already take care of installing ginkgo, if even required.

@nikatza nikatza Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. But I think we still need gingko to run the tests in parallel. With ginkgo we don't have to worry about the gNMI server state being shared across the tests as each process runs one server and the tests run sequentially there. We could refactor (again) the tests to have a gNMI server per test, or extend the server to support multiple States, but this seems too much for now.

Comment thread Makefile Outdated
Comment thread test/gnmi/gnmi_suite_test.go Outdated
func registerControllers(ctx context.Context, mgr ctrl.Manager, recorder *events.FakeRecorder, providerFn provider.ProviderFunc, locker *resourcelock.ResourceLocker) {
var err error

err = (&core.PrefixSetReconciler{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel like this list might have gotten outdated, e.g. there is no EthernetSegmentReconciler registered here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is true, but there is also no test for that. Doesn't seem necessary to register a controller that is not used.

Comment thread test/gnmi/gnmi_test.go Outdated
Comment thread test/gnmi/gnmi_test.go
conditions, err := ExtractConditions(r)
g.Expect(err).NotTo(HaveOccurred())

conditionToCheck := string(v1alpha1.ReadyCondition)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem I see is that we check for the wrong condition and the eventually might return early therefore. The logic is that we only check for "Configured" when that is found on the object. However, we don't wait for the object to report any condition before we decide that.

So generally, if a resource has no conditions, it hasn't been reconciled yet. But if it contains any conditions, then it would also contain the "Configured" condition, as we then initialize that to "Unknown".

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Merging this branch will not change overall coverage

Impacted Packages Coverage Δ 🤖
github.com/ironcore-dev/network-operator/test/gnmi 0.00% (ø)
github.com/ironcore-dev/network-operator/test/gnmi/server 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/ironcore-dev/network-operator/test/gnmi/server/server.go 0.00% (ø) 0 (-152) 0 0 (-152)

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/ironcore-dev/network-operator/test/gnmi/gnmi_suite_test.go
  • github.com/ironcore-dev/network-operator/test/gnmi/gnmi_test.go

nikatza added 3 commits August 4, 2026 16:41
This commit introduces envtest-based integration tests for gNMI functionality
using the OpenConfig provider. The tests verify the end-to-end workflow from
Kubernetes resources to provider gNMI payloads without requiring a full cluster
deployment.

The test architecture uses a per-process gNMI test server to enable parallel
test execution with Ginkgo's --procs flag. Each Ginkgo process creates its own
suite-level server in BeforeSuite, shares it across all tests within that
process, and cleans it up in AfterSuite. Tests within each process run serially,
ensuring proper isolation through per-test namespaces and state clearing between
tests.

Testdata files support optional state/preload sections to set initial
gNMI server state before reconciliation. This is for example required to
successfully reconcile devices: the controller requires the last boot
time. Added one additional section ("delete") that represents the state
of the device after the kubernetes resource has been cleaned up. This is
usually the same as the preload section. Updated test cases
accordingly.

At the beginning of the test we set device.Status.Phase to Running
directly. This unblocks the the Device controller and avoids us having
to add more of the device data into the preload section, e.g., that
related to  GetDeviceInfo, ListPorts.

As there is only one gNMI test server per process, all tests share the same device.
This means that test cases must clean up all resources they create, otherwise the
server will be polluted by the left over resources.

As Envtest runs without kube-controller-manager, there is no garbage collector
to cascade deletions, meaning each test needs to explicitly clean up resources it creates,
and it must do so in the correct order to prevent finalizer deadlocks. For example, a
Device cannot be deleted while it still has dependent resources with finalizers.

Additionally, not all custom resources in network-operator have controllers.
Resources like Interface, BGP, and OSPF have reconcilers that add finalizers and
set status conditions. Other resources (typically config-only types) are stored
in the API but have no controller — no finalizer, no conditions.

Thus, the test framework must handle: wait for conditions on controller-managed
resources, prevent blocking indefinitely on config-only ones, and clean up
resources in the correct order without relying on cascading deletion.

The waitForResource helper probes for a finalizer with a short timeout.
Controllers add finalizers early in reconciliation (within ~1 second), so if
none appears after 3 seconds, the resource is assumed to be config-only and the
helper returns immediately. For controller-managed resources, it waits for the
Ready or Configured condition.

The cleanupAllResources helper lists all network-operator resources in the
namespace, then partitions them by checking each resource's finalizers field.
Controller-managed resources (those with finalizers) are deleted first, waiting
for finalizer removal while Device still exists. Config-only resources (no
finalizers) are deleted afterward without waiting. Finally, the Device is
deleted. This approach avoids hardcoded list of resource types.

Signed-off-by: Pujol <enric.pujol@sap.com>
…lacks VLAN support)

The OpenConfig provider does not yet support VLAN interface configuration,
causing the interface_routed_vlan test to fail. Skip this test by renaming
the fixture file to .skip extension until VLAN support is implemented.

Signed-off-by: Pujol <enric.pujol@sap.com>
Signed-off-by: Pujol <enric.pujol@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants