Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/e2e/internal/object/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
ImageURLUbuntu = "https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/ubuntu/ubuntu-24.04-minimal-cloudimg-amd64.qcow2"
ImageURLAlpineBIOS = "https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/alpine/alpine-3-21-bios-base.qcow2"
ImageURLContainerImage = "cr.yandex/crpvs5j3nh1mi2tpithr/e2e/alpine/alpine-image:latest"
ImageURLMinimalQCOW = "https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/test/test.qcow2"
ImageURLMinimalISO = "https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/test/test.iso"
Mi256 = 256 * 1024 * 1024
DefaultVMClass = "generic"
DefaultCloudInit = `#cloud-config
Expand Down
44 changes: 34 additions & 10 deletions test/e2e/internal/util/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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-"),
Copy link
Contributor

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.

vmopbuilder.WithNamespace(vm.Namespace),
vmopbuilder.WithType(v1alpha2.VMOPTypeStart),
vmopbuilder.WithVirtualMachine(vm.Name),
Expand All @@ -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 &")
Copy link
Contributor

Choose a reason for hiding this comment

The 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"))),
Copy link
Contributor

Choose a reason for hiding this comment

The 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"))),
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Expand All @@ -140,7 +146,25 @@ func RebootVirtualMachineByVMOP(f *framework.Framework, vm *v1alpha2.VirtualMach
Expect(err).NotTo(HaveOccurred())
}

func RebootVirtualMachineByPodDeletion(f *framework.Framework, vm *v1alpha2.VirtualMachine) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Expand Down
Loading
Loading