[Kimchi-devel] [PATCH 2/2] bug fix: Allow changing default ports

Aline Manera alinefm at linux.vnet.ibm.com
Fri May 9 17:48:52 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

After adding nginx as a reverse proxy, 3 ports needs to be specified to
start Kimchi.
- port to list on (default 8000)
- ssl_port to enable SSL connections (default 8001)
- cherrypy_port, the cherrypy server port (default 8010)

The kimchi.conf was inconsistent to that current Kimchi logic.
So the user was not able to change the default ports without having
problems to start Kimchi.

Fix it by adding cherrypy_port to kimchi.conf file and adjusting the
kimchid script to get the correct variable values.

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 src/kimchi.conf.in      |    3 +++
 src/kimchi/config.py.in |    6 +++---
 src/kimchi/proxy.py     |    6 +++---
 src/kimchi/server.py    |    4 ++--
 src/kimchid.in          |   17 +++++++----------
 tests/test_rest.py      |   10 +++++-----
 tests/utils.py          |   15 +++++++++------
 7 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/src/kimchi.conf.in b/src/kimchi.conf.in
index 3bbe1e9..369f2c3 100644
--- a/src/kimchi.conf.in
+++ b/src/kimchi.conf.in
@@ -12,6 +12,9 @@
 # If present, start an SSL-enabled server on the given port
 #ssl_port = 8001
 
+# Cherrypy server port
+#cherrypy_port = 8010
+
 # The full path to an SSL Certificate in PEM format.  If left unspecified,
 # Kimchi will generate a self-signed certificate automatically.
 #ssl_cert =
diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in
index 858065c..0206570 100644
--- a/src/kimchi/config.py.in
+++ b/src/kimchi/config.py.in
@@ -241,9 +241,9 @@ def _get_config():
     config = SafeConfigParser()
     config.add_section("server")
     config.set("server", "host", "0.0.0.0")
-    config.set("server", "port", "8010")
-    config.set("server", "proxy_port", "8000")
-    config.set("server", "proxy_ssl_port", "8001")
+    config.set("server", "port", "8000")
+    config.set("server", "ssl_port", "8001")
+    config.set("server", "cherrypy_port", "8010")
     config.set("server", "ssl_cert", "")
     config.set("server", "ssl_key", "")
     config.set("server", "environment", "development")
diff --git a/src/kimchi/proxy.py b/src/kimchi/proxy.py
index 1ccbbcc..d924ac8 100644
--- a/src/kimchi/proxy.py
+++ b/src/kimchi/proxy.py
@@ -89,9 +89,9 @@ def _create_proxy_config(p_port, k_port, p_ssl_port, cert, key):
 
 def start_proxy(options):
     """Start nginx reverse proxy."""
