summaryrefslogtreecommitdiffstats
path: root/chrome/test/pyautolib
diff options
context:
space:
mode:
authorstanleyw@chromium.org <stanleyw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 00:15:40 +0000
committerstanleyw@chromium.org <stanleyw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 00:15:40 +0000
commit159d7ce6e3694b9ab28d54a5366bb1b50bedb7c9 (patch)
treeea0e02d4a077be66f94f26ac5149afd4cc71589c /chrome/test/pyautolib
parentd69d322dcd9d2ace6b0f27d958db6894d1cfb080 (diff)
downloadchromium_src-159d7ce6e3694b9ab28d54a5366bb1b50bedb7c9.zip
chromium_src-159d7ce6e3694b9ab28d54a5366bb1b50bedb7c9.tar.gz
chromium_src-159d7ce6e3694b9ab28d54a5366bb1b50bedb7c9.tar.bz2
Adding routing table entry for power strip
When we modify the service order, we lose our route to the power strip so we are unable to perform power strip commands. When we initialize the power strip, we need to add an entry to the routing table for the power strip so we can talk to it. Change-Id: I5d9004c09451ea2277ff2712c87cc15b39651f13 BUG=None TEST=run chromeos_wifi_sanity.py from corp network we should not see any power_strip command failures. Review URL: http://codereview.chromium.org/8304009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105974 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r--chrome/test/pyautolib/chromeos_network.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/chrome/test/pyautolib/chromeos_network.py b/chrome/test/pyautolib/chromeos_network.py
index 601cedc..9665cfa 100644
--- a/chrome/test/pyautolib/chromeos_network.py
+++ b/chrome/test/pyautolib/chromeos_network.py
@@ -140,6 +140,7 @@ class PyNetworkUITest(pyauto.PyUITest):
# effectively hiding any ssh connections that the
# test harness might be using and putting wifi ahead.
self._PushServiceOrder('vpn,bluetooth,wifi,wimax,cellular,ethernet')
+ self._ParseDefaultRoutingTable()
pyauto.PyUITest.setUp(self)
self.ForgetAllRememberedNetworks()
self._wifi_power_strip = None
@@ -150,6 +151,20 @@ class PyNetworkUITest(pyauto.PyUITest):
self._PopServiceOrder()
if self._wifi_power_strip:
self._wifi_power_strip.TurnOffUsedRouters()
+ # Remove the route entry for the power strip.
+ if hasattr(self, 'ps_route_entry'):
+ os.system('route del -net %(ipaddress)s gateway %(gateway)s netmask '
+ '%(netmask)s dev %(iface)s' % self.ps_route_entry)
+
+ def _ParseDefaultRoutingTable(self):
+ """Creates and stores a dictionary of the default routing paths."""
+ route_table_headers = ['destination', 'gateway', 'genmask', 'flags',
+ 'metric', 'ref', 'use', 'iface']
+ routes = os.popen('route -n | egrep "^0.0.0.0"').read()
+ routes = [interface.split() for interface in routes.split('\n')][:-1]
+ self.default_routes = {}
+ for iface in routes:
+ self.default_routes[iface[-1]] = dict(zip(route_table_headers, iface))
def ForgetAllRememberedNetworks(self):
"""Forgets all networks that the device has marked as remembered."""
@@ -200,6 +215,31 @@ class PyNetworkUITest(pyauto.PyUITest):
'Flimflam service order not set properly. %s != %s' % \
(old_service_order, set_service_order)
+ def _SetupRouteForPowerStrip(self, ipaddress, iface='eth'):
+ """Create a route table entry for the power strip."""
+
+ # Assume device has only one interface that is prepended with
+ # $iface and use that one.
+ try:
+ iface = [ key for key in self.default_routes.keys() if iface in key ][0]
+ except:
+ assert 'Unable to find interface of type %s.' % iface
+
+ self.ps_route_entry = {
+ 'iface' : iface,
+ 'gateway' : self.default_routes[iface]['gateway'],
+ 'netmask' : '255.255.255.255',
+ 'ipaddress' : ipaddress
+ }
+
+ os.system('route add -net %(ipaddress)s gateway %(gateway)s netmask '
+ '%(netmask)s dev %(iface)s' % self.ps_route_entry)
+
+ # Verify the route was added.
+ assert os.system('route -n | egrep "^%(ipaddress)s[[:space:]]+%(gateway)s'
+ '[[:space:]]+%(netmask)s"' % self.ps_route_entry) == 0, \
+ 'Failed to create default route for powerstrip.'
+
def InitWifiPowerStrip(self):
"""Initializes the router controller using the specified config file."""
@@ -209,6 +249,7 @@ class PyNetworkUITest(pyauto.PyUITest):
config = pyauto.PyUITest.EvalDataFrom(self._ROUTER_CONFIG_FILE)
strip_ip, routers = config['strip_ip'], config['routers']
+ self._SetupRouteForPowerStrip(strip_ip)
self._wifi_power_strip = WifiPowerStrip(strip_ip, routers)
self.RouterPower = self._wifi_power_strip.RouterPower