From 1cde53d0173fd1ae637855e15fe34bb74bb027a0 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 16 Sep 2025 16:41:37 +0400 Subject: [PATCH] test: fix several issues with tests One issue is with update hostname tests which runs against Talos v1.11 machine config which contains legacy fields which need to be removed. Another is an attempt to refactor apply-try tests. Signed-off-by: Andrey Smirnov --- internal/integration/api/apply-config.go | 53 ++++++++------------- internal/integration/api/update-hostname.go | 23 ++++++++- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/internal/integration/api/apply-config.go b/internal/integration/api/apply-config.go index 307462bf9..2d344f26c 100644 --- a/internal/integration/api/apply-config.go +++ b/internal/integration/api/apply-config.go @@ -15,7 +15,6 @@ import ( "time" "github.com/cosi-project/runtime/pkg/resource/rtestutils" - "github.com/cosi-project/runtime/pkg/safe" "github.com/siderolabs/gen/ensure" "github.com/siderolabs/gen/xslices" "github.com/siderolabs/go-pointer" @@ -561,19 +560,10 @@ func (suite *ApplyConfigSuite) TestApplyTry() { suite.ClearConnectionRefused(suite.ctx, node) nodeCtx := client.WithNode(suite.ctx, node) - getMachineConfig := func(ctx context.Context) (*mc.MachineConfig, error) { - cfg, err := safe.StateGetByID[*mc.MachineConfig](ctx, suite.Client.COSI, mc.ActiveID) - if err != nil { - return nil, err - } - - return cfg, nil - } - - provider, err := getMachineConfig(nodeCtx) + provider, err := suite.ReadConfigFromNode(nodeCtx) suite.Require().NoErrorf(err, "failed to read existing config from node %q: %s", node, err) - cfgDataOut := suite.PatchV1Alpha1Config(provider.Provider(), func(cfg *v1alpha1.Config) { + cfgDataOut := suite.PatchV1Alpha1Config(provider, func(cfg *v1alpha1.Config) { if cfg.MachineConfig.MachineNetwork == nil { cfg.MachineConfig.MachineNetwork = &v1alpha1.NetworkConfig{} } @@ -595,14 +585,22 @@ func (suite *ApplyConfigSuite) TestApplyTry() { ) suite.Assert().NoErrorf(err, "failed to apply configuration (node %q)", node) - provider, err = getMachineConfig(nodeCtx) + provider, err = suite.ReadConfigFromNode(nodeCtx) suite.Require().NoErrorf(err, "failed to read existing config from node %q", node) - suite.Assert().NotNil(provider.Config().Machine().Network()) - suite.Assert().NotNil(provider.Config().Machine().Network().Devices()) + suite.Assert().NotNil(provider.Machine().Network()) + suite.Assert().NotNil(provider.Machine().Network().Devices()) - lookupDummyInterface := func() bool { - for _, device := range provider.Config().Machine().Network().Devices() { + assertDummyInterface := func(provider config.Provider) bool { + if provider.Machine().Network() == nil { + return false + } + + if provider.Machine().Network().Devices() == nil { + return false + } + + for _, device := range provider.Machine().Network().Devices() { if device.Dummy() && device.Interface() == "dummy0" { return true } @@ -611,24 +609,11 @@ func (suite *ApplyConfigSuite) TestApplyTry() { return false } - suite.Assert().Truef(lookupDummyInterface(), "dummy interface wasn't found") + suite.Assert().Truef(assertDummyInterface(provider), "dummy interface wasn't found") - for range 100 { - provider, err = getMachineConfig(nodeCtx) - suite.Assert().NoErrorf(err, "failed to read existing config from node %q: %s", node, err) - - if provider.Config().Machine().Network() == nil { - return - } - - if !lookupDummyInterface() { - return - } - - time.Sleep(time.Millisecond * 100) - } - - suite.Fail("dummy interface wasn't removed after config try timeout") + rtestutils.AssertResource(nodeCtx, suite.T(), suite.Client.COSI, mc.ActiveID, func(r *mc.MachineConfig, asrt *assert.Assertions) { + asrt.False(assertDummyInterface(r.Provider())) + }) } // TestApplyRemovingV1Alpha1 verifies the apply config doesn't accept removal of v1alpha1 config. diff --git a/internal/integration/api/update-hostname.go b/internal/integration/api/update-hostname.go index aca30b37e..87e5cf635 100644 --- a/internal/integration/api/update-hostname.go +++ b/internal/integration/api/update-hostname.go @@ -81,6 +81,7 @@ func (suite *UpdateHostnameSuite) TestUpdateHostname() { suite.T().Logf("updating hostname of node %q to %q (IP: %s)", oldHostname, newHostname, nodeInternalIP) suite.updateHostname(nodeCtx, newHostname) + suite.ClearConnectionRefused(suite.ctx, nodeInternalIP) nodeReady := func(status corev1.ConditionStatus) bool { return status == corev1.ConditionTrue @@ -136,11 +137,31 @@ func (suite *UpdateHostnameSuite) TestUpdateHostname() { } func (suite *UpdateHostnameSuite) updateHostname(nodeCtx context.Context, newHostname string) { + // [TODO]: this should be dropped once Terraform Provider is updated for Talos 1.12 + // do a negative patch removing v1alpha1 hostname-related config + // In "normal" tests config is generated without hostname v1alpha1 parts, + // but when the cluster is generated via Terraform, it uses outdated machinery and + // generates config with v1alpha1 hostname parts. + v1alpha1Drop := map[string]any{ + "machine": map[string]any{ + "network": map[string]any{ + "hostname": map[string]any{ + "$patch": "delete", + }, + }, + "features": map[string]any{ + "stableHostname": map[string]any{ + "$patch": "delete", + }, + }, + }, + } + hostnameConfig := network.NewHostnameConfigV1Alpha1() hostnameConfig.ConfigAuto = pointer.To(nethelpers.AutoHostnameKindOff) hostnameConfig.ConfigHostname = newHostname - suite.PatchMachineConfig(nodeCtx, hostnameConfig) + suite.PatchMachineConfig(nodeCtx, v1alpha1Drop, hostnameConfig) } func init() {