-    _create_proxy_config(options.proxy_port,
-                         options.port,
-                         options.proxy_ssl_port,
+    _create_proxy_config(options.port,
+                         options.cherrypy_port,
+                         options.ssl_port,
                          options.ssl_cert,
                          options.ssl_key)
     config_dir = paths.conf_dir
diff --git a/src/kimchi/server.py b/src/kimchi/server.py
index 7a1f967..7344349 100644
--- a/src/kimchi/server.py
+++ b/src/kimchi/server.py
@@ -81,8 +81,8 @@ class Server(object):
         # as a localhost app, inaccessible to the outside
         # directly. You must go through the proxy.
         cherrypy.server.socket_host = '127.0.0.1'
-        cherrypy.server.socket_port = options.port
-        cherrypy.config.nginx_port = options.proxy_port
+        cherrypy.server.socket_port = options.cherrypy_port
+        cherrypy.config.nginx_port = options.port
 
         cherrypy.log.screen = True
         cherrypy.log.access_file = options.access_log
diff --git a/src/kimchid.in b/src/kimchid.in
index c64ba4a..d3d398f 100644
--- a/src/kimchid.in
+++ b/src/kimchid.in
@@ -19,7 +19,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301  USA
 
-import logging
 import os
 import sys
 sys.path.insert(1, '@pythondir@')
@@ -45,8 +44,8 @@ def main(options):
 
     host = config.get("server", "host")
     port = config.get("server", "port")
-    proxy_port = config.get("server", "proxy_port")
-    proxy_ssl_port = config.get("server", "proxy_ssl_port")
+    ssl_port = config.get("server", "ssl_port")
+    cherrypy_port = config.get("server", "cherrypy_port")
     runningEnv = config.get('server', 'environment')
     logDir = config.get("logging", "log_dir")
     logLevel = config.get("logging", "log_level")
@@ -55,13 +54,11 @@ def main(options):
     parser.add_option('--host', type="string", default=host,
                       help="Hostname to listen on")
     parser.add_option('--port', type="int", default=port,
-                      help="Kimchid process listen port (default %s)" % port)
-    parser.add_option('--proxy-port', type="int", default=proxy_port,
-                      help="Proxy port to listen on (default %s)" %
-                      proxy_port)
-    parser.add_option('--proxy-ssl-port', type="int", default=proxy_ssl_port,
-                      help="Proxy port to enable SSL (default %s)" %
-                      proxy_ssl_port)
+                      help="Port to listen on (default %s)" % port)
+    parser.add_option('--ssl-port', type="int", default=ssl_port,
+                      help="Port to enable SSL (default %s)" % ssl_port)
+    parser.add_option('--cherrypy_port', type="int", default=cherrypy_port,
+                      help="Cherrypy server port (default %s)" % cherrypy_port)
     parser.add_option('--log-level', default=logLevel,
                       help="Logging level")
     parser.add_option('--access-log',
diff --git a/tests/test_rest.py b/tests/test_rest.py
index bb52e3f..7ed94cb 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -43,23 +43,23 @@ test_server = None
 model = None
 host = None
 port = None
-proxy_port = None
 ssl_port = None
+cherrypy_port = None
 
 #utils.silence_server()
 
 
 def setUpModule():
-    global test_server, model, host, port, proxy_port, ssl_port
+    global test_server, model, host, port, ssl_port, cherrypy_port
 
     patch_auth()
     model = kimchi.mockmodel.MockModel('/tmp/obj-store-test')
     host = '127.0.0.1'
     port = get_free_port('http')
-    proxy_port = get_free_port('proxy_port')
     ssl_port = get_free_port('https')
+    cherrypy_port = get_free_port('cherrypy_port')
     test_server = run_server(host, port, ssl_port, test_mode=True,
-                             proxy_port=proxy_port, model=model)
+                             cherrypy_port=cherrypy_port, model=model)
 
 
 def tearDownModule():
@@ -1412,7 +1412,7 @@ class RestTests(unittest.TestCase):
     def test_config(self):
         resp = self.request('/config').read()
         conf = json.loads(resp)
-        self.assertEquals(proxy_port, conf['http_port'])
+        self.assertEquals(port, conf['http_port'])
 
     def test_capabilities(self):
         resp = self.request('/config/capabilities').read()
diff --git a/tests/utils.py b/tests/utils.py
index 11c02fb..fd9b23c 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -93,15 +93,18 @@ def get_free_port(name='http'):
         return _ports[name]
 
 
-def run_server(host, port, ssl_port, test_mode, proxy_port=None,
+def run_server(host, port, ssl_port, test_mode, cherrypy_port=None,
                model=None, environment='development'):
-    if proxy_port is None:
-        proxy_port = get_free_port('proxy_port')
+
+    if cherrypy_port is None:
+        cherrypy_port = get_free_port('cherrypy_port')
+
     if ssl_port is None:
-        ssl_port = get_free_port('ssl_port')
+        ssl_port = get_free_port('https')
+
     args = type('_', (object,),
-                {'host': host, 'port': port, 'proxy_ssl_port': ssl_port,
-                 'proxy_port': proxy_port,
+                {'host': host, 'port': port, 'ssl_port': ssl_port,
+                 'cherrypy_port': cherrypy_port,
                  'ssl_cert': '', 'ssl_key': '',
                  'test': test_mode, 'access_log': '/dev/null',
                  'error_log': '/dev/null', 'environment': environment,
-- 
1.7.10.4




More information about the Kimchi-devel mailing list