diff options
-rw-r--r-- | chrome/test/pyautolib/chromeos_network.py | 41 |
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 |