mirror of
https://github.com/siderolabs/talos.git
synced 2025-11-09 12:51:15 +01:00
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 <andrey.smirnov@siderolabs.com>
This commit is contained in:
parent
16cd127a04
commit
1cde53d017
@ -15,7 +15,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosi-project/runtime/pkg/resource/rtestutils"
|
"github.com/cosi-project/runtime/pkg/resource/rtestutils"
|
||||||
"github.com/cosi-project/runtime/pkg/safe"
|
|
||||||
"github.com/siderolabs/gen/ensure"
|
"github.com/siderolabs/gen/ensure"
|
||||||
"github.com/siderolabs/gen/xslices"
|
"github.com/siderolabs/gen/xslices"
|
||||||
"github.com/siderolabs/go-pointer"
|
"github.com/siderolabs/go-pointer"
|
||||||
@ -561,19 +560,10 @@ func (suite *ApplyConfigSuite) TestApplyTry() {
|
|||||||
suite.ClearConnectionRefused(suite.ctx, node)
|
suite.ClearConnectionRefused(suite.ctx, node)
|
||||||
nodeCtx := client.WithNode(suite.ctx, node)
|
nodeCtx := client.WithNode(suite.ctx, node)
|
||||||
|
|
||||||
getMachineConfig := func(ctx context.Context) (*mc.MachineConfig, error) {
|
provider, err := suite.ReadConfigFromNode(nodeCtx)
|
||||||
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)
|
|
||||||
suite.Require().NoErrorf(err, "failed to read existing config from node %q: %s", node, err)
|
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 {
|
if cfg.MachineConfig.MachineNetwork == nil {
|
||||||
cfg.MachineConfig.MachineNetwork = &v1alpha1.NetworkConfig{}
|
cfg.MachineConfig.MachineNetwork = &v1alpha1.NetworkConfig{}
|
||||||
}
|
}
|
||||||
@ -595,14 +585,22 @@ func (suite *ApplyConfigSuite) TestApplyTry() {
|
|||||||
)
|
)
|
||||||
suite.Assert().NoErrorf(err, "failed to apply configuration (node %q)", node)
|
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.Require().NoErrorf(err, "failed to read existing config from node %q", node)
|
||||||
|
|
||||||
suite.Assert().NotNil(provider.Config().Machine().Network())
|
suite.Assert().NotNil(provider.Machine().Network())
|
||||||
suite.Assert().NotNil(provider.Config().Machine().Network().Devices())
|
suite.Assert().NotNil(provider.Machine().Network().Devices())
|
||||||
|
|
||||||
lookupDummyInterface := func() bool {
|
assertDummyInterface := func(provider config.Provider) bool {
|
||||||
for _, device := range provider.Config().Machine().Network().Devices() {
|
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" {
|
if device.Dummy() && device.Interface() == "dummy0" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -611,24 +609,11 @@ func (suite *ApplyConfigSuite) TestApplyTry() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.Assert().Truef(lookupDummyInterface(), "dummy interface wasn't found")
|
suite.Assert().Truef(assertDummyInterface(provider), "dummy interface wasn't found")
|
||||||
|
|
||||||
for range 100 {
|
rtestutils.AssertResource(nodeCtx, suite.T(), suite.Client.COSI, mc.ActiveID, func(r *mc.MachineConfig, asrt *assert.Assertions) {
|
||||||
provider, err = getMachineConfig(nodeCtx)
|
asrt.False(assertDummyInterface(r.Provider()))
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestApplyRemovingV1Alpha1 verifies the apply config doesn't accept removal of v1alpha1 config.
|
// TestApplyRemovingV1Alpha1 verifies the apply config doesn't accept removal of v1alpha1 config.
|
||||||
|
|||||||
@ -81,6 +81,7 @@ func (suite *UpdateHostnameSuite) TestUpdateHostname() {
|
|||||||
suite.T().Logf("updating hostname of node %q to %q (IP: %s)", oldHostname, newHostname, nodeInternalIP)
|
suite.T().Logf("updating hostname of node %q to %q (IP: %s)", oldHostname, newHostname, nodeInternalIP)
|
||||||
|
|
||||||
suite.updateHostname(nodeCtx, newHostname)
|
suite.updateHostname(nodeCtx, newHostname)
|
||||||
|
suite.ClearConnectionRefused(suite.ctx, nodeInternalIP)
|
||||||
|
|
||||||
nodeReady := func(status corev1.ConditionStatus) bool {
|
nodeReady := func(status corev1.ConditionStatus) bool {
|
||||||
return status == corev1.ConditionTrue
|
return status == corev1.ConditionTrue
|
||||||
@ -136,11 +137,31 @@ func (suite *UpdateHostnameSuite) TestUpdateHostname() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *UpdateHostnameSuite) updateHostname(nodeCtx context.Context, newHostname string) {
|
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 := network.NewHostnameConfigV1Alpha1()
|
||||||
hostnameConfig.ConfigAuto = pointer.To(nethelpers.AutoHostnameKindOff)
|
hostnameConfig.ConfigAuto = pointer.To(nethelpers.AutoHostnameKindOff)
|
||||||
hostnameConfig.ConfigHostname = newHostname
|
hostnameConfig.ConfigHostname = newHostname
|
||||||
|
|
||||||
suite.PatchMachineConfig(nodeCtx, hostnameConfig)
|
suite.PatchMachineConfig(nodeCtx, v1alpha1Drop, hostnameConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user