[PATCH v5 21/25] tests: hostapd.py/wpasupplicant.py use host when execute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@xxxxxxxxx>
---
 tests/hwsim/hostapd.py       |  2 ++
 tests/hwsim/wpasupplicant.py | 29 +++++++++++++----------------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py
index 06bc4a7..5368386 100644
--- a/tests/hwsim/hostapd.py
+++ b/tests/hwsim/hostapd.py
@@ -20,6 +20,7 @@ def mac2tuple(mac):
 
 class HostapdGlobal:
     def __init__(self, hostname=None, port=8878):
+        self.host = wpaspy.Host(hostname)
         self.hostname = hostname
         self.port = port
         if hostname is None:
@@ -84,6 +85,7 @@ class HostapdGlobal:
 
 class Hostapd:
     def __init__(self, ifname, bssidx=0, hostname=None, port=8877):
+        self.host = wpaspy.Host(hostname, ifname)
         self.ifname = ifname
 
         if hostname is None:
diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py
index 8003467..de814be 100644
--- a/tests/hwsim/wpasupplicant.py
+++ b/tests/hwsim/wpasupplicant.py
@@ -21,6 +21,7 @@ class WpaSupplicant:
         self.hostname = hostname
         self.group_ifname = None
         self.gctrl_mon = None
+        self.host = wpaspy.Host(hostname, ifname)
         if ifname:
             self.set_ifname(ifname, hostname, port)
         else:
@@ -50,6 +51,7 @@ class WpaSupplicant:
         if hostname != None:
             self.ctrl = wpaspy.Ctrl(hostname, port)
             self.mon = wpaspy.Ctrl(hostname, port)
+            self.host = wpaspy.Host(hostname, ifname)
         else:
             self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
             self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
@@ -85,11 +87,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
@@ -178,18 +179,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


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux