-
Notifications
You must be signed in to change notification settings - Fork 3
/
custom_test.go
19 lines (17 loc) · 9.45 KB
/
custom_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package main
import (
"context"
"github.com/stretchr/testify/assert"
kubevirt_hooks_v1alpha2 "kubevirt.io/kubevirt/pkg/hooks/v1alpha2"
"log"
"testing"
)
func TestCustomHook(t *testing.T) {
srv := v1alpha2Server{}
domain, err := srv.OnDefineDomain(context.Background(), &kubevirt_hooks_v1alpha2.OnDefineDomainParams{
DomainXML: []byte("<domain type='kvm'>\n <name>Windows</name>\n <uuid>83541888-7d42-41ff-b3ef-9b0cd0e8db4d</uuid>\n <memory unit='KiB'>16777216</memory>\n <currentMemory unit='KiB'>16777216</currentMemory>\n <vcpu placement='static'>4</vcpu>\n <os>\n <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>\n <boot dev='hd'/>\n </os>\n <features>\n <acpi/>\n <apic/>\n <hyperv>\n <relaxed state='on'/>\n <vapic state='on'/>\n <spinlocks state='on' retries='8191'/>\n <vendor_id state='on' value='1234567890ab'/>\n </hyperv>\n <vmport state='off'/>\n </features>\n <cpu mode='host-model' check='partial'>\n <model fallback='allow'/>\n <topology sockets='1' cores='4' threads='1'/>\n </cpu>\n <clock offset='localtime'>\n <timer name='rtc' tickpolicy='catchup'/>\n <timer name='pit' tickpolicy='delay'/>\n <timer name='hpet' present='no'/>\n <timer name='hypervclock' present='yes'/>\n </clock>\n <on_poweroff>destroy</on_poweroff>\n <on_reboot>restart</on_reboot>\n <on_crash>destroy</on_crash>\n</domain>"),
Vmi: []byte("{\n \"apiVersion\": \"kubevirt.io/v1alpha3\",\n \"kind\": \"VirtualMachineInstance\",\n \"metadata\": {\n \"annotations\": {\n \"custom.kubevirt.io/domain.features.kvm.hidden.-state\": \"-state:on\", \"kubevirt.io/latest-observed-api-version\": \"v1alpha3\",\n \"kubevirt.io/storage-observed-api-version\": \"v1alpha3\"\n },\n \"creationTimestamp\": \"2020-04-09T13:07:21Z\",\n \"finalizers\": [\n \"foregroundDeleteVirtualMachine\"\n ],\n \"generateName\": \"vmi-hpm-dev\",\n \"generation\": 8,\n \"labels\": {\n \"kubevirt.io/nodeName\": \"ns3159784\",\n \"special\": \"vmi-hpm-dev\"\n },\n \"name\": \"vmi-hpm-dev\",\n \"namespace\": \"mdfunds\",\n \"ownerReferences\": [\n {\n \"apiVersion\": \"kubevirt.io/v1alpha3\",\n \"blockOwnerDeletion\": true,\n \"controller\": true,\n \"kind\": \"VirtualMachine\",\n \"name\": \"vmi-hpm-dev\",\n \"uid\": \"10e70e4b-9109-421a-9caa-20acabb36312\"\n }\n ],\n \"resourceVersion\": \"227565172\",\n \"selfLink\": \"/apis/kubevirt.io/v1alpha3/namespaces/mdfunds/virtualmachineinstances/vmi-hpm-dev\",\n \"uid\": \"7f4174fa-1cbc-49e2-be84-3ac0119c29da\"\n },\n \"spec\": {\n \"domain\": {\n \"clock\": {\n \"timer\": {\n \"hpet\": {\n \"present\": false\n },\n \"hyperv\": {\n \"present\": true\n },\n \"pit\": {\n \"present\": true,\n \"tickPolicy\": \"delay\"\n },\n \"rtc\": {\n \"present\": true,\n \"tickPolicy\": \"catchup\"\n }\n }\n },\n \"cpu\": {\n \"cores\": 4,\n \"dedicatedCpuPlacement\": true,\n \"isolateEmulatorThread\": true,\n \"sockets\": 1\n },\n \"devices\": {\n \"disks\": [\n {\n \"cache\": \"none\",\n \"disk\": {\n \"bus\": \"sata\"\n },\n \"name\": \"data\"\n }\n ],\n \"inputs\": [\n {\n \"bus\": \"usb\",\n \"name\": \"tablet1\",\n \"type\": \"tablet\"\n }\n ],\n \"interfaces\": [\n {\n \"bridge\": {},\n \"model\": \"virtio\",\n \"name\": \"default\",\n \"ports\": [\n {\n \"name\": \"notificationbus\",\n \"port\": 5000,\n \"protocol\": \"TCP\"\n },\n {\n \"name\": \"rabbitmq\",\n \"port\": 5672,\n \"protocol\": \"TCP\"\n },\n {\n \"name\": \"rdp\",\n \"port\": 3389,\n \"protocol\": \"TCP\"\n },\n {\n \"name\": \"sql\",\n \"port\": 1433,\n \"protocol\": \"TCP\"\n },\n {\n \"name\": \"winshare137\",\n \"port\": 137,\n \"protocol\": \"UDP\"\n },\n {\n \"name\": \"winshare138\",\n \"port\": 138,\n \"protocol\": \"UDP\"\n },\n {\n \"name\": \"winshare139\",\n \"port\": 139,\n \"protocol\": \"TCP\"\n },\n {\n \"name\": \"winshare445\",\n \"port\": 445,\n \"protocol\": \"TCP\"\n }\n ]\n }\n ]\n },\n \"features\": {\n \"acpi\": {\n \"enabled\": true\n },\n \"apic\": {\n \"enabled\": true\n },\n \"hyperv\": {\n \"relaxed\": {\n \"enabled\": true\n },\n \"spinlocks\": {\n \"enabled\": true,\n \"spinlocks\": 8191\n },\n \"vapic\": {\n \"enabled\": true\n }\n }\n },\n \"firmware\": {\n \"bootloader\": {\n \"efi\": {}\n },\n \"uuid\": \"d4a108f3-7503-5840-b65c-0afb23ca24a7\"\n },\n \"machine\": {\n \"type\": \"q35\"\n },\n \"resources\": {\n \"limits\": {\n \"memory\": \"8Gi\"\n },\n \"requests\": {\n \"memory\": \"8Gi\"\n }\n }\n },\n \"networks\": [\n {\n \"name\": \"default\",\n \"pod\": {}\n }\n ],\n \"nodeSelector\": {\n \"vms\": \"mdfunds\"\n },\n \"terminationGracePeriodSeconds\": 120,\n \"tolerations\": [\n {\n \"effect\": \"NoSchedule\",\n \"key\": \"vms\",\n \"operator\": \"Equal\",\n \"value\": \"mdfunds\"\n }\n ],\n \"volumes\": [\n {\n \"name\": \"data\",\n \"persistentVolumeClaim\": {\n \"claimName\": \"hpm-dev\"\n }\n }\n ]\n },\n \"status\": {\n \"conditions\": [\n {\n \"lastProbeTime\": null,\n \"lastTransitionTime\": null,\n \"message\": \"cannot migrate VMI with non-shared PVCs\",\n \"reason\": \"DisksNotLiveMigratable\",\n \"status\": \"False\",\n \"type\": \"LiveMigratable\"\n },\n {\n \"lastProbeTime\": null,\n \"lastTransitionTime\": null,\n \"message\": \"cannot migrate VMI which does not use masquerade to connect to the pod network\",\n \"reason\": \"InterfaceNotLiveMigratable\",\n \"status\": \"False\",\n \"type\": \"LiveMigratable\"\n },\n {\n \"lastProbeTime\": null,\n \"lastTransitionTime\": \"2020-04-09T13:07:27Z\",\n \"status\": \"True\",\n \"type\": \"Ready\"\n }\n ],\n \"guestOSInfo\": {},\n \"interfaces\": [\n {\n \"ipAddress\": \"10.42.5.100\",\n \"mac\": \"6a:2c:7a:b8:47:97\",\n \"name\": \"default\"\n }\n ],\n \"migrationMethod\": \"BlockMigration\",\n \"nodeName\": \"ns3159784\",\n \"phase\": \"Running\",\n \"qosClass\": \"Guaranteed\"\n }\n}"),
})
assert.NoError(t, err)
log.Print(string(domain.DomainXML))
}