summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorTodd Willey <todd@ansolabs.com>2010-11-02 18:09:52 -0400
committerTodd Willey <todd@ansolabs.com>2010-11-02 18:09:52 -0400
commitfbb82a4c2b832f9e6c86aacb664a7f1a9060e2ce (patch)
treeec190589b9a2907dc6da2971ab50e3af5f566efc /nova
parente493e324eb9a9fe31e72551b34bab768b507bc1d (diff)
parent56c7e7763fc07f26be40bb8c0c702fc9afe8b1e3 (diff)
Merge trunk.
Diffstat (limited to 'nova')
-rw-r--r--nova/api/__init__.py34
-rw-r--r--nova/tests/api/__init__.py2
-rw-r--r--nova/tests/api/openstack/fakes.py4
-rw-r--r--nova/tests/api/openstack/test_auth.py18
-rw-r--r--nova/tests/api/openstack/test_flavors.py2
-rw-r--r--nova/tests/api/openstack/test_images.py4
-rw-r--r--nova/tests/api/openstack/test_servers.py28
-rw-r--r--nova/tests/api_unittest.py6
-rw-r--r--nova/wsgi.py25
9 files changed, 64 insertions, 59 deletions
diff --git a/nova/api/__init__.py b/nova/api/__init__.py
index 27b8199db..f693225d9 100644
--- a/nova/api/__init__.py
+++ b/nova/api/__init__.py
@@ -41,37 +41,31 @@ flags.DEFINE_string('osapi_subdomain', 'api',
'subdomain running the OpenStack API')
flags.DEFINE_string('ec2api_subdomain', 'ec2',
'subdomain running the EC2 API')
-flags.DEFINE_string('FAKE_subdomain', None,
- 'set to api or ec2 to fake the subdomain of the host '
- 'for testing')
FLAGS = flags.FLAGS
class API(wsgi.Router):
"""Routes top-level requests to the appropriate controller."""
- def __init__(self):
- osapidomain = {'sub_domain': [FLAGS.osapi_subdomain]}
- ec2domain = {'sub_domain': [FLAGS.ec2api_subdomain]}
- # If someone wants to pretend they're hitting the OSAPI subdomain
- # on their local box, they can set FAKE_subdomain to 'api', which
- # removes subdomain restrictions from the OpenStack API routes below.
- if FLAGS.FAKE_subdomain == 'api':
- osapidomain = {}
- elif FLAGS.FAKE_subdomain == 'ec2':
- ec2domain = {}
+ def __init__(self, default_api):
+ osapi_subdomain = {'sub_domain': [FLAGS.osapi_subdomain]}
+ ec2api_subdomain = {'sub_domain': [FLAGS.ec2api_subdomain]}
+ if default_api == 'os':
+ osapi_subdomain = {}
+ elif default_api == 'ec2':
+ ec2api_subdomain = {}
mapper = routes.Mapper()
mapper.sub_domains = True
+
mapper.connect("/", controller=self.osapi_versions,
- conditions=osapidomain)
+ conditions=osapi_subdomain)
mapper.connect("/v1.0/{path_info:.*}", controller=openstack.API(),
- conditions=osapidomain)
+ conditions=osapi_subdomain)
mapper.connect("/", controller=self.ec2api_versions,
- conditions=ec2domain)
+ conditions=ec2api_subdomain)
mapper.connect("/services/{path_info:.*}", controller=ec2.API(),
- conditions=ec2domain)
- mapper.connect("/cloudpipe/{path_info:.*}", controller=cloudpipe.API())
+ conditions=ec2api_subdomain)
mrh = metadatarequesthandler.MetadataRequestHandler()
for s in ['/latest',
'/2009-04-04',
@@ -84,7 +78,9 @@ class API(wsgi.Router):
'/2007-01-19',
'/1.0']:
mapper.connect('%s/{path_info:.*}' % s, controller=mrh,
- conditions=ec2domain)
+ conditions=ec2api_subdomain)
+
+ mapper.connect("/cloudpipe/{path_info:.*}", controller=cloudpipe.API())
super(API, self).__init__(mapper)
@webob.dec.wsgify
diff --git a/nova/tests/api/__init__.py b/nova/tests/api/__init__.py
index 46f09e906..9caa8c9d0 100644
--- a/nova/tests/api/__init__.py
+++ b/nova/tests/api/__init__.py
@@ -42,7 +42,7 @@ class Test(unittest.TestCase):
environ_keys = {'HTTP_HOST': '%s.example.com' % subdomain}
environ_keys.update(kwargs)
req = webob.Request.blank(url, environ_keys)
- return req.get_response(api.API())
+ return req.get_response(api.API('ec2'))
def test_openstack(self):
self.stubs.Set(api.openstack, 'API', APIStub)
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index 1b8c18974..52b392601 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -34,9 +34,6 @@ from nova.tests import fake_flags
from nova.wsgi import Router
-FLAGS = flags.FLAGS
-
-
class Context(object):
pass
@@ -108,7 +105,6 @@ def stub_out_networking(stubs):
def get_my_ip():
return '127.0.0.1'
stubs.Set(nova.utils, 'get_my_ip', get_my_ip)
- FLAGS.FAKE_subdomain = 'api'
def stub_out_glance(stubs, initial_fixtures=[]):
diff --git a/nova/tests/api/openstack/test_auth.py b/nova/tests/api/openstack/test_auth.py
index b63da187f..29f4b8874 100644
--- a/nova/tests/api/openstack/test_auth.py
+++ b/nova/tests/api/openstack/test_auth.py
@@ -51,7 +51,7 @@ class Test(unittest.TestCase):
req = webob.Request.blank('/v1.0/')
req.headers['X-Auth-User'] = 'herp'
req.headers['X-Auth-Key'] = 'derp'
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '204 No Content')
self.assertEqual(len(result.headers['X-Auth-Token']), 40)
self.assertEqual(result.headers['X-CDN-Management-Url'],
@@ -65,7 +65,7 @@ class Test(unittest.TestCase):
req = webob.Request.blank('/v1.0/')
req.headers['X-Auth-User'] = 'herp'
req.headers['X-Auth-Key'] = 'derp'
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '204 No Content')
self.assertEqual(len(result.headers['X-Auth-Token']), 40)
self.assertEqual(result.headers['X-Server-Management-Url'],
@@ -79,7 +79,7 @@ class Test(unittest.TestCase):
fakes.FakeRouter)
req = webob.Request.blank('/v1.0/fake')
req.headers['X-Auth-Token'] = token
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '200 OK')
self.assertEqual(result.headers['X-Test-Success'], 'True')
@@ -103,7 +103,7 @@ class Test(unittest.TestCase):
req = webob.Request.blank('/v1.0/')
req.headers['X-Auth-Token'] = 'bacon'
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '401 Unauthorized')
self.assertEqual(self.destroy_called, True)
@@ -111,18 +111,18 @@ class Test(unittest.TestCase):
req = webob.Request.blank('/v1.0/')
req.headers['X-Auth-User'] = 'herp'
req.headers['X-Auth-Key'] = 'derp'
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '401 Unauthorized')
def test_no_user(self):
req = webob.Request.blank('/v1.0/')
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '401 Unauthorized')
def test_bad_token(self):
req = webob.Request.blank('/v1.0/')
req.headers['X-Auth-Token'] = 'baconbaconbacon'
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '401 Unauthorized')
@@ -146,7 +146,7 @@ class TestLimiter(unittest.TestCase):
req = webob.Request.blank('/v1.0/')
req.headers['X-Auth-User'] = 'herp'
req.headers['X-Auth-Key'] = 'derp'
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(len(result.headers['X-Auth-Token']), 40)
token = result.headers['X-Auth-Token']
@@ -155,7 +155,7 @@ class TestLimiter(unittest.TestCase):
req = webob.Request.blank('/v1.0/fake')
req.method = 'POST'
req.headers['X-Auth-Token'] = token
- result = req.get_response(nova.api.API())
+ result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '200 OK')
self.assertEqual(result.headers['X-Test-Success'], 'True')
diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py
index 8dd4d1f29..41018afdf 100644
--- a/nova/tests/api/openstack/test_flavors.py
+++ b/nova/tests/api/openstack/test_flavors.py
@@ -39,7 +39,7 @@ class FlavorsTest(unittest.TestCase):
def test_get_flavor_list(self):
req = webob.Request.blank('/v1.0/flavors')
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
def test_get_flavor_by_id(self):
pass
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index d61c3a99b..0f3941c29 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -203,7 +203,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase):
def test_get_image_index(self):
req = webob.Request.blank('/v1.0/images')
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
res_dict = json.loads(res.body)
fixture_index = [dict(id=f['id'], name=f['name']) for f
@@ -215,7 +215,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase):
def test_get_image_details(self):
req = webob.Request.blank('/v1.0/images/detail')
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
res_dict = json.loads(res.body)
for image in res_dict['images']:
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 785fb6f3a..8cfc6c45a 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -69,14 +69,14 @@ class ServersTest(unittest.TestCase):
def test_get_server_by_id(self):
req = webob.Request.blank('/v1.0/servers/1')
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
res_dict = json.loads(res.body)
self.assertEqual(res_dict['server']['id'], 1)
self.assertEqual(res_dict['server']['name'], 'server1')
def test_get_server_list(self):
req = webob.Request.blank('/v1.0/servers')
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
res_dict = json.loads(res.body)
i = 0
@@ -119,14 +119,14 @@ class ServersTest(unittest.TestCase):
req.method = 'POST'
req.body = json.dumps(body)
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
self.assertEqual(res.status_int, 200)
def test_update_no_body(self):
req = webob.Request.blank('/v1.0/servers/1')
req.method = 'PUT'
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
self.assertEqual(res.status_int, 422)
def test_update_bad_params(self):
@@ -145,7 +145,7 @@ class ServersTest(unittest.TestCase):
req = webob.Request.blank('/v1.0/servers/1')
req.method = 'PUT'
req.body = self.body
- req.get_response(nova.api.API())
+ req.get_response(nova.api.API('os'))
def test_update_server(self):
inst_dict = dict(name='server_test', adminPass='bacon')
@@ -161,28 +161,28 @@ class ServersTest(unittest.TestCase):
req = webob.Request.blank('/v1.0/servers/1')
req.method = 'PUT'
req.body = self.body
- req.get_response(nova.api.API())
+ req.get_response(nova.api.API('os'))
def test_create_backup_schedules(self):
req = webob.Request.blank('/v1.0/servers/1/backup_schedules')
req.method = 'POST'
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
self.assertEqual(res.status, '404 Not Found')
def test_delete_backup_schedules(self):
req = webob.Request.blank('/v1.0/servers/1/backup_schedules')
req.method = 'DELETE'
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
self.assertEqual(res.status, '404 Not Found')
def test_get_server_backup_schedules(self):
req = webob.Request.blank('/v1.0/servers/1/backup_schedules')
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
self.assertEqual(res.status, '404 Not Found')
def test_get_all_server_details(self):
req = webob.Request.blank('/v1.0/servers/detail')
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
res_dict = json.loads(res.body)
i = 0
@@ -200,7 +200,7 @@ class ServersTest(unittest.TestCase):
req.method = 'POST'
req.content_type = 'application/json'
req.body = json.dumps(body)
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
def test_server_rebuild(self):
body = dict(server=dict(
@@ -210,7 +210,7 @@ class ServersTest(unittest.TestCase):
req.method = 'POST'
req.content_type = 'application/json'
req.body = json.dumps(body)
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
def test_server_resize(self):
body = dict(server=dict(
@@ -220,7 +220,7 @@ class ServersTest(unittest.TestCase):
req.method = 'POST'
req.content_type = 'application/json'
req.body = json.dumps(body)
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
def test_delete_server_instance(self):
req = webob.Request.blank('/v1.0/servers/1')
@@ -234,7 +234,7 @@ class ServersTest(unittest.TestCase):
self.stubs.Set(nova.db.api, 'instance_destroy',
instance_destroy_mock)
- res = req.get_response(nova.api.API())
+ res = req.get_response(nova.api.API('os'))
self.assertEqual(res.status, '202 Accepted')
self.assertEqual(self.server_delete_called, True)
diff --git a/nova/tests/api_unittest.py b/nova/tests/api_unittest.py
index 0a81c575b..33d4cb294 100644
--- a/nova/tests/api_unittest.py
+++ b/nova/tests/api_unittest.py
@@ -34,10 +34,6 @@ from nova.api.ec2 import apirequest
from nova.auth import manager
-FLAGS = flags.FLAGS
-FLAGS.FAKE_subdomain = 'ec2'
-
-
class FakeHttplibSocket(object):
"""a fake socket implementation for httplib.HTTPResponse, trivial"""
def __init__(self, response_string):
@@ -109,7 +105,7 @@ class ApiEc2TestCase(test.TrialTestCase):
self.host = '127.0.0.1'
- self.app = api.API()
+ self.app = api.API('ec2')
def expect_http(self, host=None, is_secure=False):
"""Returns a new EC2 connection"""
diff --git a/nova/wsgi.py b/nova/wsgi.py
index eb305a3d3..b04b487ea 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -39,10 +39,27 @@ import webob.exc
logging.getLogger("routes.middleware").addHandler(logging.StreamHandler())
-def run_server(application, port):
- """Run a WSGI server with the given application."""
- sock = eventlet.listen(('0.0.0.0', port))
- eventlet.wsgi.server(sock, application)
+class Server(object):
+ """Server class to manage multiple WSGI sockets and applications."""
+
+ def __init__(self, threads=1000):
+ self.pool = eventlet.GreenPool(threads)
+
+ def start(self, application, port, host='0.0.0.0', backlog=128):
+ """Run a WSGI server with the given application."""
+ socket = eventlet.listen((host, port), backlog=backlog)
+ self.pool.spawn_n(self._run, application, socket)
+
+ def wait(self):
+ """Wait until all servers have completed running."""
+ try:
+ self.pool.waitall()
+ except KeyboardInterrupt:
+ pass
+
+ def _run(self, application, socket):
+ """Start a WSGI server in a new green thread."""
+ eventlet.wsgi.server(socket, application, custom_pool=self.pool)
class Application(object):