Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test that ran du cluste has compliant policies #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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, ",")),
)
},
)
},
)
Loading