brbzull0 commented on code in PR #13075:
URL: https://github.com/apache/trafficserver/pull/13075#discussion_r3091599667


##########
tests/gold_tests/autest-site/config_reload.test.ext:
##########
@@ -0,0 +1,228 @@
+'''
+AuTest extension for config reload operations.
+
+Provides Test.AddConfigReload() to replace the legacy pattern of
+fire-and-forget `traffic_ctl config reload` followed by log grepping via
+When.FileContains("finished loading", N).
+
+Test.AddConfigReload(ts, ...)
+    Triggers a reload via `traffic_ctl config reload -m` (monitor mode),
+    which blocks until the reload reaches a terminal state (default timeout
+    30s), then optionally validates the task tree via the
+    get_reload_config_status JSONRPC endpoint.
+
+Note: standalone record-triggered reloads (via traffic_ctl config set, with
+no explicit config reload) do not create tasks in the reload framework and
+cannot be verified with this extension.
+'''
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import os
+import jsonrpc
+
+_reload_counter = 0
+
+_EXPECT_EXIT_CODES = {
+    "success": 0,
+    "fail": 2,
+    "timeout": 75,
+}
+
+
+def _next_token():
+    global _reload_counter
+    _reload_counter += 1
+    return f"autest-reload-{_reload_counter}"
+
+
+def _shell_quote(s):
+    """Single-quote a string for shell, escaping embedded single quotes."""
+    return "'" + s.replace("'", "'\\''") + "'"
+
+
+def _task_matches(info, name):
+    """Check if a task matches the given name by description, filename, or 
basename."""
+    for field in ("description", "filename"):
+        val = info.get(field)
+        if not val or val == "<none>":
+            continue
+        if val == name or os.path.basename(val) == name:
+            return True
+    return False
+
+
+def _collect_task_names(info, names=None):
+    """Recursively collect human-friendly task identifiers from the task 
tree."""
+    if names is None:
+        names = set()
+    if isinstance(info, dict):
+        for field in ("description", "filename"):
+            val = info.get(field)
+            if val and val != "<none>":
+                basename = os.path.basename(val)
+                names.add(basename if basename != val else val)
+        for sub in info.get("sub_tasks", []):
+            _collect_task_names(sub, names)
+    return names
+
+
+def _find_task(info, name):
+    """Find a task by description or filename (supports basename matching)."""
+    if isinstance(info, dict):
+        if _task_matches(info, name):
+            return info
+        for sub in info.get("sub_tasks", []):
+            found = _find_task(sub, name)
+            if found:
+                return found
+    return None
+
+
+def _make_task_validator(expect_tasks, expect_absent_tasks):
+    """Build a CustomJSONRPCResponse callback for task validation."""
+
+    def validator(resp):
+        if resp.is_error():
+            return (False, f"RPC error: {resp.error_as_str()}")
+
+        result = resp.__dict__.get("result", {})
+        tasks_list = result.get("tasks", [])
+        if not tasks_list:
+            if expect_tasks:
+                return (False, "No reload tasks in response")
+            if expect_absent_tasks:
+                return (True, "No tasks present, absence confirmed")
+            return (True, "No tasks expected, none found")
+
+        info = tasks_list[0]
+        all_names = _collect_task_names(info)
+
+        if expect_tasks:
+            items = expect_tasks.items() if isinstance(expect_tasks, dict) 
else [(t, None) for t in expect_tasks]
+            for task_name, task_status in items:
+                if task_name not in all_names:
+                    return (False, f"Task '{task_name}' not found in reload. 
Found: {sorted(all_names)}")
+                if task_status is not None:
+                    task = _find_task(info, task_name)
+                    actual = task.get("status", "unknown") if task else 
"unknown"
+                    if actual != task_status:
+                        return (False, f"Task '{task_name}' status is 
'{actual}', expected '{task_status}'")
+
+        if expect_absent_tasks:
+            for task_name in expect_absent_tasks:
+                if task_name in all_names:

Review Comment:
   `_collect_task_names()` already normalizes to basenames via 
`os.path.basename()`, and all call-sites pass short names (e.g. `"sni.yaml"`, 
not full paths). The JSONRPC endpoint returns whatever was stored on the C++ 
side, which in this PR is always a filename constant (e.g. 
`ts::filename::SNI`), not an absolute path. The basename fallback is defensive.
   
   Using `_find_task()` instead would work equivalently but isn't a fix — both 
approaches resolve to the same result for the inputs this API accepts. Keeping 
the `set` lookup for presence and reserving `_find_task()` for when we need the 
actual task object (i.e. status checks) feels cleaner.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to