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

amc 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 6a28f4d  IPv6 for microserver and microDNS
6a28f4d is described below

commit 6a28f4d5b87526947f403587da631e8c0332cbcc
Author: Jesse Zhang <macisasandw...@gmail.com>
AuthorDate: Thu May 17 13:45:28 2018 -0500

    IPv6 for microserver and microDNS
    
    Update autest version
    Changed uDNS ip interface to the same as uServer
    
    
    f
    
    
    Changes
    
    
    fixes
---
 tests/gold_tests/autest-site/init.cli.ext          |  2 +-
 tests/gold_tests/autest-site/microDNS.test.ext     | 17 +++++++---
 tests/gold_tests/autest-site/microserver.test.ext  | 29 ++++++++++++-----
 .../init.cli.ext => tools/lib/IPConstants.py}      | 38 +++++++++++++++-------
 tests/tools/microDNS/uDNS.py                       | 36 +++++++++++++++-----
 tests/tools/microServer/uWServer.py                | 16 ++++++---
 6 files changed, 101 insertions(+), 37 deletions(-)

diff --git a/tests/gold_tests/autest-site/init.cli.ext 
b/tests/gold_tests/autest-site/init.cli.ext
index 5aacbfb..971836c 100644
--- a/tests/gold_tests/autest-site/init.cli.ext
+++ b/tests/gold_tests/autest-site/init.cli.ext
@@ -23,7 +23,7 @@ if sys.version_info < (3, 5, 0):
     host.WriteError(
         "You need python 3.5 or later to run these tests\n", show_stack=False)
 
