vm-import-controller/tests/integration/common_test.go
Volker Theile 29629c75f8
Enhance importer to handle several issue (#42)
- Import OpenStack server by UUID
- Import OpenStack server with upper case characters in its name

The following improvements have been done:
- Sanitize the configured `VirtualMachineName` field, e.g. convert upper case to lower case to make it RFC 1123 compliant.
- Convert UUID to real name for OpenStack imports
- Reduce waiting time to recheck if created VM is running from 5min to 2min
- Rename variable `uuid` to `serverUUID` in the OpenStack client code to do not collide with the imported uuid module
- Improve error and log messages
- Fix typos
- Add comments

Related to: https://github.com/harvester/harvester/issues/6500
Related to: https://github.com/harvester/harvester/issues/6505

Signed-off-by: Volker Theile <vtheile@suse.com>
2025-02-04 07:42:42 +01:00

100 lines
2.5 KiB
Go

package integration
import (
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
migration "github.com/harvester/vm-import-controller/pkg/apis/migration.harvesterhci.io/v1beta1"
)
var _ = Describe("perform valid dns names", func() {
var creds *corev1.Secret
var vcsim *migration.VmwareSource
var vm *migration.VirtualMachineImport
BeforeEach(func() {
creds = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "vcsim-creds",
Namespace: "default",
},
StringData: map[string]string{
"username": "user",
"password": "pass",
},
}
vcsim = &migration.VmwareSource{
ObjectMeta: metav1.ObjectMeta{
Name: "local-vm-validation",
Namespace: "default",
},
Spec: migration.VmwareSourceSpec{
EndpointAddress: "",
Datacenter: "DC0",
Credentials: corev1.SecretReference{
Name: creds.Name,
Namespace: creds.Namespace,
},
},
}
vm = &migration.VirtualMachineImport{
ObjectMeta: metav1.ObjectMeta{
Name: "vm-validation",
Namespace: "default",
},
Spec: migration.VirtualMachineImportSpec{
SourceCluster: corev1.ObjectReference{
Name: vcsim.Name,
Namespace: vcsim.Namespace,
Kind: vcsim.Kind,
APIVersion: vcsim.APIVersion,
},
VirtualMachineName: "someRandomName",
Folder: "",
},
}
err := k8sClient.Create(ctx, creds)
Expect(err).ToNot(HaveOccurred())
vcsim.Spec.EndpointAddress = fmt.Sprintf("https://localhost:%s/sdk", vcsimPort)
err = k8sClient.Create(ctx, vcsim)
Expect(err).ToNot(HaveOccurred())
err = k8sClient.Create(ctx, vm)
Expect(err).ToNot(HaveOccurred())
})
It("check virtualmachine import has failed", func() {
By("checking state of VM Import", func() {
Eventually(func() error {
vmObj := &migration.VirtualMachineImport{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: vm.Name,
Namespace: vm.Namespace}, vmObj)
if err != nil {
return err
}
if vmObj.Status.Status == migration.VirtualMachineImportInvalid {
return nil
}
return fmt.Errorf("waiting for vm obj to be marked invalid")
}, "30s", "5s").ShouldNot(HaveOccurred())
})
})
AfterEach(func() {
err := k8sClient.Delete(ctx, creds)
Expect(err).ToNot(HaveOccurred())
err = k8sClient.Delete(ctx, vcsim)
Expect(err).ToNot(HaveOccurred())
err = k8sClient.Delete(ctx, vm)
Expect(err).ToNot(HaveOccurred())
})
})