Skip to content

Commit

Permalink
Add test that ran du cluste has compliant policies
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Feb 2, 2024
1 parent 01c784b commit d3e41e3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/ran-du/internal/randuparams/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ const (
DefaultTimeout = 300 * time.Second
// TestWorkloadShellLaunchMethod is used when usin a shell script for launching the test workload.
TestWorkloadShellLaunchMethod = "shell"
// DU Hosts kubeconfig env var.

Check failure on line 16 in tests/ran-du/internal/randuparams/const.go

View workflow job for this annotation

GitHub Actions / build

exported: comment on exported const KubeEnvKey should be of the form "KubeEnvKey ..." (revive)
KubeEnvKey string = "KUBECONFIG"
)
56 changes: 56 additions & 0 deletions tests/ran-du/tests/ztp-du-policies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ran_du_system_test

import (
"fmt"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift-kni/eco-goinfra/pkg/ocm"
"github.com/openshift-kni/eco-goinfra/pkg/polarion"
"github.com/openshift-kni/eco-gosystem/tests/internal/cluster"
. "github.com/openshift-kni/eco-gosystem/tests/ran-du/internal/randuinittools"
"github.com/openshift-kni/eco-gosystem/tests/ran-du/internal/randuparams"
policiesv1 "open-cluster-management.io/governance-policy-propagator/api/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ = Describe(
"ZTPPoliciesCompliance",
Label("ZTPPoliciesCompliance"),
Ordered,
func() {
var (
clusterName string
err error
)
BeforeAll(func() {
By("Fetching Cluster name")
clusterName, err = cluster.GetClusterName(randuparams.KubeEnvKey)
Expect(err).ToNot(HaveOccurred(), "Failed to get cluster name")
})

It("All policies compliant", polarion.ID("OCP-48465"),
func() {
By("Retrieve policy list")
policies, err := ocm.ListPoliciesInAllNamespaces(
APIClient,
client.ListOptions{Namespace: clusterName},
)
Expect(err).NotTo(HaveOccurred(), "Failed to get policy list")

By("Checking for NonCompliant policies")
nonCompliantPolicies := make([]string, 0)
for _, policy := range policies {
if policy.Definition.Status.ComplianceState == policiesv1.NonCompliant {
nonCompliantPolicies = append(nonCompliantPolicies, policy.Definition.Name)
}
}
Expect(nonCompliantPolicies).To(
BeEmpty(),
fmt.Sprintf("NonCompliant policies found: %s", strings.Join(nonCompliantPolicies, ",")),
)
},
)
},
)

0 comments on commit d3e41e3

Please sign in to comment.