You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by dr...@apache.org on 2017/11/07 00:44:25 UTC

[trafficserver] branch master updated: Format some test file with autopep8 remove annoying print message that was added by mistake to the microserver extension fix syntax issue with double and txn that cause it to fail on different OS linux systems add some conditions for netstat existance

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

dragon 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 75168bd  Format some test file with autopep8 remove annoying print message that was added by mistake to the microserver extension fix syntax issue with double and txn that cause it to fail on different OS linux systems add some conditions for netstat  existance
75168bd is described below

commit 75168bdfe8ae78e0857fbdca986090600a6a42ff
Author: Jason Kenny <dr...@live.com>
AuthorDate: Mon Nov 6 17:42:21 2017 -0600

    Format some test file with autopep8
    remove annoying print message that was added by mistake to the microserver extension
    fix syntax issue with double and txn that cause it to fail on different OS linux systems
    add some conditions for netstat  existance
---
 tests/gold_tests/autest-site/microserver.test.ext | 97 ++++++++++++-----------
 tests/gold_tests/continuations/double.test.py     |  2 +-
 tests/gold_tests/headers/forwarded.test.py        | 27 ++++---
 tests/gold_tests/headers/normalize_ae.test.py     | 16 +++-
 tests/gold_tests/headers/via.test.py              |  3 +-
 tests/gold_tests/logging/ccid_ctid.test.py        |  6 +-
 tests/gold_tests/transaction/txn.test.py          |  2 +-
 7 files changed, 94 insertions(+), 59 deletions(-)

diff --git a/tests/gold_tests/autest-site/microserver.test.ext b/tests/gold_tests/autest-site/microserver.test.ext
index e06fa9a..4c7654c 100644
--- a/tests/gold_tests/autest-site/microserver.test.ext
+++ b/tests/gold_tests/autest-site/microserver.test.ext
@@ -19,39 +19,43 @@
 from ports import get_port
 import json
 
-def addMethod(self,testName, request_header, functionName):
+
+def addMethod(self, testName, request_header, functionName):
     return
 
 # creates the full request or response block using headers and message data
-def httpObject(self,header,data):
-    r=dict()
-    r["timestamp"]=""
-    r["headers"]=header
-    r["body"]=data
+
+
+def httpObject(self, header, data):
+    r = dict()
+    r["timestamp"] = ""
+    r["headers"] = header
+    r["body"] = data
     return r
 
 # addResponse adds customized response with respect to request_header. request_header and response_header are both dictionaries
-def addResponse(self,filename, testName, request_header, response_header):
+
+
+def addResponse(self, filename, testName, request_header, response_header):
 
     txn = dict()
     txn["timestamp"] = ""
     txn["uuid"] = testName
     txn["request"] = request_header
     txn["response"] = response_header
-    print("data dir",self.Variables.DataDir)
-    addTransactionToSession(txn,filename)
-    absFilepath=os.path.abspath(filename)
-    self.Setup.CopyAs(absFilepath,self.Variables.DataDir)
-    return
 
+    addTransactionToSession(txn, filename)
+    absFilepath = os.path.abspath(filename)
+    self.Setup.CopyAs(absFilepath, self.Variables.DataDir)
+    return
 
 
 # addResponse adds customized response with respect to request_header. request_header and response_header are both dictionaries
-def addResponse(self,filename, request_header, response_header):
+def addResponse(self, filename, request_header, response_header):
     requestline = request_header["headers"].split("\r\n")[0]
     requestline = requestline.split(" ")[1]
-    resourceLocation = requestline.split("/",1)
-    if len(resourceLocation)>1:
+    resourceLocation = requestline.split("/", 1)
+    if len(resourceLocation) > 1:
         rl = resourceLocation[1]
     else:
         rl = ""
@@ -61,68 +65,71 @@ def addResponse(self,filename, request_header, response_header):
     txn["request"] = request_header
     txn["response"] = response_header
     absFilepath = os.path.join(self.Variables.DataDir, filename)
-    addTransactionToSession(txn,absFilepath)
-    #absFilepath=os.path.abspath(filename)
-    #self.Setup.CopyAs(absFilepath,self.Variables.DataDir)
+    addTransactionToSession(txn, absFilepath)
+    # absFilepath=os.path.abspath(filename)
+    # self.Setup.CopyAs(absFilepath,self.Variables.DataDir)
     return
 
