This is an automated email from the ASF dual-hosted git repository.

masaori pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e45e065b7 Use ip command as a fallback in redirect_actions test 
(#12067)
6e45e065b7 is described below

commit 6e45e065b745a283cf96d324b5424f41723873ec
Author: Hiroaki Nakamura <[email protected]>
AuthorDate: Fri Mar 7 15:18:48 2025 +0900

    Use ip command as a fallback in redirect_actions test (#12067)
    
    Without this workaround, if the hostname is set to a loopback address
    redirect_actions test fails like below:
    
    ```
           file 
/home/jenkins/autest_work/sandbox/redirect_actions/_output/9-tr-Default/stream.stdout.txt
 : Checking that 
/home/jenkins/autest_work/sandbox/redirect_actions/_output/9-tr-Default/stream.stdout.txt
 matches 
/home/jenkins/trafficserver/tests/gold_tests/redirect/generated_test_data/9-tr.gold
 - Failed
              Reason: File differences
               Gold File : 
/home/jenkins/trafficserver/tests/gold_tests/redirect/generated_test_data/9-tr.gold
               Data File : 
/home/jenkins/autest_work/sandbox/redirect_actions/_output/9-tr-Default/stream.stdout.txt
               - HTTP/1.1 307 Temporary Redirect
               + HTTP/1.1 204 No Content
    ```
    
    This error happens since the address is a loopback so it is not rejected
    as expected.
    
    As a workaround, use the ip command to obtain a non-loopback IP address.
---
 tests/gold_tests/redirect/redirect_actions.test.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/gold_tests/redirect/redirect_actions.test.py 
b/tests/gold_tests/redirect/redirect_actions.test.py
index 807db3ecda..52a036bd61 100644
--- a/tests/gold_tests/redirect/redirect_actions.test.py
+++ b/tests/gold_tests/redirect/redirect_actions.test.py
@@ -53,6 +53,24 @@ try:
 except socket.gaierror:
     pass
 
+# If the hostname is set to a loopback address, use the ip command to obtain a 
non-loopback IP address.
+if any(ip.startswith('127.') for ip in ipv4addrs):
+    import json
+    from subprocess import check_output
+
+    data = json.loads(check_output(['ip', '-json', 'address', 'show']))
+
+    ipv4addrs = set(
+        [
+            addr["local"] for iface in data if iface["link_type"] != 
"loopback" for addr in iface.get("addr_info", [])
+            if addr["family"] == "inet"
+        ])
+    ipv6addrs = set(
+        [
+            addr["local"] for iface in data if iface["link_type"] != 
"loopback" for addr in iface.get("addr_info", [])
+            if addr["family"] == "inet6" and addr["scope"] != "link"
+        ])
+
 origin = Test.MakeOriginServer('origin', ip='0.0.0.0')
 ArbitraryTimestamp = '12345678'
 

Reply via email to