Skip to content

Commit 90183be

Browse files
authored
Merge pull request #2472 from dougm/issue-2440
vcsim: fix panic in QueryPerfCounter method
2 parents 879c4d0 + dff7f6b commit 90183be

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

performance/manager.go

+15
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ func (m *Manager) Query(ctx context.Context, spec []types.PerfQuerySpec) ([]type
271271
return res.Returnval, nil
272272
}
273273

274+
// QueryCounter wraps the QueryPerfCounter method.
275+
func (m *Manager) QueryCounter(ctx context.Context, ids []int32) ([]types.PerfCounterInfo, error) {
276+
req := types.QueryPerfCounter{
277+
This: m.Reference(),
278+
CounterId: ids,
279+
}
280+
281+
res, err := methods.QueryPerfCounter(ctx, m.Client(), &req)
282+
if err != nil {
283+
return nil, err
284+
}
285+
286+
return res.Returnval, nil
287+
}
288+
274289
// SampleByName uses the spec param as a template, constructing a []types.PerfQuerySpec for the given metrics and entities
275290
// and invoking the Query method.
276291
// The spec template can specify instances using the MetricId.Instance field, by default all instances are collected.

simulator/performance_manager.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (m *PerformanceManager) init(r *Registry) {
7878

7979
func (p *PerformanceManager) QueryPerfCounter(ctx *Context, req *types.QueryPerfCounter) soap.HasFault {
8080
body := new(methods.QueryPerfCounterBody)
81-
body.Req = req
81+
body.Res = new(types.QueryPerfCounterResponse)
8282
body.Res.Returnval = make([]types.PerfCounterInfo, len(req.CounterId))
8383
for i, id := range req.CounterId {
8484
if info, ok := p.perfCounterIndex[id]; !ok {
@@ -95,7 +95,6 @@ func (p *PerformanceManager) QueryPerfCounter(ctx *Context, req *types.QueryPerf
9595

9696
func (p *PerformanceManager) QueryPerfProviderSummary(ctx *Context, req *types.QueryPerfProviderSummary) soap.HasFault {
9797
body := new(methods.QueryPerfProviderSummaryBody)
98-
body.Req = req
9998
body.Res = new(types.QueryPerfProviderSummaryResponse)
10099

101100
// The entity must exist
@@ -169,15 +168,13 @@ func (p *PerformanceManager) queryAvailablePerfMetric(entity types.ManagedObject
169168

170169
func (p *PerformanceManager) QueryAvailablePerfMetric(ctx *Context, req *types.QueryAvailablePerfMetric) soap.HasFault {
171170
body := new(methods.QueryAvailablePerfMetricBody)
172-
body.Req = req
173171
body.Res = p.queryAvailablePerfMetric(req.Entity, req.IntervalId)
174172

175173
return body
176174
}
177175

178176
func (p *PerformanceManager) QueryPerf(ctx *Context, req *types.QueryPerf) soap.HasFault {
179177
body := new(methods.QueryPerfBody)
180-
body.Req = req
181178
body.Res = new(types.QueryPerfResponse)
182179
body.Res.Returnval = make([]types.BasePerfEntityMetricBase, len(req.QuerySpec))
183180

simulator/performance_manager_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ func TestQueryAvailablePerfMetric(t *testing.T) {
193193
if len(info) == 0 {
194194
t.Fatal("Expected non-empty list of host")
195195
}
196+
var ids []int32
197+
for i := range info {
198+
ids = append(ids, info[i].CounterId)
199+
}
200+
perf, err := p.QueryCounter(ctx, ids)
201+
if err != nil {
202+
t.Fatal(err)
203+
}
204+
if len(perf) != len(ids) {
205+
t.Errorf("%d counters", len(perf))
206+
}
196207
}
197208

198209
pool := Map.Any("ResourcePool").(*ResourcePool)

0 commit comments

Comments
 (0)