mirror of
https://github.com/siderolabs/omni.git
synced 2025-08-06 17:46:59 +02:00
Some checks failed
default / default (push) Has been cancelled
default / e2e-backups (push) Has been cancelled
default / e2e-forced-removal (push) Has been cancelled
default / e2e-scaling (push) Has been cancelled
default / e2e-short (push) Has been cancelled
default / e2e-short-secureboot (push) Has been cancelled
default / e2e-templates (push) Has been cancelled
default / e2e-upgrades (push) Has been cancelled
default / e2e-workload-proxy (push) Has been cancelled
All test modules were moved under `integration` tag and are now in `internal/integration` folder: no more `cmd/integration-test` executable. New Kres version is able to build the same executable from the tests directory instead. All Omni related flags were renamed, for example `--endpoint` -> `--omni.endpoint`. 2 more functional changes: - Enabled `--test.failfast` for all test runs. - Removed finalizers, which were running if the test has failed. Both of these changes should make it easier to understand the test failure: Talos node logs won't be cluttered with the finalizer tearing down the cluster. Fixes: https://github.com/siderolabs/omni/issues/1171 Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
114 lines
3.4 KiB
Go
114 lines
3.4 KiB
Go
// Copyright (c) 2025 Sidero Labs, Inc.
|
|
//
|
|
// Use of this software is governed by the Business Source License
|
|
// included in the LICENSE file.
|
|
|
|
//go:build integration
|
|
|
|
package integration_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/cosi-project/runtime/pkg/resource"
|
|
"github.com/cosi-project/runtime/pkg/resource/rtestutils"
|
|
"github.com/cosi-project/runtime/pkg/safe"
|
|
"github.com/cosi-project/runtime/pkg/state"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/siderolabs/omni/client/pkg/omni/resources"
|
|
"github.com/siderolabs/omni/client/pkg/omni/resources/omni"
|
|
"github.com/siderolabs/omni/client/pkg/omni/resources/siderolink"
|
|
)
|
|
|
|
// AssertNumberOfLinks verifies that machines are discovered by the SideroLink.
|
|
func AssertNumberOfLinks(testCtx context.Context, st state.State, expectedLinks int) TestFunc {
|
|
return func(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(testCtx, 90*time.Second)
|
|
defer cancel()
|
|
|
|
eventCh := make(chan safe.WrappedStateEvent[*siderolink.Link])
|
|
|
|
require.NoError(t,
|
|
safe.StateWatchKind(
|
|
ctx,
|
|
st,
|
|
resource.NewMetadata(resources.DefaultNamespace, siderolink.LinkType, "", resource.VersionUndefined),
|
|
eventCh,
|
|
state.WithBootstrapContents(true),
|
|
))
|
|
|
|
linksFound := 0
|
|
|
|
for linksFound < expectedLinks {
|
|
select {
|
|
case event := <-eventCh:
|
|
switch event.Type() { //nolint:exhaustive
|
|
case state.Created:
|
|
linksFound++
|
|
case state.Destroyed:
|
|
linksFound--
|
|
case state.Errored:
|
|
require.NoError(t, event.Error())
|
|
}
|
|
|
|
case <-ctx.Done():
|
|
t.Fatal("timeout")
|
|
}
|
|
|
|
t.Logf("links discovered: %d", linksFound)
|
|
}
|
|
}
|
|
}
|
|
|
|
// AssertLinksConnected verifies that all SideroLink connections are operational.
|
|
func AssertLinksConnected(testCtx context.Context, st state.State) TestFunc {
|
|
return func(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(testCtx, 320*time.Second)
|
|
defer cancel()
|
|
|
|
rtestutils.AssertAll(ctx, t, st,
|
|
func(link *siderolink.Link, assert *assert.Assertions) {
|
|
spec := link.TypedSpec().Value
|
|
|
|
assert.True(spec.Connected)
|
|
|
|
// the link counter for this link must be created
|
|
msl, err := safe.StateGet[*omni.MachineStatusLink](ctx, st,
|
|
omni.NewMachineStatusLink(resources.MetricsNamespace, link.Metadata().ID()).Metadata(),
|
|
)
|
|
assert.NoError(err)
|
|
|
|
if msl != nil {
|
|
// the link counter must have some bytes sent and received
|
|
assert.Greater(msl.TypedSpec().Value.GetSiderolinkCounter().GetBytesSent(), int64(0), resourceDetails(link))
|
|
assert.Greater(msl.TypedSpec().Value.GetSiderolinkCounter().GetBytesReceived(), int64(0), resourceDetails(link))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// AssertMachinesMatchLinks verifies that all SideroLink connections are discovered as Machines.
|
|
func AssertMachinesMatchLinks(testCtx context.Context, st state.State) TestFunc {
|
|
return func(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(testCtx, 10*time.Second)
|
|
defer cancel()
|
|
|
|
rtestutils.AssertResources(ctx, t, st,
|
|
rtestutils.ResourceIDs[*siderolink.Link](ctx, t, st),
|
|
func(machine *omni.Machine, assert *assert.Assertions) {
|
|
spec := machine.TypedSpec().Value
|
|
|
|
assert.NotEmpty(spec.ManagementAddress, resourceDetails(machine))
|
|
assert.True(spec.Connected, resourceDetails(machine))
|
|
|
|
addressLabel, ok := machine.Metadata().Labels().Get(omni.MachineAddressLabel)
|
|
assert.True(ok, resourceDetails(machine))
|
|
assert.Equal(spec.ManagementAddress, addressLabel, resourceDetails(machine))
|
|
})
|
|
}
|
|
}
|