Start up nova-api service on an unused port if 0 is specified. Fixes bug 744150

This commit is contained in:
Justin Santa Barbara
2011-03-28 09:28:18 -07:00
parent 8501cd94e3
commit 062301faf5
4 changed files with 11 additions and 1 deletions

View File

@@ -248,6 +248,12 @@ class WsgiService(object):
def wait(self):
self.wsgi_app.wait()
def get_port(self, api):
for i in xrange(len(self.apis)):
if self.apis[i] == api:
return self.wsgi_app.ports[i]
return None
class ApiService(WsgiService):
"""Class for our nova-api service"""

View File

@@ -141,6 +141,7 @@ class IntegratedUnitTestContext(object):
self.api_service = api_service
self.auth_url = 'http://localhost:8774/v1.0'
host, port = api_service.get_port('osapi')
self.auth_url = 'http://%s:%s/v1.0' % (host, port)
return api_service

View File

@@ -33,6 +33,7 @@ FLAGS.verbose = True
class LoginTest(test.TestCase):
def setUp(self):
super(LoginTest, self).setUp()
self.flags(ec2_listen_port=0, osapi_listen_port=0)
self.context = integrated_helpers.IntegratedUnitTestContext()
self.user = self.context.test_user
self.api = self.user.openstack_api

View File

@@ -61,6 +61,7 @@ class Server(object):
def __init__(self, threads=1000):
self.pool = eventlet.GreenPool(threads)
self.ports = []
def start(self, application, port, host='0.0.0.0', backlog=128):
"""Run a WSGI server with the given application."""
@@ -68,6 +69,7 @@ class Server(object):
logging.audit(_("Starting %(arg0)s on %(host)s:%(port)s") % locals())
socket = eventlet.listen((host, port), backlog=backlog)
self.pool.spawn_n(self._run, application, socket)
self.ports.append(socket.getsockname())
def wait(self):
"""Wait until all servers have completed running."""