Skip to content

Commit

Permalink
Fix flaky network test (#825)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti authored Aug 21, 2024
1 parent 3de0fc7 commit b7f7089
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions pkg/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import (
. "github.com/onsi/gomega"
"github.com/rancher/elemental-operator/api/v1beta1"
utilmocks "github.com/rancher/elemental-operator/pkg/util/mocks"
"github.com/rancher/yip/pkg/schema"
"go.uber.org/mock/gomock"
"k8s.io/apimachinery/pkg/runtime"

"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
)

func TestInstall(t *testing.T) {
func TestNetwork(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Network Suite")
}
Expand Down Expand Up @@ -75,6 +76,18 @@ var _ = Describe("configurator", Label("network", "configurator"), func() {
},
},
}
wantFiles := []schema.File{
{
Content: "[connection]\nid=Wired connection 1\n[ipv4]\naddress1=192.168.122.10",
Path: filepath.Join(systemConnectionsDir, "eth0.nmconnection"),
Permissions: 0600,
},
{
Content: "[connection]\nid=Wired connection 2\n[ipv4]\naddress1=192.168.122.11",
Path: filepath.Join(systemConnectionsDir, "eth1.nmconnection"),
Permissions: 0600,
},
}

applicator, err := networkConfigurator.GetNetworkConfigApplicator(wantNetworkConfig)
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -83,10 +96,7 @@ var _ = Describe("configurator", Label("network", "configurator"), func() {
Expect(found).To(BeTrue(), "Config should be applied at initramfs stage")

Expect(len(stage[0].Files)).To(Equal(2), "Two nmconnection files must have been copied")
Expect(stage[0].Files[0].Content).To(Equal("[connection]\nid=Wired connection 1\n[ipv4]\naddress1=192.168.122.10"))
Expect(stage[0].Files[0].Path).To(Equal(filepath.Join(systemConnectionsDir, "eth0.nmconnection")))
Expect(stage[0].Files[1].Content).To(Equal("[connection]\nid=Wired connection 2\n[ipv4]\naddress1=192.168.122.11"))
Expect(stage[0].Files[1].Path).To(Equal(filepath.Join(systemConnectionsDir, "eth1.nmconnection")))
Expect(stage[0].Files).To(ContainElements(wantFiles))
})
It("should return nmstate yip config applicator", func() {
wantNetworkConfig := v1beta1.NetworkConfig{
Expand All @@ -105,6 +115,19 @@ var _ = Describe("configurator", Label("network", "configurator"), func() {
},
}

wantFiles := []schema.File{
{
Content: "[connection]\nid=Wired connection 1\n",
Path: filepath.Join(systemConnectionsDir, "wired1.nmconnection"),
Permissions: 0600,
},
{
Content: "[connection]\nid=Wired connection 2\n",
Path: filepath.Join(systemConnectionsDir, "wired2.nmconnection"),
Permissions: 0600,
},
}

runner.EXPECT().Run("nmstatectl", "apply", nmstateTempPath).Return(nil)
//prepare some dummy nmconnection files to simulate `nmstatectl apply` result
Expect(vfs.MkdirAll(fs, systemConnectionsDir, 0700)).Should(Succeed())
Expand All @@ -121,10 +144,7 @@ var _ = Describe("configurator", Label("network", "configurator"), func() {
Expect(found).To(BeTrue(), "Config should be applied at initramfs stage")

Expect(len(stage[0].Files)).To(Equal(2), "Two nmconnection files must have been copied")
Expect(stage[0].Files[0].Content).To(Equal("[connection]\nid=Wired connection 1\n"))
Expect(stage[0].Files[0].Path).To(Equal(filepath.Join(systemConnectionsDir, "wired1.nmconnection")))
Expect(stage[0].Files[1].Content).To(Equal("[connection]\nid=Wired connection 2\n"))
Expect(stage[0].Files[1].Path).To(Equal(filepath.Join(systemConnectionsDir, "wired2.nmconnection")))
Expect(stage[0].Files).To(ContainElements(wantFiles))
})
It("should return nmc yip config applicator", func() {
wantNetworkConfig := v1beta1.NetworkConfig{
Expand All @@ -142,6 +162,18 @@ var _ = Describe("configurator", Label("network", "configurator"), func() {
},
},
}
wantFiles := []schema.File{
{
Content: "[connection]\nid=Wired connection 1\n",
Path: filepath.Join(systemConnectionsDir, "wired1.nmconnection"),
Permissions: 0600,
},
{
Content: "[connection]\nid=Wired connection 2\n",
Path: filepath.Join(systemConnectionsDir, "wired2.nmconnection"),
Permissions: 0600,
},
}

runner.EXPECT().Run("nmc", "generate", "--config-dir", nmcDesiredStatesDir, "--output-dir", nmcNewtorkConfigDir).Return(nil)
runner.EXPECT().Run("nmc", "apply", "--config-dir", nmcNewtorkConfigDir).Return(nil)
Expand All @@ -160,10 +192,7 @@ var _ = Describe("configurator", Label("network", "configurator"), func() {
Expect(found).To(BeTrue(), "Config should be applied at initramfs stage")

Expect(len(stage[0].Files)).To(Equal(2), "Two nmconnection files must have been copied")
Expect(stage[0].Files[0].Content).To(Equal("[connection]\nid=Wired connection 1\n"))
Expect(stage[0].Files[0].Path).To(Equal(filepath.Join(systemConnectionsDir, "wired1.nmconnection")))
Expect(stage[0].Files[1].Content).To(Equal("[connection]\nid=Wired connection 2\n"))
Expect(stage[0].Files[1].Path).To(Equal(filepath.Join(systemConnectionsDir, "wired2.nmconnection")))
Expect(stage[0].Files).To(ContainElements(wantFiles))
})
It("should reset network", func() {
//prepare a dummy nmconnection file to highlight the need to reset network
Expand Down

0 comments on commit b7f7089

Please sign in to comment.