Merge "Propose the backporting process"
[yardstick.git] / yardstick / common / utils.py
index 251e5cc..85cecc7 100644 (file)
@@ -37,7 +37,6 @@ from oslo_utils import encodeutils
 
 import yardstick
 from yardstick.common import exceptions
-from yardstick.common.yaml_loader import yaml_load
 
 
 logger = logging.getLogger(__name__)
@@ -530,9 +529,23 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
         raise exceptions.WaitTimeout
 
 
-def read_yaml_file(path):
-    """Read yaml file"""
+def send_socket_command(host, port, command):
+    """Send a string command to a specific port in a host
 
-    with open(path) as stream:
-        data = yaml_load(stream)
-    return data
+    :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