-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acc0d70
commit e68acd4
Showing
8 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {$imageName} | ||
storageClass: {$storageClass} | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"os/exec" | ||
"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) | ||
} | ||
}() | ||
time.Sleep(time.Hour * 10) | ||
|
||
// Create public vm | ||
storagePolicyID, _ := testData.vcClient.getStoragePolicyID() | ||
log.V(1).Info("Get storage policy", "storagePolicyID", storagePolicyID) | ||
clusterImage, _ := testData.vcClient.getClusterVirtualMachineImage() | ||
log.V(1).Info("Get cluster image", "clusterImage", clusterImage) | ||
// replace clusterImage with the real image name, storagePolicyID with the real storage policy ID in public_vm.yaml | ||
publicVMPath, _ := filepath.Abs("./manifest/testVM/public_vm.yaml") | ||
// use sed to replace the image name and storage policy ID | ||
sedCmd := fmt.Sprintf("sed -i 's/{$imageName}/%s/g' %s", clusterImage, publicVMPath) | ||
sedCmd = fmt.Sprintf("%s && sed -i 's/{$storageClass}/%s/g' %s", sedCmd, storagePolicyID, publicVMPath) | ||
cmd := exec.Command("bash", "-c", sedCmd) | ||
var stdout, stderr bytes.Buffer | ||
log.V(1).Info("sedCmd", "sedCmd", sedCmd) | ||
command := exec.Command("bash", "-c", sedCmd) | ||
command.Stdout = &stdout | ||
command.Stderr = &stderr | ||
log.V(1).Info("stdout", "stdout", stdout.String()) | ||
log.V(1).Info("stderr", "stderr", stderr.String()) | ||
|
||
log.Info("Executing", "cmd", cmd) | ||
require.NoError(t, applyYAML(publicVMPath, ns)) | ||
defer deleteYAML(publicVMPath, ns) | ||
time.Sleep(time.Hour * 10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters