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

cnf ran: ztp reporting and improvements #119

Merged
merged 1 commit into from
Jul 25, 2024
Merged
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
43 changes: 39 additions & 4 deletions tests/cnf/ran/ztp/internal/tsparams/ztpvars.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package tsparams

import (
argocdoperatorv1alpha1 "github.com/argoproj-labs/argocd-operator/api/v1alpha1"
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
cguv1alpha1 "github.com/openshift-kni/cluster-group-upgrades-operator/pkg/api/clustergroupupgrades/v1alpha1"
. "github.com/openshift-kni/eco-gotests/tests/cnf/ran/internal/raninittools"
"github.com/openshift-kni/eco-gotests/tests/cnf/ran/internal/ranparam"
"github.com/openshift-kni/k8sreporter"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/utils/ptr"
policiesv1 "open-cluster-management.io/governance-policy-propagator/api/v1"
placementrulev1 "open-cluster-management.io/multicloud-operators-subscription/pkg/apis/apps/placementrule/v1"
)

// ArgoCdGitDetails is the details for a single app in ArgoCD.
Expand All @@ -17,13 +25,40 @@ var (
// Labels represents the range of labels that can be used for test cases selection.
Labels = append(ranparam.Labels, LabelSuite)

// ReporterNamespacesToDump tells to the reporter from where to collect logs.
ReporterNamespacesToDump = map[string]string{
// ReporterHubNamespacesToDump tells to the reporter which namespaces on the hub to collect pod logs from.
ReporterHubNamespacesToDump = map[string]string{
TestNamespace: "",
ranparam.OpenshiftOperatorNamespace: "",
}

// ReporterSpokeNamespacesToDump tells the reporter which namespaces on the spokes to collect pod logs from.
ReporterSpokeNamespacesToDump = map[string]string{
TestNamespace: "",
}
// ReporterCRDsToDump tells to the reporter what CRs to dump.
ReporterCRDsToDump = []k8sreporter.CRData{

// ReporterHubCRsToDump is the CRs the reporter should dump on the hub.
ReporterHubCRsToDump = []k8sreporter.CRData{
{Cr: &corev1.NamespaceList{}},
{Cr: &corev1.PodList{}},
{Cr: &policiesv1.PolicyList{}},
{Cr: &placementrulev1.PlacementRuleList{}, Namespace: ptr.To(TestNamespace)},
{Cr: &cguv1alpha1.ClusterGroupUpgradeList{}},
{Cr: &corev1.ConfigMapList{}, Namespace: ptr.To(TestNamespace)},
{Cr: &corev1.SecretList{}, Namespace: ptr.To(TestNamespace)},
{Cr: &argocdoperatorv1alpha1.ArgoCDList{}},
}

// ReporterSpokeCRsToDump is the CRs the reporter should dump on the spokes.
ReporterSpokeCRsToDump = []k8sreporter.CRData{
{Cr: &corev1.NamespaceList{}},
{Cr: &corev1.PodList{}},
{Cr: &policiesv1.PolicyList{}},
{Cr: &corev1.PersistentVolumeList{}},
{Cr: &corev1.PersistentVolumeClaimList{}, Namespace: ptr.To(ImageRegistryNamespace)},
{Cr: &storagev1.StorageClassList{}},
{Cr: &corev1.ServiceAccountList{}, Namespace: ptr.To(CustomSourceTestNamespace)},
{Cr: &sriovv1.SriovNetworkList{}, Namespace: ptr.To(RANConfig.SriovOperatorNamespace)},
{Cr: &sriovv1.SriovNetworkList{}, Namespace: ptr.To(TestNamespace)},
}

// ArgoCdApps is the slice of the Argo CD app names defined in this package.
Expand Down
4 changes: 3 additions & 1 deletion tests/cnf/ran/ztp/tests/ztp-argocd-hub-templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ func assertTalmPodLog(client *clients.Settings, expectedSubstring string) {
var podLog string

for _, podBuilder := range podList {
if strings.HasPrefix(podBuilder.Definition.GetName(), tsparams.TalmHubPodName) {
if strings.HasPrefix(podBuilder.Object.Name, tsparams.TalmHubPodName) {
glog.V(tsparams.LogLevel).Infof("Checking logs for pod %s", podBuilder.Object.Name)

podLog, err = podBuilder.GetLog(1*time.Minute, ranparam.TalmContainerName)
Expect(err).ToNot(HaveOccurred(), "Failed to get TALM pod log")

Expand Down
29 changes: 14 additions & 15 deletions tests/cnf/ran/ztp/tests/ztp-argocd-policies-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,17 @@ var _ = Describe("ZTP Argo CD Policies Tests", Label(tsparams.LabelArgoCdPolicie
When("an image registry is configured on the DU profile", func() {
var imageRegistryConfig *imageregistry.Builder

BeforeEach(func() {
// This test requires that the spoke be configured with the ImageRegistry capability enabled in
// the ClusterVersion as a precondition. It will fail without that capability enabled.
By("checking if the image registry directory is present on spoke 1")
_, err := cluster.ExecCommandOnSNO(Spoke1APIClient, 3, fmt.Sprintf("ls %s", tsparams.ImageRegistryPath))
Expect(err).ToNot(HaveOccurred(), "Image registry directory '%s' does not exist", tsparams.ImageRegistryPath)

imageRegistryConfig, err = imageregistry.Pull(Spoke1APIClient, tsparams.ImageRegistryName)
Expect(err).ToNot(HaveOccurred(), "Failed to pull image registry config")
})

AfterEach(func() {
if imageRegistryConfig == nil {
return
}

// Reset the policies app before doing later restore actions so that they're not affected.
By("resetting the policies app to the original settings")
err := helper.SetGitDetailsInArgoCd(
tsparams.ArgoCdPoliciesAppName, tsparams.ArgoCdAppDetails[tsparams.ArgoCdPoliciesAppName], true, false)
Expect(err).ToNot(HaveOccurred(), "Failed to reset policies app git details")

if imageRegistryConfig == nil {
return
}

By("restoring the image registry configs")
err = helper.RestoreImageRegistry(Spoke1APIClient, tsparams.ImageRegistryName, imageRegistryConfig)
Expect(err).ToNot(HaveOccurred(), "Failed to restore image registry config")
Expand All @@ -150,6 +139,16 @@ var _ = Describe("ZTP Argo CD Policies Tests", Label(tsparams.LabelArgoCdPolicie

Expect(err).ToNot(HaveOccurred(), "Failed to update Argo CD git path")

// This test requires that the spoke be configured with the ImageRegistry capability enabled in
// the ClusterVersion as a precondition. If the ZTP test path exists but the capability is not
// enabled, this test will fail.
By("checking if the image registry directory is present on spoke 1")
_, err = cluster.ExecCommandOnSNO(Spoke1APIClient, 3, fmt.Sprintf("ls %s", tsparams.ImageRegistryPath))
Expect(err).ToNot(HaveOccurred(), "Image registry directory '%s' does not exist", tsparams.ImageRegistryPath)

imageRegistryConfig, err = imageregistry.Pull(Spoke1APIClient, tsparams.ImageRegistryName)
Expect(err).ToNot(HaveOccurred(), "Failed to pull image registry config")

By("waiting for the policies to exist and be compliant")
for _, policyName := range tsparams.ImageRegistryPolicies {
policy, err := helper.WaitForPolicyToExist(
Expand Down
22 changes: 20 additions & 2 deletions tests/cnf/ran/ztp/ztp_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ztp

import (
"fmt"
"path"
"runtime"
"testing"
"time"
Expand Down Expand Up @@ -50,9 +52,25 @@ var _ = AfterSuite(func() {
Expect(err).ToNot(HaveOccurred(), "Failed to delete ZTP test namespace")
})

var _ = ReportAfterEach(func(report SpecReport) {
var _ = JustAfterEach(func() {
var (
currentDir, currentFilename = path.Split(currentFile)
hubReportPath = fmt.Sprintf("%shub_%s", currentDir, currentFilename)
report = CurrentSpecReport()
)

reporter.ReportIfFailed(
report, currentFile, tsparams.ReporterNamespacesToDump, tsparams.ReporterCRDsToDump, clients.SetScheme)
report, currentFile, tsparams.ReporterSpokeNamespacesToDump, tsparams.ReporterSpokeCRsToDump, clients.SetScheme)

if HubAPIClient != nil {
reporter.ReportIfFailedOnCluster(
RANConfig.HubKubeconfig,
report,
hubReportPath,
tsparams.ReporterHubNamespacesToDump,
tsparams.ReporterHubCRsToDump,
clients.SetScheme)
}
})

var _ = ReportAfterSuite("", func(report Report) {
Expand Down
Loading