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

Unified Diff: bin/au_test_harness/cros_test_proxy.py

Issue 6597122: Refactor au_test_harness into modules and refactor to use worker design. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Nit party Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/au_test_harness/cros_au_test_harness.py ('k') | bin/au_test_harness/dev_server_wrapper.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/au_test_harness/cros_test_proxy.py
diff --git a/lib/cros_test_proxy.py b/bin/au_test_harness/cros_test_proxy.py
old mode 100755
new mode 100644
similarity index 94%
rename from lib/cros_test_proxy.py
rename to bin/au_test_harness/cros_test_proxy.py
index 464dcb539b87d835af9e15db578999bced35e9a4..0b3728638bf0c4a835562c341482100035400d73
--- a/lib/cros_test_proxy.py
+++ b/bin/au_test_harness/cros_test_proxy.py
@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+"""Module containing various classes pertaining to inserting a proxy in a test.
+"""
+
import os
import select
import socket
@@ -10,45 +13,45 @@ import threading
class Filter(object):
"""Base class for data filters.
-
+
Pass subclass of this to CrosTestProxy which will perform whatever
connection manipulation you prefer.
"""
-
+
def setup(self):
"""This setup method is called once per connection."""
pass
-
+
def InBound(self, data):
"""This method is called once per packet of incoming data.
-
+
The value returned is what is sent through the proxy. If
None is returned, the connection will be closed.
"""
- return data
+ return data
def OutBound(self, data):
"""This method is called once per packet of outgoing data.
-
+
The value returned is what is sent through the proxy. If
None is returned, the connection will be closed.
"""
- return data
+ return data
class CrosTestProxy(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
"""A transparent proxy for simulating network errors"""
-
+
class _Handler(SocketServer.BaseRequestHandler):
"""Proxy connection handler that passes data though a filter"""
def setup(self):
"""Setup is called once for each connection proxied."""
self.server.filter.setup()
-
+
def handle(self):
"""Handles each incoming connection.
-
+
Opens a new connection to the port we are proxing to, then
passes each packet along in both directions after passing
them through the filter object passed in.
@@ -60,7 +63,7 @@ class CrosTestProxy(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
while True:
rlist, wlist, xlist = select.select([s_in, s_out], [], [])
-
+
if s_in in rlist:
data = s_in.recv(1024)
data = self.server.filter.InBound(data)
@@ -83,13 +86,13 @@ class CrosTestProxy(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
s_in.close()
s_out.close()
-
+
def __init__(self,
filter,
port_in=8081,
- address_out='127.0.0.1', port_out=8080):
+ address_out='127.0.0.1', port_out=8080):
"""Configures the proxy object.
-
+
Args:
filter: An instance of a subclass of Filter.
port_in: Port on which to listen for incoming connections.
@@ -100,7 +103,7 @@ class CrosTestProxy(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
self.address_out = address_out
self.port_out = port_out
self.filter = filter
-
+
try:
SocketServer.TCPServer.__init__(self,
('', port_in),
@@ -114,5 +117,5 @@ class CrosTestProxy(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
server_thread = threading.Thread(target=self.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
-
+
return server_thread
« no previous file with comments | « bin/au_test_harness/cros_au_test_harness.py ('k') | bin/au_test_harness/dev_server_wrapper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698