Skip to content

Commit

Permalink
test(api): add e2e vm configuration test
Browse files Browse the repository at this point in the history
- Increase SSH connection timeout(required in some cases).
- Refactor helper functions.
- Optimize config file fields.

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
  • Loading branch information
Roman Sysoev committed Sep 16, 2024
1 parent 24ae25d commit 0fce78f
Show file tree
Hide file tree
Showing 25 changed files with 604 additions and 43 deletions.
1 change: 1 addition & 0 deletions tests/e2e/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tasks:
mkdir /tmp/testdata
cp -a testdata/virtualization-resources /tmp/testdata/virtualization-resources
cp -a testdata/connectivity /tmp/testdata/connectivity
cp -a testdata/vm-configuration /tmp/testdata/vm-configuration
cp -a testdata/sshkeys /tmp/testdata/sshkeys
virtctl:
cmds:
Expand Down
45 changes: 35 additions & 10 deletions tests/e2e/complex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("Complex test", Ordered, ContinueOnFailure, func() {
Context("Virtualization resources", func() {
When("Resources applied", func() {
It("Result must have no error", func() {
res := kubectl.Kustomize(conf.VirtualizationResources, kc.KustomizeOptions{})
res := kubectl.Kustomize(conf.TestData.VirtualizationResources, kc.KustomizeOptions{})
Expect(res.WasSuccess()).To(Equal(true), res.StdErr())
})
})
Expand All @@ -38,15 +38,32 @@ var _ = Describe("Complex test", Ordered, ContinueOnFailure, func() {
Context("Virtual images", func() {
When("VI applied", func() {
It(fmt.Sprintf("Phase should be %s", PhaseReady), func() {
WaitPhase("vi", PhaseReady)
WaitPhase(kc.ResourceVI, PhaseReady, kc.GetOptions{
Namespace: conf.Namespace,
Output: "jsonpath='{.items[*].metadata.name}'",
})
})
})
})

Context("Cluster virtual images", func() {
When("CVI applied", func() {
It(fmt.Sprintf("Phase should be %s", PhaseReady), func() {
WaitPhase(kc.ResourceCVI, PhaseReady, kc.GetOptions{
Namespace: conf.Namespace,
Output: "jsonpath='{.items[*].metadata.name}'",
})
})
})
})

Context("Disks", func() {
When("VD applied", func() {
It(fmt.Sprintf("Phase should be %s", PhaseReady), func() {
WaitPhase("vd", PhaseReady)
WaitPhase(kc.ResourceVD, PhaseReady, kc.GetOptions{
Namespace: conf.Namespace,
Output: "jsonpath='{.items[*].metadata.name}'",
})
})
})
})
Expand All @@ -61,38 +78,46 @@ var _ = Describe("Complex test", Ordered, ContinueOnFailure, func() {
MergePatchResource(kc.ResourceVMIP, vmipMetadataName, mergePatch)
})
It(fmt.Sprintf("Phase should be %s", PhaseBound), func() {
WaitPhase("vmip", PhaseBound)
WaitPhase(kc.ResourceVMIP, PhaseBound, kc.GetOptions{
Namespace: conf.Namespace,
Output: "jsonpath='{.items[*].metadata.name}'",
})
})
})
})

Context("Virtual machines", func() {
When("VM applied", func() {
It(fmt.Sprintf("Phase should be %s", PhaseRunning), func() {
WaitPhase("vm", PhaseRunning)
WaitPhase(kc.ResourceVM, PhaseRunning, kc.GetOptions{
Namespace: conf.Namespace,
Output: "jsonpath='{.items[*].metadata.name}'",
})
})
})
})

Context("Virtualmachine block device attachments", func() {
When("VMBDA applied", func() {
It(fmt.Sprintf("Phase should be %s", PhaseAttached), func() {
WaitPhase("vmbda", PhaseAttached)
WaitPhase(kc.ResourceVMBDA, PhaseAttached, kc.GetOptions{
Namespace: conf.Namespace,
Output: "jsonpath='{.items[*].metadata.name}'",
})
})
})
})

Context("External connection", func() {
When("VMs are running", func() {
It("All VMs must have to be connected to external network", func() {
sshKeyPath := fmt.Sprintf("%s/id_ed", conf.Sshkeys)
resourceType := kc.Resource("vm")
sshKeyPath := fmt.Sprintf("%s/id_ed", conf.TestData.Sshkeys)
output := "jsonpath='{.items[*].metadata.name}'"

res := kubectl.List(resourceType, kc.GetOptions{
res := kubectl.List(kc.ResourceVM, kc.GetOptions{
Namespace: conf.Namespace,
Output: output,
Labels: map[string]string{"testcase": namePrefix},
Labels: map[string]string{"id": namePrefix},
})
Expect(res.WasSuccess()).To(Equal(true), res.StdErr())

Expand Down
25 changes: 15 additions & 10 deletions tests/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@ type KustomizeLabel struct {
}

type Config struct {
ClusterTransport ClusterTransport `yaml:"clusterTransport"`
Disks DisksConf `yaml:"disks"`
VM VmConf `yaml:"vm"`
Ipam IpamConf `yaml:"ipam"`
HelperImages HelperImages `yaml:"helperImages"`
Namespace string `yaml:"namespaceSuffix"`
VirtualizationResources string `yaml:"virtualizationResources"`
Connectivity string `yaml:"connectivity"`
Sshkeys string `yaml:"sshKeys"`
ClusterTransport ClusterTransport `yaml:"clusterTransport"`
Disks DisksConf `yaml:"disks"`
VM VmConf `yaml:"vm"`
Ipam IpamConf `yaml:"ipam"`
HelperImages HelperImages `yaml:"helperImages"`
Namespace string `yaml:"namespaceSuffix"`
TestData TestData `yaml:"testData"`
}

type TestData struct {
VirtualizationResources string `yaml:"virtualizationResources"`
Connectivity string `yaml:"connectivity"`
VmConfiguration string `yaml:"vmConfiguration"`
Sshkeys string `yaml:"sshKeys"`
}

type ClusterTransport struct {
Expand Down Expand Up @@ -233,7 +238,7 @@ func (k *Kustomize) SetParams(filePath, namespace, namePrefix string) error {

kustomizeFile.Namespace = namespace
kustomizeFile.NamePrefix = namePrefix + "-"
kustomizeFile.Labels[0].Pairs["testcase"] = namePrefix
kustomizeFile.Labels[0].Pairs["id"] = namePrefix
updatedKustomizeFile, marshalErr := yamlv3.Marshal(&kustomizeFile)
if marshalErr != nil {
return marshalErr
Expand Down
8 changes: 5 additions & 3 deletions tests/e2e/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ipam:
testDataDir: "./testdata/ipam"
helperImages:
curlImage: "curlimages/curl"
virtualizationResources: "/tmp/testdata/virtualization-resources"
connectivity: "/tmp/testdata/connectivity"
sshKeys: "/tmp/testdata/sshkeys"
testData:
virtualizationResources: "/tmp/testdata/virtualization-resources"
connectivity: "/tmp/testdata/connectivity"
vmConfiguration: "/tmp/testdata/vm-configuration"
sshKeys: "/tmp/testdata/sshkeys"
2 changes: 2 additions & 0 deletions tests/e2e/kubectl/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ const (
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"
)
6 changes: 4 additions & 2 deletions tests/e2e/testdata/templates/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: testcases
namePrefix: pr-number-or-commit-hash-
commonLabels:
testcase: pr-number-or-commit-hash
resources:
- ns.yaml
configurations:
- transformer.yaml
labels:
- includeSelectors: true
pairs:
id: pr-number-or-commit-hash
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ configurations:
labels:
- includeSelectors: true
pairs:
testcase: pr-number-or-commit-hash
id: pr-number-or-commit-hash
12 changes: 12 additions & 0 deletions tests/e2e/testdata/vm-configuration/base/cfg/cloudinit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#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 your_email@example.com
15 changes: 15 additions & 0 deletions tests/e2e/testdata/vm-configuration/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./vm.yaml
- ./vd-root.yaml
- ./vd-blank.yaml
configurations:
- transformer.yaml
generatorOptions:
disableNameSuffixHash: true
secretGenerator:
- files:
- userdata=cfg/cloudinit.yaml
name: cloud-init
type: Opaque
54 changes: 54 additions & 0 deletions tests/e2e/testdata/vm-configuration/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
7 changes: 7 additions & 0 deletions tests/e2e/testdata/vm-configuration/base/vd-attach.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDisk
metadata:
name: vd-attach
spec:
persistentVolumeClaim:
size: 100Mi
7 changes: 7 additions & 0 deletions tests/e2e/testdata/vm-configuration/base/vd-blank.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDisk
metadata:
name: vd-blank
spec:
persistentVolumeClaim:
size: 100Mi
12 changes: 12 additions & 0 deletions tests/e2e/testdata/vm-configuration/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
23 changes: 23 additions & 0 deletions tests/e2e/testdata/vm-configuration/base/vm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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
- kind: VirtualDisk
name: vd-blank
16 changes: 16 additions & 0 deletions tests/e2e/testdata/vm-configuration/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: pr-number-or-commit-hash-
resources:
- ns.yaml
- vi
- overlays/automatic
- overlays/manual
configurations:
- transformer.yaml
labels:
- includeSelectors: true
pairs:
id: pr-number-or-commit-hash
testcase: vm-configuration
4 changes: 4 additions & 0 deletions tests/e2e/testdata/vm-configuration/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -automatic-conf
resources:
- ../../base
patches:
- patch: |-
- op: replace
path: /spec/runPolicy
value: AlwaysOn
target:
kind: VirtualMachine
name: vm
- patch: |-
- op: replace
path: /spec/disruptions/restartApprovalMode
value: Automatic
target:
kind: VirtualMachine
name: vm
labels:
- includeSelectors: true
pairs:
vm: automatic-conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -manual-conf
resources:
- ../../base
patches:
- patch: |-
- op: replace
path: /spec/runPolicy
value: AlwaysOn
target:
kind: VirtualMachine
name: vm
labels:
- includeSelectors: true
pairs:
vm: manual-conf
Loading

0 comments on commit 0fce78f

Please sign in to comment.