]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Convert Host() class to use list of arguments instead of string
authorJouni Malinen <j@w1.fi>
Sun, 24 Apr 2016 09:28:18 +0000 (12:28 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 24 Apr 2016 17:16:30 +0000 (20:16 +0300)
It is better to use a list of command line arguments for the local
execution case and convert that to a space-separated string for the
remote case.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/remotehost.py
tests/hwsim/utils.py
tests/hwsim/wpasupplicant.py

index cab204541d2d9a54b3c87bd4f847fb4644c13498..213c2fc4010a6aebc707e1b13fcefa1f362b58cb 100644 (file)
@@ -38,14 +38,10 @@ class Host():
             self.name = host
 
     def local_execute(self, command):
-        logger.debug("execute: " + command)
-        words = command.split()
-        cmd = []
-        for word in words:
-            cmd.append(word)
+        logger.debug("execute: " + str(command))
         try:
             status = 0;
-            buf = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+            buf = subprocess.check_output(command, stderr=subprocess.STDOUT)
         except subprocess.CalledProcessError as e:
             status = e.returncode
             buf = e.output
@@ -58,7 +54,7 @@ class Host():
         if self.host is None:
             return self.local_execute(command)
 
-        cmd = ["ssh", self.user + "@" + self.host, command]
+        cmd = ["ssh", self.user + "@" + self.host, ' '.join(command)]
         _cmd = self.name + " execute: "
         for c in cmd:
             _cmd = _cmd + " " + c
@@ -77,9 +73,9 @@ class Host():
     # async execute
     def execute_run(self, command, res):
         if self.host is None:
-            cmd = [command]
+            cmd = command
         else:
-            cmd = ["ssh",  self.user + "@" + self.host, command]
+            cmd = ["ssh",  self.user + "@" + self.host, ' '.join(command)]
         _cmd = self.name + " execute_run: "
         for c in cmd:
             _cmd = _cmd + " " + c
index 5fb824e4949cd93ecaaec3a2547377d9d1dc5dc6..479923cea7c9fcaa062db20041f615b2c734f1e5 100644 (file)
@@ -92,7 +92,7 @@ def get_phy(ap, ifname=None):
 
     if ifname == None:
         ifname = ap['ifname']
-    status, buf = host.execute("iw dev " + ifname + " info")
+    status, buf = host.execute(["iw", "dev", ifname, "info"])
     if status != 0:
         raise Exception("iw " + ifname + " info failed")
     lines = buf.split("\n")
index bc865b8e091d8659e21918edcb2533214080373a..b164fe00b99c57c793df4efe777c9c8a28570ae5 100644 (file)
@@ -99,7 +99,7 @@ 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):
-        status, groups = self.host.execute("id")
+        status, groups = self.host.execute(["id"])
         if status != 0:
             group = "admin"
         group = "admin" if "(admin)" in groups else "adm"
@@ -191,11 +191,11 @@ class WpaSupplicant:
         if iter == 60:
             logger.error(self.ifname + ": Driver scan state did not clear")
             print "Trying to clear cfg80211/mac80211 scan state"
-            status, buf = self.host.execute("ifconfig " + self.ifname + " down")
+            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")
+            status, buf = self.host.execute(["ifconfig", self.ifname, "up"])
             if status != 0:
                 logger.info("ifconfig failed: " + buf)
                 logger.info(status)