Skip to content

Commit

Permalink
functests/config: Add a test verifying PAO runs in master nodes
Browse files Browse the repository at this point in the history
Straight forward test that checks the node PAO is running on
is a master node.

Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
  • Loading branch information
marcel-apf committed Sep 21, 2020
1 parent 684d6ae commit 56ae514
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions functests/0_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -27,6 +28,8 @@ import (
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
"github.com/openshift-kni/performance-addon-operators/functests/utils/discovery"
"github.com/openshift-kni/performance-addon-operators/functests/utils/mcps"
"github.com/openshift-kni/performance-addon-operators/functests/utils/nodes"
"github.com/openshift-kni/performance-addon-operators/functests/utils/pods"
"github.com/openshift-kni/performance-addon-operators/functests/utils/profiles"
"github.com/openshift-kni/performance-addon-operators/pkg/apis"
performancev1 "github.com/openshift-kni/performance-addon-operators/pkg/apis/performance/v1"
Expand All @@ -37,6 +40,22 @@ import (

var _ = Describe("[performance][config] Performance configuration", func() {

It("Should run performance profile pod on a master node", func() {
pod, err := pods.GetPerformanceOperatorPod()
Expect(err).ToNot(HaveOccurred(), "Failed to find the PAO pod")

masterNodes, err := nodes.GetByRole(testutils.RoleMaster)
Expect(err).ToNot(HaveOccurred(), "Failed to query the master nodes")
for _, node := range masterNodes {
if node.Name == pod.Spec.NodeName {
return
}
}

// Fail
Expect(true).To(Reject(), "PAO is not running in a master node")
})

It("Should successfully deploy the performance profile", func() {

performanceProfile := testProfile()
Expand Down
2 changes: 2 additions & 0 deletions functests/utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func init() {
const (
// RoleWorker contains the worker role
RoleWorker = "worker"
// RoleMaster contains the master role
RoleMaster = "master"
)

const (
Expand Down
22 changes: 22 additions & 0 deletions functests/utils/pods/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"

testutils "github.com/openshift-kni/performance-addon-operators/functests/utils"
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
Expand Down Expand Up @@ -143,3 +145,23 @@ func GetContainerIDByName(pod *corev1.Pod, containerName string) (string, error)
}
return "", fmt.Errorf("failed to find the container ID for the container %q under the pod %q", containerName, pod.Name)
}

// GetPerformanceOperatorPod returns the pod running the Performance Profile Operator
func GetPerformanceOperatorPod() (*corev1.Pod, error) {
selector, err := labels.Parse(fmt.Sprintf("%s=%s", "name", "performance-operator"))
if err != nil {
return nil, err
}

pods := &corev1.PodList{}

opts := &client.ListOptions{LabelSelector: selector, Namespace: testutils.PerformanceOperatorNamespace}
if err := testclient.Client.List(context.TODO(), pods, opts); err != nil {
return nil, err
}
if len(pods.Items) != 1 {
return nil, fmt.Errorf("incorrect performance operator pods count: %d", len(pods.Items))
}

return &pods.Items[0], nil
}

0 comments on commit 56ae514

Please sign in to comment.