Skip to content

Commit

Permalink
Add e2e test case for VM creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengxiexie committed Jan 14, 2025
1 parent acc0d70 commit 70ce51f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/e2e/manifest/testVM/public_vm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: crd.nsx.vmware.com/v1alpha1
kind: Subnet
metadata:
name: public-subnet
spec:
ipv4SubnetSize: 16
accessMode: Public
DHCPConfig:
enableDHCP: false
---
apiVersion: vmoperator.vmware.com/v1alpha3
kind: VirtualMachine
metadata:
name: public-vm
spec:
network:
interfaces:
- name: eth0
network:
name: public-subnet
kind: Subnet
apiVersion: crd.nsx.vmware.com/v1alpha1
bootstrap:
cloudInit:
rawCloudConfig:
key: user-data
name: user-data-1
className: best-effort-xsmall
imageName: vmi-72c452bfd23215d72
storageClass: wcplocal-storage-profile
powerState: PoweredOn
---
apiVersion: v1
kind: Secret
metadata:
name: user-data-1
stringData:
user-data: |
#cloud-config
ssh_pwauth: true
users:
- name: vmware
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
# Password set to Admin!23
passwd: '$1$salt$SOC33fVbA/ZxeIwD5yw1u1'
shell: /bin/bash
write_files:
- path: /etc/my-plaintext
permissions: '0644'
owner: root:root
content: |
Hello, world.
38 changes: 38 additions & 0 deletions test/e2e/nsx_vm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package e2e

import (
"context"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestCreateVM(t *testing.T) {
t.Run("testCreateVMBasic", func(t *testing.T) { testCreateVMBasic(t) })
}

func testCreateVMBasic(t *testing.T) {
_, deadlineCancel := context.WithTimeout(context.Background(), defaultTimeout)
defer deadlineCancel()

ns := "test-create-vm-basic"

err := testData.createVCNamespace(ns)
if err != nil {
t.Fatalf("Failed to create VC namespace: %v", err)
}
defer func() {
err := testData.deleteVCNamespace(ns)
if err != nil {
t.Fatalf("Failed to delete VC namespace: %v", err)
}
}()

// Create public vm
vmPath, _ := filepath.Abs("./manifest/testVM/public_vm.yaml")
require.NoError(t, applyYAML(vmPath, ns))
defer deleteYAML(vmPath, ns)
time.Sleep(time.Hour * 10)
}

0 comments on commit 70ce51f

Please sign in to comment.