-autest_version ="1.5.0"
+autest_version ="1.5.3"
 if AuTestVersion() < autest_version:
     host.WriteError(
         "Tests need AuTest version {ver} or better\n Please update AuTest:\n  
pip install --upgrade autest\n".format(ver=autest_version), show_stack=False)
diff --git a/tests/gold_tests/autest-site/microDNS.test.ext 
b/tests/gold_tests/autest-site/microDNS.test.ext
index 30c8cce..513c3c0 100644
--- a/tests/gold_tests/autest-site/microDNS.test.ext
+++ b/tests/gold_tests/autest-site/microDNS.test.ext
@@ -19,7 +19,7 @@
 from ports import get_port
 import json
 import os
-
+import sys
 
 # AddRecord registers a list of ip address against hostname
 def AddRecord(hostname, list_ip_addr):
@@ -68,7 +68,7 @@ def addRecords(self, records=None, jsonFile=None):
         f.write(json.dumps(jsondata))
 
 
-def MakeDNServer(obj, name, filename="dns_file.json", port=False, 
IP='127.0.0.1', rr=False, default=None, options={}):
+def MakeDNServer(obj, name, filename="dns_file.json", port=False, 
ip='INADDR_LOOPBACK', rr=False, default=None, options={}):
     server_path = os.path.join(obj.Variables.AtsTestToolsDir, 
'microDNS/uDNS.py')
     data_dir = os.path.join(obj.RunDirectory, name)
     filepath = os.path.join(data_dir, filename)
@@ -90,7 +90,7 @@ def MakeDNServer(obj, name, filename="dns_file.json", 
port=False, IP='127.0.0.1'
     p = obj.Processes.Process(name)
     if (port == False):
         port = get_port(p, "Port")
-    command = "python3 {3} {0} {1} {2}".format(IP, port, filepath, server_path)
+    command = "python3 {0} {1} {2} {3}".format(server_path, ip, port, filepath)
 
     if rr:
         command += " --rr"
@@ -100,7 +100,16 @@ def MakeDNServer(obj, name, filename="dns_file.json", 
port=False, IP='127.0.0.1'
     p.Setup.MakeDir(data_dir)
     p.Variables.DataDir = data_dir
     p.ReturnCode = 0
-    p.Ready = When.PortOpen(port)
+
+    # to get the IP keywords in tools/lib
+    sys.path.append(obj.Variables.AtsTestToolsDir)
+    import lib.IPConstants as IPConstants
+
+    if IPConstants.isIPv6(ip):
+        p.Ready = When.PortOpenv6(port)
+    else:
+        p.Ready = When.PortOpenv4(port)
+        
     AddMethodToInstance(p, AddRecord)
     AddMethodToInstance(p, addRecords)
 
diff --git a/tests/gold_tests/autest-site/microserver.test.ext 
b/tests/gold_tests/autest-site/microserver.test.ext
index a52e9b8..17f93d9 100644
--- a/tests/gold_tests/autest-site/microserver.test.ext
+++ b/tests/gold_tests/autest-site/microserver.test.ext
@@ -22,6 +22,7 @@ import json
 import socket
 import ssl
 import time
+import sys
 
 
 def addMethod(self, testName, request_header, functionName):
@@ -131,8 +132,12 @@ def makeHeader(self, requestString, **kwargs):
     return headerStr
 
 
-def uServerUpAndRunning(host, port, isSsl):
-    plain_sock = socket.socket(socket.AF_INET)
+def uServerUpAndRunning(host, port, isSsl, isIPv6):
+    if isIPv6:
+        plain_sock = socket.socket(socket.AF_INET6)
+    else:
+        plain_sock = socket.socket(socket.AF_INET)
+
     sock = ssl.wrap_socket(plain_sock) if isSsl else plain_sock
     try:
         sock.connect((host, port))
@@ -161,19 +166,27 @@ def uServerUpAndRunning(host, port, isSsl):
 AddWhenFunction(uServerUpAndRunning)
 
 
-def MakeOriginServer(obj, name, port=False, ip=False, delay=False, ssl=False, 
lookup_key='{PATH}', mode='test', options={}):
+def MakeOriginServer(obj, name, port=False, ip='INADDR_LOOPBACK', delay=False, 
ssl=False, lookup_key='{PATH}', mode='test', options={}):
+    # to get the IP keywords in tools/lib
+    sys.path.append(obj.Variables.AtsTestToolsDir)
+    import lib.IPConstants as IPConstants
+
     server_path = os.path.join(obj.Variables.AtsTestToolsDir, 
'microServer/uWServer.py')
     data_dir = os.path.join(obj.RunDirectory, name)
     # create Process
     p = obj.Processes.Process(name)
+
     if (port == False):
         port = get_port(p, "Port")
-    if (ip == False):
-        ip = '127.0.0.1'
+
+    ipaddr = IPConstants.getIP(ip)
+
     if (delay == False):
         delay = 0
+
     command = "python3 {0} --data-dir {1} --port {2} --ip_address {3} --delay 
{4} -m test --ssl {5} --lookupkey '{6}' -m {7}".format(
-        server_path, data_dir, port, ip, delay, ssl, lookup_key, mode)
+        server_path, data_dir, port, ipaddr, delay, ssl, lookup_key, mode)
+
     for flag, value in options.items():
         command += " {} {}".format(flag, value)
 
@@ -186,7 +199,7 @@ def MakeOriginServer(obj, name, port=False, ip=False, 
delay=False, ssl=False, lo
 
     # Set up health check.
     addResponse(p, "healthcheck.json", {
-        "headers": "GET /ruok HTTP/1.1\r\nHost: {}\r\n\r\n".format(ip),
+        "headers": "GET /ruok HTTP/1.1\r\nHost: {}\r\n\r\n".format(ipaddr),
         "timestamp": "1469733493.993",
         "body": ""
     }, {
@@ -196,7 +209,7 @@ def MakeOriginServer(obj, name, port=False, ip=False, 
delay=False, ssl=False, lo
         "options": "skipHooks"
     })
 
-    p.Ready = When.uServerUpAndRunning(ip, port, ssl)
+    p.Ready = When.uServerUpAndRunning(ipaddr, port, ssl, 
IPConstants.isIPv6(ip))
     p.ReturnCode = Any(None, 0)
 
     return p
diff --git a/tests/gold_tests/autest-site/init.cli.ext 
b/tests/tools/lib/IPConstants.py
similarity index 60%
copy from tests/gold_tests/autest-site/init.cli.ext
copy to tests/tools/lib/IPConstants.py
index 5aacbfb..d21b1b1 100644
--- a/tests/gold_tests/autest-site/init.cli.ext
+++ b/tests/tools/lib/IPConstants.py
@@ -16,19 +16,33 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-import os
+import ipaddress
 
-import sys
-if sys.version_info < (3, 5, 0):
-    host.WriteError(
-        "You need python 3.5 or later to run these tests\n", show_stack=False)
+# convenience functions
 
-autest_version ="1.5.0"
-if AuTestVersion() < autest_version:
-    host.WriteError(
-        "Tests need AuTest version {ver} or better\n Please update AuTest:\n  
pip install --upgrade autest\n".format(ver=autest_version), show_stack=False)
+IPkw = {'INADDR_LOOPBACK':'127.0.0.1',
+               'IN6ADDR_LOOPBACK':'::1',
+               'INADDR_ANY':'0.0.0.0',
+               'IN6ADDR_ANY':'::'}
 
+def isIPv6(addr):
+       if addr in IPkw:
+               addr = IPkw[addr]
 
-Settings.path_argument(["--ats-bin"],
-                       required=True,
-                       help="A user provided directory to ATS bin")
+
+       return ipaddress.ip_address(addr).version == 6
+
+
+def isIPv4(addr):
+       if addr in IPkw:
+               addr = IPkw[addr]
+
+       return ipaddress.ip_address(addr).version == 4
+
+
+def getIP(addr):
+       if addr in IPkw:
+               addr = IPkw[addr]
+
+       return str(ipaddress.ip_address(addr))
+ 
diff --git a/tests/tools/microDNS/uDNS.py b/tests/tools/microDNS/uDNS.py
index 458d734..2ca7118 100644
--- a/tests/tools/microDNS/uDNS.py
+++ b/tests/tools/microDNS/uDNS.py
@@ -24,12 +24,22 @@ import codecs
 import json
 from dnslib import *
 
+sys.path.append(
+    os.path.normpath(
+        os.path.join(
+            os.path.dirname(os.path.abspath(__file__)),
+            '..'
+        )
+    )
+)
+
+import lib.IPConstants as IPConstants
+
 TTL = 60 * 5  # completely arbitrary TTL value
 round_robin = False
 default_records = list()
 records = dict()
 
-
 class DomainName(str):
     def __getattr__(self, item):
         return DomainName(item + '.' + self)
@@ -88,11 +98,12 @@ def build_domain_mappings(path):
             # this loop only runs once, kind of a hack to access the only key 
in the dict
             domain_name = DomainName(d)
             print("Domain name:", domain_name)
-            records[domain_name] = [A(x) for x in domain[domain_name]]
+            # we can test using python's built-in ipaddress module, but this 
should suffice
+            records[domain_name] = [A(x) if ":" not in x else AAAA(x) for x in 
domain[domain_name]] 
             print(records[domain_name])
 
     if 'otherwise' in zone_file:
-        default_records.extend([A(d) for d in zone_file['otherwise']])
+        default_records.extend([A(d) if ":" not in d else AAAA(d) for d in 
zone_file['otherwise']])
 
 
 def add_authoritative_records(reply, domain):
@@ -152,23 +163,31 @@ def dns_response(data):
 if __name__ == '__main__':
     # handle cmd line args
     parser = argparse.ArgumentParser()
-    parser.add_argument("ip_addr", type=str, help="Interface", 
default="127.0.0.1")
+    parser.add_argument("ip", type=str, help="Interface")
     parser.add_argument("port", type=int, help="port uDNS should listen on")
     parser.add_argument("zone_file", help="path to zone file")
     parser.add_argument("--rr", action='store_true',
                         help='round robin load balances if multiple IP 
addresses are present for 1 domain')
     args = parser.parse_args()
 
+    if IPConstants.isIPv6(args.ip):
+        #  *UDPServer derives from TCPServer, so setting one will affect the 
other
+        socketserver.TCPServer.address_family = socket.AF_INET6
+
+    # exit(1)
+
     if args.rr:
         round_robin = True
     build_domain_mappings(args.zone_file)
 
+    ipaddr = IPConstants.getIP(args.ip)
+
     servers = [
-        socketserver.ThreadingUDPServer((args.ip_addr, args.port), 
UDPRequestHandler),
-        socketserver.ThreadingTCPServer((args.ip_addr, args.port), 
TCPRequestHandler),
+        socketserver.ThreadingUDPServer((ipaddr, args.port), 
UDPRequestHandler),
+        socketserver.ThreadingTCPServer((ipaddr, args.port), 
TCPRequestHandler),
     ]
 
-    print("Starting DNS...")
+    print("Starting DNS on address {0} port {1}...".format(ipaddr, args.port))
     for s in servers:
         thread = threading.Thread(target=s.serve_forever)  # that thread will 
start one more thread for each request
         thread.daemon = True  # exit the server thread when the main thread 
terminates
@@ -181,7 +200,8 @@ if __name__ == '__main__':
             sys.stdout.flush()
 
     except KeyboardInterrupt:
-        pass
+        print("Got SigINT")
+        # pass
     finally:
         for s in servers:
             s.shutdown()
diff --git a/tests/tools/microServer/uWServer.py 
b/tests/tools/microServer/uWServer.py
index 87a04af..8f6354a 100644
--- a/tests/tools/microServer/uWServer.py
+++ b/tests/tools/microServer/uWServer.py
@@ -49,6 +49,7 @@ sys.path.append(
 )
 
 import sessionvalidation.sessionvalidation as sv
+import lib.IPConstants as IPConstants
 
 
 SERVER_PORT = 5005  # default port
@@ -595,6 +596,7 @@ def _bool(arg):
                                                                                
    opt_true_values | opt_false_values)
         raise ValueError(msg)
 
+
 def _argparse_bool(arg):
     try:
         _bool(arg)
@@ -614,7 +616,7 @@ def main():
 
     parser.add_argument("--ip_address", "-ip",
                         type=str,
-                        default='',
+                        default='INADDR_LOOPBACK',
                         help="IP address of the interface to serve on"
                         )
 
@@ -687,12 +689,18 @@ def main():
         global lookup_key_
         lookup_key_ = args.lookupkey
         MyHandler.protocol_version = HTTP_VERSION
+
+        if IPConstants.isIPv6(options.ip_address):
+            print("Server running on IPv6")
+            HTTPServer.address_family = socket.AF_INET6
+
         if options.ssl == "True" or options.ssl == "true":
-            server = SSLServer((options.ip_address, options.port), MyHandler, 
options)
+            server = SSLServer((IPConstants.getIP(options.ip_address), 
options.port), MyHandler, options)
         else:
-            server = ThreadingServer((options.ip_address, options.port), 
MyHandler, options)
+            server = ThreadingServer((IPConstants.getIP(options.ip_address), 
options.port), MyHandler, options)
+
         server.timeout = 5
-        print("started server on port {0}".format(options.port))
+        print("Started server on port {0}".format(options.port))
         server_thread = threading.Thread(target=server.serve_forever())
         server_thread.daemon = True
         server_thread.start()

-- 
To stop receiving notification emails like this one, please contact
a...@apache.org.

Reply via email to