-#adds transaction in json format to the specified file
-def addTransactionToSession(txn,JFile):
-    jsondata=None
+# adds transaction in json format to the specified file
+
+
+def addTransactionToSession(txn, JFile):
+    jsondata = None
     if not os.path.exists(os.path.dirname(JFile)):
         os.makedirs(os.path.dirname(JFile))
     if os.path.exists(JFile):
-        jf = open(JFile,'r')
+        jf = open(JFile, 'r')
         jsondata = json.load(jf)
 
     if jsondata == None:
         jsondata = dict()
-        jsondata["version"]='0.1'
-        jsondata["timestamp"]="1234567890.098"
-        jsondata["encoding"]="url_encoded"
-        jsondata["txns"]=list()
+        jsondata["version"] = '0.1'
+        jsondata["timestamp"] = "1234567890.098"
+        jsondata["encoding"] = "url_encoded"
+        jsondata["txns"] = list()
         jsondata["txns"].append(txn)
     else:
         jsondata["txns"].append(txn)
-    with open(JFile,'w+') as jf:
+    with open(JFile, 'w+') as jf:
         jf.write(json.dumps(jsondata))
 
 
-#make headers with the key and values provided
-def makeHeader(self,requestString, **kwargs):
-    headerStr = requestString+'\r\n'
-    for k,v in kwargs.iteritems():
-        headerStr += k+': '+v+'\r\n'
-    headerStr = headerStr+'\r\n'
+# make headers with the key and values provided
+def makeHeader(self, requestString, **kwargs):
+    headerStr = requestString + '\r\n'
+    for k, v in kwargs.iteritems():
+        headerStr += k + ': ' + v + '\r\n'
+    headerStr = headerStr + '\r\n'
     return headerStr
 
 
-def MakeOriginServer(obj, name,port=False, ip=False, delay=False, public_ip=False,ssl=False,options={}):
-    server_path= os.path.join(obj.Variables.AtsTestToolsDir,'microServer/uWServer.py')
+def MakeOriginServer(obj, name, port=False, ip=False, delay=False, public_ip=False, ssl=False, options={}):
+    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")
-        print("port num",port)
+        port = get_port(p, "Port")
     if (ip == False):
         ip = '127.0.0.1'
     if (delay == False):
         delay = 0
-    command = "python3 {0} --data-dir {1} --port {2} --ip_address {3} --delay {4} --public {5} -m test --ssl {6}".format(server_path, data_dir, port, ip, delay, public_ip,ssl)
-    for flag,value in options.items() :
-        command += " {} {}".format(flag,value)
+    command = "python3 {0} --data-dir {1} --port {2} --ip_address {3} --delay {4} --public {5} -m test --ssl {6}".format(
+        server_path, data_dir, port, ip, delay, public_ip, ssl)
+    for flag, value in options.items():
+        command += " {} {}".format(flag, value)
 
     # create process
     p.Command = command
     p.Setup.MakeDir(data_dir)
     p.Variables.DataDir = data_dir
-    p.Ready = When.PortOpen(port,ip)
+    p.Ready = When.PortOpen(port, ip)
     p.ReturnCode = None
-    AddMethodToInstance(p,addResponse)
-    AddMethodToInstance(p,addTransactionToSession)
+    AddMethodToInstance(p, addResponse)
+    AddMethodToInstance(p, addTransactionToSession)
 
     return p
 
