-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
refactor: Replace deprecated NewRandomVirtualMachine* functions by using libvmi directly #11621
base: main
Are you sure you want to change the base?
Conversation
Hi @TheRealSibasishBehera. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
tests/migration/migration.go
Outdated
@@ -1017,7 +1017,36 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() { | |||
Expect(err.Error()).To(ContainSubstring("DisksNotLiveMigratable")) | |||
}) | |||
It("[test_id:1479][storage-req] should migrate a vmi with a shared block disk", decorators.StorageReq, func() { | |||
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany) | |||
if !libstorage.HasCDI() { | |||
Skip("Skip DataVolume tests when CDI is not present") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR. We should work hard to eliminate the catch-all tests/utils file.
These Skip
s were here before your PR, but now they are more spread out. Skip
should not be used in tests, because they may cause us to ignore a test silently and unintentionally. Besides, I bet (but not sure) that the [storage-req]
label means that these tests are executed only when storage requirements (CDI, block storage) are available. Please avoid them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense , i will change that
tests/migration/migration.go
Outdated
|
||
dataVolume, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
libstorage.EventuallyDV(dataVolume, 240, Or(HaveSucceeded(), WaitForFirstConsumer())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that waiting for the DV here is necessary or helpful.
tests/migration/migration.go
Outdated
@@ -1077,7 +1106,37 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() { | |||
|
|||
It("[test_id:1854]should migrate a VMI with shared and non-shared disks", func() { | |||
// Start the VirtualMachineInstance with PVC and Ephemeral Disks | |||
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany) | |||
if !libstorage.HasCDI() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/migration/migration.go is already too long. I would prefer it that you define a private function such as vmi, err := newAlpineWithDV()
and reuse it in this file.
/sig code-quality |
tests/migration/migration.go
Outdated
@@ -1017,7 +1017,36 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() { | |||
Expect(err.Error()).To(ContainSubstring("DisksNotLiveMigratable")) | |||
}) | |||
It("[test_id:1479][storage-req] should migrate a vmi with a shared block disk", decorators.StorageReq, func() { | |||
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany) | |||
if !libstorage.HasCDI() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheRealSibasishBehera you can refer to the document that Felix is writing as part of #11456 . It is still in progress but there is some guidelines to avoid Skip
and use the decorators.
Hence you should assume that the feature and components are there and failing as consequence. Hence, this becomes:
Expect(libstorage.HasCDI()).To(BeTrue())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes ,i will make the changes . Thanks
tests/migration/migration.go
Outdated
Skip("Skip DataVolume tests when CDI is not present") | ||
} | ||
sc, exists := libstorage.GetRWXBlockStorageClass() | ||
if !exists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with the skip
@TheRealSibasishBehera I think we need to create another function that wraps all those code duplications. You could create a new template in the factory.go. func NewAlpineWithDataVolume(sc string, accessMode k8sv1.AccessMode, opts ...libvmi.Option) *kvirtv1.VirtualMachineInstance {} You can also include there the CDI and storage class checks and the dv creation there. In this way you can call the function with different option libvmifact.NewAlpineWithDataVolume(
sc, k8sv1.ReadWriteMany,
libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
....
) |
…libvmi equivalents Signed-off-by: TheRealSibasishBehera <fangedhamster3114@gmail.com>
a589256
to
290772a
Compare
cd "kubevirt.io/kubevirt/tests/containerdisk" | ||
"kubevirt.io/kubevirt/tests/framework/kubevirt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this PR adds a lot of dependencies to this file. Must the new functions be introduced here? Did you consider keeping them closer to their callers?
I think that @akalenyu is working on a similar thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. However, different approach #11670
I believe the DV should be fully passed in, and we could expose certain presets from libdv if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @alicefr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akalenyu we can, it is just more repetition of the dv specifications, but I guess we want to avoid too many variation of the functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akalenyu we can, it is just more repetition of the dv specifications, but I guess we want to avoid too many variation of the functions
From my investigation a "one-fits-all" DV would also not work unfortunately,
but yes, I definitely agree we should settle on one of them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheRealSibasishBehera do you mind passing an entire DV as part of the function NewAlpineWithDataVolume
and adjust the function calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alicefr would you prefer I handle this in my other PR so this PR doesn't have to diverge much?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akalenyu mh maybe it is better. However, this function should also be called outside the storage code, see the changes of this PR in migration.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'll move it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akalenyu mh maybe it is better. However, this function should also be called outside the storage code, see the changes of this PR in migration.go
yeah @alicefr i agree on that part , this function would be called outside storage so it better to keep it in libvmifact .
an alternative can be keeping it in something like libvmifact/storage.go which will have functions involving storage related operations
|
||
func getVolumeModeForAccessMode(accessMode k8sv1.PersistentVolumeAccessMode) k8sv1.PersistentVolumeMode { | ||
if accessMode == k8sv1.ReadWriteMany { | ||
return k8sv1.PersistentVolumeBlock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that ReadWriteMany
implies PersistentVolumeBlock
only in specific tests or a specific test framework. I think it would be better if the DV requests exactly what it wants to get,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah those two are not coupled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will change that
@@ -1017,7 +1017,11 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() { | |||
Expect(err.Error()).To(ContainSubstring("DisksNotLiveMigratable")) | |||
}) | |||
It("[test_id:1479][storage-req] should migrate a vmi with a shared block disk", decorators.StorageReq, func() { | |||
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany) | |||
Expect(libstorage.HasCDI()).To(BeTrue()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a trailing reason string, so that if this fails, we'd see a clear failure reason?
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@TheRealSibasishBehera thank you so much for contributing, this is great! |
Hey this will need to be rebase and changed a bit because of #11624 |
Yes , I plan to complete this . |
Thanks @RoniKishner I will change that |
Right so the whole approach of having this type of factory is being challenged, |
Before this PR: The codebase was using deprecated
NewRandomVirtualMachineInstanceWithBlockDisk
,NewRandomVirtualMachineInstanceWithFileDisk
, andNewRandomVirtualMachineInstanceWithDisk
functions for testing purposes.After this PR: Replaced all occurrences of deprecated
NewRandomVirtualMachine*
functions with equivalent functions from thelibvmi
library.Fixes #11565
Why we need it and why it was done in this way
The
NewRandomVirtualMachine*
functions were deprecated and needed to be replaced to ensure compatibility with future releases. This PR updates the codebase to use the recommendedlibvmi
functions for improved maintainability.The following tradeoffs were made:
The following alternatives were considered:
Links to places where the discussion took place:
Special notes for your reviewer
Checklist
This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.
Release note