diff --git a/tests/cnf/ran/ztp/internal/tsparams/ztpvars.go b/tests/cnf/ran/ztp/internal/tsparams/ztpvars.go index 55679faac..3f4599b25 100644 --- a/tests/cnf/ran/ztp/internal/tsparams/ztpvars.go +++ b/tests/cnf/ran/ztp/internal/tsparams/ztpvars.go @@ -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. @@ -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. diff --git a/tests/cnf/ran/ztp/tests/ztp-argocd-hub-templating.go b/tests/cnf/ran/ztp/tests/ztp-argocd-hub-templating.go index c13ca44d6..edc84f968 100644 --- a/tests/cnf/ran/ztp/tests/ztp-argocd-hub-templating.go +++ b/tests/cnf/ran/ztp/tests/ztp-argocd-hub-templating.go @@ -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") diff --git a/tests/cnf/ran/ztp/tests/ztp-argocd-policies-app.go b/tests/cnf/ran/ztp/tests/ztp-argocd-policies-app.go index d68ef5637..208ec47d4 100644 --- a/tests/cnf/ran/ztp/tests/ztp-argocd-policies-app.go +++ b/tests/cnf/ran/ztp/tests/ztp-argocd-policies-app.go @@ -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") @@ -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( diff --git a/tests/cnf/ran/ztp/ztp_suite_test.go b/tests/cnf/ran/ztp/ztp_suite_test.go index 1c865a645..d48655c80 100644 --- a/tests/cnf/ran/ztp/ztp_suite_test.go +++ b/tests/cnf/ran/ztp/ztp_suite_test.go @@ -1,6 +1,8 @@ package ztp import ( + "fmt" + "path" "runtime" "testing" "time" @@ -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) {