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

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

commit f3ed27f969f7b3a6766a5c0e0b63f85b07897fe3
Author: Aaron Canary <acan...@verizonmedia.com>
AuthorDate: Tue Feb 25 12:47:17 2020 -0600

    Using dynamic ports in AUtest
    
    This resolves "failed to reserve port" failures.
---
 tests/gold_tests/h2/h2spec.test.py                 |  1 -
 tests/gold_tests/headers/forwarded.test.py         |  9 ++++----
 tests/gold_tests/headers/via.test.py               |  1 -
 .../pluginTest/cert_update/cert_update.test.py     | 26 +++++++++++++---------
 tests/gold_tests/remap/remap_https.test.py         |  7 +++---
 .../tls/tls_check_cert_selection.test.py           |  1 -
 tests/gold_tests/tls/tls_forward_nonhttp.test.py   | 19 ++++++++++------
 7 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/tests/gold_tests/h2/h2spec.test.py 
b/tests/gold_tests/h2/h2spec.test.py
index 7bb7fd4..206e58a 100644
--- a/tests/gold_tests/h2/h2spec.test.py
+++ b/tests/gold_tests/h2/h2spec.test.py
@@ -40,7 +40,6 @@ ts = Test.MakeATSProcess("ts", select_ports=False)
 ts.addSSLfile("ssl/server.pem")
 ts.addSSLfile("ssl/server.key")
 
-ts.Variables.ssl_port = 4443
 ts.Disk.remap_config.AddLine(
     'map / http://127.0.0.1:{0}'.format(httpbin.Variables.Port)
 )
diff --git a/tests/gold_tests/headers/forwarded.test.py 
b/tests/gold_tests/headers/forwarded.test.py
index 5fed205..fcc7760 100644
--- a/tests/gold_tests/headers/forwarded.test.py
+++ b/tests/gold_tests/headers/forwarded.test.py
@@ -18,6 +18,7 @@ Test the Forwarded header and related configuration..
 #  limitations under the License.
 
 import os