-AddTestRunSet(MakeOriginServer,name="MakeOriginServer")
-AddTestRunSet(MakeOriginServer,name="MakeOrigin")
+
+AddTestRunSet(MakeOriginServer, name="MakeOriginServer")
+AddTestRunSet(MakeOriginServer, name="MakeOrigin")
diff --git a/tests/gold_tests/continuations/double.test.py b/tests/gold_tests/continuations/double.test.py
index 15b845d..cde236a 100644
--- a/tests/gold_tests/continuations/double.test.py
+++ b/tests/gold_tests/continuations/double.test.py
@@ -61,7 +61,7 @@ tr.Processes.Default.StartBefore(ts, ready=When.PortOpen(ts.Variables.port))
 tr.StillRunningAfter = ts
 
 comparator_command = '''
-if [ "`traffic_ctl metric get continuations_verify.{0}.close.1 | cut -d ' ' -f 2`" == "`traffic_ctl metric get continuations_verify.{0}.close.2 | cut -d ' ' -f 2`" ]; then\
+if test "`traffic_ctl metric get continuations_verify.{0}.close.1 | cut -d ' ' -f 2`" -eq "`traffic_ctl metric get continuations_verify.{0}.close.2 | cut -d ' ' -f 2`" ; then\
      echo yes;\
     else \
     echo no; \
diff --git a/tests/gold_tests/headers/forwarded.test.py b/tests/gold_tests/headers/forwarded.test.py
index e45a9d4..e03f190 100644
--- a/tests/gold_tests/headers/forwarded.test.py
+++ b/tests/gold_tests/headers/forwarded.test.py
@@ -27,7 +27,8 @@ Test FORWARDED header.
 Test.SkipUnless(
     Condition.HasATSFeature('TS_USE_TLS_ALPN'),
     Condition.HasCurlFeature('http2'),
-    Condition.HasCurlFeature('IPv6')
+    Condition.HasCurlFeature('IPv6'),
+    Condition.HasProgram("netstat", "netstat need to be installed on system for this test to work")
 )
 Test.ContinueOnFail = True
 
@@ -78,6 +79,7 @@ server.addResponse("sessionlog.json", request_header, response_header)
 forwarded_log_id = Test.Disk.File("forwarded.log")
 forwarded_log_id.Content = "forwarded.gold"
 
+
 def baselineTsSetup(ts, sslPort):
 
     ts.addSSLfile("../remap/ssl/server.pem")
@@ -87,14 +89,14 @@ def baselineTsSetup(ts, sslPort):
 
     ts.Disk.records_config.update({
         # 'proxy.config.diags.debug.enabled': 1,
-        'proxy.config.url_remap.pristine_host_hdr': 1, # Retain Host header in original incoming client request.
-        'proxy.config.http.cache.http': 0, # Make sure each request is forwarded to the origin server.
-        'proxy.config.proxy_name': 'Poxy_Proxy', # This will be the server name.
+        'proxy.config.url_remap.pristine_host_hdr': 1,  # Retain Host header in original incoming client request.
+        'proxy.config.http.cache.http': 0,  # Make sure each request is forwarded to the origin server.
+        'proxy.config.proxy_name': 'Poxy_Proxy',  # This will be the server name.
         'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
         'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
         'proxy.config.http.server_ports': (
             'ipv4:{0} ipv4:{1}:proto=http2;http:ssl ipv6:{0} ipv6:{1}:proto=http2;http:ssl'
-                .format(ts.Variables.port, ts.Variables.ssl_port))
+            .format(ts.Variables.port, ts.Variables.ssl_port))
     })
 
     ts.Disk.ssl_multicert_config.AddLine(
@@ -105,6 +107,7 @@ def baselineTsSetup(ts, sslPort):
         'map http://www.no-oride.com http://127.0.0.1:{0}'.format(server.Variables.Port)
     )
 
+
 ts = Test.MakeATSProcess("ts", select_ports=False)
 
 baselineTsSetup(ts, 4443)
@@ -156,9 +159,12 @@ ts.Disk.remap_config.AddLine(
 
 # Ask the OS if the port is ready for connect()
 #
+
+
 def CheckPort(Port):
     return lambda: 0 == subprocess.call('netstat --listen --tcp -n | grep -q :{}'.format(Port), shell=True)
 
+
 # Basic HTTP 1.1 -- No Forwarded by default
 tr = Test.AddTestRun()
 # Wait for the micro server
@@ -167,10 +173,11 @@ tr.Processes.Default.StartBefore(server, ready=CheckPort(server.Variables.Port))
 tr.Processes.Default.StartBefore(Test.Processes.ts, ready=CheckPort(ts.Variables.ssl_port))
 #
 tr.Processes.Default.Command = (
-  'curl --verbose --ipv4 --http1.1 --proxy localhost:{} http://www.no-oride.com'.format(ts.Variables.port)
+    'curl --verbose --ipv4 --http1.1 --proxy localhost:{} http://www.no-oride.com'.format(ts.Variables.port)
 )
 tr.Processes.Default.ReturnCode = 0
 
+
 def TestHttp1_1(host):
 
     tr = Test.AddTestRun()
@@ -179,6 +186,7 @@ def TestHttp1_1(host):
     )
     tr.Processes.Default.ReturnCode = 0
 
+
 # Basic HTTP 1.1 -- No Forwarded -- explicit configuration.
 #
 TestHttp1_1('www.forwarded-none.com')
@@ -207,7 +215,7 @@ ts2.Variables.port += 1
 baselineTsSetup(ts2, 4444)
 
 ts2.Disk.records_config.update({
-    'proxy.config.url_remap.pristine_host_hdr': 1, # Retain Host header in original incoming client request.
+    'proxy.config.url_remap.pristine_host_hdr': 1,  # Retain Host header in original incoming client request.
     'proxy.config.http.insert_forwarded': 'by=uuid'})
 
 ts2.Disk.remap_config.AddLine(
@@ -270,7 +278,7 @@ tr.Processes.Default.ReturnCode = 0
 tr = Test.AddTestRun()
 tr.Processes.Default.Command = (
     'curl --verbose --ipv4 --http1.1 --insecure --header "Host: www.no-oride.com" https://localhost:{}'
-        .format(ts2.Variables.ssl_port)
+    .format(ts2.Variables.ssl_port)
 )
 tr.Processes.Default.ReturnCode = 0
 
@@ -284,6 +292,7 @@ tr.Processes.Default.ReturnCode = 0
 
 tr = Test.AddTestRun()
 tr.Processes.Default.Command = (
-    'curl --verbose --ipv6 --http1.1 --insecure --header "Host: www.no-oride.com" https://localhost:{}'.format(ts2.Variables.ssl_port)
+    'curl --verbose --ipv6 --http1.1 --insecure --header "Host: www.no-oride.com" https://localhost:{}'.format(
+        ts2.Variables.ssl_port)
 )
 tr.Processes.Default.ReturnCode = 0
diff --git a/tests/gold_tests/headers/normalize_ae.test.py b/tests/gold_tests/headers/normalize_ae.test.py
index d5e122e..64c689c 100644
--- a/tests/gold_tests/headers/normalize_ae.test.py
+++ b/tests/gold_tests/headers/normalize_ae.test.py
@@ -24,6 +24,12 @@ Test.Summary = '''
 Test normalizations of the Accept-Encoding header field.
 '''
 
+Test.SkipUnless(
+    Condition.HasProgram(
+        "curl", "Curl need to be installed on system for this test to work"),
+    Condition.HasProgram("netstat", "netstat need to be installed on system for this test to work")
+)
+
 Test.ContinueOnFail = True
 
 server = Test.MakeOriginServer("server", options={'--load': os.path.join(Test.TestDirectory, 'normalize_ae_observer.py')})
@@ -43,11 +49,12 @@ server.addResponse("sessionlog.json", request_header, response_header)
 # Define first ATS
 ts = Test.MakeATSProcess("ts", select_ports=False)
 
+
 def baselineTsSetup(ts):
 
     ts.Disk.records_config.update({
         # 'proxy.config.diags.debug.enabled': 1,
-        'proxy.config.http.cache.http': 0, # Make sure each request is sent to the origin server.
+        'proxy.config.http.cache.http': 0,  # Make sure each request is sent to the origin server.
         'proxy.config.http.server_ports': 'ipv4:{}'.format(ts.Variables.port)
     })
 
@@ -67,6 +74,7 @@ def baselineTsSetup(ts):
         ' @plugin=conf_remap.so @pparam=proxy.config.http.normalize_ae=2'
     )
 
+
 baselineTsSetup(ts)
 
 # set up to check the output after the tests have run.
@@ -76,10 +84,14 @@ normalize_ae_log_id.Content = "normalize_ae.gold"
 
 # ask the os if the port is ready for connect()
 #
+
+
 def CheckPort(port):
     return lambda: 0 == subprocess.call('netstat --listen --tcp -n | grep -q :{}'.format(port), shell=True)
 
 # Try various Accept-Encoding header fields for a particular traffic server and host.
+
+
 def allAEHdrs(shouldWaitForUServer, shouldWaitForTs, ts, host):
 
     tr = test.AddTestRun()
@@ -123,12 +135,14 @@ def allAEHdrs(shouldWaitForUServer, shouldWaitForTs, ts, host):
     tr.Processes.Default.Command = baseCurl + curlTail('gzip;q=0.3, whatever;q=0.666, br;q=0.7')
     tr.Processes.Default.ReturnCode = 0
 
+
 def perTsTest(shouldWaitForUServer, ts):
     allAEHdrs(shouldWaitForUServer, True, ts, 'www.no-oride.com')
     allAEHdrs(False, False, ts, 'www.ae-0.com')
     allAEHdrs(False, False, ts, 'www.ae-1.com')
     allAEHdrs(False, False, ts, 'www.ae-2.com')
 
+
 perTsTest(True, ts)
 
 # Define second ATS
diff --git a/tests/gold_tests/headers/via.test.py b/tests/gold_tests/headers/via.test.py
index 37cc61a..76bd547 100644
--- a/tests/gold_tests/headers/via.test.py
+++ b/tests/gold_tests/headers/via.test.py
@@ -28,7 +28,8 @@ Check VIA header for protocol stack data.
 Test.SkipUnless(
     Condition.HasATSFeature('TS_USE_TLS_ALPN'),
     Condition.HasCurlFeature('http2'),
-    Condition.HasCurlFeature('IPv6')
+    Condition.HasCurlFeature('IPv6'),
+    Condition.HasProgram("netstat", "netstat need to be installed on system for this test to work")
 )
 Test.ContinueOnFail = True
 
diff --git a/tests/gold_tests/logging/ccid_ctid.test.py b/tests/gold_tests/logging/ccid_ctid.test.py
index ef60083..ab783e1 100644
--- a/tests/gold_tests/logging/ccid_ctid.test.py
+++ b/tests/gold_tests/logging/ccid_ctid.test.py
@@ -28,7 +28,8 @@ Test.SkipUnless(
         "curl", "Curl need to be installed on system for this test to work"),
     # Condition.IsPlatform("linux"), Don't see the need for this.
     Condition.HasATSFeature('TS_USE_TLS_ALPN'),
-    Condition.HasCurlFeature('http2')
+    Condition.HasCurlFeature('http2'),
+    Condition.HasProgram("netstat", "netstat need to be installed on system for this test to work")
 )
 
 # Define default ATS.  "select_ports=False" needed because SSL port used.
@@ -71,9 +72,12 @@ log.ascii {
 
 # Ask the OS if the port is ready for connect()
 #
+
+
 def CheckPort(Port):
     return lambda: 0 == subprocess.call('netstat --listen --tcp -n | grep -q :{}'.format(Port), shell=True)
 
+
 tr = Test.AddTestRun()
 # Delay on readiness of ssl port
 tr.Processes.Default.StartBefore(Test.Processes.ts, ready=CheckPort(ts.Variables.ssl_port))
diff --git a/tests/gold_tests/transaction/txn.test.py b/tests/gold_tests/transaction/txn.test.py
index f2d1d7b..1caa19c 100644
--- a/tests/gold_tests/transaction/txn.test.py
+++ b/tests/gold_tests/transaction/txn.test.py
@@ -82,7 +82,7 @@ tr.Processes.Default.Streams.All = Testers.ContainsExpression(
 tr.StillRunningAfter = ts
 
 comparator_command = '''
-if [ "`traffic_ctl metric get ssntxnorder_verify.{0}.start | cut -d ' ' -f 2`" == "`traffic_ctl metric get ssntxnorder_verify.{0}.close | cut -d ' ' -f 2`" ]; then\
+if test "`traffic_ctl metric get ssntxnorder_verify.{0}.start | cut -d ' ' -f 2`" -eq "`traffic_ctl metric get ssntxnorder_verify.{0}.close | cut -d ' ' -f 2`" ; then\
      echo yes;\
     else \
     echo no; \

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].