diff --git a/test/e2e/nncp_default_bridged_network_test.go b/test/e2e/nncp_default_bridged_network_test.go index 55dd279115..b52992fbc9 100644 --- a/test/e2e/nncp_default_bridged_network_test.go +++ b/test/e2e/nncp_default_bridged_network_test.go @@ -1,7 +1,6 @@ package e2e import ( - "context" "fmt" "time" @@ -12,11 +11,8 @@ import ( yaml "sigs.k8s.io/yaml" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - framework "github.com/operator-framework/operator-sdk/pkg/test" - nmstatev1alpha1 "github.com/nmstate/kubernetes-nmstate/pkg/apis/nmstate/v1alpha1" ) diff --git a/test/e2e/reboot_test.go b/test/e2e/reboot_test.go new file mode 100644 index 0000000000..de61eb3df8 --- /dev/null +++ b/test/e2e/reboot_test.go @@ -0,0 +1,60 @@ +package e2e + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + nmstatev1alpha1 "github.com/nmstate/kubernetes-nmstate/pkg/apis/nmstate/v1alpha1" +) + +var _ = Describe("Nmstate network configuration", func() { + var ( + vlan101 = nmstatev1alpha1.State(`interfaces: +interfaces: + - name: eth0.101 + type: vlan + state: up + vlan: + base-iface: eth0 + id: 101 +`) + ) + Context("when node reboots", func() { + BeforeEach(func() { + By("Apply policy") + setDesiredStateWithPolicy("vlan-eth0.101", vlan101) + + By("Move kubernetes configuration to prevent start up") + _, errs := runAtNodes("sudo", "mv", "/etc/kubernetes", "/etc/kubernetes.bak") + Expect(errs).ToNot(ContainElement(HaveOccurred())) + + By("Reboot the nodes") + runAtNodes("sudo", "reboot") + + By("Wait for nodes to come back") + _, errs = runAtNodes("true") + Expect(errs).ToNot(ContainElement(HaveOccurred())) + }) + + AfterEach(func() { + By("Move kubernetes configuration back") + _, errs := runAtNodes("sudo", "mv", "/etc/kubernetes.bak", "/etc/kubernetes") + Expect(errs).ToNot(ContainElement(HaveOccurred())) + + By("Wait for k8s to be ready") + waitForNodesReady() + }) + It("should have nmstate connections before kubelet starts", func() { + + By("Check that kubelet is down") + Consistently(func() []error { + _, errs := runAtNodes("pidof", "kubelet") + return errs + }).ShouldNot(ContainElement(Succeed())) + + By("Vlan interface is there") + _, errs := runAtNodes("sudo", "ip", "link", "show", "eth0.101") + Expect(errs).ToNot(ContainElement(HaveOccurred())) + }) + }) +}) diff --git a/test/e2e/utils.go b/test/e2e/utils.go index 6cfbb69220..df6e5f8c50 100644 --- a/test/e2e/utils.go +++ b/test/e2e/utils.go @@ -347,3 +347,26 @@ func hasVlans(bridgeVlans string, connection string, minVlan int, maxVlan int) { } } + +func nodeReadyConditionStatus(nodeName string) (corev1.ConditionStatus, error) { + key := types.NamespacedName{Name: nodeName} + node := corev1.Node{} + err := framework.Global.Client.Get(context.TODO(), key, &node) + if err != nil { + return "", err + } + for _, condition := range node.Status.Conditions { + if condition.Type == corev1.NodeReady { + return condition.Status, nil + } + } + return corev1.ConditionUnknown, nil +} + +func waitForNodesReady() { + for _, node := range nodes { + Eventually(func() (corev1.ConditionStatus, error) { + return nodeReadyConditionStatus(node) + }, ReadTimeout, ReadInterval).Should(Equal(corev1.ConditionTrue)) + } +}