Skip to content

Commit

Permalink
Move extra VDDK arguments functional test.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mrnold committed Jan 7, 2025
1 parent 0fe6322 commit 49cd30f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 51 deletions.
43 changes: 0 additions & 43 deletions tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,25 +1184,6 @@ var _ = Describe("[vendor:[email protected]][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, "")
Expand Down Expand Up @@ -1273,30 +1254,6 @@ var _ = Describe("[vendor:[email protected]][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
Expand Down
32 changes: 32 additions & 0 deletions tests/framework/vddk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions tests/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,63 @@ var _ = Describe("[rfe_id:1115][crit:high][vendor:[email protected]][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() {
Expand Down
11 changes: 3 additions & 8 deletions tools/vddk-test/vddk-test-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 49cd30f

Please sign in to comment.