-
Notifications
You must be signed in to change notification settings - Fork 3
test: exclude power state checks from complex test #1841
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,13 @@ package util | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| vmopbuilder "github.com/deckhouse/virtualization-controller/pkg/builder/vmop" | ||
|
|
@@ -100,7 +101,7 @@ func StartVirtualMachine(f *framework.Framework, vm *v1alpha2.VirtualMachine, op | |
| GinkgoHelper() | ||
|
|
||
| opts := []vmopbuilder.Option{ | ||
| vmopbuilder.WithGenerateName("vmop-e2e-"), | ||
| vmopbuilder.WithGenerateName("vmop-start-"), | ||
| vmopbuilder.WithNamespace(vm.Namespace), | ||
| vmopbuilder.WithType(v1alpha2.VMOPTypeStart), | ||
| vmopbuilder.WithVirtualMachine(vm.Name), | ||
|
|
@@ -112,19 +113,24 @@ func StartVirtualMachine(f *framework.Framework, vm *v1alpha2.VirtualMachine, op | |
| Expect(err).NotTo(HaveOccurred()) | ||
| } | ||
|
|
||
| func StopVirtualMachineFromOS(f *framework.Framework, vm *v1alpha2.VirtualMachine) error { | ||
| _, err := f.SSHCommand(vm.Name, vm.Namespace, "sudo init 0") | ||
| if err != nil && strings.Contains(err.Error(), "unexpected EOF") { | ||
| return nil | ||
| } | ||
| return err | ||
| func StopVirtualMachineFromOS(f *framework.Framework, vm *v1alpha2.VirtualMachine) { | ||
| GinkgoHelper() | ||
|
|
||
| _, err := f.SSHCommand(vm.Name, vm.Namespace, "nohup sh -c \"sleep 5 && sudo init 0\" > /dev/null 2>&1 &") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the solution does not work on Alpine OS. If this is a common solution, it should work on other operating systems. |
||
| Expect(err).To(SatisfyAny( | ||
| Not(HaveOccurred()), | ||
| MatchError(MatchError(ContainSubstring("unexpected EOF"))), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this error expected here? |
||
| )) | ||
| } | ||
|
|
||
| func RebootVirtualMachineBySSH(f *framework.Framework, vm *v1alpha2.VirtualMachine) { | ||
| GinkgoHelper() | ||
|
|
||
| _, err := f.SSHCommand(vm.Name, vm.Namespace, "sudo reboot") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| _, err := f.SSHCommand(vm.Name, vm.Namespace, "nohup sh -c \"sleep 5 && sudo reboot\" > /dev/null 2>&1 &") | ||
| Expect(err).To(SatisfyAny( | ||
| Not(HaveOccurred()), | ||
| MatchError(MatchError(ContainSubstring("unexpected EOF"))), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this error expected here? |
||
| )) | ||
| } | ||
|
|
||
| func RebootVirtualMachineByVMOP(f *framework.Framework, vm *v1alpha2.VirtualMachine) { | ||
|
|
@@ -140,7 +146,25 @@ func RebootVirtualMachineByVMOP(f *framework.Framework, vm *v1alpha2.VirtualMach | |
| Expect(err).NotTo(HaveOccurred()) | ||
| } | ||
|
|
||
| func RebootVirtualMachineByPodDeletion(f *framework.Framework, vm *v1alpha2.VirtualMachine) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it work with length and indexes, instead of an active pod? |
||
| GinkgoHelper() | ||
|
|
||
| Expect(vm.Status.VirtualMachinePods).To(HaveLen(1)) | ||
|
|
||
| var pod corev1.Pod | ||
| err := framework.GetClients().GenericClient().Get(context.Background(), types.NamespacedName{ | ||
| Namespace: vm.Namespace, | ||
| Name: vm.Status.VirtualMachinePods[0].Name, | ||
| }, &pod) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| err = framework.GetClients().GenericClient().Delete(context.Background(), &pod) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| } | ||
|
|
||
| func UntilVirtualMachineRebooted(key client.ObjectKey, previousRunningTime time.Time, timeout time.Duration) { | ||
| GinkgoHelper() | ||
|
|
||
| Eventually(func() error { | ||
| vm := &v1alpha2.VirtualMachine{} | ||
| err := framework.GetClients().GenericClient().Get(context.Background(), key, vm) | ||
|
|
||
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.
It should be in the same style as
reboot, with a prefix. You can create the prefix constants in one place.