1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
8 from telemetry.core import forwarders
9 from telemetry.core import util
10 from telemetry.core.forwarders import do_nothing_forwarder
13 class CrOsForwarderFactory(forwarders.ForwarderFactory):
15 def __init__(self, cri):
16 super(CrOsForwarderFactory, self).__init__()
19 def Create(self, port_pairs, forwarding_flag='R'): # pylint: disable=W0221
21 return do_nothing_forwarder.DoNothingForwarder(port_pairs)
22 return CrOsSshForwarder(self._cri, forwarding_flag, port_pairs)
25 class CrOsSshForwarder(forwarders.Forwarder):
27 def __init__(self, cri, forwarding_flag, port_pairs):
28 super(CrOsSshForwarder, self).__init__(port_pairs)
31 self._forwarding_flag = forwarding_flag
33 if self._forwarding_flag == 'R':
34 command_line = ['-%s%i:%s:%i' % (self._forwarding_flag,
35 port_pair.remote_port,
38 for port_pair in port_pairs if port_pair]
40 command_line = ['-%s%i:%s:%i' % (self._forwarding_flag,
43 port_pair.remote_port)
44 for port_pair in port_pairs if port_pair]
45 self._proc = subprocess.Popen(
46 self._cri.FormSSHCommandLine(['sleep', '999999999'], command_line),
47 stdout=subprocess.PIPE,
48 stderr=subprocess.PIPE,
49 stdin=subprocess.PIPE,
52 lambda: self._cri.IsHTTPServerRunningOnPort(self.host_port), 60)
53 logging.debug('Server started on %s:%d' % (self.host_ip, self.host_port))
57 return self._port_pairs.http.remote_port
63 super(CrOsSshForwarder, self).Close()