Skip to content

Commit

Permalink
Merge pull request #376 from openshift-cherrypick-robot/cherry-pick-3…
Browse files Browse the repository at this point in the history
…75-to-release-4.6

[release-4.6] functests: ensure deleted objects are really gone
  • Loading branch information
openshift-merge-robot committed Sep 28, 2020
2 parents db8ccff + 1591aa7 commit ec36742
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion functests/1_performance/cpu_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", func() {
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("error looking for the optional selector: %v", err))
Expect(workerRTNodes).ToNot(BeEmpty())
workerRTNode = &workerRTNodes[0]

profile, err = profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
By(fmt.Sprintf("Checking the profile %s with cpus %#v", profile.Name, profile.Spec.CPU))

Expect(err).ToNot(HaveOccurred())
Expect(profile.Spec.HugePages).ToNot(BeNil())

Expand Down
1 change: 1 addition & 0 deletions functests/1_performance/performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ var _ = Describe("[rfe_id:27368][performance]", func() {

By("Remove second profile and verify that KubeletConfig and MachineConfig were removed")
Expect(testclient.Client.Delete(context.TODO(), secondProfile)).ToNot(HaveOccurred())
Expect(profiles.WaitForDeletion(secondProfile, 60*time.Second)).ToNot(HaveOccurred())

Consistently(func() corev1.ConditionStatus {
return mcps.GetConditionStatus(testutils.RoleWorkerCNF, machineconfigv1.MachineConfigPoolUpdating)
Expand Down
8 changes: 7 additions & 1 deletion functests/4_latency/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ var _ = Describe("[performance] Latency Test", func() {
})

AfterEach(func() {
if err := testclient.Client.Delete(context.TODO(), oslatPod); err != nil {
var err error
err = testclient.Client.Delete(context.TODO(), oslatPod)
if err != nil {
klog.Error(err)
}
err = pods.WaitForDeletion(oslatPod, 60*time.Second)
if err != nil {
klog.Error(err)
}
})
Expand Down
4 changes: 4 additions & 0 deletions functests/utils/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"time"

"github.com/openshift-kni/performance-addon-operators/pkg/controller/performanceprofile/components/profile"

Expand All @@ -12,6 +13,7 @@ import (
"github.com/openshift-kni/performance-addon-operators/functests/utils"
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
"github.com/openshift-kni/performance-addon-operators/functests/utils/mcps"
"github.com/openshift-kni/performance-addon-operators/functests/utils/profiles"
performancev1 "github.com/openshift-kni/performance-addon-operators/pkg/apis/performance/v1"
"github.com/openshift-kni/performance-addon-operators/pkg/controller/performanceprofile/components"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
Expand Down Expand Up @@ -45,6 +47,8 @@ func All() {
Expect(err).ToNot(HaveOccurred(), "Failed to find perf profile")
err = testclient.Client.Delete(context.TODO(), &perfProfile)
Expect(err).ToNot(HaveOccurred(), "Failed to delete perf profile")
err = profiles.WaitForDeletion(&perfProfile, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "Failed to wait for perf profile deletion")

mcpLabel := profile.GetMachineConfigLabel(&perfProfile)
key, value := components.GetFirstKeyAndValue(mcpLabel)
Expand Down
20 changes: 20 additions & 0 deletions functests/utils/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import (
"context"
"fmt"
"reflect"
"time"

. "github.com/onsi/gomega"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"

testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
performancev1 "github.com/openshift-kni/performance-addon-operators/pkg/apis/performance/v1"
v1 "github.com/openshift/custom-resource-status/conditions/v1"
Expand Down Expand Up @@ -36,6 +41,21 @@ func GetByNodeLabels(nodeLabels map[string]string) (*performancev1.PerformancePr
return result, nil
}

// WaitForDeletion waits until the pod will be removed from the cluster
func WaitForDeletion(prof *performancev1.PerformanceProfile, timeout time.Duration) error {
key := types.NamespacedName{
Name: prof.Name,
Namespace: prof.Namespace,
}
return wait.PollImmediate(time.Second, timeout, func() (bool, error) {
prof := &performancev1.PerformanceProfile{}
if err := testclient.Client.Get(context.TODO(), key, prof); errors.IsNotFound(err) {
return true, nil
}
return false, nil
})
}

// GetConditionMessage gets the performance profile message for the given type
func GetConditionMessage(nodeLabels map[string]string, conditionType v1.ConditionType) string {
profile, err := GetByNodeLabels(nodeLabels)
Expand Down

0 comments on commit ec36742

Please sign in to comment.