You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@warble.apache.org by hu...@apache.org on 2018/06/12 14:11:15 UTC
[incubator-warble-node] 04/05: add generic tcp test class
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-node.git
commit 0d5d510cf8be2bb06a11c15ae8e236d51d4e651b
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 12 09:09:01 2018 -0500
add generic tcp test class
---
plugins/basics/unittests.py | 10 ++++++++
plugins/tests/__init__.py | 2 ++
plugins/tests/tcp.py | 60 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/plugins/basics/unittests.py b/plugins/basics/unittests.py
index 4353ffa..b484d15 100644
--- a/plugins/basics/unittests.py
+++ b/plugins/basics/unittests.py
@@ -55,6 +55,16 @@ def uprint(t, params):
def run(gc):
gc['debug'] = True
+ # TCP test
+ params = {
+ 'host': 'www-us.apache.org',
+ 'port': 80
+ }
+ t = plugins.tests.tcp.test(gc)
+ uprint(t, params)
+ t.run(params)
+ spit(t)
+
# HTTP test
params = {
'host': 'www-eu.apache.org',
diff --git a/plugins/tests/__init__.py b/plugins/tests/__init__.py
index 6138558..6ca6524 100644
--- a/plugins/tests/__init__.py
+++ b/plugins/tests/__init__.py
@@ -1,7 +1,9 @@
+import plugins.tests.tcp
import plugins.tests.http
import plugins.tests.smtp
__all__ = [
+ 'tcp',
'http',
'smtp'
]
diff --git a/plugins/tests/tcp.py b/plugins/tests/tcp.py
new file mode 100644
index 0000000..1038191
--- /dev/null
+++ b/plugins/tests/tcp.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# 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.
+
+"""
+This is the generic TCP test suite for Apache Warble (incubating).
+It basically just connects to an port and disconnects.
+"""
+
+import plugins.basics
+import plugins.reports
+
+class test:
+ def __init__(self, globalConfig):
+ self.config = globalConfig
+
+ # Initialize a report object to store our findings
+ self.report = plugins.reports.generic.template(self.config)
+
+ def run(self, testParameters):
+
+
+ try:
+ # Open up a TCP socket, tie to the report object and pass test parameters (host, port etc)
+ request = plugins.basics.socket.tcp(testParameters, self.report)
+
+ # Connect to host
+ request.connect()
+
+ # If SSL, wrap the socket to OpenSSL via the built-in secure() call.
+ SSL = testParameters.get('SSL', False)
+ if SSL == True:
+ request.secure(SNI = testParameters.get('host'))
+
+ # We're connected, that's it! goodbye!
+ self.report.debug("Connected to host")
+ request.status_code = "Connection accepted"
+ status = True
+ self.report.timer('data')
+ self.report.debug("All went well, closing socket.")
+ self.report.timer('end')
+
+ except Exception as err:
+ print("Caught error:" + str(err))
+ if not self.report.error:
+ self.report.error('response', str(err))
+
--
To stop receiving notification emails like this one, please contact
humbedooh@apache.org.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org