Yeela Kaplan has uploaded a new change for review. Change subject: utils: add a utility to create a socket ......................................................................
utils: add a utility to create a socket Needed for use both in jsonrpc unit tests and jsonrpc migration Change-Id: Ib66bf3c1d292cd25bb91ea2bf36c641ab6f68310 Signed-off-by: Yeela Kaplan <[email protected]> --- M lib/vdsm/utils.py M tests/jsonRpcHelper.py 2 files changed, 19 insertions(+), 15 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/41893/1 diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index e4e7be1..1f75dae 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -47,11 +47,13 @@ import select import shutil import signal +import socket import stat import string import threading import time import vdsm.infra.zombiereaper as zombiereaper +from M2Crypto import SSL from cpopen import CPopen from . import cmdutils @@ -1282,3 +1284,15 @@ """ count = int(n + size - 1) // size return count * size + + +def create_socket(host, port, sslctx=None, timeout=None): + sock = None + if sslctx: + sock = SSL.Connection(sslctx.context) + else: + sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM) + sock.settimeout(timeout) + sock.connect((host, port)) + return sock diff --git a/tests/jsonRpcHelper.py b/tests/jsonRpcHelper.py index 2345f29..59e6267 100644 --- a/tests/jsonRpcHelper.py +++ b/tests/jsonRpcHelper.py @@ -26,7 +26,6 @@ from xmlrpclib import Transport, dumps, Fault from contextlib import contextmanager from itertools import product -from M2Crypto import SSL from rpc.bindingxmlrpc import BindingXMLRPC, XmlDetector from yajsonrpc.betterAsyncore import Reactor from yajsonrpc.stompreactor import StompDetector, StompRpcClient @@ -37,6 +36,7 @@ from yajsonrpc import Notification from protocoldetector import MultiProtocolAcceptor from rpc.bindingjsonrpc import BindingJsonRpc +from vdsm import utils from sslhelper import DEAFAULT_SSL_CONTEXT PERMUTATIONS = tuple(product((True, False), ("xml", "stomp"))) @@ -138,24 +138,14 @@ ) def clientFactory(): - return client(create_socket( - sslctx, + return client(utils.create_socket( acceptor._host, - acceptor._port + acceptor._port, + sslctx=sslctx, + timeout=TIMEOUT )) yield clientFactory - - -def create_socket(sslctx, host, port): - sock = None - if sslctx: - sock = SSL.Connection(sslctx.context) - else: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.settimeout(TIMEOUT) - sock.connect((host, port)) - return sock class XMLClient(): -- To view, visit https://gerrit.ovirt.org/41893 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib66bf3c1d292cd25bb91ea2bf36c641ab6f68310 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yeela Kaplan <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
