diff options
-rw-r--r-- | chrome/test/functional/chromeos_wifi.py | 12 | ||||
-rw-r--r-- | chrome/test/functional/chromeos_wifi_compliance.py | 49 | ||||
-rw-r--r-- | chrome/test/pyautolib/chromeos/power_strip.py | 59 | ||||
-rw-r--r-- | chrome/test/pyautolib/chromeos_network.py | 8 |
4 files changed, 117 insertions, 11 deletions
diff --git a/chrome/test/functional/chromeos_wifi.py b/chrome/test/functional/chromeos_wifi.py index 131f4a6..e757ebf 100644 --- a/chrome/test/functional/chromeos_wifi.py +++ b/chrome/test/functional/chromeos_wifi.py @@ -25,5 +25,17 @@ class ChromeosWifi(chromeos_network.PyNetworkUITest): self.assertTrue(result) logging.debug(result) + def testConnectToHiddenWiFiNonExistent(self): + """Connecting to a non-existent network should fail. + + Assume network 'ThisIsANonExistentNetwork' is not a valid ssid within + the vicinity of where this test is run. + """ + ssid = 'ThisIsANonExistentNetwork' + error = self.ConnectToHiddenWifiNetwork(ssid, 'SECURITY_NONE') + self.assertTrue(error, msg='Device connected to a non-existent ' + 'network "%s".' % ssid) + + if __name__ == '__main__': pyauto_functional.Main() diff --git a/chrome/test/functional/chromeos_wifi_compliance.py b/chrome/test/functional/chromeos_wifi_compliance.py index b66be87..5ae3b07 100644 --- a/chrome/test/functional/chromeos_wifi_compliance.py +++ b/chrome/test/functional/chromeos_wifi_compliance.py @@ -38,16 +38,63 @@ class ChromeosWifiCompliance(chromeos_network.PyNetworkUITest): 'Did not successfully connect to wifi network %s.' % ssid) self.DisconnectFromWifiNetwork() - self.RouterPower(router_name, False) def testConnectBelkinG(self): """Test connecting to the Belkin G router.""" self._BasicConnectRouterCompliance('Belkin_G') + def testConnectBelkinNPlus(self): + """Test connecting to the Belkin N+ router.""" + self._BasicConnectRouterCompliance('Belkin_N+') + + def testConnectDLinkN150(self): + """Test connecting to the D-Link N150 router.""" + self._BasicConnectRouterCompliance('D-Link_N150') + + def testConnectLinksysE3000(self): + """Test connecting to the Linksys E3000 router. + + The LinksysE3000 supports broadcasting of up to 2 SSID's. + This test will try connecting to each of them one at a time. + """ + self._BasicConnectRouterCompliance('LinksysE3000') + self._BasicConnectRouterCompliance('LinksysE3000_2') + def testConnectLinksysWRT54G2(self): """Test connecting to the Linksys WRT54G2 router.""" self._BasicConnectRouterCompliance('Linksys_WRT54G2') + def testConnectLinksysWRT54GL(self): + """Test connecting to the LinksysWRT54GL router.""" + self._BasicConnectRouterCompliance('Linksys_WRT54GL') + + def testConnectNetgearN300(self): + """Test connecting to the Netgear N300 router.""" + self._BasicConnectRouterCompliance('Netgear_N300') + + def testConnectNetgearWGR614(self): + """Test connecting to the Netgear WGR 614 router.""" + self._BasicConnectRouterCompliance('Netgear_WGR614') + + def testConnectNfiniti(self): + """Test connecting to the Nfiniti router.""" + self._BasicConnectRouterCompliance('Belkin_N+') + + def testConnectSMCWBR145(self): + """Test connecting to the SMC WBR 145 router.""" + self._BasicConnectRouterCompliance('SMC_WBR145') + + def testConnectTrendnet_639gr(self): + """Test connecting to the Trendnet 639gr router. + + The LinksysE3000 supports broadcasting of up to 4 SSID's. + This test will try connecting to each of them one at a time. + """ + self._BasicConnectRouterCompliance('Trendnet_639gr') + self._BasicConnectRouterCompliance('Trendnet_639gr_2') + self._BasicConnectRouterCompliance('Trendnet_639gr_3') + self._BasicConnectRouterCompliance('Trendnet_639gr_4') + if __name__ == '__main__': pyauto_functional.Main() diff --git a/chrome/test/pyautolib/chromeos/power_strip.py b/chrome/test/pyautolib/chromeos/power_strip.py index 50d7b19..b614b67 100644 --- a/chrome/test/pyautolib/chromeos/power_strip.py +++ b/chrome/test/pyautolib/chromeos/power_strip.py @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import logging +import re import telnetlib @@ -17,6 +19,8 @@ class PowerStrip(object): Opens a new connection for every command. """ + TIMEOUT = 10 + def __init__(self, host, user='admn', password='admn'): self._host = host self._user = user @@ -67,12 +71,49 @@ class PowerStrip(object): <command> <outlet>. outlet: The outlet ID defined on the switch (eg. .a14). """ - tn = telnetlib.Telnet(self._host) - tn.read_until('Username: ') - tn.write(self._user + '\n') - tn.read_until('Password: ') - tn.write(self._password + '\n') - tn.read_until('Switched CDU: ') - tn.write('%s %s\n' % (command, outlet)) - tn.read_some() - tn.close() + tn = telnetlib.Telnet() + # To avoid 'Connection Reset by Peer: 104' exceptions when rapid calls + # are made to the telnet server on the power strip, we retry executing + # a command. + retry = range(5) + for attempt in retry: + try: + tn.open(self._host, timeout=PowerStrip.TIMEOUT) + resp = tn.read_until('Username:', timeout=PowerStrip.TIMEOUT) + assert 'Username' in resp, 'Username not found in response. (%s)' % resp + tn.write(self._user + '\n') + + resp = tn.read_until('Password:', timeout=PowerStrip.TIMEOUT) + assert 'Password' in resp, 'Password not found in response. (%s)' % resp + tn.write(self._password + '\n') + + resp = tn.read_until('Switched CDU:', timeout=PowerStrip.TIMEOUT) + assert 'Switched CDU' in resp, 'Standard prompt not found in ' \ + 'response. (%s)' % resp + tn.write('%s %s\n' % (command, outlet)) + + # Obtain the output of command and make sure it matches with the action + # we performed. + # Sample valid output: + # .A1 TowerA_Outlet1 On On + resp = tn.read_until('Switched CDU:', timeout=PowerStrip.TIMEOUT) + if not re.search('%s\s+\S+\s+%s\s+%s' % (outlet, command, command), + resp, re.I): + raise Exception('Command \'%s\' execution failed. (%s)' % + (command, resp)) + + # Exiting the telnet session cleanly significantly reduces the chance of + # connection error on initiating the following telnet session. + tn.write('exit\n') + tn.read_all() + + # If we've gotten this far, there is no need to retry. + break + except Exception as e: + logging.debug('Power strip retry on cmd "%s". Reason: %s' + % (command, str(e))) + if attempt == retry[-1]: + raise Exception('Sentry Command "%s" failed. ' + 'Reason: %s' % (command, str(e))) + finally: + tn.close() diff --git a/chrome/test/pyautolib/chromeos_network.py b/chrome/test/pyautolib/chromeos_network.py index 9146be0..f7fba95 100644 --- a/chrome/test/pyautolib/chromeos_network.py +++ b/chrome/test/pyautolib/chromeos_network.py @@ -136,7 +136,13 @@ class PyNetworkUITest(pyauto.PyUITest): def _SetServiceOrder(self, service_order): self._manager.SetServiceOrder(service_order) - self._manager.DisableTechnology('wifi') + # Flimflam throws a dbus exception if device is already disabled. This + # is not an error. + try: + self._manager.DisableTechnology('wifi') + except dbus.DBusException as e: + if 'org.chromium.flimflam.Error.AlreadyDisabled' not in str(e): + raise e self._manager.EnableTechnology('wifi') def _PushServiceOrder(self, service_order): |