Skip to content

Commit 3e9b85c

Browse files
authored
xds/internal/server: stop using a fake xDS client in listenerWrapper tests (#6700)
1 parent c76442c commit 3e9b85c

File tree

8 files changed

+346
-398
lines changed

8 files changed

+346
-398
lines changed

internal/testutils/xds/e2e/clientresources.go

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,48 @@ func marshalAny(m proto.Message) *anypb.Any {
137137
return a
138138
}
139139

140-
// DefaultServerListener returns a basic xds Listener resource to be used on
141-
// the server side.
142-
func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3listenerpb.Listener {
140+
// DefaultServerListener returns a basic xds Listener resource to be used on the
141+
// server side. The returned Listener resource contains an inline route
142+
// configuration with the name of routeName.
143+
func DefaultServerListener(host string, port uint32, secLevel SecurityLevel, routeName string) *v3listenerpb.Listener {
144+
return defaultServerListenerCommon(host, port, secLevel, routeName, true)
145+
}
146+
147+
func defaultServerListenerCommon(host string, port uint32, secLevel SecurityLevel, routeName string, inlineRouteConfig bool) *v3listenerpb.Listener {
148+
var hcm *v3httppb.HttpConnectionManager
149+
if inlineRouteConfig {
150+
hcm = &v3httppb.HttpConnectionManager{
151+
RouteSpecifier: &v3httppb.HttpConnectionManager_RouteConfig{
152+
RouteConfig: &v3routepb.RouteConfiguration{
153+
Name: routeName,
154+
VirtualHosts: []*v3routepb.VirtualHost{{
155+
// This "*" string matches on any incoming authority. This is to ensure any
156+
// incoming RPC matches to Route_NonForwardingAction and will proceed as
157+
// normal.
158+
Domains: []string{"*"},
159+
Routes: []*v3routepb.Route{{
160+
Match: &v3routepb.RouteMatch{
161+
PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/"},
162+
},
163+
Action: &v3routepb.Route_NonForwardingAction{},
164+
}}}}},
165+
},
166+
HttpFilters: []*v3httppb.HttpFilter{RouterHTTPFilter},
167+
}
168+
} else {
169+
hcm = &v3httppb.HttpConnectionManager{
170+
RouteSpecifier: &v3httppb.HttpConnectionManager_Rds{
171+
Rds: &v3httppb.Rds{
172+
ConfigSource: &v3corepb.ConfigSource{
173+
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{Ads: &v3corepb.AggregatedConfigSource{}},
174+
},
175+
RouteConfigName: routeName,
176+
},
177+
},
178+
HttpFilters: []*v3httppb.HttpFilter{RouterHTTPFilter},
179+
}
180+
}
181+
143182
var tlsContext *v3tlspb.DownstreamTlsContext
144183
switch secLevel {
145184
case SecurityLevelNone:
@@ -212,27 +251,8 @@ func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3
212251
},
213252
Filters: []*v3listenerpb.Filter{
214253
{
215-
Name: "filter-1",
216-
ConfigType: &v3listenerpb.Filter_TypedConfig{
217-
TypedConfig: marshalAny(&v3httppb.HttpConnectionManager{
218-
RouteSpecifier: &v3httppb.HttpConnectionManager_RouteConfig{
219-
RouteConfig: &v3routepb.RouteConfiguration{
220-
Name: "routeName",
221-
VirtualHosts: []*v3routepb.VirtualHost{{
222-
// This "*" string matches on any incoming authority. This is to ensure any
223-
// incoming RPC matches to Route_NonForwardingAction and will proceed as
224-
// normal.
225-
Domains: []string{"*"},
226-
Routes: []*v3routepb.Route{{
227-
Match: &v3routepb.RouteMatch{
228-
PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/"},
229-
},
230-
Action: &v3routepb.Route_NonForwardingAction{},
231-
}}}}},
232-
},
233-
HttpFilters: []*v3httppb.HttpFilter{RouterHTTPFilter},
234-
}),
235-
},
254+
Name: "filter-1",
255+
ConfigType: &v3listenerpb.Filter_TypedConfig{TypedConfig: marshalAny(hcm)},
236256
},
237257
},
238258
TransportSocket: ts,
@@ -260,27 +280,8 @@ func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3
260280
},
261281
Filters: []*v3listenerpb.Filter{
262282
{
263-
Name: "filter-1",
264-
ConfigType: &v3listenerpb.Filter_TypedConfig{
265-
TypedConfig: marshalAny(&v3httppb.HttpConnectionManager{
266-
RouteSpecifier: &v3httppb.HttpConnectionManager_RouteConfig{
267-
RouteConfig: &v3routepb.RouteConfiguration{
268-
Name: "routeName",
269-
VirtualHosts: []*v3routepb.VirtualHost{{
270-
// This "*" string matches on any incoming authority. This is to ensure any
271-
// incoming RPC matches to Route_NonForwardingAction and will proceed as
272-
// normal.
273-
Domains: []string{"*"},
274-
Routes: []*v3routepb.Route{{
275-
Match: &v3routepb.RouteMatch{
276-
PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/"},
277-
},
278-
Action: &v3routepb.Route_NonForwardingAction{},
279-
}}}}},
280-
},
281-
HttpFilters: []*v3httppb.HttpFilter{RouterHTTPFilter},
282-
}),
283-
},
283+
Name: "filter-1",
284+
ConfigType: &v3listenerpb.Filter_TypedConfig{TypedConfig: marshalAny(hcm)},
284285
},
285286
},
286287
TransportSocket: ts,
@@ -289,6 +290,13 @@ func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3
289290
}
290291
}
291292

