@@ -18,13 +18,14 @@ Implement the Proxy Verifier test server extension.
1818# limitations under the License.
1919
2020import os
21+
2122from ports import get_port
22- from verifier_common import create_address_argument
23+ from verifier_common import create_address_argument, substitute_context_in_replay_file
2324
2425
2526def _configure_server(obj, process, name, replay_path, http_ports=None, https_ports=None,
2627 http3_ports=None, ssl_cert='', ca_cert='', verbose=True,
27- other_args=''):
28+ other_args='', context=None ):
2829 """
2930 Configure the provided process to run a verifier-server command.
3031
@@ -119,8 +120,13 @@ def _configure_server(obj, process, name, replay_path, http_ports=None, https_po
119120 command += ' --ca-certs "{}" '.format(run_ca_cert)
120121
121122 if replay_path:
122- # Create a copy of the replay directory in the run directory.
123+ if context:
124+ # replace the passed replay file with the new one generated using the passed
125+ # context
126+ replay_path = substitute_context_in_replay_file(process, replay_path, context)
127+
123128 run_replay_path = os.path.join(server_dir, os.path.basename(replay_path))
129+ # Create a copy of the replay directory in the run directory.
124130 process.Setup.Copy(replay_path, run_replay_path, CopyLogic.SoftFiles)
125131 command += "{} ".format(run_replay_path)
126132
@@ -141,7 +147,7 @@ def _configure_server(obj, process, name, replay_path, http_ports=None, https_po
141147
142148def MakeVerifierServerProcess(test, name, replay_path, http_ports=None,
143149 https_ports=None, http3_ports=None, ssl_cert='',
144- ca_cert='', verbose=True, other_args=''):
150+ ca_cert='', verbose=True, other_args='', context=None ):
145151 """
146152 Create a verifier-server process for the Test.
147153
@@ -174,19 +180,30 @@ def MakeVerifierServerProcess(test, name, replay_path, http_ports=None,
174180
175181 other_args: (str) Any other arbitrary options to pass to verifier-server.
176182
183+ context: Any dictionary-like object with keys that match the placeholders
184+ in the replay file.
185+ Template strings support $-based substitutions in the
186+ replay file.
187+ You can refer to https://docs.python.org/3/library/string.html#template-strings
188+ for more information how to add template strings to the replay file.
177189 Raises:
178190 ValueError if https_ports is non-empty and a valid ssl_cert could not
179191 be derived.
192+ If context substitution is expected to be done but a directory is passed as a
193+ replay_path.
194+ OSError in case of any issues related to I/O error, ie: File Not found for the replay
195+ file when a context substitution is expected.
196+ KeyError if placeholders are missing from the mapping between context and the replay file.
180197 """
181198 server = test.Processes.Process(name)
182199 _configure_server(test, server, name, replay_path, http_ports, https_ports,
183- http3_ports, ssl_cert, ca_cert, verbose, other_args)
200+ http3_ports, ssl_cert, ca_cert, verbose, other_args, context )
184201 return server
185202
186203
187204def AddVerifierServerProcess(run, name, replay_path, http_ports=None,
188205 https_ports=None, http3_ports=None, ssl_cert='',
189- ca_cert='', verbose=True, other_args=''):
206+ ca_cert='', verbose=True, other_args='', context=None ):
190207 """
191208 Create a verifier-server process and configure it for the given TestRun.
192209
@@ -201,7 +218,7 @@ def AddVerifierServerProcess(run, name, replay_path, http_ports=None,
201218
202219 server = run.Processes.Process(name)
203220 _configure_server(run, server, name, replay_path, http_ports, https_ports,
204- http3_ports, ssl_cert, ca_cert, verbose, other_args)
221+ http3_ports, ssl_cert, ca_cert, verbose, other_args, context )
205222
206223 client = run.Processes.Default
207224 client.StartBefore(server)
0 commit comments