Skip to content
Merged
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: 0 additions & 2 deletions test/e2e/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ clusterTransport:
helperImages:
curlImage: "curlimages/curl"
testData:
affinityToleration: "/tmp/testdata/affinity-toleration"
complexTest: "/tmp/testdata/complex-test"
diskResizing: "/tmp/testdata/disk-resizing"
imageHotplug: "/tmp/testdata/image-hotplug"
Expand All @@ -20,7 +19,6 @@ testData:
vmMigration: "/tmp/testdata/vm-migration"
vmMigrationCancel: "/tmp/testdata/vm-migration-cancel"
vmEvacuation: "/tmp/testdata/vm-evacuation"
vmDiskAttachment: "/tmp/testdata/vm-disk-attachment"
vdSnapshots: "/tmp/testdata/vd-snapshots"
sshKey: "/tmp/testdata/sshkeys/id_ed"
sshUser: "cloud"
Expand Down
23 changes: 11 additions & 12 deletions test/e2e/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,17 @@ type Config struct {
}

type TestData struct {
AffinityToleration string `yaml:"affinityToleration"`
ComplexTest string `yaml:"complexTest"`
DiskResizing string `yaml:"diskResizing"`
ImageHotplug string `yaml:"imageHotplug"`
VMLabelAnnotation string `yaml:"vmLabelAnnotation"`
VMMigration string `yaml:"vmMigration"`
VMMigrationCancel string `yaml:"vmMigrationCancel"`
VMEvacuation string `yaml:"vmEvacuation"`
VMDiskAttachment string `yaml:"vmDiskAttachment"`
VdSnapshots string `yaml:"vdSnapshots"`
Sshkey string `yaml:"sshKey"`
SSHUser string `yaml:"sshUser"`
ComplexTest string `yaml:"complexTest"`
DiskResizing string `yaml:"diskResizing"`
ImageHotplug string `yaml:"imageHotplug"`
VMLabelAnnotation string `yaml:"vmLabelAnnotation"`
VMMigration string `yaml:"vmMigration"`
VMMigrationCancel string `yaml:"vmMigrationCancel"`
VMEvacuation string `yaml:"vmEvacuation"`
VMVersions string `yaml:"vmVersions"`
VdSnapshots string `yaml:"vdSnapshots"`
Sshkey string `yaml:"sshKey"`
SSHUser string `yaml:"sshUser"`
}

type StorageClass struct {
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/internal/util/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package util

import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -194,3 +195,34 @@ func GetExpectedDiskPhaseByVolumeBindingMode() string {
return string(v1alpha2.DiskReady)
}
}

// GetDiskCount returns the number of block devices attached to a VM.
// Uses lsblk --nodeps --json to get the list of block devices.
func GetDiskCount(f *framework.Framework, vmName, vmNamespace string) (int, error) {
cmd := "lsblk --nodeps --json"
result, err := f.SSHCommand(vmName, vmNamespace, cmd)
if err != nil {
return 0, fmt.Errorf("failed to execute command: %w: %s", err, result)
}

var disks Disks
err = json.Unmarshal([]byte(result), &disks)
if err != nil {
return 0, fmt.Errorf("failed to parse lsblk output: %w", err)
}

return len(disks.BlockDevices), nil
}

// Disks represents the JSON output of lsblk --nodeps --json command.
// It contains a list of block devices attached to the VM.
type Disks struct {
BlockDevices []BlockDevice `json:"blockdevices"`
}

// BlockDevice represents a single block device in the lsblk JSON output.
type BlockDevice struct {
Name string `json:"name"`
Size string `json:"size"`
Type string `json:"type"`
}
79 changes: 79 additions & 0 deletions test/e2e/legacy/image_hotplug.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
virtv1 "kubevirt.io/api/core/v1"

"github.com/deckhouse/virtualization/api/core/v1alpha2"
Expand All @@ -33,8 +34,13 @@ import (
kc "github.com/deckhouse/virtualization/test/e2e/internal/kubectl"
"github.com/deckhouse/virtualization/test/e2e/internal/label"
"github.com/deckhouse/virtualization/test/e2e/internal/object"
"github.com/deckhouse/virtualization/test/e2e/internal/util"
)

const unacceptableCount = -1000

var APIVersion = v1alpha2.SchemeGroupVersion.String()

var _ = Describe("ImageHotplug", Ordered, label.Legacy(), func() {
const (
viCount = 2
Expand Down Expand Up @@ -336,3 +342,76 @@ func IsBlockDeviceReadOnly(vmNamespace, vmName, blockDeviceID string) (bool, err
roOpt := options[0]
return roOpt == "ro", nil
}

// lsblk JSON output
type Disks struct {
BlockDevices []BlockDevice `json:"blockdevices"`
}

type BlockDevices struct {
BlockDevices []BlockDevice `json:"blockdevices"`
}

type BlockDevice struct {
Name string `json:"name"`
Size string `json:"size"`
Type string `json:"type"`
}

func AttachBlockDevice(vmNamespace, vmName, blockDeviceName string, blockDeviceType v1alpha2.VMBDAObjectRefKind, labels map[string]string, testDataPath string) {
vmbdaFilePath := fmt.Sprintf("%s/vmbda/%s.yaml", testDataPath, blockDeviceName)
err := CreateVMBDAManifest(vmbdaFilePath, vmName, blockDeviceName, blockDeviceType, labels)
Expect(err).NotTo(HaveOccurred(), "%v", err)

res := kubectl.Apply(kc.ApplyOptions{
Filename: []string{vmbdaFilePath},
FilenameOption: kc.Filename,
Namespace: vmNamespace,
})
Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr())
}

func CreateVMBDAManifest(filePath, vmName, blockDeviceName string, blockDeviceType v1alpha2.VMBDAObjectRefKind, labels map[string]string) error {
vmbda := &v1alpha2.VirtualMachineBlockDeviceAttachment{
TypeMeta: metav1.TypeMeta{
APIVersion: APIVersion,
Kind: v1alpha2.VirtualMachineBlockDeviceAttachmentKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: blockDeviceName,
Labels: labels,
},
Spec: v1alpha2.VirtualMachineBlockDeviceAttachmentSpec{
VirtualMachineName: vmName,
BlockDeviceRef: v1alpha2.VMBDAObjectRef{
Kind: blockDeviceType,
Name: blockDeviceName,
},
},
}

err := util.WriteYamlObject(filePath, vmbda)
if err != nil {
return err
}

return nil
}

func GetDisksMetadata(vmNamespace, vmName string, disks *Disks) error {
GinkgoHelper()
cmd := "lsblk --nodeps --json"
res := framework.GetClients().D8Virtualization().SSHCommand(vmName, cmd, d8.SSHOptions{
Namespace: vmNamespace,
Username: conf.TestData.SSHUser,
IdentityFile: conf.TestData.Sshkey,
})
if res.Error() != nil {
return fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr())
}
err := json.Unmarshal(res.StdOutBytes(), disks)
if err != nil {
return fmt.Errorf("failed when getting disk count\nvirtualMachine: %s/%s\nstderr: %s", vmNamespace, vmName, res.StdErr())
}
return nil
}
15 changes: 0 additions & 15 deletions test/e2e/legacy/testdata/affinity-toleration/kustomization.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions test/e2e/legacy/testdata/affinity-toleration/ns.yaml

This file was deleted.

52 changes: 0 additions & 52 deletions test/e2e/legacy/testdata/affinity-toleration/transformer.yaml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading