Skip to content

Commit

Permalink
Test that connections persist a reboot
Browse files Browse the repository at this point in the history
It will create a vlan interface with a policy and reboot the nodes
preventing k8s from starting up, the vlan connection has to be there
since is NM the one configured and it's persistent.

The teardown code puts back the k8s configuration and ensure that
k8s is at good shape.

Closes #143

Signed-off-by: Quique Llorente <[email protected]>
  • Loading branch information
qinqon committed Sep 13, 2019
1 parent d58333e commit a214102
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 27 deletions.
27 changes: 0 additions & 27 deletions test/e2e/nncp_default_bridged_network_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2e

import (
"context"
"fmt"
"time"

Expand All @@ -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"
)

Expand Down Expand Up @@ -145,26 +141,3 @@ func dhcpFlag(node string, name string) bool {
path := fmt.Sprintf("interfaces.#(name==\"%s\").ipv4.dhcp", name)
return gjson.ParseBytes(currentStateJSON(node)).Get(path).Bool()
}

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)
}, 15*time.Second, 1*time.Second).Should(Equal(corev1.ConditionTrue))
}
}
60 changes: 60 additions & 0 deletions test/e2e/reboot_test.go
Original file line number Diff line number Diff line change
@@ -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 connnections persistency", func() {
var (
vlan101 = nmstatev1alpha1.State(`interfaces:
interfaces:
- name: eth0.101
type: vlan
state: up
vlan:
base-iface: eth0
id: 101
`)
)
Context("after rebooting a node with applied configuration", 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()))
})
})
})
23 changes: 23 additions & 0 deletions test/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit a214102

Please sign in to comment.