summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorachuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-13 07:46:02 +0000
committerachuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-13 07:46:02 +0000
commitb90586a7b0cd132a03df1126a36992738e08a05a (patch)
treef323365a9f54fd4ee0c2a61dce280bac646802a1 /tools
parent038b08dee84ddadd8e4e113d1fdecd71ad7dcba1 (diff)
downloadchromium_src-b90586a7b0cd132a03df1126a36992738e08a05a.zip
chromium_src-b90586a7b0cd132a03df1126a36992738e08a05a.tar.gz
chromium_src-b90586a7b0cd132a03df1126a36992738e08a05a.tar.bz2
Support for local mode in cros_interface.
Most methods of CrosInterface can now be called locally on a cros device. * Allow CrosInterface to be initialized without a hostname. * Add property local to CrosInterface. * Add unit tests for 2 public methods of CrosInterface FileExistsOnDevice and IsServiceRunning. BUG=178278 TEST=run_tests textExistsLocal and testIsServiceRunningLocal on cros_device/linux desktop. NOTRY=true Review URL: https://codereview.chromium.org/12667002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/telemetry/telemetry/core/chrome/cros_interface.py24
-rw-r--r--tools/telemetry/telemetry/core/chrome/cros_interface_unittest.py16
2 files changed, 36 insertions, 4 deletions
diff --git a/tools/telemetry/telemetry/core/chrome/cros_interface.py b/tools/telemetry/telemetry/core/chrome/cros_interface.py
index a7ce360..2e2d087 100644
--- a/tools/telemetry/telemetry/core/chrome/cros_interface.py
+++ b/tools/telemetry/telemetry/core/chrome/cros_interface.py
@@ -200,8 +200,14 @@ class KeylessLoginRequiredException(LoginException):
class CrOSInterface(object):
# pylint: disable=R0923
- def __init__(self, hostname, ssh_identity = None):
+ def __init__(self, hostname = None, ssh_identity = None):
self._hostname = hostname
+ # List of ports generated from GetRemotePort() that may not be in use yet.
+ self._reserved_ports = []
+
+ if self.local:
+ return
+
self._ssh_identity = None
self._hostfile = tempfile.NamedTemporaryFile()
self._hostfile.flush()
@@ -211,17 +217,21 @@ class CrOSInterface(object):
'-o PreferredAuthentications=publickey',
'-o UserKnownHostsFile=%s' % self._hostfile.name]
- # List of ports generated from GetRemotePort() that may not be in use yet.
- self._reserved_ports = []
-
if ssh_identity:
self._ssh_identity = os.path.abspath(os.path.expanduser(ssh_identity))
@property
+ def local(self):
+ return not self._hostname
+
+ @property
def hostname(self):
return self._hostname
def FormSSHCommandLine(self, args, extra_ssh_args=None):
+ if self.local:
+ return args
+
full_args = ['ssh',
'-o ForwardX11=no',
'-o ForwardX11Trusted=no',
@@ -257,6 +267,7 @@ class CrOSInterface(object):
def TryLogin(self):
logging.debug('TryLogin()')
+ assert not self.local
stdout, stderr = self.RunCmdOnDevice(['echo', '$USER'], quiet=True)
if stderr != '':
if 'Host key verification failed' in stderr:
@@ -280,6 +291,9 @@ class CrOSInterface(object):
self._hostname, stdout))
def FileExistsOnDevice(self, file_name, quiet=False):
+ if self.local:
+ return os.path.exists(file_name)
+
stdout, stderr = self.RunCmdOnDevice([
'if', 'test', '-a', file_name, ';',
'then', 'echo', '1', ';',
@@ -297,6 +311,7 @@ class CrOSInterface(object):
return exists
def PushFile(self, filename, remote_filename):
+ assert not self.local
args = ['scp', '-r' ] + self._ssh_args
if self._ssh_identity:
args.extend(['-i', self._ssh_identity])
@@ -317,6 +332,7 @@ class CrOSInterface(object):
self.PushFile(f.name, remote_filename)
def GetFileContents(self, filename):
+ assert not self.local
with tempfile.NamedTemporaryFile() as f:
args = ['scp'] + self._ssh_args
if self._ssh_identity:
diff --git a/tools/telemetry/telemetry/core/chrome/cros_interface_unittest.py b/tools/telemetry/telemetry/core/chrome/cros_interface_unittest.py
index a97cbb8..3e7c612 100644
--- a/tools/telemetry/telemetry/core/chrome/cros_interface_unittest.py
+++ b/tools/telemetry/telemetry/core/chrome/cros_interface_unittest.py
@@ -7,6 +7,7 @@
# a bit.
import unittest
import socket
+import sys
from telemetry.core import util
from telemetry.core.chrome import cros_browser_backend
@@ -69,6 +70,15 @@ class CrOSInterfaceTest(unittest.TestCase):
self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
+ def testExistsLocal(self):
+ if not sys.platform.startswith('linux'):
+ return
+
+ cri = cros_interface.CrOSInterface()
+ self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
+ self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
+ self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
+
@run_tests.RequiresBrowserOfType('cros-chrome')
def testGetFileContents(self): # pylint: disable=R0201
remote = options_for_unittests.GetCopy().cros_remote
@@ -112,6 +122,12 @@ class CrOSInterfaceTest(unittest.TestCase):
self.assertTrue(cri.IsServiceRunning('openssh-server'))
+ def testIsServiceRunningLocal(self):
+ if not sys.platform.startswith('linux'):
+ return
+ cri = cros_interface.CrOSInterface()
+ self.assertTrue(cri.IsServiceRunning('dbus'))
+
@run_tests.RequiresBrowserOfType('cros-chrome')
def testGetRemotePortAndIsHTTPServerRunningOnPort(self):
remote = options_for_unittests.GetCopy().cros_remote