Skip to content

Commit c0bb153

Browse files
authored
vSphere resource pool test (#740)
* Add vsphere resource pool unit test * Add vsphere e2e scenario with resource pool and improve scenario matcher * Add prow job for vsphere resource pool provisioning * Fix rebase issue
1 parent 8ab8325 commit c0bb153

File tree

5 files changed

+248
-103
lines changed

5 files changed

+248
-103
lines changed

.prow.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,28 @@ presubmits:
484484
memory: 1Gi
485485
cpu: 500m
486486

487+
- name: pull-machine-controller-e2e-vsphere-resource-pool
488+
always_run: true
489+
decorate: true
490+
error_on_eviction: true
491+
clone_uri: "ssh://[email protected]/kubermatic/machine-controller.git"
492+
labels:
493+
preset-vsphere: "true"
494+
preset-rhel: "true"
495+
preset-hetzner: "true"
496+
preset-e2e-ssh: "true"
497+
spec:
498+
containers:
499+
- image: golang:1.13.8
500+
command:
501+
- "./hack/ci-e2e-test.sh"
502+
args:
503+
- "TestVsphereResourcePoolProvisioningE2E"
504+
resources:
505+
requests:
506+
memory: 1Gi
507+
cpu: 500m
508+
487509
postsubmits:
488510
- name: ci-push-machine-controller-image
489511
always_run: true

pkg/cloudprovider/provider/vsphere/helper_test.go

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ package vsphere
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"log"
2322
"strings"
2423
"testing"
2524
"time"
2625

26+
"github.com/vmware/govmomi/object"
2727
"github.com/vmware/govmomi/simulator"
2828
"github.com/vmware/govmomi/vim25/methods"
2929
"github.com/vmware/govmomi/vim25/soap"
3030
"github.com/vmware/govmomi/vim25/types"
3131
)
3232

33-
func Test_resolveDatastoreRef(t *testing.T) {
33+
func TestResolveDatastoreRef(t *testing.T) {
3434
tests := []struct {
3535
name string
3636
config *Config
@@ -112,7 +112,6 @@ func Test_resolveDatastoreRef(t *testing.T) {
112112
t.Fatalf("error getting virtual machines: %v", err)
113113
}
114114

115-
fmt.Printf("%s with %d hosts", session.Client.Client.ServiceContent.About.ApiType, model.Count().Host)
116115
got, err := resolveDatastoreRef(ctx, tt.config, session, vms[2], vmFolder, &types.VirtualMachineCloneSpec{})
117116
if (err != nil) != tt.wantErr {
118117
t.Errorf("resolveDatastoreRef() error = %v, wantErr %v", err, tt.wantErr)
@@ -159,3 +158,88 @@ func (c *CustomStorageResourceManager) RecommendDatastores(req *types.RecommendD
159158
body.Res = res
160159
return body
161160
}
161+
162+
func TestResolveResourcePoolRef(t *testing.T) {
163+
tests := []struct {
164+
name string
165+
config *Config
166+
wantErr bool
167+
wantResourcePool bool
168+
expectedResourcePool string
169+
}{
170+
{
171+
name: "No Resource Pool specified",
172+
config: &Config{},
173+
wantErr: false,
174+
wantResourcePool: false,
175+
},
176+
{
177+
name: "Resource Pool specified",
178+
config: &Config{
179+
ResourcePool: "DC0_C0_RP1",
180+
},
181+
wantErr: false,
182+
wantResourcePool: true,
183+
expectedResourcePool: "DC0_C0_RP1",
184+
},
185+
{
186+
name: "Resource Pool specified missing",
187+
config: &Config{
188+
ResourcePool: "DC0_C0_RP1_WRONG",
189+
},
190+
wantErr: true,
191+
wantResourcePool: false,
192+
},
193+
}
194+
for _, tt := range tests {
195+
t.Run(tt.name, func(t *testing.T) {
196+
ctx := context.Background()
197+
198+
model := simulator.VPX()
199+
model.Pool++
200+
model.Cluster++
201+
202+
defer model.Remove()
203+
err := model.Create()
204+
if err != nil {
205+
log.Fatal(err)
206+
}
207+
208+
s := model.Service.NewServer()
209+
defer s.Close()
210+
211+
// Setup config to be able to login to the simulator
212+
// Remove trailing `/sdk` as it is appended by the session constructor
213+
tt.config.VSphereURL = strings.TrimSuffix(s.URL.String(), "/sdk")
214+
tt.config.Username = simulator.DefaultLogin.Username()
215+
tt.config.Password, _ = simulator.DefaultLogin.Password()
216+
tt.config.Datacenter = "DC0"
217+
218+
session, err := NewSession(ctx, tt.config)
219+
defer session.Logout()
220+
if err != nil {
221+
t.Fatalf("error creating session: %v", err)
222+
}
223+
224+
// Obtain a VM from the simulator
225+
obj := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
226+
vm := object.NewVirtualMachine(session.Client.Client, obj.Reference())
227+
228+
got, err := resolveResourcePoolRef(ctx, tt.config, session, vm)
229+
if (err != nil) != tt.wantErr {
230+
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
231+
return
232+
}
233+
if tt.wantResourcePool != (got != nil) {
234+
t.Errorf("resourcePool = %v, wantResourcePool %v", got, tt.wantResourcePool)
235+
}
236+
if tt.wantResourcePool {
237+
rp := object.NewResourcePool(session.Client.Client, got.Reference())
238+
n, _ := rp.ObjectName(ctx)
239+
if e, a := tt.expectedResourcePool, n; e != a {
240+
t.Errorf("expected resource pool %v but got %+v", e, a)
241+
}
242+
}
243+
})
244+
}
245+
}

0 commit comments

Comments
 (0)