Skip to content

chore(test): add disks tests #930

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
28 changes: 28 additions & 0 deletions tests/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ type Kustomize struct {
Namespace string `yaml:"namespace"`
NamePrefix string `yaml:"namePrefix"`
Resources []string `yaml:"resources"`
Patches []Patch `json:"patches,omitempty" yaml:"patches,omitempty"`
}

type Patch struct {
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
Target *Selector `json:"target,omitempty" yaml:"target,omitempty"`
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"`
}

type Selector struct {
ResId `json:",inline,omitempty" yaml:",inline,omitempty"`
AnnotationSelector string `json:"annotationSelector,omitempty" yaml:"annotationSelector,omitempty"`
LabelSelector string `json:"labelSelector,omitempty" yaml:"labelSelector,omitempty"`
}

type ResId struct {
Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
}

type Gvk struct {
Group string `json:"group,omitempty" yaml:"group,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
isClusterScoped bool
}

type KustomizeLabel struct {
Expand All @@ -141,6 +168,7 @@ type TestData struct {
ComplexTest string `yaml:"complexTest"`
Connectivity string `yaml:"connectivity"`
DiskResizing string `yaml:"diskResizing"`
DisksCreation string `yaml:"disksCreation"`
SizingPolicy string `yaml:"sizingPolicy"`
ImporterNetworkPolicy string `yaml:"importerNetworkPolicy"`
ImageHotplug string `yaml:"imageHotplug"`
Expand Down
169 changes: 169 additions & 0 deletions tests/e2e/disks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
Copyright 2024 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
storagev1 "k8s.io/api/storage/v1"

sdsrepvolv1 "github.com/deckhouse/sds-replicated-volume/api/v1alpha1"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/tests/e2e/config"
"github.com/deckhouse/virtualization/tests/e2e/ginkgoutil"
. "github.com/deckhouse/virtualization/tests/e2e/helper"
kc "github.com/deckhouse/virtualization/tests/e2e/kubectl"
)

var _ = Describe("Virtual disks creation", ginkgoutil.CommonE2ETestDecorators(), func() {
var (
immediateStorageClassName string // require for unattached virtual disk snapshots
testCaseLabel = map[string]string{"testcase": "disks-creation"}
)

BeforeEach(func() {
if config.IsReusable() {
Skip("Test not available in REUSABLE mode: not supported yet.")
}
})

AfterEach(func() {
if CurrentSpecReport().Failed() {
SaveTestResources(testCaseLabel, CurrentSpecReport().LeafNodeText)
}
})

Context("Preparing the environment", func() {
It("sets the namespace", func() {
kustomization := fmt.Sprintf("%s/%s", conf.TestData.DisksCreation, "kustomization.yaml")
ns, err := kustomize.GetNamespace(kustomization)
Expect(err).NotTo(HaveOccurred(), "%w", err)
conf.SetNamespace(ns)
})

It("prepares `Immediate` storage class and virtual disk that use it", func() {
sc, err := GetDefaultStorageClass()
Expect(err).NotTo(HaveOccurred(), "cannot get default storage class\nstderr: %s", err)

defaultVolumeSnapshotClassName, err := GetVolumeSnapshotClassName(sc)
Expect(err).NotTo(HaveOccurred(), "cannot define default `VolumeSnapshotClass`\nstderr: %s", err)

if sc.Provisioner == LinstorProviderName {
storagePoolName := sc.Parameters["replicated.csi.storage.deckhouse.io/storagePool"]
storagePoolObj := sdsrepvolv1.ReplicatedStoragePool{}
err := GetObject(kc.ResourceReplicatedStoragePool, storagePoolName, &storagePoolObj, kc.GetOptions{})
Expect(err).NotTo(HaveOccurred(), "cannot get `storagePoolObj`: %s\nstderr: %s", storagePoolName, err)
Expect(storagePoolObj.Spec.Type).To(Equal(LVMThinName), "type of replicated storage pool should be `LVMThin`")
}

if *sc.VolumeBindingMode != storagev1.VolumeBindingImmediate {
immediateStorageClassName, err = CreateImmediateStorageClass(sc.Provisioner, testCaseLabel)
Expect(err).NotTo(HaveOccurred(), "%s", err)

virtualDisk := virtv2.VirtualDisk{}
vdFilePath := fmt.Sprintf("%s/vd/vd-alpine-http.yaml", conf.TestData.DisksCreation)
err = UnmarshalResource(vdFilePath, &virtualDisk)
Expect(err).NotTo(HaveOccurred(), "cannot get object from file: %s\nstderr: %s", vdFilePath, err)

virtualDisk.Spec.PersistentVolumeClaim.StorageClass = &immediateStorageClassName
err = WriteYamlObject(vdFilePath, &virtualDisk)
Expect(err).NotTo(HaveOccurred(), "cannot update virtual disk with custom storage class: %s\nstderr: %s", vdFilePath, err)
} else {
immediateStorageClassName = sc.Name
}

virtualDiskSnapshot := virtv2.VirtualDiskSnapshot{}
vdSnapshotFilePath := fmt.Sprintf("%s/vdsnapshot/vdsnapshot.yaml", conf.TestData.DisksCreation)
err = UnmarshalResource(vdSnapshotFilePath, &virtualDiskSnapshot)
Expect(err).NotTo(HaveOccurred(), "cannot get object from file: %s\nstderr: %s", vdSnapshotFilePath, err)

virtualDiskSnapshot.Spec.VolumeSnapshotClassName = defaultVolumeSnapshotClassName
err = WriteYamlObject(vdSnapshotFilePath, &virtualDiskSnapshot)
Expect(err).NotTo(HaveOccurred(), "cannot update virtual disk with custom storage class: %s\nstderr: %s", vdSnapshotFilePath, err)
})
})

Context("When resources are applied", func() {
It("result should be succeeded", func() {
res := kubectl.Apply(kc.ApplyOptions{
Filename: []string{conf.TestData.DisksCreation},
FilenameOption: kc.Kustomize,
})
Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr())
})
})

Context("When base virtual resources are ready", func() {
It("checks VD phase", func() {
By(fmt.Sprintf("VD should be in %s phase", virtv2.DiskReady))
WaitPhaseByLabel(kc.ResourceVD, string(virtv2.DiskReady), kc.WaitOptions{
Labels: testCaseLabel,
Namespace: conf.Namespace,
Timeout: MaxWaitTimeout,
})
})

It("checks VDSnapshot phase", func() {
By(fmt.Sprintf("VDSnapshot should be in %s phase", virtv2.VirtualDiskSnapshotPhaseReady))
WaitPhaseByLabel(kc.ResourceVDSnapshot, string(virtv2.VirtualDiskSnapshotPhaseReady), kc.WaitOptions{
Labels: testCaseLabel,
Namespace: conf.Namespace,
Timeout: MaxWaitTimeout,
})
})
})

Context("When virtual images are applied", func() {
It("checks VIs phases", func() {
By(fmt.Sprintf("VIs should be in %s phases", virtv2.ImageReady))
WaitPhaseByLabel(kc.ResourceVI, string(virtv2.ImageReady), kc.WaitOptions{
Labels: testCaseLabel,
Namespace: conf.Namespace,
Timeout: MaxWaitTimeout,
})
})

It("checks CVIs phases", func() {
By(fmt.Sprintf("CVIs should be in %s phases", virtv2.ImageReady))
WaitPhaseByLabel(kc.ResourceCVI, string(virtv2.ImageReady), kc.WaitOptions{
Labels: testCaseLabel,
Namespace: conf.Namespace,
Timeout: MaxWaitTimeout,
})
})
})

Context("When test is completed", func() {
It("deletes test case resources", func() {
DeleteTestCaseResources(ResourcesToDelete{
KustomizationDir: conf.TestData.DisksCreation,
AdditionalResources: []AdditionalResource{
{
Resource: kc.ResourceReplicatedStorageClass,
Labels: testCaseLabel,
},
{
Resource: kc.ResourceStorageClass,
Labels: testCaseLabel,
},
},
})
})
})
})
9 changes: 9 additions & 0 deletions tests/e2e/testdata/disks-creation/cvi/cvi_http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: ClusterVirtualImage
metadata:
name: cvi-http
spec:
dataSource:
type: "HTTP"
http:
url: https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/alpine/alpine-virt-3.21.0-x86.iso
9 changes: 9 additions & 0 deletions tests/e2e/testdata/disks-creation/cvi/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./cvi_http.yaml
- ./cvi_containerimage.yaml
- ./cvi_objectref_cvi.yaml
- ./cvi_objectref_vi.yaml
- ./cvi_objectref_vd.yaml
- ./cvi_objectref_vdsnapshot.yaml
17 changes: 17 additions & 0 deletions tests/e2e/testdata/disks-creation/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: testcases
namePrefix: pr-number-or-commit-hash-
resources:
- ns.yaml
- vd
- vdsnapshot
- vi
- cvi
configurations:
- transformer.yaml
labels:
- includeSelectors: true
pairs:
id: pr-number-or-commit-hash
testcase: disks-creation
4 changes: 4 additions & 0 deletions tests/e2e/testdata/disks-creation/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: default
51 changes: 51 additions & 0 deletions tests/e2e/testdata/disks-creation/transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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
- path: spec/virtualDiskName
kind: VirtualDiskSnapshot
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
- kind: VirtualMachine
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineName
kind: VirtualMachineBlockDeviceAttachment
- kind: VirtualDiskSnapshot
version: v1alpha2
fieldSpecs:
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
4 changes: 4 additions & 0 deletions tests/e2e/testdata/disks-creation/vd/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:
- vd-alpine-http.yaml
12 changes: 12 additions & 0 deletions tests/e2e/testdata/disks-creation/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://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/alpine/alpine-3-21-uefi-perf.qcow2
persistentVolumeClaim:
size: 370Mi
16 changes: 16 additions & 0 deletions tests/e2e/testdata/disks-creation/vd/vd-http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDisk
metadata:
name: vd-http
spec:
dataSource:
type: HTTP
---
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDisk
metadata:
name: vd-pvc-http
spec:
dataSource:
type: HTTP
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- vdsnapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDiskSnapshot
metadata:
name: vdsnapshot
spec:
requiredConsistency: true
virtualDiskName: vd-alpine-http
10 changes: 10 additions & 0 deletions tests/e2e/testdata/disks-creation/vi/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./vi_http.yaml
- ./vi_containerimage.yaml
- ./vi_objectref_cvi.yaml
- ./vi_objectref_vi.yaml
- ./vi_pvc_objectref_vi.yaml
- ./vi_objectref_vd.yaml
- ./vi_objectref_vdsnapshot.yaml
23 changes: 23 additions & 0 deletions tests/e2e/testdata/disks-creation/vi/vi_http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualImage
metadata:
name: vi-http
namespace: test-d8-virtualization
spec:
storage: ContainerRegistry
dataSource:
type: "HTTP"
http:
url: https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/alpine/alpine-virt-3.21.0-x86.iso
---
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualImage
metadata:
name: vi-pvc-http
namespace: test-d8-virtualization
spec:
storage: PersistentVolumeClaim
dataSource:
type: "HTTP"
http:
url: https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/alpine/alpine-virt-3.21.0-x86.iso
Loading
Loading