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

Side by Side Diff: tools/telemetry/telemetry/cros_interface.py

Issue 11231087: Removing flake in TemporaryHTTPServer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
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 """A wrapper around ssh for common operations on a CrOS-based device""" 4 """A wrapper around ssh for common operations on a CrOS-based device"""
5 import logging 5 import logging
6 import os 6 import os
7 import re 7 import re
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import time 10 import time
11 import tempfile 11 import tempfile
12 12
13 from telemetry import util 13 from telemetry import util
14 14
15 _next_remote_port = 9224
16
17 # TODO(nduca): This whole file is built up around making individual ssh calls 15 # TODO(nduca): This whole file is built up around making individual ssh calls
18 # for each operation. It really could get away with a single ssh session built 16 # for each operation. It really could get away with a single ssh session built
19 # around pexpect, I suspect, if we wanted it to be faster. But, this was 17 # around pexpect, I suspect, if we wanted it to be faster. But, this was
20 # convenient. 18 # convenient.
21 19
22 def RunCmd(args, cwd=None, quiet=False): 20 def RunCmd(args, cwd=None, quiet=False):
23 """Opens a subprocess to execute a program and returns its return value. 21 """Opens a subprocess to execute a program and returns its return value.
24 22
25 Args: 23 Args:
26 args: A string or a sequence of program arguments. The program to execute is 24 args: A string or a sequence of program arguments. The program to execute is
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return running 364 return running
367 365
368 def GetCmdOutput(self, args, quiet=False): 366 def GetCmdOutput(self, args, quiet=False):
369 stdout, stderr = self.GetAllCmdOutput(args, quiet=True) 367 stdout, stderr = self.GetAllCmdOutput(args, quiet=True)
370 assert stderr == '' 368 assert stderr == ''
371 if not quiet: 369 if not quiet:
372 logging.debug("GetCmdOutput(%s)->%s" % (repr(args), stdout)) 370 logging.debug("GetCmdOutput(%s)->%s" % (repr(args), stdout))
373 return stdout 371 return stdout
374 372
375 def GetRemotePort(self): 373 def GetRemotePort(self):
376 global _next_remote_port 374 netstat = self.GetAllCmdOutput(['netstat', '-ant'])
377 port = _next_remote_port 375 netstat = netstat[0].split('\n')
378 _next_remote_port += 1 376 ports_in_use = []
379 return port 377
378 for line in netstat[2:]:
379 if not line:
380 continue
381 address_in_use = line.split()[3]
382 port_in_use = address_in_use.split(':')[-1]
383 ports_in_use.append(int(port_in_use))
384
385 return sorted(ports_in_use)[-1] + 1
386
387 def IsHTTPServerRunningOnPort(self, port):
388 wget_output = self.GetAllCmdOutput(
389 ['wget', 'localhost:%i' % (port), '-T1', '-t1'])
390
391 if 'Connection refused' in wget_output[1]:
392 return False
393
394 return True
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/cros_browser_backend.py ('k') | tools/telemetry/telemetry/cros_interface_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698