Skip to content

Commit

Permalink
CI: fix ifacer e2e case
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclinder committed Oct 31, 2023
1 parent 608f60a commit f2222bd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test/e2e/common/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
PodStartTimeout = time.Minute * 5
PodReStartTimeout = time.Minute * 5
IPReclaimTimeout = time.Minute * 5
ExecCommandTimeout = time.Minute
ExecCommandTimeout = time.Minute * 5
EventOccurTimeout = time.Second * 30
ServiceAccountReadyTimeout = time.Second * 20
NodeReadyTimeout = time.Minute
Expand Down
64 changes: 50 additions & 14 deletions test/e2e/ifacer/ifacer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,51 +108,78 @@ var _ = Describe("test ifacer", Label("ifacer"), func() {
GinkgoWriter.Printf("Try to create Deployment: %v/%v \n", namespace, dsName)
Expect(frame.CreateDaemonSet(dsObject)).NotTo(HaveOccurred())

GinkgoWriter.Println("Check that each node where the Pod is located should have a vlan sub-interface.")
ctx, cancel := context.WithTimeout(context.Background(), common.ExecCommandTimeout)
defer cancel()
checkMasterUPString := fmt.Sprintf("ip link show %s | grep 'state UP mode' ", common.NIC1)
checkIPLinkString := fmt.Sprintf("ip link show | grep %s.%d | grep 'state UP mode' ", common.NIC1, vlanInterface)

err := frame.WaitPodListRunning(dsObject.Spec.Template.Labels, 2, ctx)
Expect(err).NotTo(HaveOccurred())

GinkgoWriter.Println("Check that each node where the Pod is located should have a vlan sub-interface.")
checkMasterUPString := fmt.Sprintf("ip link show up %s ", common.NIC1)
checkIPLinkString := fmt.Sprintf("ip link show up %s.%d ", common.NIC1, vlanInterface)
Eventually(func() bool {
for _, node := range frame.Info.KindNodeList {
showMasterResult, err := frame.DockerExecCommand(ctx, node, checkMasterUPString)
if err != nil {
GinkgoWriter.Printf("Failed to execute command on the node, error is %v \n", string(showMasterResult))
GinkgoWriter.Printf("Failed to execute command on the node %s : %v \n", node, err)
return false
}

if string(showMasterResult) == "" {
GinkgoWriter.Printf("master interface %s is down, waiting \n", common.NIC1)
return false
}

showResult, err := frame.DockerExecCommand(ctx, node, checkIPLinkString)
if err != nil {
GinkgoWriter.Printf("Failed to execute command on the node, error is %v \n", string(showResult))
GinkgoWriter.Printf("Failed to execute command on the node %s: %v \n", node, err)
return false
}

if string(showResult) == "" {
GinkgoWriter.Printf("vlan interface %s is down, waiting... \n", vlanInterface)
return false
}

}
return true
}, common.ResourceDeleteTimeout, common.ForcedWaitingTime).Should(BeTrue())

GinkgoWriter.Println("Create a vlan sub-interface with the same name, its network card status is down, and it is automatically set to up")
ctx, cancel = context.WithTimeout(context.Background(), common.ExecCommandTimeout)
defer cancel()

setDownString := fmt.Sprintf("ip link set %s.%d down", common.NIC1, vlanInterface)
for _, node := range frame.Info.KindNodeList {
showResult, err := frame.DockerExecCommand(ctx, node, setDownString)
Expect(err).NotTo(HaveOccurred(), "Failed to execute down nic command on the node, error is %v", string(showResult))
_, err := frame.DockerExecCommand(ctx, node, setDownString)
Expect(err).NotTo(HaveOccurred(), "Failed to execute down %s on the node %s: %v", vlanInterface, err)
}
GinkgoWriter.Println("Restart all pods")
podList, err := frame.GetPodListByLabel(dsObject.Spec.Template.Labels)
Expect(err).NotTo(HaveOccurred(), "failed to get Pod list, Pod list is %v", len(podList.Items))
Expect(frame.DeletePodList(podList)).NotTo(HaveOccurred())

GinkgoWriter.Println("Check the nic status should be up")
time.Sleep(time.Second * 5)

ctx, cancel = context.WithTimeout(context.Background(), common.PodReStartTimeout)
defer cancel()
checkIPLinkUpString := fmt.Sprintf("ip link show %s.%d | grep 'state UP mode'", common.NIC1, vlanInterface)

err = frame.WaitPodListRunning(dsObject.Spec.Template.Labels, 2, ctx)
Expect(err).NotTo(HaveOccurred())

GinkgoWriter.Println("Check the nic status should be up")
checkIPLinkUpString := fmt.Sprintf("ip link show up %s.%d", common.NIC1, vlanInterface)
Eventually(func() bool {
for _, node := range frame.Info.KindNodeList {
showResult, err := frame.DockerExecCommand(ctx, node, checkIPLinkUpString)
if err != nil {
GinkgoWriter.Printf("Failed to execute command on the node, error is %v \n", string(showResult))
GinkgoWriter.Printf("Failed to execute \"%s\" on the node %s: %v \n", checkIPLinkUpString, node, err)
return false
}

if string(showResult) == "" {
GinkgoWriter.Printf("vlan interface %s is down, waiting... \n", vlanInterface)
}
}
return true
}, common.ResourceDeleteTimeout, common.ForcedWaitingTime).Should(BeTrue())
Expand All @@ -163,8 +190,8 @@ var _ = Describe("test ifacer", Label("ifacer"), func() {
deleteIPLinkString := fmt.Sprintf("ip link delete dev %s.%d", common.NIC1, vlanInterface)
Eventually(func() bool {
for _, node := range frame.Info.KindNodeList {
showResult, err := frame.DockerExecCommand(ctx, node, deleteIPLinkString)
Expect(err).NotTo(HaveOccurred(), "Failed to execute the delete sub-interface command on the node, error is %v", string(showResult))
_, err := frame.DockerExecCommand(ctx, node, deleteIPLinkString)
Expect(err).NotTo(HaveOccurred(), "Failed to execute the delete sub-interface command on the node %s %v", node, err)
}
return true
}, common.ResourceDeleteTimeout, common.ForcedWaitingTime).Should(BeTrue())
Expand All @@ -177,12 +204,21 @@ var _ = Describe("test ifacer", Label("ifacer"), func() {
GinkgoWriter.Println("The sub-interfaces of all nodes are automatically rebuilt, and the status is UP")
ctx, cancel = context.WithTimeout(context.Background(), common.ExecCommandTimeout)
defer cancel()
checkIPLinkString = fmt.Sprintf("ip link show %s.%d | grep 'state UP mode'", common.NIC1, vlanInterface)

err = frame.WaitPodListRunning(dsObject.Spec.Template.Labels, 2, ctx)
Expect(err).NotTo(HaveOccurred())

checkIPLinkString = fmt.Sprintf("ip link show up %s.%d", common.NIC1, vlanInterface)
Eventually(func() bool {
for _, node := range frame.Info.KindNodeList {
showResult, err := frame.DockerExecCommand(ctx, node, checkIPLinkUpString)
if err != nil {
GinkgoWriter.Printf("Checking subinterfaces failed on node, error is %v \n", string(showResult))
GinkgoWriter.Printf("failed to check if subinterfaces is up on node %s: %v \n", node, err)
return false
}

if len(showResult) == 0 {
GinkgoWriter.Printf("sub-vlan interfaces is down, waiting...")
return false
}
}
Expand Down

0 comments on commit f2222bd

Please sign in to comment.