From patchwork Tue Jul 26 12:01:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Boca X-Patchwork-Id: 652720 X-Patchwork-Delegate: guru@ovn.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3rzGwg0Y6Nz9t1D for ; Tue, 26 Jul 2016 22:03:15 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 515FA10AD9; Tue, 26 Jul 2016 05:03:14 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 8089510A52 for ; Tue, 26 Jul 2016 05:03:12 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 167DB1E03BD for ; Tue, 26 Jul 2016 06:03:12 -0600 (MDT) X-ASG-Debug-ID: 1469534591-09eadd464858db00001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar5.cudamail.com with ESMTP id x9l03OQFGvyinpZK (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 26 Jul 2016 06:03:11 -0600 (MDT) X-Barracuda-Envelope-From: pboca@cloudbasesolutions.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO cbssmtp1.cloudbase.local) (91.232.152.5) by mx3-pf3.cudamail.com with SMTP; 26 Jul 2016 12:03:10 -0000 Received-SPF: pass (mx3-pf3.cudamail.com: SPF record at cloudbasesolutions.com designates 91.232.152.5 as permitted sender) X-Barracuda-Apparent-Source-IP: 91.232.152.5 X-Barracuda-RBL-IP: 91.232.152.5 Received: from localhost (localhost [127.0.0.1]) by cbssmtp1.cloudbase.local (Postfix) with ESMTP id 42E52408BD for ; Tue, 26 Jul 2016 15:03:09 +0300 (EEST) X-Virus-Scanned: amavisd-new at cloudbasesolutions.com Received: from cbssmtp1.cloudbase.local ([127.0.0.1]) by localhost (cbssmtp1.cloudbase.local [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pbi9eN6KJInA for ; Tue, 26 Jul 2016 15:02:48 +0300 (EEST) Received: from CBSEX1.cloudbase.local (unknown [10.77.78.3]) by cbssmtp1.cloudbase.local (Postfix) with ESMTP id 3E29C406BA for ; Tue, 26 Jul 2016 15:01:04 +0300 (EEST) Received: from CBSEX1.cloudbase.local ([10.77.78.3]) by CBSEX1.cloudbase.local ([10.77.78.3]) with mapi id 14.03.0301.000; Tue, 26 Jul 2016 14:01:04 +0200 X-CudaMail-Envelope-Sender: pboca@cloudbasesolutions.com From: Paul Boca To: "dev@openvswitch.org" X-CudaMail-MID: CM-V3-725006203 X-CudaMail-DTE: 072616 X-CudaMail-Originating-IP: 91.232.152.5 Thread-Topic: [PATCH V9 01/17] python tests: Implemented signal.alarm for Windows X-ASG-Orig-Subj: [##CM-V3-725006203##][PATCH V9 01/17] python tests: Implemented signal.alarm for Windows Thread-Index: AQHR5zVi1SB9dfyqxEihEi/HMtJYgg== Date: Tue, 26 Jul 2016 12:01:03 +0000 Message-ID: <1469534454-7672-2-git-send-email-pboca@cloudbasesolutions.com> References: <1469534454-7672-1-git-send-email-pboca@cloudbasesolutions.com> In-Reply-To: <1469534454-7672-1-git-send-email-pboca@cloudbasesolutions.com> Accept-Language: en-US, it-IT Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.77.78.1] MIME-Version: 1.0 X-GBUdb-Analysis: 0, 91.232.152.5, Ugly c=0.308711 p=-0.5 Source Normal X-MessageSniffer-Rules: 0-0-0-9159-c X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1469534591 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.10 X-Barracuda-Spam-Status: No, SCORE=0.10 using global scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.31531 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS Subject: [ovs-dev] [PATCH V9 01/17] python tests: Implemented signal.alarm for Windows X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" signal.alarm is not available in Windows and would trigger an exception when called. Implemented this to mentain compatibility between Windows and Linux for python tests. Signed-off-by: Paul-Daniel Boca Acked-by: Alin Gabriel Serdean --- V2: No changes V3: Code styling changes V4: No changes V5: No changes V6: No changes V7: Added function signal_alarm in fatal_signal.py to avoid duplicating code V8: No changes V9: No changes --- python/ovs/fatal_signal.py | 24 +++++++++++++++++++++++- tests/appctl.py | 4 ++-- tests/test-ovsdb.py | 4 ++-- tests/test-unix-socket.py | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/python/ovs/fatal_signal.py b/python/ovs/fatal_signal.py index 7308039..14605ac 100644 --- a/python/ovs/fatal_signal.py +++ b/python/ovs/fatal_signal.py @@ -15,7 +15,7 @@ import atexit import os import signal - +import sys import ovs.vlog _hooks = [] @@ -134,3 +134,25 @@ def _init(): if signal.getsignal(signr) == signal.SIG_DFL: signal.signal(signr, _signal_handler) atexit.register(_atexit_handler) + + +def signal_alarm(timeout): + if sys.platform == "win32": + import os + import time + import threading + + class Alarm (threading.Thread): + def __init__(self, timeout): + super(Alarm, self).__init__() + self.timeout = timeout + self.setDaemon(True) + + def run(self): + time.sleep(self.timeout) + os._exit(1) + + alarm = Alarm(timeout) + alarm.start() + else: + signal.alarm(timeout) diff --git a/tests/appctl.py b/tests/appctl.py index e5bcf2c..e4f0696 100644 --- a/tests/appctl.py +++ b/tests/appctl.py @@ -13,7 +13,6 @@ # limitations under the License. import argparse -import signal import sys import ovs.daemon @@ -21,6 +20,7 @@ import ovs.unixctl import ovs.unixctl.client import ovs.util import ovs.vlog +from ovs.fatal_signal import signal_alarm def connect_to_target(target): @@ -52,7 +52,7 @@ def main(): args = parser.parse_args() if args.timeout: - signal.alarm(int(args.timeout)) + signal_alarm(int(args.timeout)) ovs.vlog.Vlog.init() target = args.target diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py index 83fe4af..c7c42c8 100644 --- a/tests/test-ovsdb.py +++ b/tests/test-ovsdb.py @@ -17,7 +17,6 @@ from __future__ import print_function import getopt import re import os -import signal import sys import uuid @@ -29,6 +28,7 @@ import ovs.db.types import ovs.ovsuuid import ovs.poller import ovs.util +from ovs.fatal_signal import signal_alarm import six @@ -647,7 +647,7 @@ def main(argv): except TypeError: raise error.Error("value %s on -t or --timeout is not at " "least 1" % value) - signal.alarm(timeout) + signal_alarm(timeout) else: sys.exit(0) diff --git a/tests/test-unix-socket.py b/tests/test-unix-socket.py index ebfa054..c80fb13 100644 --- a/tests/test-unix-socket.py +++ b/tests/test-unix-socket.py @@ -19,6 +19,7 @@ import socket import sys import ovs.socket_util +from ovs.fatal_signal import signal_alarm def main(argv): @@ -33,7 +34,7 @@ def main(argv): sockname2 = sockname1 signal.signal(signal.SIGALRM, signal.SIG_DFL) - signal.alarm(5) + signal_alarm(5) # Create a listening socket under name 'sockname1'. error, sock1 = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, False,