blob: 6e511aee62c09f3636f97657abf84f3be221bce6 [file] [log] [blame]
from autotest_lib.client.bin import test
from autotest_lib.client.common_lib import error
import os
import re
import sys
import time
import wifi
class network_WifiAuthenticationTests(test.test):
Tests that we can connect to the routers specified in router-test.dat
The test attempts to connect to each router using the given password,
once a connection is established we will verify that the IP returned
by ifconfig matches an ip range specifed in the same config file.
version = 1
def run_once(self):
fd = open(os.path.join(self.bindir, "router-test.dat"))
router_test_data = eval(
success = self.RunConnectionTests(router_test_data)
if not success:
raise error.TestFail("failed to connect")
except Exception, e:
raise error.TestFail("Error running the test")
def GetWifiIP(self):
cli = os.popen(
"/sbin/ifconfig wlan0 | grep \"inet addr\"").readline().strip(" ")
r ="inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)", cli)
ip = "NONE"
ip =
except Exception, e:
print e
return ip
def IsConnected(self, ip_prefix):
wlan_ip = ""
wlan_ip = self.GetWifiIP()
except Exception, e:
print e
return wlan_ip.find(ip_prefix) == 0
def RunConnectionTests(self, routers):
passed = 0
failed = 0
skipped = 0
for ssid, properties in routers.iteritems():
available_networks = wifi.Scan()
if not available_networks.has_key(ssid):
print "Unable to scan for % s" % ssid
skipped += 1
wifi.AddNetwork(ssid, properties.get("passphrase", None))
if self.IsConnected(properties.get("ip-prefix", "UNKNOWN")):
passed += 1
failed += 1
return failed == 0