Skip to content

Commit a0f4cf5

Browse files
authored
remap_reload.test.py: fix override warnings (#12640)
remap_reload.test.py updates the remap.config file and issues a `traffic_ctl config reload` to dynamically integrate those changes into the running ATS process. Before this patch, this was done via creating a new tr.Disk.File() object and writing to it. But this resulted in warnings for overriding the already existing remap.config Disk.File from the setup of the ATS process in the first place. This transitions the test to modify the file via a Setup function instead. This achieves the same result without alarming the autest framework about the conflicting Disk.File object. This patch cleans up these warnings: ``` ╰─➤ ./autest.sh --sandbox /tmp/sb --clean=none -f remap_reload Running Test remap_reload:Warning: Overriding file object /tmp/sb/remap_reload/ts/config/remap.config Warning: Overriding file object /tmp/sb/remap_reload/ts/config/remap.config ........ Passed ``
1 parent 69d1c79 commit a0f4cf5

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

tests/gold_tests/remap/remap_reload.test.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
# limitations under the License.
1616
import os
1717

18+
19+
def update_remap_config(path: str, lines: list) -> None:
20+
"""Update the remap.config file.
21+
22+
This is used to update the config file between test runs without
23+
triggering framework warnings about overriding file objects.
24+
25+
:param path: The path to the remap.config file.
26+
:param lines: The list of lines to write to the file.
27+
"""
28+
with open(path, 'w') as f:
29+
f.write('\n'.join(lines) + '\n')
30+
31+
1832
Test.Summary = '''
1933
Test remap reloading
2034
'''
@@ -54,15 +68,15 @@
5468
tr.AddVerifierClientProcess("client", replay_file_1, http_ports=[tm.Variables.port])
5569

5670
tr = Test.AddTestRun("Change remap.config to have only two lines")
57-
tr.Processes.Default.Env = tm.Env
58-
tr.Processes.Default.Command = 'echo "Change remap.config, two lines"'
59-
tr.Disk.File(remap_cfg_path).WriteOn("")
60-
tr.Disk.File(
61-
remap_cfg_path, typename="ats:config").AddLines(
62-
[
71+
p = tr.Processes.Default
72+
p.Env = tm.Env
73+
p.Command = 'echo "Change remap.config, two lines"'
74+
p.Setup.Lambda(
75+
lambda: update_remap_config(
76+
remap_cfg_path, [
6377
f"map http://alpha.ex http://alpha.ex:{pv_port}",
6478
f"map http://bravo.ex http://bravo.ex:{pv_port}",
65-
])
79+
]))
6680

6781
tr = Test.AddTestRun("remap_config reload, fails")
6882
tr.Processes.Default.Env = tm.Env
@@ -75,18 +89,18 @@
7589
tr.Processes.Default.StartBefore(await_config_reload)
7690

7791
tr = Test.AddTestRun("Change remap.config to have more than three lines")
78-
tr.Processes.Default.Env = tm.Env
79-
tr.Processes.Default.Command = 'echo "Change remap.config, more than three lines"'
80-
tr.Disk.File(remap_cfg_path).WriteOn("")
81-
tr.Disk.File(
82-
remap_cfg_path, typename="ats:config").AddLines(
83-
[
92+
p = tr.Processes.Default
93+
p.Env = tm.Env
94+
p.Command = 'echo "Change remap.config, more than three lines"'
95+
p.Setup.Lambda(
96+
lambda: update_remap_config(
97+
remap_cfg_path, [
8498
f"map http://echo.ex http://echo.ex:{pv_port}",
8599
f"map http://foxtrot.ex http://foxtrot.ex:{pv_port}",
86100
f"map http://golf.ex http://golf.ex:{pv_port}",
87101
f"map http://hotel.ex http://hotel.ex:{pv_port}",
88102
f"map http://india.ex http://india.ex:{pv_port}",
89-
])
103+
]))
90104

91105
tr = Test.AddTestRun("remap_config reload, succeeds")
92106
tr.Processes.Default.Env = tm.Env

0 commit comments

Comments
 (0)