diff options
author | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-05-19 19:31:37 +0100 |
---|---|---|
committer | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-06-14 07:16:06 +0000 |
commit | c70be07682566ae05bafbf05a7e8c85ae4e1297e (patch) | |
tree | c5e52918e1e85941898d622eb20487ac39de1c4e /yardstick/common | |
parent | c601ff364311f0aae04b40b1672ea47bb487c327 (diff) |
Add send socket commands function
Pktgen provides a TCP socket connection to allow the user to control
it from a remote console or program [1].
This new method will provide Yardstick the ability to send string
commands to a port in a remote host.
[1] http://pktgen-dpdk.readthedocs.io/en/latest/socket.html
JIRA: YARDSTICK-1186
Change-Id: I9d64ccad662fa3599de65654c5dab02833fcc91d
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Diffstat (limited to 'yardstick/common')
-rw-r--r-- | yardstick/common/utils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py index 108ee17bc..958ec627c 100644 --- a/yardstick/common/utils.py +++ b/yardstick/common/utils.py @@ -492,3 +492,25 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None): if exception and issubclass(exception, Exception): raise exception # pylint: disable=raising-bad-type raise exceptions.WaitTimeout + + +def send_socket_command(host, port, command): + """Send a string command to a specific port in a host + + :param host: (str) ip or hostname of the host + :param port: (int) port number + :param command: (str) command to send + :return: 0 if success, error number if error + """ + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + ret = 0 + try: + err_number = sock.connect_ex((host, int(port))) + if err_number != 0: + return err_number + sock.sendall(six.b(command)) + except Exception: # pylint: disable=broad-except + ret = 1 + finally: + sock.close() + return ret |