Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1088)

Side by Side Diff: build/android/pylib/fake_dns.py

Issue 22903016: [android] Adds constants.GetOutDirectory() and converts test scripts to use it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix provision_devices.py which never set the build type Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/device_stats_monitor.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import android_commands 5 import android_commands
6 import constants 6 import constants
7 import logging 7 import logging
8 import os 8 import os
9 import subprocess 9 import subprocess
10 import time 10 import time
(...skipping 12 matching lines...) Expand all
23 self._fake_dns = None 23 self._fake_dns = None
24 self._original_dns = None 24 self._original_dns = None
25 25
26 def _PushAndStartFakeDns(self): 26 def _PushAndStartFakeDns(self):
27 """Starts the fake_dns server that replies all name queries 127.0.0.1. 27 """Starts the fake_dns server that replies all name queries 127.0.0.1.
28 28
29 Returns: 29 Returns:
30 subprocess instance connected to the fake_dns process on the device. 30 subprocess instance connected to the fake_dns process on the device.
31 """ 31 """
32 self._adb.PushIfNeeded( 32 self._adb.PushIfNeeded(
33 os.path.join(constants.DIR_SOURCE_ROOT, 'out', constants.GetBuildType(), 33 os.path.join(constants.GetOutDirectory(), 'fake_dns'),
34 'fake_dns'),
35 FakeDns._FAKE_DNS_PATH) 34 FakeDns._FAKE_DNS_PATH)
36 return subprocess.Popen( 35 return subprocess.Popen(
37 ['adb', '-s', self._adb._adb.GetSerialNumber(), 36 ['adb', '-s', self._adb._adb.GetSerialNumber(),
38 'shell', '%s -D' % FakeDns._FAKE_DNS_PATH]) 37 'shell', '%s -D' % FakeDns._FAKE_DNS_PATH])
39 38
40 def SetUp(self): 39 def SetUp(self):
41 """Configures the system to point to a DNS server that replies 127.0.0.1. 40 """Configures the system to point to a DNS server that replies 127.0.0.1.
42 41
43 This can be used in combination with the forwarder to forward all web 42 This can be used in combination with the forwarder to forward all web
44 traffic to a replay server. 43 traffic to a replay server.
45 44
46 The TearDown() method will perform all cleanup. 45 The TearDown() method will perform all cleanup.
47 """ 46 """
48 self._adb.RunShellCommand('ip route add 8.8.8.0/24 via 127.0.0.1 dev lo') 47 self._adb.RunShellCommand('ip route add 8.8.8.0/24 via 127.0.0.1 dev lo')
49 self._fake_dns = self._PushAndStartFakeDns() 48 self._fake_dns = self._PushAndStartFakeDns()
50 self._original_dns = self._adb.RunShellCommand('getprop net.dns1')[0] 49 self._original_dns = self._adb.RunShellCommand('getprop net.dns1')[0]
51 self._adb.RunShellCommand('setprop net.dns1 127.0.0.1') 50 self._adb.RunShellCommand('setprop net.dns1 127.0.0.1')
52 time.sleep(2) # Time for server to start and the setprop to take effect. 51 time.sleep(2) # Time for server to start and the setprop to take effect.
53 52
54 def TearDown(self): 53 def TearDown(self):
55 """Shuts down the fake_dns.""" 54 """Shuts down the fake_dns."""
56 if self._fake_dns: 55 if self._fake_dns:
57 if not self._original_dns or self._original_dns == '127.0.0.1': 56 if not self._original_dns or self._original_dns == '127.0.0.1':
58 logging.warning('Bad original DNS, falling back to Google DNS.') 57 logging.warning('Bad original DNS, falling back to Google DNS.')
59 self._original_dns = '8.8.8.8' 58 self._original_dns = '8.8.8.8'
60 self._adb.RunShellCommand('setprop net.dns1 %s' % self._original_dns) 59 self._adb.RunShellCommand('setprop net.dns1 %s' % self._original_dns)
61 self._fake_dns.kill() 60 self._fake_dns.kill()
62 self._adb.RunShellCommand('ip route del 8.8.8.0/24 via 127.0.0.1 dev lo') 61 self._adb.RunShellCommand('ip route del 8.8.8.0/24 via 127.0.0.1 dev lo')
OLDNEW
« no previous file with comments | « build/android/pylib/device_stats_monitor.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698