github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/adminvdc_nsxt_test.go (about) 1 //go:build org || functional || nsxt || ALL 2 3 /* 4 * Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. 5 */ 6 7 package govcd 8 9 // This file tests out NSX-T related Org VDC capabilities 10 11 import ( 12 "fmt" 13 14 "github.com/vmware/go-vcloud-director/v2/types/v56" 15 . "gopkg.in/check.v1" 16 ) 17 18 func (vcd *TestVCD) Test_CreateNsxtOrgVdc(check *C) { 19 if vcd.skipAdminTests { 20 check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) 21 } 22 23 skipNoNsxtConfiguration(vcd, check) 24 25 adminOrg, err := vcd.client.GetAdminOrgByName(vcd.org.Org.Name) 26 check.Assert(err, IsNil) 27 check.Assert(adminOrg, NotNil) 28 29 pVdcs, err := QueryProviderVdcByName(vcd.client, vcd.config.VCD.NsxtProviderVdc.Name) 30 check.Assert(err, IsNil) 31 32 if len(pVdcs) == 0 { 33 check.Skip(fmt.Sprintf("No NSX-T Provider VDC found with name '%s'", vcd.config.VCD.NsxtProviderVdc.Name)) 34 } 35 providerVdcHref := pVdcs[0].HREF 36 37 pvdcStorageProfile, err := vcd.client.QueryProviderVdcStorageProfileByName(vcd.config.VCD.NsxtProviderVdc.StorageProfile, providerVdcHref) 38 39 check.Assert(err, IsNil) 40 providerVdcStorageProfileHref := pvdcStorageProfile.HREF 41 42 networkPools, err := QueryNetworkPoolByName(vcd.client, vcd.config.VCD.NsxtProviderVdc.NetworkPool) 43 check.Assert(err, IsNil) 44 if len(networkPools) == 0 { 45 check.Skip(fmt.Sprintf("No network pool found with name '%s'", vcd.config.VCD.NsxtProviderVdc.NetworkPool)) 46 } 47 48 networkPoolHref := networkPools[0].HREF 49 50 allocationModels := []string{"AllocationVApp", "AllocationPool", "ReservationPool", "Flex"} 51 trueValue := true 52 for i, allocationModel := range allocationModels { 53 vdcConfiguration := &types.VdcConfiguration{ 54 Name: fmt.Sprintf("%s%d", "TestNsxtVdc", i), 55 Xmlns: types.XMLNamespaceVCloud, 56 AllocationModel: allocationModel, 57 ComputeCapacity: []*types.ComputeCapacity{ 58 &types.ComputeCapacity{ 59 CPU: &types.CapacityWithUsage{ 60 Units: "MHz", 61 Allocated: 1024, 62 Limit: 1024, 63 }, 64 Memory: &types.CapacityWithUsage{ 65 Allocated: 1024, 66 Limit: 1024, 67 }, 68 }, 69 }, 70 VdcStorageProfile: []*types.VdcStorageProfileConfiguration{&types.VdcStorageProfileConfiguration{ 71 Enabled: addrOf(true), 72 Units: "MB", 73 Limit: 1024, 74 Default: true, 75 ProviderVdcStorageProfile: &types.Reference{ 76 HREF: providerVdcStorageProfileHref, 77 }, 78 }, 79 }, 80 NetworkPoolReference: &types.Reference{ 81 HREF: networkPoolHref, 82 }, 83 ProviderVdcReference: &types.Reference{ 84 HREF: providerVdcHref, 85 }, 86 IsEnabled: true, 87 IsThinProvision: true, 88 UsesFastProvisioning: true, 89 } 90 91 if allocationModel == "Flex" { 92 vdcConfiguration.IsElastic = &trueValue 93 vdcConfiguration.IncludeMemoryOverhead = &trueValue 94 } 95 96 vdc, _ := adminOrg.GetVDCByName(vdcConfiguration.Name, false) 97 if vdc != nil { 98 err = vdc.DeleteWait(true, true) 99 check.Assert(err, IsNil) 100 } 101 102 // expected to fail due to missing value 103 task, err := adminOrg.CreateOrgVdcAsync(vdcConfiguration) 104 check.Assert(err, Not(IsNil)) 105 check.Assert(task, Equals, Task{}) 106 // checks function validation 107 check.Assert(err.Error(), Equals, "VdcConfiguration missing required field: ComputeCapacity[0].Memory.Units") 108 109 vdcConfiguration.ComputeCapacity[0].Memory.Units = "MB" 110 111 vdc, err = adminOrg.CreateOrgVdc(vdcConfiguration) 112 check.Assert(vdc, NotNil) 113 check.Assert(err, IsNil) 114 115 AddToCleanupList(vdcConfiguration.Name, "vdc", vcd.org.Org.Name, check.TestName()) 116 117 adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, true) 118 check.Assert(err, IsNil) 119 check.Assert(vdc, NotNil) 120 check.Assert(vdc.Vdc.Name, Equals, vdcConfiguration.Name) 121 check.Assert(vdc.Vdc.IsEnabled, Equals, vdcConfiguration.IsEnabled) 122 check.Assert(vdc.Vdc.AllocationModel, Equals, vdcConfiguration.AllocationModel) 123 check.Assert(len(adminVdc.AdminVdc.ResourcePoolRefs.VimObjectRef) > 0, Equals, true) 124 125 // Test update 126 adminVdc.AdminVdc.Description = "updated-description" + check.TestName() 127 updatedAdminVdc, err := adminVdc.Update() 128 check.Assert(err, IsNil) 129 check.Assert(updatedAdminVdc.AdminVdc, Equals, adminVdc.AdminVdc) 130 131 err = vdc.DeleteWait(true, true) 132 check.Assert(err, IsNil) 133 134 vdc, err = adminOrg.GetVDCByName(vdcConfiguration.Name, true) 135 check.Assert(err, NotNil) 136 check.Assert(vdc, IsNil) 137 } 138 }