+import ports
 
 Test.Summary = '''
 Test FORWARDED header.
@@ -77,12 +78,12 @@ forwarded_log_id = Test.Disk.File("forwarded.log")
 forwarded_log_id.Content = "forwarded.gold"
 
 
-def baselineTsSetup(ts, sslPort):
+def baselineTsSetup(ts):
 
     ts.addSSLfile("../remap/ssl/server.pem")
     ts.addSSLfile("../remap/ssl/server.key")
 
-    ts.Variables.ssl_port = sslPort
+    ports.get_port(ts, 'ssl_port')
 
     ts.Disk.records_config.update({
         # 'proxy.config.diags.debug.enabled': 1,
@@ -107,7 +108,7 @@ def baselineTsSetup(ts, sslPort):
 
 ts = Test.MakeATSProcess("ts", select_ports=False)
 
-baselineTsSetup(ts, 4443)
+baselineTsSetup(ts)
 
 ts.Disk.remap_config.AddLine(
     'map http://www.forwarded-none.com 
http://127.0.0.1:{0}'.format(server.Variables.Port) +
@@ -201,7 +202,7 @@ ts2 = Test.MakeATSProcess("ts2", command="traffic_manager", 
select_ports=False)
 
 ts2.Variables.port += 1
 
-baselineTsSetup(ts2, 4444)
+baselineTsSetup(ts2)
 
 ts2.Disk.records_config.update({
     'proxy.config.url_remap.pristine_host_hdr': 1,  # Retain Host header in 
original incoming client request.
diff --git a/tests/gold_tests/headers/via.test.py 
b/tests/gold_tests/headers/via.test.py
index 5e275d1..28938c2 100644
--- a/tests/gold_tests/headers/via.test.py
+++ b/tests/gold_tests/headers/via.test.py
@@ -45,7 +45,6 @@ server.addResponse("sessionlog.json", request_header, 
response_header)
 ts.addSSLfile("../remap/ssl/server.pem")
 ts.addSSLfile("../remap/ssl/server.key")
 
-ts.Variables.ssl_port = 4443
 ts.Disk.records_config.update({
     'proxy.config.http.insert_request_via_str': 4,
     'proxy.config.http.insert_response_via_str': 4,
diff --git a/tests/gold_tests/pluginTest/cert_update/cert_update.test.py 
b/tests/gold_tests/pluginTest/cert_update/cert_update.test.py
index 0e2beb4..7c1dc17 100644
--- a/tests/gold_tests/pluginTest/cert_update/cert_update.test.py
+++ b/tests/gold_tests/pluginTest/cert_update/cert_update.test.py
@@ -17,13 +17,15 @@ Test the cert_update plugin.
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
+import ports
+
 Test.Summary = '''
 Test cert_update plugin.
 '''
 
 Test.SkipUnless(
-    Condition.HasProgram("openssl","Openssl need to be installed on system for 
this test to work")
-    )
+    Condition.HasProgram("openssl", "Openssl need to be installed on system 
for this test to work")
+)
 
 # Set up origin server
 server = Test.MakeOriginServer("server")
@@ -41,9 +43,8 @@ ts.addSSLfile("ssl/server2.pem")
 ts.addSSLfile("ssl/client1.pem")
 ts.addSSLfile("ssl/client2.pem")
 
-# Setup ssl ports
-ts.Variables.ssl_port = 4443
-s_server_port = 12345
+# reserve port, attach it to 'ts' so it is released later
+ports.get_port(ts, 's_server_port')
 
 ts.Disk.records_config.update({
     'proxy.config.diags.debug.enabled': 1,
@@ -63,7 +64,7 @@ ts.Disk.ssl_multicert_config.AddLine(
 
 ts.Disk.remap_config.AddLines([
     'map https://bar.com http://127.0.0.1:{0}'.format(server.Variables.Port),
-    'map https://foo.com https://127.0.0.1:{0}'.format(s_server_port)
+    'map https://foo.com 
https://127.0.0.1:{0}'.format(ts.Variables.s_server_port)
 ])
 
 ts.Disk.sni_yaml.AddLines([
@@ -108,8 +109,9 @@ ts.StillRunningAfter = server
 # Client-Cert-Pre
 # s_server should see client (Traffic Server) as alice.com
 tr = Test.AddTestRun("Client-Cert-Pre")
-s_server = tr.Processes.Process("s_server", "openssl s_server -www -key 
{0}/server1.pem -cert {0}/server1.pem -accept 12345 -Verify 1 
-msg".format(ts.Variables.SSLDir))
-s_server.Ready = When.PortReady(12345)
+s_server = tr.Processes.Process(
+    "s_server", "openssl s_server -www -key {0}/server1.pem -cert 
{0}/server1.pem -accept {1} -Verify 1 -msg".format(ts.Variables.SSLDir, 
ts.Variables.s_server_port))
+s_server.Ready = When.PortReady(ts.Variables.s_server_port)
 tr.Command = 'curl --verbose --insecure --header "Host: foo.com" 
https://localhost:{}'.format(ts.Variables.ssl_port)
 tr.Processes.Default.StartBefore(s_server)
 s_server.Streams.all = "gold/client-cert-pre.gold"
@@ -120,7 +122,8 @@ ts.StillRunningAfter = server
 tr = Test.AddTestRun("Client-Cert-Update")
 tr.Processes.Default.Env = ts.Env
 tr.Processes.Default.Command = (
-    'mv {0}/client2.pem {0}/client1.pem && {1}/traffic_ctl plugin msg 
cert_update.client {0}/client1.pem'.format(ts.Variables.SSLDir, 
ts.Variables.BINDIR)
+    'mv {0}/client2.pem {0}/client1.pem && {1}/traffic_ctl plugin msg 
cert_update.client {0}/client1.pem'.format(
+        ts.Variables.SSLDir, ts.Variables.BINDIR)
 )
 ts.Streams.all = "gold/update.gold"
 ts.StillRunningAfter = server
@@ -128,8 +131,9 @@ ts.StillRunningAfter = server
 # Client-Cert-After
 # after use traffic_ctl to update client cert, s_server should see client 
(Traffic Server) as bob.com
 tr = Test.AddTestRun("Client-Cert-After")
-s_server = tr.Processes.Process("s_server", "openssl s_server -www -key 
{0}/server1.pem -cert {0}/server1.pem -accept 12345 -Verify 1 
-msg".format(ts.Variables.SSLDir))
-s_server.Ready = When.PortReady(12345)
+s_server = tr.Processes.Process(
+    "s_server", "openssl s_server -www -key {0}/server1.pem -cert 
{0}/server1.pem -accept {1} -Verify 1 -msg".format(ts.Variables.SSLDir, 
ts.Variables.s_server_port))
+s_server.Ready = When.PortReady(ts.Variables.s_server_port)
 tr.Processes.Default.Env = ts.Env
 # Move client2.pem to replace client1.pem since cert path matters in client 
context mapping
 tr.Command = 'curl --verbose --insecure --header "Host: foo.com" 
https://localhost:{0}'.format(ts.Variables.ssl_port)
diff --git a/tests/gold_tests/remap/remap_https.test.py 
b/tests/gold_tests/remap/remap_https.test.py
index 1ceaf3d..cf9eb99 100644
--- a/tests/gold_tests/remap/remap_https.test.py
+++ b/tests/gold_tests/remap/remap_https.test.py
@@ -26,7 +26,7 @@ ts = Test.MakeATSProcess("ts", select_ports=False)
 server = Test.MakeOriginServer("server")
 server2 = Test.MakeOriginServer("server2", ssl=True)
 
-#**testname is required**
+# **testname is required**
 testName = ""
 request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n",
                   "timestamp": "1469733493.993", "body": ""}
@@ -40,7 +40,6 @@ server2.addResponse("sessionlog.json", request_header, 
response_header)
 ts.addSSLfile("ssl/server.pem")
 ts.addSSLfile("ssl/server.key")
 
-ts.Variables.ssl_port = 4443
 ts.Disk.records_config.update({
     'proxy.config.diags.debug.enabled': 1,
     'proxy.config.diags.debug.tags': 'lm|ssl',
@@ -59,7 +58,7 @@ ts.Disk.remap_config.AddLine(
     'map https://www.example.com:{1} 
http://127.0.0.1:{0}'.format(server.Variables.Port, ts.Variables.ssl_port)
 )
 ts.Disk.remap_config.AddLine(
-    'map https://www.anotherexample.com 
https://127.0.0.1:{0}'.format(server2.Variables.SSL_Port,ts.Variables.ssl_port)
+    'map https://www.anotherexample.com 
https://127.0.0.1:{0}'.format(server2.Variables.SSL_Port, ts.Variables.ssl_port)
 )
 
 
@@ -99,7 +98,7 @@ tr.Processes.Default.Streams.stderr = 
"gold/remap-https-200.gold"
 
 # www.example.com:8080 host
 tr = Test.AddTestRun()
-tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H 
"Host: www.example.com:4443" --verbose'.format(
+tr.Processes.Default.Command = 'curl --http1.1 -k https://127.0.0.1:{0} -H 
"Host: www.example.com:{0}" --verbose'.format(
     ts.Variables.ssl_port)
 tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Streams.stderr = "gold/remap-https-200.gold"
diff --git a/tests/gold_tests/tls/tls_check_cert_selection.test.py 
b/tests/gold_tests/tls/tls_check_cert_selection.test.py
index aa027ac..48eb401 100644
--- a/tests/gold_tests/tls/tls_check_cert_selection.test.py
+++ b/tests/gold_tests/tls/tls_check_cert_selection.test.py
@@ -40,7 +40,6 @@ ts.addSSLfile("ssl/server.key")
 ts.addSSLfile("ssl/signer.pem")
 ts.addSSLfile("ssl/signer.key")
 
-ts.Variables.ssl_port = 4443
 ts.Disk.remap_config.AddLine(
     'map / https://foo.com:{1}'.format(ts.Variables.ssl_port, 
server.Variables.SSL_Port))
 
diff --git a/tests/gold_tests/tls/tls_forward_nonhttp.test.py 
b/tests/gold_tests/tls/tls_forward_nonhttp.test.py
index bd1887b..1d3db0f 100644
--- a/tests/gold_tests/tls/tls_forward_nonhttp.test.py
+++ b/tests/gold_tests/tls/tls_forward_nonhttp.test.py
@@ -17,6 +17,8 @@
 #  limitations under the License.
 
 import os
+import ports
+
 Test.Summary = '''
 Forwarding a non-HTTP protocol out of TLS
 '''
@@ -28,6 +30,9 @@ ts = Test.MakeATSProcess("ts", select_ports=True, 
enable_tls=True)
 ts.addSSLfile("ssl/server.pem")
 ts.addSSLfile("ssl/server.key")
 
+# reserve a port of the s_client that will be released with 'ts'
+ports.get_port(ts, 's_client_port')
+
 # Need no remap rules.  Everything should be proccessed by sni
 
 # Make sure the TS server certs are different from the origin certs
@@ -40,7 +45,7 @@ ts.Disk.ssl_multicert_config.AddLine(
 ts.Disk.records_config.update({
     '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.connect_ports': '{0} 
4444'.format(ts.Variables.ssl_port),
+    'proxy.config.http.connect_ports': '{0} {1}'.format(ts.Variables.ssl_port, 
ts.Variables.s_client_port),
     'proxy.config.ssl.server.cipher_suite': 
'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES-CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2',
     'proxy.config.exec_thread.autoconfig.scale': 1.0,
     'proxy.config.url_remap.pristine_host_hdr': 1
@@ -49,17 +54,17 @@ ts.Disk.records_config.update({
 # foo.com should not terminate.  Just tunnel to server_foo
 # bar.com should terminate.  Forward its tcp stream to server_bar
 ts.Disk.sni_yaml.AddLines([
-  "sni:",
-  "- fqdn: bar.com",
-  "  forward_route: localhost:4444"
-  ])
+    "sni:",
+    "- fqdn: bar.com",
+    "  forward_route: localhost:{0}".format(ts.Variables.s_client_port)
+])
 
 tr = Test.AddTestRun("forward-non-http")
 tr.Setup.Copy("test-nc-s_client.sh")
-tr.Processes.Default.Command = "sh test-nc-s_client.sh 4444 
{0}".format(ts.Variables.ssl_port)
+tr.Processes.Default.Command = "sh test-nc-s_client.sh {1} 
{0}".format(ts.Variables.ssl_port, ts.Variables.s_client_port)
 tr.ReturnCode = 0
 tr.Processes.Default.StartBefore(Test.Processes.ts)
 tr.StillRunningAfter = ts
 testout_path = os.path.join(Test.RunDirectory, "test.out")
-tr.Disk.File(testout_path, id = "testout")
+tr.Disk.File(testout_path, id="testout")
 tr.Processes.Default.Streams.All += Testers.IncludesExpression("This is a 
reply", "s_client should get response")

Reply via email to