github.com/openshift/installer@v1.4.17/pkg/tfvars/ovirt/ovirt_test.go (about) 1 package ovirt 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/openshift/cluster-api-provider-ovirt/pkg/apis/ovirtprovider/v1beta1" 9 "github.com/openshift/installer/pkg/types/ovirt" 10 ) 11 12 func defaultMachineSpec() *v1beta1.OvirtMachineProviderSpec { 13 return &v1beta1.OvirtMachineProviderSpec{ 14 InstanceTypeId: "", 15 CPU: &v1beta1.CPU{ 16 Sockets: 1, 17 Cores: 8, 18 Threads: 1, 19 }, 20 MemoryMB: 16000, 21 OSDisk: &v1beta1.Disk{SizeGB: 31}, 22 VMType: "high_performance", 23 AffinityGroupsNames: []string{"clusterName-xxxxx-controlplane"}, 24 AutoPinningPolicy: "none", 25 } 26 } 27 28 var defaultTerraformOvirtVarsJSON = `{ 29 "ovirt_url": "https://ovirt-engine.com", 30 "ovirt_username": "admin", 31 "ovirt_password": "test", 32 "ovirt_cafile": "ca-file-content", 33 "ovirt_ca_bundle": "", 34 "ovirt_insecure": false, 35 "ovirt_cluster_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 36 "ovirt_storage_domain_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 37 "ovirt_network_name": "ovirt-network", 38 "ovirt_vnic_profile_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 39 "ovirt_affinity_groups": [ 40 { 41 "description": "AffinityGroup for spreading each control plane machines to a different host", 42 "enforcing": true, 43 "name": "clusterName-xxxxx-controlplane", 44 "priority": 5 45 }, 46 { 47 "description": "AffinityGroup for spreading each compute machine to a different host", 48 "enforcing": true, 49 "name": "clusterName-xxxxx-compute", 50 "priority": 3 51 } 52 ], 53 "ovirt_base_image_name": "some-base-image", 54 "ovirt_master_instance_type_id": "", 55 "ovirt_master_vm_type": "high_performance", 56 "ovirt_master_memory": 16000, 57 "ovirt_master_cores": 8, 58 "ovirt_master_sockets": 1, 59 "ovirt_master_threads": 1, 60 "ovirt_master_os_disk_gb": 31, 61 "ovirt_master_affinity_groups": [ 62 "clusterName-xxxxx-controlplane" 63 ], 64 "ovirt_master_auto_pinning_policy": "none", 65 "ovirt_master_hugepages": 0, 66 "ovirt_master_clone": null, 67 "ovirt_master_sparse": null, 68 "ovirt_master_format": "" 69 }` 70 71 func TestSetPlatformDefaults(t *testing.T) { 72 cases := []struct { 73 name string 74 auth Auth 75 clusterID string 76 storageDomainID string 77 networkName string 78 vnicProfileID string 79 baseImage string 80 infraID string 81 masterSpec *v1beta1.OvirtMachineProviderSpec 82 affinityGroups []ovirt.AffinityGroup 83 masterCount int 84 expected []byte 85 }{ 86 { 87 name: "default", 88 auth: Auth{ 89 URL: "https://ovirt-engine.com", 90 Username: "admin", 91 Password: "test", 92 Cafile: "ca-file-content", 93 }, 94 clusterID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 95 storageDomainID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 96 networkName: "ovirt-network", 97 vnicProfileID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 98 baseImage: "some-base-image", 99 infraID: "clusterName-xxxxx", 100 masterSpec: defaultMachineSpec(), 101 affinityGroups: []ovirt.AffinityGroup{{ 102 Name: "controlplane", 103 Priority: 5, 104 Description: "AffinityGroup for spreading each control plane machines to a different host", 105 Enforcing: true, 106 }, { 107 Name: "compute", 108 Priority: 3, 109 Description: "AffinityGroup for spreading each compute machine to a different host", 110 Enforcing: true, 111 }}, 112 masterCount: 3, 113 expected: []byte(defaultTerraformOvirtVarsJSON), 114 }, 115 } 116 for _, tc := range cases { 117 t.Run(tc.name, func(t *testing.T) { 118 tfVar, err := TFVars( 119 tc.auth, tc.clusterID, tc.storageDomainID, tc.networkName, 120 tc.vnicProfileID, tc.baseImage, tc.infraID, tc.masterSpec, 121 tc.affinityGroups) 122 if err != nil { 123 t.Fatalf("failed during test case %s: %v", tc.name, err) 124 } 125 assert.JSONEq(t, string(tc.expected), string(tfVar), "unexpected ovirt-specific Terraform variables file") 126 }) 127 } 128 }