From 49cd30f08eccafc153d3ec0db8d8ac7822c79f1b Mon Sep 17 00:00:00 2001 From: Matthew Arnold Date: Tue, 7 Jan 2025 16:59:02 -0500 Subject: [PATCH] Move extra VDDK arguments functional test. Put this in import_test and assert the values there, instead of in the VDDK test plugin. The VDDK plugin logs the given values, and then the test scans the log for what it expects to see. Signed-off-by: Matthew Arnold --- tests/datavolume_test.go | 43 ---------------------- tests/framework/vddk.go | 32 +++++++++++++++++ tests/import_test.go | 57 ++++++++++++++++++++++++++++++ tools/vddk-test/vddk-test-plugin.c | 11 ++---- 4 files changed, 92 insertions(+), 51 deletions(-) diff --git a/tests/datavolume_test.go b/tests/datavolume_test.go index a0fa34d5ee..0af8362fde 100644 --- a/tests/datavolume_test.go +++ b/tests/datavolume_test.go @@ -1184,25 +1184,6 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests", return dv } - createVddkDataVolumeWithExtraArgs := func(dataVolumeName, size, url string) *cdiv1.DataVolume { - dv := createVddkDataVolumeWithInitImageURL(dataVolumeName, size, url) - extraArguments := v1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: f.Namespace.Name, - Name: "vddk-extra-args-map", - }, - Data: map[string]string{ // Must match vddk-test-plugin - common.VddkArgsKeyName: "VixDiskLib.nfcAio.Session.BufSizeIn64KB=16", - }, - } - _, err := f.K8sClient.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), &extraArguments, metav1.CreateOptions{}) - if !k8serrors.IsAlreadyExists(err) { - Expect(err).ToNot(HaveOccurred()) - } - controller.AddAnnotation(dv, controller.AnnVddkExtraArgs, extraArguments.Name) - return dv - } - // Similar to previous table, but with additional cleanup steps to save and restore VDDK image config map DescribeTable("should", Serial, func(args dataVolumeTestArguments) { _, err := utils.CopyConfigMap(f.K8sClient, f.CdiInstallNs, common.VddkConfigMap, f.CdiInstallNs, savedVddkConfigMap, "") @@ -1273,30 +1254,6 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests", Message: "Import Complete", Reason: "Completed", }}), - Entry("[test_id:5083]succeed importing VDDK data volume with extra arguments ConfigMap set", dataVolumeTestArguments{ - name: "dv-import-vddk", - size: "1Gi", - url: vcenterURL, - dvFunc: createVddkDataVolumeWithExtraArgs, - eventReason: dvc.ImportSucceeded, - phase: cdiv1.Succeeded, - checkPermissions: false, - readyCondition: &cdiv1.DataVolumeCondition{ - Type: cdiv1.DataVolumeReady, - Status: v1.ConditionTrue, - }, - boundCondition: &cdiv1.DataVolumeCondition{ - Type: cdiv1.DataVolumeBound, - Status: v1.ConditionTrue, - Message: "PVC dv-import-vddk Bound", - Reason: "Bound", - }, - runningCondition: &cdiv1.DataVolumeCondition{ - Type: cdiv1.DataVolumeRunning, - Status: v1.ConditionFalse, - Message: "Import Complete", - Reason: "Completed", - }}), ) // similar to other tables but with check of quota diff --git a/tests/framework/vddk.go b/tests/framework/vddk.go index b752271a5e..2f9e873e12 100644 --- a/tests/framework/vddk.go +++ b/tests/framework/vddk.go @@ -12,6 +12,38 @@ import ( "kubevirt.io/containerized-data-importer/tests/utils" ) +// CreateVddkDataVolume returns a VDDK data volume +func (f *Framework) CreateVddkDataVolume(dataVolumeName, size, url string) *cdiv1.DataVolume { + // Find vcenter-simulator pod + pod, err := utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, "vcenter-deployment", "app=vcenter") + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(pod).ToNot(gomega.BeNil()) + + // Get test VM UUID + id, err := f.RunKubectlCommand("exec", "-n", pod.Namespace, pod.Name, "--", "cat", "/tmp/vmid") + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + vmid, err := uuid.Parse(strings.TrimSpace(id)) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + + // Get disk name + disk, err := f.RunKubectlCommand("exec", "-n", pod.Namespace, pod.Name, "--", "cat", "/tmp/vmdisk") + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + disk = strings.TrimSpace(disk) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + + // Create VDDK login secret + stringData := map[string]string{ + common.KeyAccess: "user", + common.KeySecret: "pass", + } + backingFile := disk + secretRef := "vddksecret" + thumbprint := "testprint" + s, _ := utils.CreateSecretFromDefinition(f.K8sClient, utils.NewSecretDefinition(nil, stringData, nil, f.Namespace.Name, secretRef)) + + return utils.NewDataVolumeWithVddkImport(dataVolumeName, size, backingFile, s.Name, thumbprint, url, vmid.String()) +} + // CreateVddkWarmImportDataVolume fetches snapshot information from vcsim and returns a multi-stage VDDK data volume func (f *Framework) CreateVddkWarmImportDataVolume(dataVolumeName, size, url string) *cdiv1.DataVolume { // Find vcenter-simulator pod diff --git a/tests/import_test.go b/tests/import_test.go index b13a74ba23..8b6e4d0215 100644 --- a/tests/import_test.go +++ b/tests/import_test.go @@ -189,6 +189,63 @@ var _ = Describe("[rfe_id:1115][crit:high][vendor:cnv-qe@redhat.com][level:compo Expect(importer.DeletionTimestamp).To(BeNil()) } }) + + It("[test_id:6689]succeed importing VDDK data volume with extra arguments ConfigMap set", Label("VDDK"), func() { + vddkConfigOptions := []string{ + "VixDiskLib.nfcAio.Session.BufSizeIn64KB=16", + "vixDiskLib.nfcAio.Session.BufCount=4", + } + + vddkConfigMap := &v1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "vddk-extras", + }, + Data: map[string]string{ + common.VddkArgsKeyName: strings.Join(vddkConfigOptions, "\n"), + }, + } + + _, err := f.K8sClient.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), vddkConfigMap, metav1.CreateOptions{}) + if !k8serrors.IsAlreadyExists(err) { + Expect(err).ToNot(HaveOccurred()) + } + + vcenterURL := fmt.Sprintf(utils.VcenterURL, f.CdiInstallNs) + dataVolume := f.CreateVddkDataVolume("import-pod-vddk-config-test", "100Mi", vcenterURL) + + By(fmt.Sprintf("Create new DataVolume %s", dataVolume.Name)) + controller.AddAnnotation(dataVolume, controller.AnnPodRetainAfterCompletion, "true") + controller.AddAnnotation(dataVolume, controller.AnnVddkExtraArgs, "vddk-extras") + dataVolume, err = utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, dataVolume) + Expect(err).ToNot(HaveOccurred()) + + By("Verify PVC was created") + pvc, err := utils.WaitForPVC(f.K8sClient, dataVolume.Namespace, dataVolume.Name) + Expect(err).ToNot(HaveOccurred()) + f.ForceBindIfWaitForFirstConsumer(pvc) + + By("Wait for import to be completed") + err = utils.WaitForDataVolumePhase(f, dataVolume.Namespace, cdiv1.Succeeded, dataVolume.Name) + Expect(err).ToNot(HaveOccurred(), "DataVolume not in phase succeeded in time") + + By("Find importer pods after completion") + pvcName := dataVolume.Name + // When using populators, the PVC Prime name is used to build the importer pod + if usePopulator, _ := dvc.CheckPVCUsingPopulators(pvc); usePopulator { + pvcName = populators.PVCPrimeName(pvc) + } + By("Find importer pod " + pvcName) + importer, err := utils.FindPodByPrefixOnce(f.K8sClient, dataVolume.Namespace, common.ImporterPodName, common.CDILabelSelector) + Expect(err).ToNot(HaveOccurred()) + Expect(importer.DeletionTimestamp).To(BeNil()) + + logs, err := f.RunKubectlCommand("logs", "-n", dataVolume.Namespace, importer.Name) + Expect(err).To(BeNil()) + for _, option := range vddkConfigOptions { + By(fmt.Sprintf("Check for configuration value %s in nbdkit logs", option)) + Expect(strings.Contains(logs, option)).To(BeTrue()) + } + }) }) var _ = Describe("[Istio] Namespace sidecar injection", Serial, func() { diff --git a/tools/vddk-test/vddk-test-plugin.c b/tools/vddk-test/vddk-test-plugin.c index 7967c2d50d..c0ccf788f3 100644 --- a/tools/vddk-test/vddk-test-plugin.c +++ b/tools/vddk-test/vddk-test-plugin.c @@ -42,14 +42,9 @@ int fakevddk_config(const char *key, const char *value) { nbdkit_error("Failed to open VDDK extra configuration file %s!\n", value); return -1; } - char extras[50]; - if (fgets(extras, 50, f) == NULL) { // Expect only one line of test data - nbdkit_error("Failed to read VDDK extra configuration file %s! Error was: %s", value, strerror(errno)); - return -1; - } - if (strcmp(extras, "VixDiskLib.nfcAio.Session.BufSizeIn64KB=16") != 0) { // Must match datavolume_test - nbdkit_error("Unexpected content in VDDK extra configuration file %s: %s\n", value, extras); - return -1; + char extras[512]; // Importer test will scan debug log for given values, just pass them back + while (fgets(extras, 512, f) != NULL) { + nbdkit_debug("Extra configuration data: %s\n", extras); } fclose(f); }