[PATCH 3/4] tests: hostapd.py/wpasupplicant.py use Host when execute

Janusz Dziedzic janusz.dziedzic at tieto.com
Tue Mar 8 05:28:04 PST 2016


In case of execute commands use Host. This allow to use
remote hosts as well.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic at tieto.com>
---
 tests/hwsim/hostapd.py       |  3 +++
 tests/hwsim/wpasupplicant.py | 31 ++++++++++++++-----------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py
index 0a4ad72..400c89c 100644
--- a/tests/hwsim/hostapd.py
+++ b/tests/hwsim/hostapd.py
@@ -10,6 +10,7 @@ import logging
 import binascii
 import struct
 import wpaspy
+import remotehost
 
 logger = logging.getLogger()
 hapd_ctrl = '/var/run/hostapd'
@@ -20,6 +21,7 @@ def mac2tuple(mac):
 
 class HostapdGlobal:
     def __init__(self, hostname=None, port=8878):
+        self.host = remotehost.Host(hostname)
         self.hostname = hostname
         self.port = port
         if hostname is None:
@@ -110,6 +112,7 @@ class HostapdGlobal:
 
 class Hostapd:
     def __init__(self, ifname, bssidx=0, hostname=None, port=8877):
+        self.host = remotehost.Host(hostname, ifname)
         self.ifname = ifname
         if hostname is None:
             self.ctrl = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py
index 3978b86..e9ea424 100644
--- a/tests/hwsim/wpasupplicant.py
+++ b/tests/hwsim/wpasupplicant.py
@@ -10,8 +10,8 @@ import logging
 import binascii
 import re
 import struct
-import subprocess
 import wpaspy
+import remotehost
 
 logger = logging.getLogger()
 wpas_ctrl = '/var/run/wpa_supplicant'
@@ -22,6 +22,7 @@ class WpaSupplicant:
         self.hostname = hostname
         self.group_ifname = None
         self.gctrl_mon = None
+        self.host = remotehost.Host(hostname, ifname)
         if ifname:
             self.set_ifname(ifname, hostname, port)
         else:
@@ -58,6 +59,7 @@ class WpaSupplicant:
         if hostname != None:
             self.ctrl = wpaspy.Ctrl(hostname, port)
             self.mon = wpaspy.Ctrl(hostname, port)
+            self.host = remotehost.Host(hostname, ifname)
         else:
             self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
             self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
@@ -93,11 +95,10 @@ class WpaSupplicant:
     def interface_add(self, ifname, config="", driver="nl80211",
                       drv_params=None, br_ifname=None, create=False,
                       set_ifname=True, all_params=False, if_type=None):
-        try:
-            groups = subprocess.check_output(["id"])
-            group = "admin" if "(admin)" in groups else "adm"
-        except Exception, e:
+        status, groups = self.host.execute("id")
+        if status != 0:
             group = "admin"
+        group = "admin" if "(admin)" in groups else "adm"
         cmd = "INTERFACE_ADD " + ifname + "\t" + config + "\t" + driver + "\tDIR=/var/run/wpa_supplicant GROUP=" + group
         if drv_params:
             cmd = cmd + '\t' + drv_params
@@ -186,18 +187,14 @@ class WpaSupplicant:
         if iter == 60:
             logger.error(self.ifname + ": Driver scan state did not clear")
             print "Trying to clear cfg80211/mac80211 scan state"
-            try:
-                cmd = ["ifconfig", self.ifname, "down"]
-                subprocess.call(cmd)
-            except subprocess.CalledProcessError, e:
-                logger.info("ifconfig failed: " + str(e.returncode))
-                logger.info(e.output)
-            try:
-                cmd = ["ifconfig", self.ifname, "up"]
-                subprocess.call(cmd)
-            except subprocess.CalledProcessError, e:
-                logger.info("ifconfig failed: " + str(e.returncode))
-                logger.info(e.output)
+            status, buf = self.host.execute("ifconfig " + self.ifname + " down")
+            if status != 0:
+                logger.info("ifconfig failed: " + buf)
+                logger.info(status)
+            status, buf = self.host.execute("ifconfig " + self.ifname + " up")
+            if status != 0:
+                logger.info("ifconfig failed: " + buf)
+                logger.info(status)
         if iter > 0:
             # The ongoing scan could have discovered BSSes or P2P peers
             logger.info("Run FLUSH again since scan was in progress")
-- 
1.9.1




More information about the Hostap mailing list