[Kimchi-devel] [PATCH v5 3/4] Github #329: changes in mockmodel, model/config and tests
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Apr 16 15:29:17 UTC 2014
On 04/16/2014 02:51 AM, Daniel Barboza wrote:
> From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>
> Changed mockmodel and model/config.py to point to the proxy
> port instead of the kimchid port, which is not exposed
> anymore.
>
> tests/utils was changed to launch a proxy instance
> for each run_server call.
>
> tests/test_rest.py changed to reflect the changes in model
> and mockmodel.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
> ---
> src/kimchi/mockmodel.py | 2 +-
> src/kimchi/model/config.py | 2 +-
> tests/test_rest.py | 8 +++++---
> tests/utils.py | 16 ++++++++++++----
> 4 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index 8c7d7bb..82f75e3 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -832,7 +832,7 @@ class MockModel(object):
> return disks.get_partition_details(name)
>
> def config_lookup(self, name):
> - return {'http_port': cherrypy.server.socket_port,
> + return {'http_port': cherrypy.config.nginx_port,
> 'display_proxy_port':
> kconfig.get('display', 'display_proxy_port'),
> 'version': config.get_version()}
> diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py
> index 7081373..c9e3e9d 100644
> --- a/src/kimchi/model/config.py
> +++ b/src/kimchi/model/config.py
> @@ -40,7 +40,7 @@ class ConfigModel(object):
>
> def lookup(self, name):
> proxy_port = kconfig.get('display', 'display_proxy_port')
> - return {'http_port': cherrypy.server.socket_port,
> + return {'http_port': cherrypy.config.nginx_port,
> 'display_proxy_port': proxy_port,
> 'version': get_version()}
>
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index a40ba93..ddb0aa9 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -49,14 +49,16 @@ ssl_port = None
>
>
> def setUpModule():
> - global test_server, model, host, port, ssl_port
> + global test_server, model, host, port, proxy_port, ssl_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')
> - test_server = run_server(host, port, ssl_port, test_mode=True, model=model)
> + test_server = run_server(host, port, ssl_port, test_mode=True,
> + proxy_port=proxy_port, model=model)
>
>
> def tearDownModule():
> @@ -1356,7 +1358,7 @@ class RestTests(unittest.TestCase):
> def test_config(self):
> resp = self.request('/config').read()
> conf = json.loads(resp)
> - self.assertEquals(port, conf['http_port'])
> + self.assertEquals(proxy_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 fe03a1a..c642141 100644
> --- a/tests/utils.py
> +++ b/tests/utils.py
> @@ -33,6 +33,7 @@ from lxml import etree
>
>
> import kimchi.server
> +from kimchi.proxy import create_proxy_config, start_proxy
> from kimchi.exception import OperationFailed
>
> _ports = {}
> @@ -92,17 +93,25 @@ def get_free_port(name='http'):
> _ports[name] = sock.getsockname()[1]
> return _ports[name]
>
> -
> -def run_server(host, port, ssl_port, test_mode,
> +def run_server(host, port, ssl_port, test_mode, proxy_port=None,
> model=None, environment='development'):
> + if proxy_port is None:
> + proxy_port = get_free_port('proxy_port')
> args = type('_', (object,),
> - {'host': host, 'port': port, 'ssl_port': ssl_port,
> + {'host': host, 'port': port, 'proxy_ssl_port': ssl_port,
> + 'proxy_port': proxy_port,
> 'ssl_cert': '', 'ssl_key': '',
> 'test': test_mode, 'access_log': '/dev/null',
> 'error_log': '/dev/null', 'environment': environment,
> 'log_level': 'debug'})()
> if model is not None:
> setattr(args, 'model', model)
> + # Launch reverse proxy: create config file and start.
> + if ssl_port is None:
> + ssl_port = get_free_port('ssl_port')
> + create_proxy_config(proxy_port, port, ssl_port)
> + start_proxy()
> +
> s = kimchi.server.Server(args)
> t = threading.Thread(target=s.start)
> t.setDaemon(True)
> @@ -110,7 +119,6 @@ def run_server(host, port, ssl_port, test_mode,
> cherrypy.engine.wait(cherrypy.engine.states.STARTED)
> return s
>
> -
Keep the above line otherwise "make check-local" will fail
> def silence_server():
> """
> Silence server status messages on stdout
More information about the Kimchi-devel
mailing list