Skip to content

Commit

Permalink
test: fix failed e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
choujimmy committed May 12, 2020
1 parent cd9c729 commit e04e4da
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
75 changes: 38 additions & 37 deletions test/e2e/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auth_test

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -39,7 +40,7 @@ var _ = Describe("E2e", func() {
},
}

result, err := client.AuthV1().LocalGroups().Create(&group)
result, err := client.AuthV1().LocalGroups().Create(context.Background(), &group, metav1.CreateOptions{})
Expect(err).To(BeNil())
groupID = result.Name

Expand All @@ -52,7 +53,7 @@ var _ = Describe("E2e", func() {
},
}

localidentity, err := client.AuthV1().LocalIdentities().Create(&user)
localidentity, err := client.AuthV1().LocalIdentities().Create(context.Background(), &user, metav1.CreateOptions{})
Expect(err).To(BeNil())
userID = localidentity.Name

Expand All @@ -69,7 +70,7 @@ var _ = Describe("E2e", func() {
},
}}

pol, err := client.AuthV1().Policies().Create(&policy)
pol, err := client.AuthV1().Policies().Create(context.Background(), &policy, metav1.CreateOptions{})
Expect(err).To(BeNil())
policyID = pol.Name

Expand All @@ -81,16 +82,16 @@ var _ = Describe("E2e", func() {
Policies: []string{policyID},
}}

rol, err := client.AuthV1().Roles().Create(&role)
rol, err := client.AuthV1().Roles().Create(context.Background(), &role, metav1.CreateOptions{})
Expect(err).To(BeNil())
roleID = rol.Name
})

AfterEach(func() {
_ = client.AuthV1().LocalIdentities().Delete(userID, &metav1.DeleteOptions{})
_ = client.AuthV1().LocalIdentities().Delete(context.Background(), userID, metav1.DeleteOptions{})

err = wait.Poll(1*time.Second, 10*time.Second, func() (bool, error) {
_, err = client.AuthV1().LocalIdentities().Get(userID, metav1.GetOptions{})
_, err = client.AuthV1().LocalIdentities().Get(context.Background(), userID, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
return true, nil
}
Expand All @@ -102,9 +103,9 @@ var _ = Describe("E2e", func() {
})
Expect(err).To(BeNil())

_ = client.AuthV1().LocalGroups().Delete(groupID, &metav1.DeleteOptions{})
_ = client.AuthV1().LocalGroups().Delete(context.Background(), groupID, metav1.DeleteOptions{})
err = wait.Poll(1*time.Second, 10*time.Second, func() (bool, error) {
_, err = client.AuthV1().LocalGroups().Get(groupID, metav1.GetOptions{})
_, err = client.AuthV1().LocalGroups().Get(context.Background(), groupID, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
return true, nil
}
Expand All @@ -117,9 +118,9 @@ var _ = Describe("E2e", func() {

Expect(err).To(BeNil())

_ = client.AuthV1().Policies().Delete(policyID, &metav1.DeleteOptions{})
_ = client.AuthV1().Policies().Delete(context.Background(), policyID, metav1.DeleteOptions{})
err = wait.Poll(1*time.Second, 10*time.Second, func() (bool, error) {
_, err = client.AuthV1().Policies().Get(policyID, metav1.GetOptions{})
_, err = client.AuthV1().Policies().Get(context.Background(), policyID, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
return true, nil
}
Expand All @@ -135,17 +136,17 @@ var _ = Describe("E2e", func() {

It("test group binding", func() {

localIdentity, err := client.AuthV1().LocalIdentities().Get(userID, metav1.GetOptions{})
localIdentity, err := client.AuthV1().LocalIdentities().Get(context.Background(), userID, metav1.GetOptions{})
Expect(err).To(BeNil())

_, err = client.AuthV1().LocalGroups().Get(groupID, metav1.GetOptions{})
_, err = client.AuthV1().LocalGroups().Get(context.Background(), groupID, metav1.GetOptions{})
Expect(err).To(BeNil())

var subjects []authv1.Subject
subjects = append(subjects, authv1.Subject{ID: userID})
binding := authv1.Binding{Users: subjects}
localGroup := &authv1.LocalGroup{}
err = client.AuthV1().RESTClient().Post().Resource("localgroups").SubResource("binding").Name(groupID).Body(&binding).Do().Into(localGroup)
err = client.AuthV1().RESTClient().Post().Resource("localgroups").SubResource("binding").Name(groupID).Body(&binding).Do(context.Background()).Into(localGroup)
Expect(err).To(BeNil())

found := false
Expand All @@ -161,7 +162,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var groupList = &authv1.GroupList{}
err := client.AuthV1().RESTClient().Get().Resource("localidentities").SubResource("groups").Name(userID).Do().Into(groupList)
err := client.AuthV1().RESTClient().Get().Resource("localidentities").SubResource("groups").Name(userID).Do(context.Background()).Into(groupList)
if err != nil {
return false, err
}
Expand All @@ -181,18 +182,18 @@ var _ = Describe("E2e", func() {

It("test policy binding", func() {

localIdentity, err := client.AuthV1().LocalIdentities().Get(userID, metav1.GetOptions{})
localIdentity, err := client.AuthV1().LocalIdentities().Get(context.Background(), userID, metav1.GetOptions{})
Expect(err).To(BeNil())

group, err := client.AuthV1().LocalGroups().Get(groupID, metav1.GetOptions{})
group, err := client.AuthV1().LocalGroups().Get(context.Background(), groupID, metav1.GetOptions{})
Expect(err).To(BeNil())

_, err = client.AuthV1().Policies().Get(policyID, metav1.GetOptions{})
_, err = client.AuthV1().Policies().Get(context.Background(), policyID, metav1.GetOptions{})
Expect(err).To(BeNil())

binding := authv1.Binding{Users: []authv1.Subject{{ID: userID}}, Groups: []authv1.Subject{{ID: groupID}}}
policy := &authv1.Policy{}
err = client.AuthV1().RESTClient().Post().Resource("policies").SubResource("binding").Name(policyID).Body(&binding).Do().Into(policy)
err = client.AuthV1().RESTClient().Post().Resource("policies").SubResource("binding").Name(policyID).Body(&binding).Do(context.Background()).Into(policy)
Expect(err).To(BeNil())

found := false
Expand All @@ -217,7 +218,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var policyList = &authv1.PolicyList{}
err := client.AuthV1().RESTClient().Get().Resource("localidentities").SubResource("policies").Name(userID).Do().Into(policyList)
err := client.AuthV1().RESTClient().Get().Resource("localidentities").SubResource("policies").Name(userID).Do(context.Background()).Into(policyList)
if err != nil {
return false, err
}
Expand All @@ -236,7 +237,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var policyList = &authv1.PolicyList{}
err := client.AuthV1().RESTClient().Get().Resource("users").SubResource("policies").Name(util.CombineTenantAndName("default", userID)).Do().Into(policyList)
err := client.AuthV1().RESTClient().Get().Resource("users").SubResource("policies").Name(util.CombineTenantAndName("default", userID)).Do(context.Background()).Into(policyList)
if err != nil {
return false, err
}
Expand All @@ -256,7 +257,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var policyList = &authv1.PolicyList{}
err := client.AuthV1().RESTClient().Get().Resource("localgroups").SubResource("policies").Name(groupID).Do().Into(policyList)
err := client.AuthV1().RESTClient().Get().Resource("localgroups").SubResource("policies").Name(groupID).Do(context.Background()).Into(policyList)
if err != nil {
return false, err
}
Expand All @@ -275,7 +276,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var policyList = &authv1.PolicyList{}
err := client.AuthV1().RESTClient().Get().Resource("groups").SubResource("policies").Name(util.CombineTenantAndName("default", groupID)).Do().Into(policyList)
err := client.AuthV1().RESTClient().Get().Resource("groups").SubResource("policies").Name(util.CombineTenantAndName("default", groupID)).Do(context.Background()).Into(policyList)
if err != nil {
return false, err
}
Expand All @@ -294,21 +295,21 @@ var _ = Describe("E2e", func() {

It("test role binding", func() {

localIdentity, err := client.AuthV1().LocalIdentities().Get(userID, metav1.GetOptions{})
localIdentity, err := client.AuthV1().LocalIdentities().Get(context.Background(), userID, metav1.GetOptions{})
Expect(err).To(BeNil())

group, err := client.AuthV1().LocalGroups().Get(groupID, metav1.GetOptions{})
group, err := client.AuthV1().LocalGroups().Get(context.Background(), groupID, metav1.GetOptions{})
Expect(err).To(BeNil())

_, err = client.AuthV1().Policies().Get(policyID, metav1.GetOptions{})
_, err = client.AuthV1().Policies().Get(context.Background(), policyID, metav1.GetOptions{})
Expect(err).To(BeNil())

role, err := client.AuthV1().Roles().Get(roleID, metav1.GetOptions{})
role, err := client.AuthV1().Roles().Get(context.Background(), roleID, metav1.GetOptions{})
Expect(err).To(BeNil())

binding := authv1.Binding{Users: []authv1.Subject{{ID: userID}}, Groups: []authv1.Subject{{ID: groupID}}}
role = &authv1.Role{}
err = client.AuthV1().RESTClient().Post().Resource("roles").SubResource("binding").Name(roleID).Body(&binding).Do().Into(role)
err = client.AuthV1().RESTClient().Post().Resource("roles").SubResource("binding").Name(roleID).Body(&binding).Do(context.Background()).Into(role)
Expect(err).To(BeNil())

found := false
Expand All @@ -333,7 +334,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var roleList = &authv1.RoleList{}
err := client.AuthV1().RESTClient().Get().Resource("localidentities").SubResource("roles").Name(userID).Do().Into(roleList)
err := client.AuthV1().RESTClient().Get().Resource("localidentities").SubResource("roles").Name(userID).Do(context.Background()).Into(roleList)
if err != nil {
return false, err
}
Expand All @@ -352,7 +353,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var roleList = &authv1.RoleList{}
err := client.AuthV1().RESTClient().Get().Resource("users").SubResource("roles").Name(util.CombineTenantAndName("default", userID)).Do().Into(roleList)
err := client.AuthV1().RESTClient().Get().Resource("users").SubResource("roles").Name(util.CombineTenantAndName("default", userID)).Do(context.Background()).Into(roleList)
if err != nil {
return false, err
}
Expand All @@ -372,7 +373,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var roleList = &authv1.RoleList{}
err := client.AuthV1().RESTClient().Get().Resource("localgroups").SubResource("roles").Name(groupID).Do().Into(roleList)
err := client.AuthV1().RESTClient().Get().Resource("localgroups").SubResource("roles").Name(groupID).Do(context.Background()).Into(roleList)
if err != nil {
return false, err
}
Expand All @@ -391,7 +392,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var roleList = &authv1.RoleList{}
err := client.AuthV1().RESTClient().Get().Resource("groups").SubResource("roles").Name(util.CombineTenantAndName("default", groupID)).Do().Into(roleList)
err := client.AuthV1().RESTClient().Get().Resource("groups").SubResource("roles").Name(util.CombineTenantAndName("default", groupID)).Do(context.Background()).Into(roleList)
if err != nil {
return false, err
}
Expand All @@ -409,15 +410,15 @@ var _ = Describe("E2e", func() {
})

It("test role policybinding", func() {
policy, err := client.AuthV1().Policies().Get(policyID, metav1.GetOptions{})
policy, err := client.AuthV1().Policies().Get(context.Background(), policyID, metav1.GetOptions{})
Expect(err).To(BeNil())

_, err = client.AuthV1().Roles().Get(roleID, metav1.GetOptions{})
_, err = client.AuthV1().Roles().Get(context.Background(), roleID, metav1.GetOptions{})
Expect(err).To(BeNil())

binding := authv1.PolicyBinding{Policies: []string{policyID}}
role := &authv1.Role{}
err = client.AuthV1().RESTClient().Post().Resource("roles").SubResource("policybinding").Name(roleID).Body(&binding).Do().Into(role)
err = client.AuthV1().RESTClient().Post().Resource("roles").SubResource("policybinding").Name(roleID).Body(&binding).Do(context.Background()).Into(role)
Expect(err).To(BeNil())

found := false
Expand All @@ -433,7 +434,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var policyList = &authv1.PolicyList{}
err := client.AuthV1().RESTClient().Get().Resource("roles").SubResource("policies").Name(roleID).Do().Into(policyList)
err := client.AuthV1().RESTClient().Get().Resource("roles").SubResource("policies").Name(roleID).Do(context.Background()).Into(policyList)
if err != nil {
return false, err
}
Expand All @@ -450,7 +451,7 @@ var _ = Describe("E2e", func() {
Expect(found).To(BeTrue())

role = &authv1.Role{}
err = client.AuthV1().RESTClient().Post().Resource("roles").SubResource("policyunbinding").Name(roleID).Body(&binding).Do().Into(role)
err = client.AuthV1().RESTClient().Post().Resource("roles").SubResource("policyunbinding").Name(roleID).Body(&binding).Do(context.Background()).Into(role)
Expect(err).To(BeNil())

found = false
Expand All @@ -466,7 +467,7 @@ var _ = Describe("E2e", func() {
found = false
err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
var policyList = &authv1.PolicyList{}
err := client.AuthV1().RESTClient().Get().Resource("roles").SubResource("policies").Name(roleID).Do().Into(policyList)
err := client.AuthV1().RESTClient().Get().Resource("roles").SubResource("policies").Name(roleID).Do(context.Background()).Into(policyList)
if err != nil {
return false, err
}
Expand Down
21 changes: 11 additions & 10 deletions test/e2e/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package cluster_test

import (
"context"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -84,7 +85,7 @@ var _ = Describe("cluster lifecycle", func() {
TenantID: "default",
Version: "1.14.6",
ClusterCIDR: "10.244.0.0/16",
Type: platformv1.ClusterBaremetal,
Type: "Baremetal",
Features: platformv1.ClusterFeature{EnableMasterSchedule: true},
}}
for _, one := range masterNodes {
Expand All @@ -97,13 +98,13 @@ var _ = Describe("cluster lifecycle", func() {
}

By("create cluster")
cluster, err = client.PlatformV1().Clusters().Create(cluster)
cluster, err = client.PlatformV1().Clusters().Create(context.Background(), cluster, metav1.CreateOptions{})
Expect(err).To(BeNil())
clusterName := cluster.Name

By(fmt.Sprintf("wait cluster(%s) status is running", clusterName))
err = wait.Poll(5*time.Second, 5*time.Minute, func() (bool, error) {
cluster, err = client.PlatformV1().Clusters().Get(clusterName, metav1.GetOptions{})
cluster, err = client.PlatformV1().Clusters().Get(context.Background(), clusterName, metav1.GetOptions{})
if err != nil {
return false, nil
}
Expand All @@ -114,7 +115,7 @@ var _ = Describe("cluster lifecycle", func() {
machine := &platformv1.Machine{
Spec: platformv1.MachineSpec{
ClusterName: clusterName,
Type: platformv1.BaremetalMachine,
Type: "Baremetal",
IP: one.InternalIP,
Port: one.Port,
Username: one.Username,
Expand All @@ -123,24 +124,24 @@ var _ = Describe("cluster lifecycle", func() {
}

By(fmt.Sprintf("add work nodes(%s) to cluster", one.InternalIP))
machine, err = client.PlatformV1().Machines().Create(machine)
machine, err = client.PlatformV1().Machines().Create(context.Background(), machine, metav1.CreateOptions{})
Expect(err).To(BeNil())
machineName := machine.Name

By(fmt.Sprintf("wait worker node(%s) status is running", one.InternalIP))
err = wait.Poll(5*time.Second, 5*time.Minute, func() (bool, error) {
machine, err = client.PlatformV1().Machines().Get(machineName, metav1.GetOptions{})
machine, err = client.PlatformV1().Machines().Get(context.Background(), machineName, metav1.GetOptions{})
if err != nil {
return false, nil
}
return machine.Status.Phase == platformv1.MachineRunning, nil
})

By(fmt.Sprintf("delete work nodes(%s) from cluster", one.InternalIP))
err = client.PlatformV1().Machines().Delete(machineName, &metav1.DeleteOptions{})
err = client.PlatformV1().Machines().Delete(context.Background(), machineName, metav1.DeleteOptions{})
Expect(err).To(BeNil())
err = wait.Poll(5*time.Second, 5*time.Minute, func() (bool, error) {
_, err = client.PlatformV1().Machines().Get(machineName, metav1.GetOptions{})
_, err = client.PlatformV1().Machines().Get(context.Background(), machineName, metav1.GetOptions{})
if errors.IsNotFound(err) {
return true, nil
}
Expand All @@ -149,10 +150,10 @@ var _ = Describe("cluster lifecycle", func() {
}

By(fmt.Sprintf("delete cluster(%s)", clusterName))
err = client.PlatformV1().Clusters().Delete(clusterName, &metav1.DeleteOptions{})
err = client.PlatformV1().Clusters().Delete(context.Background(), clusterName, metav1.DeleteOptions{})
Expect(err).To(BeNil())
err = wait.Poll(5*time.Second, 5*time.Minute, func() (bool, error) {
_, err = client.PlatformV1().Clusters().Get(clusterName, metav1.GetOptions{})
_, err = client.PlatformV1().Clusters().Get(context.Background(), clusterName, metav1.GetOptions{})
if errors.IsNotFound(err) {
return true, nil
}
Expand Down

0 comments on commit e04e4da

Please sign in to comment.