Skip to content

Commit

Permalink
port more tests from mao
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Dec 3, 2018
1 parent 41bd879 commit 0864e12
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 4 deletions.
14 changes: 14 additions & 0 deletions test/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,19 @@ func runSuite() error {
}
glog.Info("PASS: ExpectOneClusterObject")

glog.Info("RUN: ExpectAllMachinesLinkedToANode")
if err := testConfig.ExpectAllMachinesLinkedToANode(); err != nil {
glog.Errorf("FAIL: ExpectAllMachinesLinkedToANode: %v", err)
return err
}
glog.Info("PASS: ExpectAllMachinesLinkedToANode")

glog.Info("RUN: ExpectNewNodeWhenDeletingMachine")
if err := testConfig.ExpectNewNodeWhenDeletingMachine(); err != nil {
glog.Errorf("FAIL: ExpectNewNodeWhenDeletingMachine: %v", err)
return err
}
glog.Info("PASS: ExpectNewNodeWhenDeletingMachine")

return nil
}
147 changes: 143 additions & 4 deletions test/e2e/provider_expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (

"context"
"errors"
"fmt"
"github.com/golang/glog"
kappsapi "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
capiv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
Expand All @@ -32,10 +34,7 @@ func (tc *testConfig) ExpectProviderAvailable() error {
glog.Errorf("error querying api for Deployment object: %v, retrying...", err)
return false, nil
}
if d.Status.ReadyReplicas < 1 {
return false, nil
}
return true, nil
return d.Status.ReadyReplicas > 0, nil
})
return err
}
Expand All @@ -58,3 +57,143 @@ func (tc *testConfig) ExpectOneClusterObject() error {
})
return err
}

func (tc *testConfig) ExpectAllMachinesLinkedToANode() error {
machineAnnotationKey := "machine"
listOptions := client.ListOptions{
Namespace: namespace,
}
machineList := capiv1alpha1.MachineList{}
nodeList := corev1.NodeList{}

err := wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &machineList); err != nil {
glog.Errorf("error querying api for machineList object: %v, retrying...", err)
return false, nil
}
if err := tc.client.List(context.TODO(), &listOptions, &nodeList); err != nil {
glog.Errorf("error querying api for nodeList object: %v, retrying...", err)
return false, nil
}
glog.Infof("Waiting for %d machines to become nodes", len(machineList.Items))
return len(machineList.Items) == len(nodeList.Items), nil
})
if err != nil {
return err
}

return wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
nodeNameToMachineAnnotation := make(map[string]string)
for _, node := range nodeList.Items {
nodeNameToMachineAnnotation[node.Name] = node.Annotations[machineAnnotationKey]
}
for _, machine := range machineList.Items {
if machine.Status.NodeRef == nil {
glog.Errorf("machine %s has no NodeRef, retrying...", machine.Name)
return false, nil
}
nodeName := machine.Status.NodeRef.Name
if nodeNameToMachineAnnotation[nodeName] != fmt.Sprintf("%s/%s", namespace, machine.Name) {
glog.Errorf("node name %s does not match expected machine name %s, retrying...", nodeName, machine.Name)
return false, nil
}
}
return true, nil
})
}

func (tc *testConfig) ExpectNewNodeWhenDeletingMachine() error {
listOptions := client.ListOptions{
Namespace: namespace,
}
machineList := capiv1alpha1.MachineList{}
nodeList := corev1.NodeList{}

glog.Info("Get machineList")
err := wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &machineList); err != nil {
glog.Errorf("error querying api for machineList object: %v, retrying...", err)
return false, nil
}
return true, nil
})
if err != nil {
return err
}

glog.Info("Get nodeList")
err = wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &nodeList); err != nil {
glog.Errorf("error querying api for nodeList object: %v, retrying...", err)
return false, nil
}
return true, nil
})
if err != nil {
return err
}

clusterInitialTotalNodes := len(nodeList.Items)
clusterInitialTotalMachines := len(machineList.Items)
var triagedWorkerMachine capiv1alpha1.Machine
var triagedWorkerNode corev1.Node
MachineLoop:
for _, m := range machineList.Items {
if m.Labels["sigs.k8s.io/cluster-api-machine-role"] == "worker" {
for _, n := range nodeList.Items {
if m.Status.NodeRef == nil {
glog.Errorf("no NodeRef found in machine %v", m.Name)
return errors.New("no NodeRef found in machine")
}
if n.Name == m.Status.NodeRef.Name {
triagedWorkerMachine = m
triagedWorkerNode = n
break MachineLoop
}
}
}
}

glog.Info("Delete machine")
err = wait.PollImmediate(1*time.Second, waitShort, func() (bool, error) {
if err := tc.client.Delete(context.TODO(), &triagedWorkerMachine); err != nil {
glog.Errorf("error querying api for Deployment object: %v, retrying...", err)
return false, nil
}
return true, nil
})
if err != nil {
return err
}

err = wait.PollImmediate(1*time.Second, waitMedium, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &machineList); err != nil {
glog.Errorf("error querying api for machineList object: %v, retrying...", err)
return false, nil
}
glog.Info("Expect new machine to come up")
return len(machineList.Items) == clusterInitialTotalMachines, nil
})
if err != nil {
return err
}

err = wait.PollImmediate(1*time.Second, waitLong, func() (bool, error) {
if err := tc.client.List(context.TODO(), &listOptions, &nodeList); err != nil {
glog.Errorf("error querying api for nodeList object: %v, retrying...", err)
return false, nil
}
glog.Info("Expect deleted machine node to go away")
for _, n := range nodeList.Items {
if n.Name == triagedWorkerNode.Name {
return false, nil
}
}
glog.Info("Expect new node to come up")
return len(nodeList.Items) == clusterInitialTotalNodes, nil
})
if err != nil {
return err
}
return nil
}

0 comments on commit 0864e12

Please sign in to comment.