293+
// DefaultServerListenerWithRouteConfigName returns a basic xds Listener
294+
// resource to be used on the server side. The returned Listener resource
295+
// contains a RouteCongiguration resource name that needs to be resolved.
296+
func DefaultServerListenerWithRouteConfigName(host string, port uint32, secLevel SecurityLevel, routeName string) *v3listenerpb.Listener {
297+
return defaultServerListenerCommon(host, port, secLevel, routeName, false)
298+
}
299+
292300
// HTTPFilter constructs an xds HttpFilter with the provided name and config.
293301
func HTTPFilter(name string, config proto.Message) *v3httppb.HttpFilter {
294302
return &v3httppb.HttpFilter{

test/xds/xds_client_ignore_resource_deletion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func resourceWithListenerForGRPCServer(t *testing.T, nodeID string) (e2e.UpdateO
337337
if err != nil {
338338
t.Fatalf("Failed to retrieve host and port of listener at %q: %v", lis.Addr(), err)
339339
}
340-
listener := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone)
340+
listener := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone, "routeName")
341341
resources := e2e.UpdateOptions{
342342
NodeID: nodeID,
343343
Listeners: []*listenerpb.Listener{listener},

test/xds/xds_security_config_nack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (s) TestUnmarshalListener_WithUpdateValidatorFunc(t *testing.T) {
169169
})
170170

171171
// Create an inbound xDS listener resource for the server side.
172-
inboundLis := e2e.DefaultServerListener(host, port, e2e.SecurityLevelMTLS)
172+
inboundLis := e2e.DefaultServerListener(host, port, e2e.SecurityLevelMTLS, "routeName")
173173
for _, fc := range inboundLis.GetFilterChains() {
174174
fc.TransportSocket = test.securityConfig
175175
}

test/xds/xds_server_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (s) TestServerSideXDS_Fallback(t *testing.T) {
153153
// Create an inbound xDS listener resource for the server side that does not
154154
// contain any security configuration. This should force the server-side
155155
// xdsCredentials to use fallback.
156-
inboundLis := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone)
156+
inboundLis := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone, "routeName")
157157
resources.Listeners = append(resources.Listeners, inboundLis)
158158

159159
// Setup the management server with client and server-side resources.
@@ -238,7 +238,7 @@ func (s) TestServerSideXDS_FileWatcherCerts(t *testing.T) {
238238
// Create an inbound xDS listener resource for the server side that
239239
// contains security configuration pointing to the file watcher
240240
// plugin.
241-
inboundLis := e2e.DefaultServerListener(host, port, test.secLevel)
241+
inboundLis := e2e.DefaultServerListener(host, port, test.secLevel, "routeName")
242242
resources.Listeners = append(resources.Listeners, inboundLis)
243243

244244
// Setup the management server with client and server resources.
@@ -306,7 +306,7 @@ func (s) TestServerSideXDS_SecurityConfigChange(t *testing.T) {
306306
// Create an inbound xDS listener resource for the server side that does not
307307
// contain any security configuration. This should force the xDS credentials
308308
// on server to use its fallback.
309-
inboundLis := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone)
309+
inboundLis := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone, "routeName")
310310
resources.Listeners = append(resources.Listeners, inboundLis)
311311

312312
// Setup the management server with client and server-side resources.
@@ -360,7 +360,7 @@ func (s) TestServerSideXDS_SecurityConfigChange(t *testing.T) {
360360
Port: port,
361361
SecLevel: e2e.SecurityLevelMTLS,
362362
})
363-
inboundLis = e2e.DefaultServerListener(host, port, e2e.SecurityLevelMTLS)
363+
inboundLis = e2e.DefaultServerListener(host, port, e2e.SecurityLevelMTLS, "routeName")
364364
resources.Listeners = append(resources.Listeners, inboundLis)
365365
if err := managementServer.Update(ctx, resources); err != nil {
366366
t.Fatal(err)

test/xds/xds_server_serving_mode_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (s) TestServerSideXDS_RedundantUpdateSuppression(t *testing.T) {
7575
if err != nil {
7676
t.Fatalf("failed to retrieve host and port of server: %v", err)
7777
}
78-
listener := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone)
78+
listener := e2e.DefaultServerListener(host, port, e2e.SecurityLevelNone, "routeName")
7979
resources := e2e.UpdateOptions{
8080
NodeID: nodeID,
8181
Listeners: []*v3listenerpb.Listener{listener},
@@ -221,12 +221,12 @@ func (s) TestServerSideXDS_ServingModeChanges(t *testing.T) {
221221
if err != nil {
222222
t.Fatalf("failed to retrieve host and port of server: %v", err)
223223
}
224-
listener1 := e2e.DefaultServerListener(host1, port1, e2e.SecurityLevelNone)
224+
listener1 := e2e.DefaultServerListener(host1, port1, e2e.SecurityLevelNone, "routeName")
225225
host2, port2, err := hostPortFromListener(lis2)
226226
if err != nil {
227227
t.Fatalf("failed to retrieve host and port of server: %v", err)
228228
}
229-
listener2 := e2e.DefaultServerListener(host2, port2, e2e.SecurityLevelNone)
229+
listener2 := e2e.DefaultServerListener(host2, port2, e2e.SecurityLevelNone, "routeName")
230230
resources := e2e.UpdateOptions{
231231
NodeID: nodeID,
232232
Listeners: []*v3listenerpb.Listener{listener1, listener2},

0 commit comments

Comments
 (0)