28
28
from absl .testing import absltest
29
29
from google .protobuf import json_format
30
30
import grpc
31
+ from typing_extensions import TypeAlias
31
32
32
33
from framework import xds_flags
33
34
from framework import xds_k8s_flags
68
69
ClientDeploymentArgs = k8s_xds_client_runner .ClientDeploymentArgs
69
70
KubernetesServerRunner = k8s_xds_server_runner .KubernetesServerRunner
70
71
KubernetesClientRunner = k8s_xds_client_runner .KubernetesClientRunner
72
+ TestConfig : TypeAlias = skips .TestConfig
73
+ Lang : TypeAlias = skips .Lang
71
74
_LoadBalancerStatsResponse = grpc_testing .LoadBalancerStatsResponse
72
75
_LoadBalancerAccumulatedStatsResponse = (
73
76
grpc_testing .LoadBalancerAccumulatedStatsResponse
89
92
_TD_CONFIG_MAX_WAIT_SEC : Final [int ] = int (TD_CONFIG_MAX_WAIT .total_seconds ())
90
93
91
94
92
- def evaluate_test_config (
93
- check : Callable [[skips .TestConfig ], bool ]
94
- ) -> skips .TestConfig :
95
- """Evaluates the test config check against Abseil flags.
95
+ def parse_lang_spec_from_flags () -> TestConfig :
96
+ test_config = TestConfig (
97
+ client_lang = skips .get_lang (xds_k8s_flags .CLIENT_IMAGE .value ),
98
+ server_lang = skips .get_lang (xds_k8s_flags .SERVER_IMAGE .value ),
99
+ version = xds_flags .TESTING_VERSION .value ,
100
+ )
101
+ logger .info ("Detected language and version: %s" , test_config )
102
+ return test_config
96
103
97
- TODO(sergiitk): split into parse_lang_spec and check_is_supported.
98
- """
104
+
105
+ def evaluate_is_supported (
106
+ test_config : TestConfig , is_supported_fn : Callable [[TestConfig ], bool ]
107
+ ):
108
+ """Evaluates the suite-specific is_supported against the test_config."""
99
109
# NOTE(lidiz) a manual skip mechanism is needed because absl/flags
100
110
# cannot be used in the built-in test-skipping decorators. See the
101
111
# official FAQs:
102
112
# https://abseil.io/docs/python/guides/flags#faqs
103
- test_config = skips .TestConfig (
104
- client_lang = skips .get_lang (xds_k8s_flags .CLIENT_IMAGE .value ),
105
- server_lang = skips .get_lang (xds_k8s_flags .SERVER_IMAGE .value ),
106
- version = xds_flags .TESTING_VERSION .value ,
107
- )
108
- if not check (test_config ):
113
+ if not is_supported_fn (test_config ):
109
114
logger .info ("Skipping %s" , test_config )
110
115
raise absltest .SkipTest (f"Unsupported test config: { test_config } " )
111
116
112
- logger .info ("Detected language and version: %s" , test_config )
113
- return test_config
114
-
115
117
116
118
class TdPropagationRetryableError (Exception ):
117
119
"""Indicates that TD config hasn't propagated yet, and it's safe to retry"""
118
120
119
121
120
122
class XdsKubernetesBaseTestCase (base_testcase .BaseTestCase ):
121
- lang_spec : skips . TestConfig
123
+ lang_spec : TestConfig
122
124
client_namespace : str
123
125
client_runner : KubernetesClientRunner
124
126
ensure_firewall : bool = False
@@ -151,7 +153,7 @@ class XdsKubernetesBaseTestCase(base_testcase.BaseTestCase):
151
153
enable_dualstack : bool = False
152
154
153
155
@staticmethod
154
- def is_supported (config : skips . TestConfig ) -> bool :
156
+ def is_supported (config : TestConfig ) -> bool :
155
157
"""Overridden by the test class to decide if the config is supported.
156
158
157
159
Returns:
@@ -168,9 +170,20 @@ def setUpClass(cls):
168
170
logger .info ("----- Testing %s -----" , cls .__name__ )
169
171
logger .info ("Logs timezone: %s" , time .localtime ().tm_zone )
170
172
173
+ lang_spec = parse_lang_spec_from_flags ()
174
+
175
+ # Currently it's possible to lang_spec.server_lang to be out of sync
176
+ # with the server_image when a test_suite overrides the server_image
177
+ # at the end of its setUpClass().
178
+ # A common example is overriding the server image to canonical.
179
+ # This can be fixed by moving server image overrides to its own
180
+ # class method and re-parsing the lang spec.
181
+ # TODO(sergiitk): provide custom server_image_override(TestConfig)
182
+
171
183
# Raises unittest.SkipTest if given client/server/version does not
172
184
# support current test case.
173
- cls .lang_spec = evaluate_test_config (cls .is_supported )
185
+ evaluate_is_supported (lang_spec , cls .is_supported )
186
+ cls .lang_spec = lang_spec
174
187
175
188
# Must be called before KubernetesApiManager or GcpApiManager init.
176
189
xds_flags .set_socket_default_timeout_from_flag ()
0 commit comments