Skip to content

Commit 228a102

Browse files
committedJan 15, 2025·
vcsim: fix lookup service deferred registration
With this change, List() can be called withing having called RetrieveServiceContent() Signed-off-by: Doug MacEachern <dougm@broadcom.com>
1 parent d7fe78d commit 228a102

File tree

4 files changed

+37
-79
lines changed

4 files changed

+37
-79
lines changed
 

‎lookup/simulator/example_test.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2020 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package simulator_test
186

‎lookup/simulator/registration_info.go

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018-2023 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package simulator
186

@@ -31,10 +19,11 @@ var (
3119

3220
// registrationInfo returns a ServiceRegistration populated with vcsim's OptionManager settings.
3321
// The complete list can be captured using: govc sso.service.ls -dump
34-
func registrationInfo() []types.LookupServiceRegistrationInfo {
35-
vc := simulator.Map.Get(vim25.ServiceInstance).(*simulator.ServiceInstance)
36-
setting := simulator.Map.OptionManager().Setting
37-
sm := simulator.Map.SessionManager()
22+
func registrationInfo(ctx *simulator.Context) []types.LookupServiceRegistrationInfo {
23+
vctx := ctx.For(vim25.Path)
24+
vc := vctx.Map.Get(vim25.ServiceInstance).(*simulator.ServiceInstance)
25+
setting := vctx.Map.OptionManager().Setting
26+
sm := vctx.Map.SessionManager()
3827
opts := make(map[string]string, len(setting))
3928

4029
for _, o := range setting {

‎lookup/simulator/simulator.go

+23-30
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package simulator
186

@@ -52,12 +40,10 @@ func New() *simulator.Registry {
5240
r.Put(&ServiceInstance{
5341
ManagedObjectReference: lookup.ServiceInstance,
5442
Content: content,
55-
register: func() {
56-
r.Put(&ServiceRegistration{
57-
ManagedObjectReference: *content.ServiceRegistration,
58-
Info: registrationInfo(),
59-
})
60-
},
43+
})
44+
45+
r.Put(&ServiceRegistration{
46+
ManagedObjectReference: *content.ServiceRegistration,
6147
})
6248

6349
return r
@@ -67,15 +53,11 @@ type ServiceInstance struct {
6753
vim.ManagedObjectReference
6854

6955
Content types.LookupServiceContent
70-
71-
instance sync.Once
72-
register func()
7356
}
7457

75-
func (s *ServiceInstance) RetrieveServiceContent(_ *types.RetrieveServiceContent) soap.HasFault {
76-
// defer register to this point to ensure we can include vcsim's cert in ServiceEndpoints.SslTrust
77-
// TODO: we should be able to register within New(), but this is the only place that currently depends on vcsim's cert.
78-
s.instance.Do(s.register)
58+
func (s *ServiceInstance) RetrieveServiceContent(ctx *simulator.Context, _ *types.RetrieveServiceContent) soap.HasFault {
59+
// Initialize prior to List() being called (see ExampleServiceRegistration)
60+
ctx.Map.Get(*content.ServiceRegistration).(*ServiceRegistration).info(ctx)
7961

8062
return &methods.RetrieveServiceContentBody{
8163
Res: &types.RetrieveServiceContentResponse{
@@ -88,6 +70,8 @@ type ServiceRegistration struct {
8870
vim.ManagedObjectReference
8971

9072
Info []types.LookupServiceRegistrationInfo
73+
74+
register sync.Once
9175
}
9276

9377
func (s *ServiceRegistration) GetSiteId(_ *types.GetSiteId) soap.HasFault {
@@ -130,7 +114,16 @@ func matchEndpointType(filter, info *types.LookupServiceRegistrationEndpointType
130114
return true
131115
}
132116

133-
func (s *ServiceRegistration) List(req *types.List) soap.HasFault {
117+
// defer register to this point to ensure we can include vcsim's cert in ServiceEndpoints.SslTrust
118+
// TODO: we should be able to register within New(), but this is the only place that currently depends on vcsim's cert
119+
func (s *ServiceRegistration) info(ctx *simulator.Context) []types.LookupServiceRegistrationInfo {
120+
s.register.Do(func() {
121+
s.Info = registrationInfo(ctx)
122+
})
123+
return s.Info
124+
}
125+
126+
func (s *ServiceRegistration) List(ctx *simulator.Context, req *types.List) soap.HasFault {
134127
body := new(methods.ListBody)
135128
filter := req.FilterCriteria
136129

@@ -143,7 +136,7 @@ func (s *ServiceRegistration) List(req *types.List) soap.HasFault {
143136
}
144137
body.Res = new(types.ListResponse)
145138

146-
for _, info := range s.Info {
139+
for _, info := range s.info(ctx) {
147140
if filter.SiteId != "" {
148141
if filter.SiteId != info.SiteId {
149142
continue

‎lookup/simulator/simulator_test.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package simulator
186

0 commit comments

Comments
 (0)
Please sign in to comment.