[Kimchi-devel] [PATCH] [Wok] Do not use proxy when running tests
Lucio Correia
luciojhc at linux.vnet.ibm.com
Fri Feb 24 20:54:23 UTC 2017
Currently administration permissions are required to
run tests in order to change nginx configuration.
With this patch, tests requests are handled directly by
cherrypy, without being proxied by nginx. This allows
tests to be run without administration permissions.
Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
src/wok/server.py | 3 ++-
tests/utils.py | 17 ++++++++++++-----
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/wok/server.py b/src/wok/server.py
index fc2e167..cdffe6d 100644
--- a/src/wok/server.py
+++ b/src/wok/server.py
@@ -69,7 +69,8 @@ class Server(object):
config.config.set(sec, item, str(getattr(options, item)))
# Check proxy configuration
- check_proxy_config()
+ if not hasattr(options, 'no_proxy') or not options.no_proxy:
+ check_proxy_config()
make_dirs = [
os.path.abspath(config.get_log_download_path()),
diff --git a/tests/utils.py b/tests/utils.py
index 3c7e9da..2e4c63a 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -40,6 +40,7 @@ from wok.exception import NotFoundError, OperationFailed
from wok.utils import wok_log
HOST = '0.0.0.0'
+PORT = 8010
PROXY_PORT = 8001
fake_user = {'admin': 'letmein!', 'user': 'letmein!'}
@@ -88,14 +89,15 @@ if sys.version_info[:2] == (2, 6):
unittest.TestCase.assertNotIn = assertNotIn
-def run_server(test_mode, environment='dev', server_root=''):
+def run_server(test_mode, environment='dev', server_root='', no_proxy=True):
+ port = PORT if no_proxy else PROXY_PORT
args = type('_', (object,),
- {'cherrypy_port': 8010, 'max_body_size': '4*1024',
+ {'cherrypy_port': port, 'max_body_size': '4*1024',
'test': test_mode, 'access_log': '/dev/null',
'error_log': '/dev/null', 'environment': environment,
'log_level': 'debug', 'session_timeout': 10,
- 'server_root': server_root})()
+ 'server_root': server_root, 'no_proxy': no_proxy})()
s = wok.server.Server(args)
t = threading.Thread(target=s.start)
@@ -121,8 +123,8 @@ def _request(conn, path, data, method, headers, user):
return conn.getresponse()
-def request(path, data=None, method='GET', headers=None, user='admin'):
- # verify if HTTPSConnection has context parameter
+def requestHttps(path, data=None, method='GET', headers=None, user='admin'):
+ # To work, this requires run_server() to be called with no_proxy=False.
if "context" in inspect.getargspec(httplib.HTTPSConnection.__init__).args:
context = ssl._create_unverified_context()
conn = httplib.HTTPSConnection(HOST, PROXY_PORT, context=context)
@@ -132,6 +134,11 @@ def request(path, data=None, method='GET', headers=None, user='admin'):
return _request(conn, path, data, method, headers, user)
+def request(path, data=None, method='GET', headers=None, user='admin'):
+ conn = httplib.HTTPConnection(HOST, PORT)
+ return _request(conn, path, data, method, headers, user)
+
+
class FakeUser(User):
auth_type = "fake"
--
2.7.4
More information about the Kimchi-devel
mailing list