From patchwork Tue Mar 8 13:28:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 594202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4E7BA140BA7 for ; Wed, 9 Mar 2016 00:29:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=tieto.com header.i=@tieto.com header.b=X8z9VYW7; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1adHh0-0005wq-0r; Tue, 08 Mar 2016 13:28:54 +0000 Received: from mail-lb0-x22c.google.com ([2a00:1450:4010:c04::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1adHgv-0005bc-Ti for hostap@lists.infradead.org; Tue, 08 Mar 2016 13:28:52 +0000 Received: by mail-lb0-x22c.google.com with SMTP id k15so18023117lbg.0 for ; Tue, 08 Mar 2016 05:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XVSsOlxcLFPXGNnNVXVLh6FO8Y9T58XEWdPYqqYQyfE=; b=X8z9VYW7ehXzor7SKskK+fdehjiumYzHMnlEsemu+HqyE7rDyk5TltR3rPwWylaPnQ z2ZgT7S7Ixg1OuCoJRNOuLRyFqviv/z+9j41IHNVtb1GtSvyc1fXSt35nDFq/uKyMDXf uVuia953EBCkeoC02TldkTS9F+gQcNohIovNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XVSsOlxcLFPXGNnNVXVLh6FO8Y9T58XEWdPYqqYQyfE=; b=dBLQ7OqEgcbSKcK9NwmSuQu4MoryKJj1QoEol36Fw/mCxgQnF5khqBJLzCQLdsC/b0 rWiNIpdLT0/OyFS1brOb0X5NRqznihk9NaOHQbqH88Lk+VJyb6Vm5i9ilfnMyCjzWLXe eYps3pl08XyvKRMKTeJHDxb0G7VoDlne9cHdjHooNqqvq/HF/B7Q+NDBddCUD2Jsk6oN sl+l5j8BirsDZpRqDwr/uJqaISA5D+98ahjOKYZAjLYnYNCSK7n8yNnmWIwh6QzQtDba dHyhdzIu8N62zN4lrH8SJ8hmdhzA12Cb6xzKqE70T/PNDN+LwScE/tkHq2VG6E6/W7RU G6yA== X-Gm-Message-State: AD7BkJIl1O31zKZNud6/Q+xEGC5AgLzgqT1QWrGmFaoe4uTgDBXpEI+yRSaCPwdyFSHjlzQD4t7K29+VYCB/SuAH0YC0USQRxgLvPb5O0GExaNbKeQt5aLnJPxd33ZTL8rOkMiNNsgeiMnQ2ioa5wEjN159ayF8E9lMh8MvQKMvfm/XFAQ7vZWjAejbrnnJJUGpc X-Received: by 10.25.90.3 with SMTP id o3mr9473866lfb.147.1457443705809; Tue, 08 Mar 2016 05:28:25 -0800 (PST) Received: from dell6430.guest.wifi ([91.198.246.8]) by smtp.gmail.com with ESMTPSA id r200sm468962lfr.47.2016.03.08.05.28.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Mar 2016 05:28:25 -0800 (PST) From: Janusz Dziedzic To: hostap@lists.infradead.org Subject: [PATCH 2/4] tests: add remotehost.py and Host class Date: Tue, 8 Mar 2016 14:28:03 +0100 Message-Id: <1457443685-854-2-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457443685-854-1-git-send-email-janusz.dziedzic@tieto.com> References: <1457443685-854-1-git-send-email-janusz.dziedzic@tieto.com> X-DomainID: tieto.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160308_052850_301069_1A7F53CD X-CRM114-Status: GOOD ( 13.50 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c04:0:0:0:22c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Janusz Dziedzic MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This class allow to execute commands on remote hosts/machine. This base on authorized keys. So, you should be able to execute such command without any password: ssh @ id By default user is root. Support for sync and asnyc calls included. Signed-off-by: Janusz Dziedzic --- tests/hwsim/remotehost.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/hwsim/remotehost.py diff --git a/tests/hwsim/remotehost.py b/tests/hwsim/remotehost.py new file mode 100644 index 0000000..79ba403 --- /dev/null +++ b/tests/hwsim/remotehost.py @@ -0,0 +1,97 @@ +# Host class +# Copyright (c) 2016, Qualcomm Atheros, Inc. +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. +import logging +import subprocess +import threading + +logger = logging.getLogger() + +def execute_thread(command, reply): + try: + status = 0; + buf = subprocess.check_output(command, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + status = e.returncode + buf = e.output + + cmd = "" + for c in command: + cmd = cmd + " " + c + logger.debug("thread cmd: " + cmd) + logger.debug("thread exit status: " + str(status)) + logger.debug("thread exit buf: " + str(buf)) + reply.append(status) + reply.append(buf) + +class Host(): + def __init__(self, host=None, ifname=None, port=None, name="", user="root"): + self.host = host + self.name = name + self.user = user + self.ifname = ifname + self.port = port + if self.name == "" and host != None: + self.name = host + def local_execute(self, command): + logger.debug("execute: " + command) + words = command.split() + cmd = [] + for word in words: + cmd.append(word) + try: + status = 0; + buf = subprocess.check_output(cmd, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + status = e.returncode + buf = e.output + + logger.debug("status: " + str(status)) + logger.debug("buf: " + str(buf)) + return status, buf + + def execute(self, command): + if self.host is None: + return self.local_execute(command) + + cmd = ["ssh", self.user + "@" + self.host, command] + _cmd = self.name + " execute: " + for c in cmd: + _cmd = _cmd + " " + c + logger.debug(_cmd) + try: + status = 0 + buf = subprocess.check_output(cmd, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + status = e.returncode + buf = e.output + + logger.debug(self.name + " status: " + str(status)) + logger.debug(self.name + " buf: " + str(buf)) + return status, buf + + # async execute + def execute_run(self, command, res): + if self.host is None: + cmd = [command] + else: + cmd = ["ssh", self.user + "@" + self.host, command] + _cmd = self.name + " execute_run: " + for c in cmd: + _cmd = _cmd + " " + c + logger.debug(_cmd) + t = threading.Thread(target = execute_thread, args=(cmd, res)) + t.start() + return t + + def wait_execute_complete(self, t, wait=None): + if wait == None: + wait_str = "infinite" + else: + wait_str = str(wait) + "s" + + logger.debug(self.name + " wait_execute_complete(" + wait_str + "): ") + if t.isAlive(): + t.join(wait)