-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a "validation" test suite that perform very basic tests. It checks that all the crds are deployed, and that the pods are running correctly. This serves two purpouses: - having a toggle to understand when a deployment finished (implemented by the make deploy-wait rule) - having a set of tests able to prevent DOA releases, verifying that the operator deploys correctly (even without needing a baremetal cluster) Signed-off-by: Federico Paolinelli <[email protected]>
- Loading branch information
Showing
7 changed files
with
243 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
ATTEMPTS=0 | ||
MAX_ATTEMPTS=72 | ||
ready=false | ||
sleep_time=10 | ||
|
||
until $ready || [ $ATTEMPTS -eq $MAX_ATTEMPTS ] | ||
do | ||
echo "running tests" | ||
if SUITE=./test/validation ./hack/run-e2e-conformance.sh; then | ||
echo "succeeded" | ||
ready=true | ||
else | ||
echo "failed, retrying" | ||
sleep $sleep_time | ||
fi | ||
(( ATTEMPTS++ )) | ||
done | ||
|
||
if ! $ready; then | ||
echo "Timed out waiting for features to be ready" | ||
oc get nodes | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package conformance | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
"github.com/onsi/ginkgo/reporters" | ||
. "github.com/onsi/gomega" | ||
|
||
testclient "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/client" | ||
|
||
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/k8sreporter" | ||
_ "github.com/k8snetworkplumbingwg/sriov-network-operator/test/validation/tests" | ||
) | ||
|
||
var ( | ||
junitPath *string | ||
dumpOutput *bool | ||
) | ||
|
||
func init() { | ||
junitPath = flag.String("junit", "junit.xml", "the path for the junit format report") | ||
dumpOutput = flag.Bool("dump", false, "dump informations for failed tests") | ||
} | ||
|
||
func TestTest(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
|
||
rr := []Reporter{} | ||
if junitPath != nil { | ||
rr = append(rr, reporters.NewJUnitReporter(*junitPath)) | ||
} | ||
|
||
reporterFile := os.Getenv("REPORTER_OUTPUT") | ||
|
||
clients := testclient.New("") | ||
|
||
if reporterFile != "" { | ||
f, err := os.OpenFile(reporterFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to open the file: %v\n", err) | ||
return | ||
} | ||
defer f.Close() | ||
rr = append(rr, k8sreporter.New(clients, f)) | ||
|
||
} else if *dumpOutput { | ||
rr = append(rr, k8sreporter.New(clients, os.Stdout)) | ||
} | ||
|
||
RunSpecsWithDefaultAndCustomReporters(t, "SRIOV Operator validation tests", rr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
goclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" | ||
testclient "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/client" | ||
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster" | ||
) | ||
|
||
var ( | ||
machineConfigPoolNodeSelector string | ||
) | ||
|
||
var ( | ||
clients *testclient.ClientSet | ||
operatorNamespace string | ||
) | ||
|
||
func init() { | ||
operatorNamespace = os.Getenv("OPERATOR_NAMESPACE") | ||
if operatorNamespace == "" { | ||
operatorNamespace = "openshift-sriov-network-operator" | ||
} | ||
|
||
clients = testclient.New("") | ||
} | ||
|
||
const ( | ||
sriovOperatorDeploymentName = "sriov-network-operator" | ||
// SriovNetworkNodePolicies contains the name of the sriov network node policies CRD | ||
sriovNetworkNodePolicies = "sriovnetworknodepolicies.sriovnetwork.openshift.io" | ||
// sriovNetworkNodeStates contains the name of the sriov network node state CRD | ||
sriovNetworkNodeStates = "sriovnetworknodestates.sriovnetwork.openshift.io" | ||
// sriovNetworks contains the name of the sriov network CRD | ||
sriovNetworks = "sriovnetworks.sriovnetwork.openshift.io" | ||
// sriovOperatorConfigs contains the name of the sriov Operator config CRD | ||
sriovOperatorConfigs = "sriovoperatorconfigs.sriovnetwork.openshift.io" | ||
) | ||
|
||
func init() { | ||
roleWorkerCNF := os.Getenv("ROLE_WORKER_CNF") | ||
if roleWorkerCNF == "" { | ||
roleWorkerCNF = "worker-cnf" | ||
} | ||
|
||
machineConfigPoolNodeSelector = fmt.Sprintf("node-role.kubernetes.io/%s", roleWorkerCNF) | ||
} | ||
|
||
var _ = Describe("validation", func() { | ||
|
||
Context("sriov", func() { | ||
It("should have the sriov namespace", func() { | ||
_, err := clients.Namespaces().Get(context.Background(), operatorNamespace, metav1.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should have the sriov operator deployment in running state", func() { | ||
deploy, err := clients.Deployments(operatorNamespace).Get(context.Background(), sriovOperatorDeploymentName, metav1.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(deploy.Status.Replicas).To(Equal(deploy.Status.ReadyReplicas)) | ||
|
||
pods, err := clients.Pods(operatorNamespace).List(context.Background(), metav1.ListOptions{ | ||
LabelSelector: fmt.Sprintf("name=%s", sriovOperatorDeploymentName)}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(len(pods.Items)).To(Equal(1)) | ||
Expect(pods.Items[0].Status.Phase).To(Equal(corev1.PodRunning)) | ||
}) | ||
|
||
It("Should have the sriov CRDs available in the cluster", func() { | ||
crd := &apiext.CustomResourceDefinition{} | ||
err := clients.Client.Get(context.TODO(), goclient.ObjectKey{Name: sriovNetworkNodePolicies}, crd) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = clients.Client.Get(context.TODO(), goclient.ObjectKey{Name: sriovNetworkNodeStates}, crd) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = clients.Client.Get(context.TODO(), goclient.ObjectKey{Name: sriovNetworks}, crd) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = clients.Client.Get(context.TODO(), goclient.ObjectKey{Name: sriovOperatorConfigs}, crd) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should deploy the injector pod if requested", func() { | ||
operatorConfig := &sriovv1.SriovOperatorConfig{} | ||
err := clients.Client.Get(context.TODO(), goclient.ObjectKey{Name: "default", Namespace: operatorNamespace}, operatorConfig) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
if *operatorConfig.Spec.EnableInjector { | ||
daemonset, err := clients.DaemonSets(operatorNamespace).Get(context.Background(), "network-resources-injector", metav1.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(daemonset.Status.DesiredNumberScheduled).To(Equal(daemonset.Status.NumberReady)) | ||
} else { | ||
_, err := clients.DaemonSets(operatorNamespace).Get(context.Background(), "network-resources-injector", metav1.GetOptions{}) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(errors.IsNotFound(err)).To(BeTrue()) | ||
} | ||
}) | ||
|
||
It("should deploy the operator webhook if requested", func() { | ||
operatorConfig := &sriovv1.SriovOperatorConfig{} | ||
err := clients.Get(context.TODO(), goclient.ObjectKey{Name: "default", Namespace: operatorNamespace}, operatorConfig) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
if *operatorConfig.Spec.EnableOperatorWebhook { | ||
daemonset, err := clients.DaemonSets(operatorNamespace).Get(context.Background(), "operator-webhook", metav1.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(daemonset.Status.DesiredNumberScheduled).To(Equal(daemonset.Status.NumberReady)) | ||
} else { | ||
_, err := clients.DaemonSets(operatorNamespace).Get(context.Background(), "operator-webhook", metav1.GetOptions{}) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(errors.IsNotFound(err)).To(BeTrue()) | ||
} | ||
}) | ||
|
||
It("should have SR-IOV node statuses not in progress", func() { | ||
CheckStable() | ||
}) | ||
}) | ||
}) | ||
|
||
func CheckStable() { | ||
res, err := cluster.SriovStable(operatorNamespace, clients) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(res).To(BeTrue(), "SR-IOV status is not stable") | ||
|
||
isClusterReady, err := cluster.IsClusterStable(clients) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(isClusterReady).To(BeFalse(), "Cluster is not stable") | ||
} |