Skip to content
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

test(api): add e2e virtual disk snapshots test case #550

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions tests/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type TestData struct {
VmLabelAnnotation string `yaml:"vmLabelAnnotation"`
VmMigration string `yaml:"vmMigration"`
VmDiskAttachment string `yaml:"vmDiskAttachment"`
VdSnapshots string `yaml:"vdSnapshots"`
Sshkey string `yaml:"sshKey"`
SshUser string `yaml:"sshUser"`
}
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ testData:
vmLabelAnnotation: "/tmp/testdata/vm-label-annotation"
vmMigration: "/tmp/testdata/vm-migration"
vmDiskAttachment: "/tmp/testdata/vm-disk-attachment"
vdSnapshots: "/tmp/testdata/vd-snapshots"
sshKey: "/tmp/testdata/sshkeys/id_ed"
sshUser: "cloud"
2 changes: 2 additions & 0 deletions tests/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module github.com/deckhouse/virtualization/tests/e2e
go 1.22.7

require (
github.com/deckhouse/sds-replicated-volume/api v0.0.0-20241109122839-a1ae840eb5db
github.com/deckhouse/virtualization/api v0.0.0-20240923080356-bb5809dba578
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.0.0
github.com/onsi/ginkgo/v2 v2.20.0
github.com/onsi/gomega v1.34.1
gopkg.in/yaml.v3 v3.0.1
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckhouse/sds-replicated-volume/api v0.0.0-20241109122839-a1ae840eb5db h1:ArXEN2TeIX+cX4DUGUtHpRhkJpSzzk80PNqY4PGxNi0=
github.com/deckhouse/sds-replicated-volume/api v0.0.0-20241109122839-a1ae840eb5db/go.mod h1:6yz0RtbkLVJtK2DeuvgfaqBZRl5V5ax1WsfPF5pbnvo=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
Expand Down Expand Up @@ -119,6 +121,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.0.0 h1:mjQG0Vakr2h246kEDR85U8y8ZhPgT3bguTCajRa/jaw=
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.0.0/go.mod h1:E3vdYxHj2C2q6qo8/Da4g7P+IcwqRZyy3gJBzYybV9Y=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
Expand Down
14 changes: 14 additions & 0 deletions tests/e2e/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ func WriteYamlObject(filePath string, obj client.Object) error {

return nil
}

func UnmarshalResource(filePath string, obj client.Object) error {
file, err := os.ReadFile(filePath)
if err != nil {
return err
}

err = yaml.Unmarshal(file, obj)
if err != nil {
return err
}

return nil
}
38 changes: 21 additions & 17 deletions tests/e2e/kubectl/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ limitations under the License.
package kubectl

const (
ResourceNode Resource = "node"
ResourceNamespace Resource = "namespace"
ResourcePod Resource = "pod"
ResourceService Resource = "service"
ResourceStorageClass Resource = "storageclasses.storage.k8s.io"
ResourceKubevirtVM Resource = "internalvirtualizationvirtualmachines.internal.virtualization.deckhouse.io"
ResourceKubevirtVMI Resource = "internalvirtualizationvirtualmachineinstances.internal.virtualization.deckhouse.io"
ResourceKubevirtVMIM Resource = "internalvirtualizationvirtualmachineinstancemigrations.internal.virtualization.deckhouse.io"
ResourceModuleConfig Resource = "moduleconfigs.deckhouse.io"
ResourceVD Resource = "virtualdisks.virtualization.deckhouse.io"
ResourceVM Resource = "virtualmachine.virtualization.deckhouse.io"
ResourceVMClass Resource = "virtualmachineclasses.virtualization.deckhouse.io"
ResourceVMIP Resource = "virtualmachineipaddresses.virtualization.deckhouse.io"
ResourceVMIPLease Resource = "virtualmachineipaddressleases.virtualization.deckhouse.io"
ResourceCVI Resource = "clustervirtualimages.virtualization.deckhouse.io"
ResourceVI Resource = "virtualimages.virtualization.deckhouse.io"
ResourceVMBDA Resource = "virtualmachineblockdeviceattachments.virtualization.deckhouse.io"
ResourceNode Resource = "node"
ResourceNamespace Resource = "namespace"
ResourcePod Resource = "pod"
ResourceService Resource = "service"
ResourceStorageClass Resource = "storageclasses.storage.k8s.io"
ResourceVolumeSnapshotClass Resource = "volumesnapshotclasses.snapshot.storage.k8s.io"
ResourceReplicatedStorageClass Resource = "replicatedstorageclasses.storage.deckhouse.io"
ResourceReplicatedStoragePool Resource = "replicatedstoragepools.storage.deckhouse.io"
ResourceKubevirtVM Resource = "internalvirtualizationvirtualmachines.internal.virtualization.deckhouse.io"
ResourceKubevirtVMI Resource = "internalvirtualizationvirtualmachineinstances.internal.virtualization.deckhouse.io"
ResourceKubevirtVMIM Resource = "internalvirtualizationvirtualmachineinstancemigrations.internal.virtualization.deckhouse.io"
ResourceModuleConfig Resource = "moduleconfigs.deckhouse.io"
ResourceVD Resource = "virtualdisks.virtualization.deckhouse.io"
ResourceVDSnapshot Resource = "virtualdisksnapshots.virtualization.deckhouse.io"
ResourceVM Resource = "virtualmachine.virtualization.deckhouse.io"
ResourceVMClass Resource = "virtualmachineclasses.virtualization.deckhouse.io"
ResourceVMIP Resource = "virtualmachineipaddresses.virtualization.deckhouse.io"
ResourceVMIPLease Resource = "virtualmachineipaddressleases.virtualization.deckhouse.io"
ResourceCVI Resource = "clustervirtualimages.virtualization.deckhouse.io"
ResourceVI Resource = "virtualimages.virtualization.deckhouse.io"
ResourceVMBDA Resource = "virtualmachineblockdeviceattachments.virtualization.deckhouse.io"
)
16 changes: 16 additions & 0 deletions tests/e2e/testdata/vd-snapshots/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: testcases
namePrefix: commit-
resources:
- ns.yaml
- vd
- vi
- vm
configurations:
- transformer.yaml
labels:
- includeSelectors: true
pairs:
id: commit
testcase: vd-snapshots
4 changes: 4 additions & 0 deletions tests/e2e/testdata/vd-snapshots/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: default
Empty file.
52 changes: 52 additions & 0 deletions tests/e2e/testdata/vd-snapshots/transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace:
- kind: ClusterVirtualImage
path: spec/dataSource/objectRef/namespace
nameReference:
- kind: VirtualImage
version: v1alpha2 # optional
fieldSpecs:
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualDisk
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- kind: ClusterVirtualImage
version: v1alpha2 # optional
fieldSpecs:
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualDisk
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- kind: VirtualDisk
version: v1alpha2 # optional
fieldSpecs:
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- path: spec/blockDeviceRef/name
kind: VirtualMachineBlockDeviceAttachment
- kind: Secret
fieldSpecs:
- path: spec/provisioning/userDataRef/name
kind: VirtualMachine
- kind: VirtualMachineIPAddress
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineIPAddressName
kind: VirtualMachine
- kind: VirtualMachine
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineName
kind: VirtualMachineBlockDeviceAttachment
- kind: VirtualMachineClass
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineClassName
kind: VirtualMachine
8 changes: 8 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- vd-alpine-http.yaml
labels:
- includeSelectors: true
pairs:
hasNoConsumer: "vd-snapshots"
12 changes: 12 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vd/vd-alpine-http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDisk
metadata:
name: vd-alpine-http
spec:
dataSource:
type: HTTP
http:
url: https://0e773854-6b4e-4e76-a65b-d9d81675451a.selstorage.ru/alpine/alpine-v3-20.qcow2
persistentVolumeClaim:
size: 260Mi
4 changes: 4 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vi/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- vi-alpine-http.yaml
11 changes: 11 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vi/vi-alpine-http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualImage
metadata:
name: vi-alpine-http
spec:
storage: ContainerRegistry
dataSource:
type: HTTP
http:
url: https://0e773854-6b4e-4e76-a65b-d9d81675451a.selstorage.ru/alpine/alpine-v3-20.qcow2
51 changes: 51 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vm/base/cfg/cloudinit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#cloud-config
users:
- name: cloud
# passwd: cloud
passwd: $6$rounds=4096$vln/.aPHBOI7BMYR$bBMkqQvuGs5Gyd/1H5DP4m9HjQSy.kgrxpaGEHwkX7KEFV8BS.HZWPitAtZ2Vd8ZqIZRqmlykRCagTgPejt1i.
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
chpasswd: { expire: False }
lock_passwd: false
ssh_authorized_keys:
# testcases
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxcXHmwaGnJ8scJaEN5RzklBPZpVSic4GdaAsKjQoeA [email protected]
write_files:
- path: /etc/init.d/ping-service
permissions: "0755"
content: |
#!/sbin/openrc-run

command="/usr/bin/ping-service.sh"
pidfile="/var/run/${RC_SVCNAME}.pid"

depend() {
need localmount
after bootmisc
}

start() {
ebegin "Starting ${RC_SVCNAME}"
start-stop-daemon --start --background --exec $command --pidfile $pidfile -- $command_args
eend $?
}

stop() {
ebegin "Stopping ${RC_SVCNAME}"
start-stop-daemon --stop --exec $command --pidfile $pidfile
eend $?
}
- path: /usr/bin/ping-service.sh
permissions: "0755"
content: |
#!/bin/bash

while true; do
ping -W1 -D 1.1.1.1 >> /tmp/ping.log
done
final_message: "\U0001F525\U0001F525\U0001F525 The system is finally up, after $UPTIME seconds \U0001F525\U0001F525\U0001F525"
runcmd:
- "echo \"\U0001F7E1 Starting runcmd at $(date +%H:%M:%S)\""
- rc-update add ping-service default
- rc-service ping-service start
- "echo \"\U0001F7E1 Finished runcmd at $(date +%H:%M:%S)\""
14 changes: 14 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vm/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./vm.yaml
- ./vd-root.yaml
configurations:
- transformer.yaml
generatorOptions:
disableNameSuffixHash: true
secretGenerator:
- files:
- userData=cfg/cloudinit.yaml
name: cloud-init
type: provisioning.virtualization.deckhouse.io/cloud-init
54 changes: 54 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vm/base/transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md#transformer-configurations

namespace:
- kind: ClusterVirtualImage
path: spec/dataSource/objectRef/namespace
nameReference:
- kind: VirtualImage
version: v1alpha2 # optional
fieldSpecs:
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualDisk
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- kind: ClusterVirtualImage
version: v1alpha2 # optional
fieldSpecs:
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualDisk
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- kind: VirtualDisk
version: v1alpha2 # optional
fieldSpecs:
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- path: spec/blockDeviceRef/name
kind: VirtualMachineBlockDeviceAttachment
- kind: Secret
fieldSpecs:
- path: spec/provisioning/userDataRef/name
kind: VirtualMachine
- kind: VirtualMachineIPAddress
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineIPAddressName
kind: VirtualMachine
- kind: VirtualMachine
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineName
kind: VirtualMachineBlockDeviceAttachment
- kind: VirtualMachineClass
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineClassName
kind: VirtualMachine
12 changes: 12 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vm/base/vd-root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDisk
metadata:
name: vd-root
spec:
persistentVolumeClaim:
size: 512Mi
dataSource:
type: ObjectRef
objectRef:
kind: VirtualImage
name: vi-alpine-http
21 changes: 21 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vm/base/vm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualMachine
metadata:
name: vm
spec:
virtualMachineClassName: generic
cpu:
cores: 1
coreFraction: 5%
memory:
size: 256Mi
disruptions:
restartApprovalMode: Manual
provisioning:
type: UserDataRef
userDataRef:
kind: Secret
name: cloud-init
blockDeviceRefs:
- kind: VirtualDisk
name: vd-root
5 changes: 5 additions & 0 deletions tests/e2e/testdata/vd-snapshots/vm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- overlays/automatic
- overlays/automatic-with-hotplug
Loading
Loading