]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Add functions to execute shell commands on interface host
authorJonathan Afek <jonathan@wizery.com>
Tue, 7 Jun 2016 13:42:40 +0000 (16:42 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 19 Jun 2016 20:48:07 +0000 (23:48 +0300)
Add the feature to execute shell commands on each wpa_supplicant/hostapd
interface host. When executing remote tests the interfaces are not all
on a single host so when executing shell commands the test needs to
execute the command on the host which the interface relevant for the
command is on. This patch enables tests to execute the command on the
relevant host.

Signed-off-by: Jonathan Afek <jonathanx.afek@intel.com>
tests/hwsim/hostapd.py
tests/hwsim/wpasupplicant.py

index 6d6d641d4194f49d46ab7fd7dd948a52cbf5c29d..9d670768b9a1a98198c135056a6858266ffa1c88 100644 (file)
@@ -12,6 +12,7 @@ import struct
 import wpaspy
 import remotehost
 import utils
+import subprocess
 
 logger = logging.getLogger()
 hapd_ctrl = '/var/run/hostapd'
@@ -41,6 +42,17 @@ class HostapdGlobal:
             self.dbg = hostname + "/" + str(port)
         self.mon.attach()
 
+    def cmd_execute(self, cmd_array):
+        if self.hostname is None:
+            cmd = ' '.join(cmd_array)
+            proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
+                                    stdout=subprocess.PIPE, shell=True)
+            out = proc.communicate()[0]
+            ret = proc.returncode
+            return ret, out
+        else:
+            return self.host.execute(cmd_array)
+
     def request(self, cmd, timeout=10):
         logger.debug(self.dbg + ": CTRL(global): " + cmd)
         return self.ctrl.request(cmd, timeout)
@@ -134,6 +146,20 @@ class Hostapd:
         self.bssid = None
         self.bssidx = bssidx
 
+    def cmd_execute(self, cmd_array):
+        if self.hostname is None:
+            cmd = ""
+            for arg in cmd_array:
+                cmd += arg + " "
+            cmd = cmd.strip()
+            proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
+                                    stdout=subprocess.PIPE, shell=True)
+            out = proc.communicate()[0]
+            ret = proc.returncode
+            return ret, out
+        else:
+            return self.host.execute(cmd_array)
+
     def close_ctrl(self):
         if self.mon is not None:
             self.mon.detach()
@@ -561,3 +587,7 @@ def ht40_minus_params(channel="1", ssid=None, country=None):
     params = ht20_params(channel, ssid, country)
     params['ht_capab'] = "[HT40-]"
     return params
+
+def cmd_execute(apdev, cmd):
+    hapd_global = HostapdGlobal(apdev)
+    return hapd_global.cmd_execute(cmd)
index 7d80d6ba73d4858ce86e0b0c38ccb5fbf8bb2af4..1f456905b37d84a5a93bbd32f8cb68df9f4c5f6a 100644 (file)
@@ -12,6 +12,7 @@ import re
 import struct
 import wpaspy
 import remotehost
+import subprocess
 
 logger = logging.getLogger()
 wpas_ctrl = '/var/run/wpa_supplicant'
@@ -48,6 +49,17 @@ class WpaSupplicant:
         else:
             self.global_mon = None
 
+    def cmd_execute(self, cmd_array):
+        if self.hostname is None:
+            cmd = ' '.join(cmd_array)
+            proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
+                                    stdout=subprocess.PIPE, shell=True)
+            out = proc.communicate()[0]
+            ret = proc.returncode
+            return ret, out
+        else:
+            return self.host.execute(cmd_array)
+
     def terminate(self):
         if self.global_mon:
             self.global_mon.detach()