Example #1
0
 def __init__(self, device=None):
     super(CrosPlatformBackend, self).__init__(device)
     if device:
         self._cri = cros_interface.CrOSInterface(device.host_name,
                                                  device.ssh_identity)
         self._cri.TryLogin()
     else:
         self._cri = cros_interface.CrOSInterface()
     self._powermonitor = cros_power_monitor.CrosPowerMonitor(self)
 def testGetFileContents(self):  # pylint: disable=R0201
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         hosts = cri.GetFileContents('/etc/lsb-release')
         self.assertTrue('CHROMEOS' in hosts)
Example #3
0
 def setUp(self):
     options = options_for_unittests.GetCopy()
     self._cri = cros_interface.CrOSInterface(options.cros_remote,
                                              options.cros_ssh_identity)
     self._is_guest = options.browser_type == 'cros-chrome-guest'
     self._username = options.browser_options.username
     self._password = options.browser_options.password
     self._load_extension = None
 def testExists(self):
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
         self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
         self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
 def testGetFileNonExistent(self):
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         f = tempfile.NamedTemporaryFile()
         cri.PushContents('testGetFileNonExistent', f.name)
         cri.RmRF(f.name)
         self.assertRaises(OSError, lambda: cri.GetFile(f.name))
 def testPushContents(self):
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         cri.RunCmdOnDevice(['rm', '-rf', '/tmp/testPushContents'])
         cri.PushContents('hello world', '/tmp/testPushContents')
         contents = cri.GetFileContents('/tmp/testPushContents')
         self.assertEquals(contents, 'hello world')
 def testGetFile(self):  # pylint: disable=R0201
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         f = tempfile.NamedTemporaryFile()
         cri.GetFile('/etc/lsb-release', f.name)
         with open(f.name, 'r') as f2:
             res = f2.read()
             self.assertTrue('CHROMEOS' in res)
Example #8
0
    def Start(self, local_app_path=None):
        """ Connects to the ChromeOS device and logs in.
    Args:
      local_app_path: A path on the local device containing the Smart Lock app
                      to use instead of the app on the ChromeOS device.
    Return:
      |self| for using in a "with" statement.
    """
        assert (self._browser is None)

        finder_opts = browser_options.BrowserFinderOptions('cros-chrome')
        finder_opts.CreateParser().parse_args(args=[])
        finder_opts.cros_remote = self._remote_address
        if self._ssh_port is not None:
            finder_opts.cros_remote_ssh_port = self._ssh_port
        finder_opts.verbosity = 1

        browser_opts = finder_opts.browser_options
        browser_opts.create_browser_with_oobe = True
        browser_opts.disable_component_extensions_with_background_pages = False
        browser_opts.gaia_login = True
        browser_opts.username = self._username
        browser_opts.password = self._password
        browser_opts.auto_login = True

        self._cros_interface = cros_interface.CrOSInterface(
            finder_opts.cros_remote, finder_opts.cros_remote_ssh_port,
            finder_opts.cros_ssh_identity)

        browser_opts.disable_default_apps = local_app_path is not None
        if local_app_path is not None:
            easy_unlock_app = extension_to_load.ExtensionToLoad(
                path=local_app_path,
                browser_type='cros-chrome',
                is_component=True)
            finder_opts.extensions_to_load.append(easy_unlock_app)

        retries = 3
        while self._browser is not None or retries > 0:
            try:
                browser_to_create = browser_finder.FindBrowser(finder_opts)
                self._browser = browser_to_create.Create(finder_opts)
                break
            except (exceptions.LoginException) as e:
                logger.error('Timed out logging in: %s' % e)
                if retries == 1:
                    raise

        bg_page_path = '/_generated_background_page.html'
        util.WaitFor(
            lambda: self._FindSmartLockAppPage(bg_page_path) is not None, 10)
        self._background_page = self._FindSmartLockAppPage(bg_page_path)
        return self
    def testGetRemotePortReservedPorts(self):
        remote = options_for_unittests.GetCopy().cros_remote
        with cros_interface.CrOSInterface(
                remote,
                options_for_unittests.GetCopy().cros_ssh_identity) as cri:

            # Should return 2 separate ports even though the first one isn't
            # technically being used yet.
            remote_port_1 = cri.GetRemotePort()
            remote_port_2 = cri.GetRemotePort()

            self.assertTrue(remote_port_1 != remote_port_2)
    def testEscapeCmdArguments(self):
        ''' Commands and their arguments that are executed through the cros
    interface should follow bash syntax. This test needs to run on remotely
    and locally on the device to check for consistency.
    '''
        with cros_interface.CrOSInterface(
                options_for_unittests.GetCopy().cros_remote,
                options_for_unittests.GetCopy().cros_ssh_identity) as cri:

            # Check arguments with no special characters
            stdout, _ = cri.RunCmdOnDevice(
                ['echo', '--arg1=value1', '--arg2=value2', '--arg3="value3"'])
            assert stdout.strip(
            ) == '--arg1=value1 --arg2=value2 --arg3=value3'

            # Check argument with special characters escaped
            stdout, _ = cri.RunCmdOnDevice(['echo', '--arg=A\\; echo \\"B\\"'])
            assert stdout.strip() == '--arg=A; echo "B"'

            # Check argument with special characters in quotes
            stdout, _ = cri.RunCmdOnDevice(['echo', "--arg='$HOME;;$PATH'"])
            assert stdout.strip() == "--arg=$HOME;;$PATH"
    def testGetRemotePortAndIsHTTPServerRunningOnPort(self):
        remote = options_for_unittests.GetCopy().cros_remote
        with cros_interface.CrOSInterface(
                remote,
                options_for_unittests.GetCopy().cros_ssh_identity) as cri:

            # Create local server.
            sock = socket.socket()
            sock.bind(('', 0))
            port = sock.getsockname()[1]
            sock.listen(0)

            # Get remote port and ensure that it was unused.
            remote_port = cri.GetRemotePort()
            self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port))

            # Forward local server's port to remote device's remote_port.
            forwarder = cros_forwarder.CrOsForwarderFactory(cri).Create(
                forwarders.PortPairs(http=forwarders.PortPair(
                    port, remote_port),
                                     https=None,
                                     dns=None))

            # At this point, remote device should be able to connect to local server.
            self.assertTrue(cri.IsHTTPServerRunningOnPort(remote_port))

            # Next remote port shouldn't be the same as remote_port, since remote_port
            # is now in use.
            self.assertTrue(cri.GetRemotePort() != remote_port)

            # Close forwarder and local server ports.
            forwarder.Close()
            sock.close()

            # Device should no longer be able to connect to remote_port since it is no
            # longer in use.
            self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port))
Example #12
0
 def testIsServiceRunningLocal(self):
     with cros_interface.CrOSInterface() as cri:
         self.assertTrue(cri.IsServiceRunning('dbus'))
Example #13
0
 def testExistsLocal(self):
     with cros_interface.CrOSInterface() as cri:
         self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
         self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
         self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
Example #14
0
 def _GetCRI(self):
     remote = options_for_unittests.GetCopy().cros_remote
     remote_ssh_port = options_for_unittests.GetCopy().cros_remote_ssh_port
     return cros_interface.CrOSInterface(
         remote, remote_ssh_port,
         options_for_unittests.GetCopy().cros_ssh_identity)
 def testIsServiceRunning(self):
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         self.assertTrue(cri.IsServiceRunning('openssh-server'))