|
| 1 | +// Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package tests |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "testing" |
| 20 | + "tests/helpers" |
| 21 | + |
| 22 | + "github.com/nvidia/nvsentinel/data-models/pkg/protos" |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | + "sigs.k8s.io/e2e-framework/pkg/envconf" |
| 25 | + "sigs.k8s.io/e2e-framework/pkg/features" |
| 26 | +) |
| 27 | + |
| 28 | +type PlatformConnectorTestContext struct { |
| 29 | + NodeName string |
| 30 | + ConfigMapBackup []byte |
| 31 | + TestNamespace string |
| 32 | +} |
| 33 | + |
| 34 | +func TestPlatformConnectorWithProcessingStrategy(t *testing.T) { |
| 35 | + feature := features.New("TestPlatformConnector"). |
| 36 | + WithLabel("suite", "platform-connector") |
| 37 | + |
| 38 | + var testCtx *PlatformConnectorTestContext |
| 39 | + |
| 40 | + feature.Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { |
| 41 | + client, err := c.NewClient() |
| 42 | + require.NoError(t, err) |
| 43 | + |
| 44 | + nodeName := helpers.SelectTestNodeFromUnusedPool(ctx, t, client) |
| 45 | + |
| 46 | + testCtx = &PlatformConnectorTestContext{ |
| 47 | + NodeName: nodeName, |
| 48 | + } |
| 49 | + |
| 50 | + return ctx |
| 51 | + }) |
| 52 | + |
| 53 | + feature.Assess("Check that platform connector is not applying node events/conditions for STORE_ONLY events", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { |
| 54 | + client, err := c.NewClient() |
| 55 | + require.NoError(t, err) |
| 56 | + |
| 57 | + event := helpers.NewHealthEvent(testCtx.NodeName). |
| 58 | + WithErrorCode(helpers.ERRORCODE_79). |
| 59 | + WithMessage("XID error occurred"). |
| 60 | + WithProcessingStrategy(int(protos.ProcessingStrategy_STORE_ONLY)) |
| 61 | + helpers.SendHealthEvent(ctx, t, event) |
| 62 | + |
| 63 | + t.Logf("Node %s should not have condition SysLogsXIDError", testCtx.NodeName) |
| 64 | + helpers.EnsureNodeConditionNotPresent(ctx, t, client, testCtx.NodeName, "SysLogsXIDError") |
| 65 | + |
| 66 | + event = helpers.NewHealthEvent(testCtx.NodeName). |
| 67 | + WithErrorCode(helpers.ERRORCODE_31). |
| 68 | + WithMessage("XID error occurred"). |
| 69 | + WithFatal(false). |
| 70 | + WithProcessingStrategy(int(protos.ProcessingStrategy_STORE_ONLY)) |
| 71 | + helpers.SendHealthEvent(ctx, t, event) |
| 72 | + |
| 73 | + t.Logf("Node %s should not have event SysLogsXIDError", testCtx.NodeName) |
| 74 | + helpers.EnsureNodeEventNotPresent(ctx, t, client, testCtx.NodeName, "SysLogsXIDError", "SysLogsXIDErrorIsNotHealthy") |
| 75 | + |
| 76 | + event = helpers.NewHealthEvent(testCtx.NodeName). |
| 77 | + WithErrorCode(helpers.ERRORCODE_79). |
| 78 | + WithMessage("XID error occurred"). |
| 79 | + WithProcessingStrategy(int(protos.ProcessingStrategy_EXECUTE_REMEDIATION)) |
| 80 | + helpers.SendHealthEvent(ctx, t, event) |
| 81 | + |
| 82 | + t.Logf("Node %s should have condition SysLogsXIDError", testCtx.NodeName) |
| 83 | + helpers.CheckNodeConditionExists(ctx, client, testCtx.NodeName, "SysLogsXIDError", "SysLogsXIDErrorIsNotHealthy") |
| 84 | + |
| 85 | + event = helpers.NewHealthEvent(testCtx.NodeName). |
| 86 | + WithErrorCode(helpers.ERRORCODE_31). |
| 87 | + WithMessage("XID error occurred"). |
| 88 | + WithFatal(false). |
| 89 | + WithProcessingStrategy(int(protos.ProcessingStrategy_EXECUTE_REMEDIATION)) |
| 90 | + helpers.SendHealthEvent(ctx, t, event) |
| 91 | + |
| 92 | + t.Logf("Node %s should have event SysLogsXIDError", testCtx.NodeName) |
| 93 | + helpers.CheckNodeEventExists(ctx, client, testCtx.NodeName, "SysLogsXIDError", "SysLogsXIDErrorIsNotHealthy") |
| 94 | + |
| 95 | + return ctx |
| 96 | + }) |
| 97 | + |
| 98 | + feature.Teardown(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { |
| 99 | + helpers.SendHealthyEvent(ctx, t, testCtx.NodeName) |
| 100 | + return ctx |
| 101 | + }) |
| 102 | + |
| 103 | + testEnv.Test(t, feature.Feature()) |
| 104 | +} |
0 commit comments