-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from rf152/test-cloudinit
Test Cloud-init
- Loading branch information
Showing
5 changed files
with
125 additions
and
2 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
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,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
wget -O /tmp/jammy-server-cloudimg-amd64.img https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img |
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,55 @@ | ||
package api_test | ||
|
||
import ( | ||
"testing" | ||
|
||
pxapi "github.com/Telmate/proxmox-api-go/proxmox" | ||
api_test "github.com/Telmate/proxmox-api-go/test/api" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Cloud_Init_VM(t *testing.T) { | ||
Test := api_test.Test{} | ||
_ = Test.CreateTest() | ||
config := _create_vm_spec(true) | ||
vmref := _create_vmref() | ||
|
||
// Create network | ||
configNetwork := _create_network_spec() | ||
|
||
err := configNetwork.CreateNetwork(Test.GetClient()) | ||
require.NoError(t, err) | ||
_, err = Test.GetClient().ApplyNetwork("pve") | ||
require.NoError(t, err) | ||
|
||
disk := make(map[string]interface{}) | ||
disk["import-from"] = "/tmp/jammy-server-cloudimg-amd64.img" | ||
disk["type"] = "virtio" | ||
disk["storage"] = "local" | ||
|
||
config.QemuDisks[0] = disk | ||
config.Name = "Base-Image" | ||
|
||
err = config.CreateVm(vmref, Test.GetClient()) | ||
require.NoError(t, err) | ||
|
||
config.Ipconfig = pxapi.IpconfigMap{} | ||
config.Boot = "order=virtio0;ide2;net0" | ||
|
||
config.Ipconfig[0] = "gw=10.0.0.1,ip=10.0.0.2/24" | ||
|
||
err = config.UpdateConfig(vmref, Test.GetClient()) | ||
require.NoError(t, err) | ||
|
||
testConfig, _ := pxapi.NewConfigQemuFromApi(vmref, Test.GetClient()) | ||
|
||
require.Equal(t, testConfig.Ipconfig[0], "gw=10.0.0.1,ip=10.0.0.2/24") | ||
|
||
_, err = Test.GetClient().DeleteVm(vmref) | ||
require.NoError(t, err) | ||
|
||
_, err = Test.GetClient().DeleteNetwork("pve", "vmbr0") | ||
require.NoError(t, err) | ||
_, err = Test.GetClient().ApplyNetwork("pve") | ||
require.NoError(t, err) | ||
} |
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,59 @@ | ||
package api_test | ||
|
||
import ( | ||
pxapi "github.com/Telmate/proxmox-api-go/proxmox" | ||
) | ||
|
||
func _create_vmref() (ref *pxapi.VmRef) { | ||
ref = pxapi.NewVmRef(101) | ||
ref.SetNode("pve") | ||
ref.SetVmType("qemu") | ||
return ref | ||
} | ||
|
||
func _create_vm_spec(network bool) pxapi.ConfigQemu { | ||
|
||
disks := make(pxapi.QemuDevices) | ||
|
||
networks := make(pxapi.QemuDevices) | ||
if network { | ||
networks[0] = make(map[string]interface{}) | ||
networks[0]["bridge"] = "vmbr0" | ||
networks[0]["firewall"] = "true" | ||
networks[0]["id"] = "0" | ||
networks[0]["macaddr"] = "B6:8F:9D:7C:8F:BC" | ||
networks[0]["model"] = "virtio" | ||
} | ||
|
||
config := pxapi.ConfigQemu{ | ||
Name: "test-qemu01", | ||
Bios: "seabios", | ||
Tablet: pxapi.PointerBool(true), | ||
Memory: 2048, | ||
QemuOs: "l26", | ||
QemuCores: 1, | ||
QemuSockets: 1, | ||
QemuCpu: "kvm64", | ||
QemuNuma: pxapi.PointerBool(false), | ||
QemuKVM: pxapi.PointerBool(true), | ||
Hotplug: "network,disk,usb", | ||
QemuNetworks: networks, | ||
QemuIso: "none", | ||
Boot: "order=ide2;net0", | ||
Scsihw: "virtio-scsi-pci", | ||
QemuDisks: disks, | ||
} | ||
|
||
return config | ||
} | ||
|
||
func _create_network_spec() pxapi.ConfigNetwork { | ||
config := pxapi.ConfigNetwork{ | ||
Type: "bridge", | ||
Iface: "vmbr0", | ||
Node: "pve", | ||
Autostart: true, | ||
} | ||
|
||
return config | ||
} |
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