Skip to content

Commit 8a94e77

Browse files
author
Valeriy Khorunzhin
committed
add test
Signed-off-by: Valeriy Khorunzhin <[email protected]>
1 parent 7371c0c commit 8a94e77

File tree

12 files changed

+1132
-1
lines changed

12 files changed

+1132
-1
lines changed

images/virtualization-artifact/pkg/builder/cvi/option.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ func WithDatasource(datasource v1alpha2.ClusterVirtualImageDataSource) func(cvi
8080
}
8181
}
8282

83+
func WithDataSourceHTTPWithOnlyURL(url string) Option {
84+
return func(cvi *v1alpha2.ClusterVirtualImage) {
85+
cvi.Spec.DataSource = v1alpha2.ClusterVirtualImageDataSource{
86+
Type: v1alpha2.DataSourceTypeHTTP,
87+
HTTP: &v1alpha2.DataSourceHTTP{
88+
URL: url,
89+
},
90+
}
91+
}
92+
}
93+
8394
func WithPhase(phase v1alpha2.ImagePhase) func(cvi *v1alpha2.ClusterVirtualImage) {
8495
return func(cvi *v1alpha2.ClusterVirtualImage) {
8596
cvi.Status.Phase = phase

images/virtualization-artifact/pkg/builder/vd/option.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func WithDataSourceHTTP(url string, checksum *v1alpha2.Checksum, caBundle []byte
5555
}
5656
}
5757

58+
func WithDataSourceHTTPWithOnlyURL(url string) Option {
59+
return func(vd *v1alpha2.VirtualDisk) {
60+
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
61+
Type: v1alpha2.DataSourceTypeHTTP,
62+
HTTP: &v1alpha2.DataSourceHTTP{
63+
URL: url,
64+
},
65+
}
66+
}
67+
}
68+
5869
func WithDataSourceContainerImage(image, imagePullSecretName string, caBundle []byte) Option {
5970
return func(vd *v1alpha2.VirtualDisk) {
6071
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{

images/virtualization-artifact/pkg/builder/vi/option.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,20 @@ func WithStorage(storage v1alpha2.StorageType) func(vi *v1alpha2.VirtualImage) {
9191
vi.Spec.Storage = storage
9292
}
9393
}
94+
95+
func WithStorageType(storageType *v1alpha2.StorageType) func(vi *v1alpha2.VirtualImage) {
96+
return func(vi *v1alpha2.VirtualImage) {
97+
vi.Spec.Storage = *storageType
98+
}
99+
}
100+
101+
func WithDataSourceHTTPWithOnlyURL(url string) Option {
102+
return func(vi *v1alpha2.VirtualImage) {
103+
vi.Spec.DataSource = v1alpha2.VirtualImageDataSource{
104+
Type: v1alpha2.DataSourceTypeHTTP,
105+
HTTP: &v1alpha2.DataSourceHTTP{
106+
URL: url,
107+
},
108+
}
109+
}
110+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package vmbda
15+
16+
import (
17+
"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
18+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
19+
)
20+
21+
type Option func(vd *v1alpha2.VirtualMachineBlockDeviceAttachment)
22+
23+
var (
24+
WithName = meta.WithName[*v1alpha2.VirtualMachineBlockDeviceAttachment]
25+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualMachineBlockDeviceAttachment]
26+
WithLabel = meta.WithLabel[*v1alpha2.VirtualMachineBlockDeviceAttachment]
27+
WithLabels = meta.WithLabels[*v1alpha2.VirtualMachineBlockDeviceAttachment]
28+
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualMachineBlockDeviceAttachment]
29+
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualMachineBlockDeviceAttachment]
30+
)
31+
32+
func WithBlockDeviceRef(bdRef v1alpha2.VMBDAObjectRef) func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
33+
return func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
34+
vmbda.Spec.BlockDeviceRef = bdRef
35+
}
36+
}
37+
38+
func WithVMName(vmName string) func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
39+
return func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
40+
vmbda.Spec.VirtualMachineName = vmName
41+
}
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package vmbda
15+
16+
import (
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
19+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
20+
)
21+
22+
func New(options ...Option) *v1alpha2.VirtualMachineBlockDeviceAttachment {
23+
vmbda := NewEmpty("", "")
24+
ApplyOptions(vmbda, options)
25+
return vmbda
26+
}
27+
28+
func ApplyOptions(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment, opts []Option) {
29+
if vmbda == nil {
30+
return
31+
}
32+
for _, opt := range opts {
33+
opt(vmbda)
34+
}
35+
}
36+
37+
func NewEmpty(name, namespace string) *v1alpha2.VirtualMachineBlockDeviceAttachment {
38+
return &v1alpha2.VirtualMachineBlockDeviceAttachment{
39+
TypeMeta: metav1.TypeMeta{
40+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
41+
Kind: v1alpha2.VirtualMachineBlockDeviceAttachmentKind,
42+
},
43+
ObjectMeta: metav1.ObjectMeta{
44+
Name: name,
45+
Namespace: namespace,
46+
},
47+
}
48+
}

images/virtualization-artifact/pkg/builder/vmop/option.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ func WithForce(force *bool) Option {
5151
vmop.Spec.Force = force
5252
}
5353
}
54+
55+
func WithRestoreSpec(restoreSpec *v1alpha2.VirtualMachineOperationRestoreSpec) Option {
56+
return func(vmop *v1alpha2.VirtualMachineOperation) {
57+
vmop.Spec.Restore = restoreSpec
58+
}
59+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package vmsnapshot
18+
19+
import (
20+
"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
21+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
22+
)
23+
24+
type Option func(vmop *v1alpha2.VirtualMachineSnapshot)
25+
26+
var (
27+
WithName = meta.WithName[*v1alpha2.VirtualMachineSnapshot]
28+
WithGenerateName = meta.WithGenerateName[*v1alpha2.VirtualMachineSnapshot]
29+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualMachineSnapshot]
30+
WithLabel = meta.WithLabel[*v1alpha2.VirtualMachineSnapshot]
31+
WithLabels = meta.WithLabels[*v1alpha2.VirtualMachineSnapshot]
32+
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualMachineSnapshot]
33+
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualMachineSnapshot]
34+
WithFinalizer = meta.WithFinalizer[*v1alpha2.VirtualMachineSnapshot]
35+
)
36+
37+
func WithRequiredConsistency(required bool) Option {
38+
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
39+
vmop.Spec.RequiredConsistency = required
40+
}
41+
}
42+
43+
func WithVM(vmName string) Option {
44+
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
45+
vmop.Spec.VirtualMachineName = vmName
46+
}
47+
}
48+
49+
func WithKeepIPAddress(keepIPAddress v1alpha2.KeepIPAddress) Option {
50+
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
51+
vmop.Spec.KeepIPAddress = keepIPAddress
52+
}
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package vmsnapshot
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
23+
)
24+
25+
func New(options ...Option) *v1alpha2.VirtualMachineSnapshot {
26+
vmSnapshot := NewEmpty("", "")
27+
ApplyOptions(vmSnapshot, options...)
28+
return vmSnapshot
29+
}
30+
31+
func ApplyOptions(vmSnapshot *v1alpha2.VirtualMachineSnapshot, opts ...Option) {
32+
if vmSnapshot == nil {
33+
return
34+
}
35+
for _, opt := range opts {
36+
opt(vmSnapshot)
37+
}
38+
}
39+
40+
func NewEmpty(name, namespace string) *v1alpha2.VirtualMachineSnapshot {
41+
return &v1alpha2.VirtualMachineSnapshot{
42+
TypeMeta: metav1.TypeMeta{
43+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
44+
Kind: v1alpha2.VirtualMachineSnapshotKind,
45+
},
46+
ObjectMeta: metav1.ObjectMeta{
47+
Name: name,
48+
Namespace: namespace,
49+
},
50+
}
51+
}

tests/e2e/framework/framework.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"maps"
2323
"sync"
2424

25+
"github.com/deckhouse/virtualization/tests/e2e/config"
2526
"github.com/onsi/ginkgo/v2"
2627
"github.com/onsi/gomega"
2728
corev1 "k8s.io/api/core/v1"
@@ -83,13 +84,16 @@ func (f *Framework) Before() {
8384
gomega.Expect(err).NotTo(gomega.HaveOccurred())
8485
ginkgo.By(fmt.Sprintf("Created namespace %s", ns.Name))
8586
f.namespace = ns
86-
f.DeferNamespaceDelete(ns.Name)
8787
}
8888
}
8989

9090
func (f *Framework) After() {
9191
ginkgo.GinkgoHelper()
9292

93+
if !config.IsCleanUpNeeded() {
94+
return
95+
}
96+
9397
for _, obj := range f.objectsToDelete {
9498
ginkgo.By(fmt.Sprintf("Delete object %s", obj.GetName()))
9599
err := f.GenericClient().Delete(context.Background(), obj)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package virtualmachinerestoreoperationtest
18+
19+
const cloudInit = `#cloud-config
20+
users:
21+
- name: cloud
22+
passwd: $6$rounds=4096$vln/.aPHBOI7BMYR$bBMkqQvuGs5Gyd/1H5DP4m9HjQSy.kgrxpaGEHwkX7KEFV8BS.HZWPitAtZ2Vd8ZqIZRqmlykRCagTgPejt1i.
23+
shell: /bin/bash
24+
sudo: ALL=(ALL) NOPASSWD:ALL
25+
chpasswd: { expire: False }
26+
lock_passwd: false
27+
ssh_authorized_keys:
28+
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxcXHmwaGnJ8scJaEN5RzklBPZpVSic4GdaAsKjQoeA [email protected]
29+
30+
runcmd:
31+
- [bash, -c, "apt update"]
32+
- [bash, -c, "apt install qemu-guest-agent -y"]
33+
- [bash, -c, "systemctl enable qemu-guest-agent"]
34+
- [bash, -c, "systemctl start qemu-guest-agent"]`

0 commit comments

Comments
 (0)