Skip to content
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
1 change: 1 addition & 0 deletions tests/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ type TestData struct {
SSHUser string `yaml:"sshUser"`
IPAM string `yaml:"ipam"`
VMVpc string `yaml:"vmVpc"`
VMTpm string `yaml:"vmTpm"`
}

type StorageClass struct {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/config/reusable.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// ReusableEnv defines an environment variable used to reuse resources created previously.
// By default, it retains all resources created during the e2e test after its completion (no cleanup by default in this mode).
// Use the `WITH_POST_CLEANUP=yes` environment variable to clean up resources created or used during the test.
// Use the `POST_CLEANUP=yes` environment variable to clean up resources created or used during the test.
//
// When a test starts, it will reuse existing virtual machines created earlier, if they exist.
// If no virtual machines were found, they will be created.
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 @@ -41,6 +41,7 @@ testData:
sshKey: "/tmp/testdata/sshkeys/id_ed"
sshUser: "cloud"
vmVpc: "/tmp/testdata/vm-vpc"
vmTpm: "/tmp/testdata/vm-tpm"
logFilter:
- "pattern to exclude"
- "validation failed for data source objectref" # Err.
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/testdata/vm-tpm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: test-vm-tpm
namePrefix: tpm-
resources:
- ns.yaml
- vi
- vm
configurations:
- transformer.yaml
labels:
- includeSelectors: true
pairs:
id: pr-number-or-commit-hash
testcase: vm-check-tpm
4 changes: 4 additions & 0 deletions tests/e2e/testdata/vm-tpm/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: default
52 changes: 52 additions & 0 deletions tests/e2e/testdata/vm-tpm/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
4 changes: 4 additions & 0 deletions tests/e2e/testdata/vm-tpm/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-debian-http.yaml
11 changes: 11 additions & 0 deletions tests/e2e/testdata/vm-tpm/vi/vi-debian-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-debian-http
spec:
storage: ContainerRegistry
dataSource:
type: HTTP
http:
url: https://89d64382-20df-4581-8cc7-80df331f67fa.selstorage.ru/debian/debian-12-generic-amd64-20250814-2204.qcow2
16 changes: 16 additions & 0 deletions tests/e2e/testdata/vm-tpm/vm/base/cfg/cloud-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#cloud-config
ssh_pwauth: True
users:
- name: cloud
passwd: "$6$rounds=4096$saltsalt$fPmUsbjAuA7mnQNTajQM6ClhesyG0.yyQhvahas02ejfMAq1ykBo1RquzS0R6GgdIDlvS.kbUwDablGZKZcTP/"
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: False
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxcXHmwaGnJ8scJaEN5RzklBPZpVSic4GdaAsKjQoeA [email protected]
packages:
- qemu-guest-agent
- tpm2-tools
runcmd:
- systemctl enable qemu-guest-agent --now
- chown -R cloud:cloud /home/cloud
13 changes: 13 additions & 0 deletions tests/e2e/testdata/vm-tpm/vm/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./vmclass-discovery.yaml
- ./vd-root.yaml
- ./vm.yaml
generatorOptions:
disableNameSuffixHash: true
secretGenerator:
- name: cloud-init
files:
- userData=./cfg/cloud-config.yaml
type: provisioning.virtualization.deckhouse.io/cloud-init
12 changes: 12 additions & 0 deletions tests/e2e/testdata/vm-tpm/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:
dataSource:
type: ObjectRef
objectRef:
kind: VirtualImage
name: vi-debian-http
persistentVolumeClaim:
size: 4Gi
21 changes: 21 additions & 0 deletions tests/e2e/testdata/vm-tpm/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:
cpu:
cores: 1
memory:
size: 512Mi
virtualMachineClassName: discovery
provisioning:
type: UserDataRef
userDataRef:
kind: Secret
name: cloud-init
blockDeviceRefs:
- kind: VirtualDisk
name: vd-root
bootloader: EFI
disruptions:
restartApprovalMode: Automatic
16 changes: 16 additions & 0 deletions tests/e2e/testdata/vm-tpm/vm/base/vmclass-discovery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualMachineClass
metadata:
name: discovery
spec:
cpu:
discovery:
nodeSelector:
matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: DoesNotExist
type: Discovery
sizingPolicies:
- cores:
max: 320
min: 1
4 changes: 4 additions & 0 deletions tests/e2e/testdata/vm-tpm/vm/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:
- overlays/vm-tpm
10 changes: 10 additions & 0 deletions tests/e2e/testdata/vm-tpm/vm/overlays/vm-tpm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -check-tpm
resources:
- ../../base
patches:
- path: vm.yaml
target:
kind: VirtualMachine
name: vm
6 changes: 6 additions & 0 deletions tests/e2e/testdata/vm-tpm/vm/overlays/vm-tpm/vm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualMachine
metadata:
name: vm
spec:
osType: Windows
75 changes: 75 additions & 0 deletions tests/e2e/vm_tpm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
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"

"github.com/deckhouse/virtualization/tests/e2e/config"
"github.com/deckhouse/virtualization/tests/e2e/ginkgoutil"
kc "github.com/deckhouse/virtualization/tests/e2e/kubectl"
)

var _ = Describe("VMCheckTPM", ginkgoutil.CommonE2ETestDecorators(), func() {
testCaseLabel := map[string]string{"testcase": "vm-check-tpm"}
var (
ns string
vmName = fmt.Sprintf("%s-vm-check-tpm", namePrefix)
)
BeforeAll(func() {
kustomization := fmt.Sprintf("%s/%s", conf.TestData.VMTpm, "kustomization.yaml")
var err error
ns, err = kustomize.GetNamespace(kustomization)
Expect(err).NotTo(HaveOccurred(), "%w", err)
})

It("checks if tpm exists in VM", func() {
By("checks if vm already exists in cluster. Reusable flag.", func() {
if config.IsReusable() {
res := kubectl.List(kc.ResourceVM, kc.GetOptions{
Labels: testCaseLabel,
Namespace: ns,
Output: "jsonpath='{.items[*].metadata.name}'",
})
Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr())

if res.StdOut() != "" {
return
}
}

CreateNamespace(ns)
res := kubectl.Apply(kc.ApplyOptions{
Filename: []string{conf.TestData.VMTpm},
FilenameOption: kc.Kustomize,
})
Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr())
})

By("waits qemu agent to be ready")
WaitVMAgentReady(kc.WaitOptions{
Labels: testCaseLabel,
Namespace: ns,
Timeout: MaxWaitTimeout,
})
By("checks from OS that VM has tpm module version 2.0")
CheckResultSSHCommand(ns, vmName, `sudo tpm2_getcap properties-fixed | grep -A2 TPM2_PT_FAMILY_INDICATOR | grep value | awk -F"\"" "{print \$2}"`, "2.0")
})
})
Loading