Move wsgi module to murano/common
* Resolve all import issues * Update sample config * Resolve pep8 doc string issues Change-Id: Ib95add96b1f3cd04ecf3666d24ef307e3c6bba42 Closes-Bug: #bug/1363892
This commit is contained in:
@@ -217,6 +217,19 @@
|
||||
#metadata_dir=./meta
|
||||
|
||||
|
||||
#
|
||||
# Options defined in murano.common.wsgi
|
||||
#
|
||||
|
||||
# Number of backlog requests to configure the socket with
|
||||
# (integer value)
|
||||
#backlog=4096
|
||||
|
||||
# Sets the value of TCP_KEEPIDLE in seconds for each server
|
||||
# socket. Not supported on OS X. (integer value)
|
||||
#tcp_keepidle=600
|
||||
|
||||
|
||||
#
|
||||
# Options defined in murano.openstack.common.eventlet_backdoor
|
||||
#
|
||||
@@ -349,19 +362,6 @@
|
||||
#policy_default_rule=default
|
||||
|
||||
|
||||
#
|
||||
# Options defined in murano.openstack.common.wsgi
|
||||
#
|
||||
|
||||
# Number of backlog requests to configure the socket with
|
||||
# (integer value)
|
||||
#backlog=4096
|
||||
|
||||
# Sets the value of TCP_KEEPIDLE in seconds for each server
|
||||
# socket. Not supported on OS X. (integer value)
|
||||
#tcp_keepidle=600
|
||||
|
||||
|
||||
[database]
|
||||
|
||||
#
|
||||
|
@@ -14,10 +14,10 @@
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from murano.common import wsgi
|
||||
import murano.context
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
import murano.openstack.common.log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
context_opts = [
|
||||
cfg.StrOpt('admin_role', default='admin',
|
||||
|
@@ -20,7 +20,7 @@ import traceback
|
||||
from oslo.config import cfg
|
||||
import webob
|
||||
|
||||
from murano.openstack.common import wsgi
|
||||
from murano.common import wsgi
|
||||
from murano.packages import exceptions as pkg_exc
|
||||
|
||||
cfg.CONF.import_opt('debug', 'murano.openstack.common.log')
|
||||
|
@@ -21,9 +21,9 @@ return
|
||||
from oslo.config import cfg
|
||||
|
||||
from murano.api import versions
|
||||
from murano.common import wsgi
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
import murano.openstack.common.log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@@ -15,6 +15,7 @@
|
||||
from webob import exc
|
||||
|
||||
from murano.common import policy
|
||||
from murano.common import wsgi
|
||||
from murano.db import models
|
||||
from murano.db.services import environments as envs
|
||||
from murano.db.services import sessions
|
||||
@@ -22,7 +23,6 @@ from murano.db import session as db_session
|
||||
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
from murano.services import actions
|
||||
|
||||
|
||||
|
@@ -25,14 +25,15 @@ from webob import exc
|
||||
import murano.api.v1
|
||||
from murano.api.v1 import schemas
|
||||
from murano.common import policy
|
||||
from murano.common import wsgi
|
||||
from murano.db.catalog import api as db_api
|
||||
from murano.openstack.common import exception
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
from murano.packages import exceptions as pkg_exc
|
||||
from murano.packages import load_utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
@@ -18,12 +18,12 @@ from murano.api.v1 import request_statistics
|
||||
from murano.common.helpers import token_sanitizer
|
||||
from murano.common import policy
|
||||
from murano.common import utils
|
||||
from murano.common import wsgi
|
||||
from murano.db import models
|
||||
from murano.db import session as db_session
|
||||
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@@ -20,6 +20,7 @@ from murano.api.v1 import request_statistics
|
||||
from murano.api.v1 import sessions
|
||||
from murano.common import policy
|
||||
from murano.common import utils
|
||||
from murano.common import wsgi
|
||||
from murano.db import models
|
||||
from murano.db.services import core_services
|
||||
from murano.db.services import environments as envs
|
||||
@@ -27,7 +28,6 @@ from murano.db import session as db_session
|
||||
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@@ -14,11 +14,11 @@
|
||||
|
||||
from murano.api.v1 import request_statistics
|
||||
from murano.common import policy
|
||||
from murano.common import wsgi
|
||||
from murano.db.services import instances
|
||||
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@@ -15,9 +15,9 @@
|
||||
import time
|
||||
|
||||
from murano.api import v1
|
||||
from murano.common import wsgi
|
||||
from murano.db.services import stats
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import routes
|
||||
|
||||
from murano.api.v1 import actions
|
||||
@@ -21,7 +22,7 @@ from murano.api.v1 import instance_statistics
|
||||
from murano.api.v1 import request_statistics
|
||||
from murano.api.v1 import services
|
||||
from murano.api.v1 import sessions
|
||||
from murano.openstack.common import wsgi
|
||||
from murano.common import wsgi
|
||||
|
||||
|
||||
class API(wsgi.Router):
|
||||
|
@@ -11,6 +11,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import functools as func
|
||||
|
||||
from webob import exc
|
||||
@@ -18,10 +19,9 @@ from webob import exc
|
||||
|
||||
from murano.api.v1 import request_statistics
|
||||
from murano.common.helpers import token_sanitizer
|
||||
from murano.common import wsgi
|
||||
from murano.db.services import core_services
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
from murano import utils
|
||||
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
from webob import exc
|
||||
|
||||
from murano.api.v1 import request_statistics
|
||||
from murano.common import wsgi
|
||||
from murano.db import models
|
||||
from murano.db.services import environments as envs
|
||||
from murano.db.services import sessions
|
||||
@@ -22,7 +23,6 @@ from murano.db import session as db_session
|
||||
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
API_NAME = 'Sessions'
|
||||
|
@@ -17,8 +17,8 @@ import httplib
|
||||
from oslo.config import cfg
|
||||
import webob.dec
|
||||
|
||||
from murano.common import wsgi
|
||||
from murano.openstack.common import jsonutils
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@@ -14,12 +14,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import eventlet
|
||||
import os
|
||||
import sys
|
||||
|
||||
import eventlet
|
||||
|
||||
|
||||
if os.name == 'nt':
|
||||
# eventlet monkey patching causes subprocess.Popen to fail on Windows
|
||||
# when using pipes due to missing non blocking I/O support
|
||||
@@ -38,9 +36,9 @@ from murano.common import config
|
||||
from murano.common import policy
|
||||
from murano.common import server
|
||||
from murano.common import statservice as stats
|
||||
from murano.common import wsgi
|
||||
from murano.openstack.common import log
|
||||
from murano.openstack.common import service
|
||||
from murano.openstack.common import wsgi
|
||||
|
||||
|
||||
def main():
|
||||
|
@@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack Foundation.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
@@ -22,8 +20,8 @@ eventlet.patcher.monkey_patch(all=False, socket=True)
|
||||
|
||||
import datetime
|
||||
import errno
|
||||
import re
|
||||
import jsonschema
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
@@ -39,7 +37,7 @@ from xml.parsers import expat
|
||||
|
||||
from murano.api.v1 import schemas
|
||||
from murano.openstack.common import exception
|
||||
from murano.openstack.common.gettextutils import _
|
||||
from murano.openstack.common.gettextutils import _ # noqa
|
||||
from murano.openstack.common import jsonutils
|
||||
from murano.openstack.common import log as logging
|
||||
from murano.openstack.common import service
|
||||
@@ -69,8 +67,7 @@ def run_server(application, port):
|
||||
|
||||
|
||||
class Service(service.Service):
|
||||
"""
|
||||
Provides a Service API for wsgi servers.
|
||||
"""Provides a Service API for wsgi servers.
|
||||
|
||||
This gives us the ability to launch wsgi servers with the
|
||||
Launcher classes in service.py.
|
||||
@@ -105,7 +102,7 @@ class Service(service.Service):
|
||||
if sslutils.is_enabled():
|
||||
sock = sslutils.wrap(sock)
|
||||
|
||||
except socket.error, err:
|
||||
except socket.error as err:
|
||||
if err.args[0] != errno.EADDRINUSE:
|
||||
raise
|
||||
eventlet.sleep(0.1)
|
||||
@@ -165,8 +162,7 @@ class Service(service.Service):
|
||||
|
||||
|
||||
class Middleware(object):
|
||||
"""
|
||||
Base WSGI middleware wrapper. These classes require an application to be
|
||||
"""Base WSGI middleware wrapper. These classes require an application to be
|
||||
initialized that will be called next. By default the middleware will
|
||||
simply call its wrapped app, or you can override __call__ to customize its
|
||||
behavior.
|
||||
@@ -176,8 +172,7 @@ class Middleware(object):
|
||||
self.application = application
|
||||
|
||||
def process_request(self, req):
|
||||
"""
|
||||
Called on each request.
|
||||
"""Called on each request.
|
||||
|
||||
If this returns None, the next application down the stack will be
|
||||
executed. If it returns a response then that response will be returned
|
||||
@@ -199,8 +194,7 @@ class Middleware(object):
|
||||
|
||||
|
||||
class Debug(Middleware):
|
||||
"""
|
||||
Helper class that can be inserted into any WSGI application chain
|
||||
"""Helper class that can be inserted into any WSGI application chain
|
||||
to get information about the request and response.
|
||||
"""
|
||||
|
||||
@@ -208,13 +202,13 @@ class Debug(Middleware):
|
||||
def __call__(self, req):
|
||||
print ("*" * 40) + " REQUEST ENVIRON"
|
||||
for key, value in req.environ.items():
|
||||
print key, "=", value
|
||||
print(key, "=", value)
|
||||
print
|
||||
resp = req.get_response(self.application)
|
||||
|
||||
print ("*" * 40) + " RESPONSE HEADERS"
|
||||
for (key, value) in resp.headers.iteritems():
|
||||
print key, "=", value
|
||||
print(key, "=", value)
|
||||
print
|
||||
|
||||
resp.app_iter = self.print_generator(resp.app_iter)
|
||||
@@ -223,8 +217,7 @@ class Debug(Middleware):
|
||||
|
||||
@staticmethod
|
||||
def print_generator(app_iter):
|
||||
"""
|
||||
Iterator that prints the contents of a wrapper string iterator
|
||||
"""Iterator that prints the contents of a wrapper string iterator
|
||||
when iterated.
|
||||
"""
|
||||
print ("*" * 40) + " BODY"
|
||||
@@ -236,13 +229,10 @@ class Debug(Middleware):
|
||||
|
||||
|
||||
class Router(object):
|
||||
"""
|
||||
WSGI middleware that maps incoming requests to WSGI apps.
|
||||
"""
|
||||
"""WSGI middleware that maps incoming requests to WSGI apps."""
|
||||
|
||||
def __init__(self, mapper):
|
||||
"""
|
||||
Create a router for the given routes.Mapper.
|
||||
"""Create a router for the given routes.Mapper.
|
||||
|
||||
Each route in `mapper` must specify a 'controller', which is a
|
||||
WSGI app to call. You'll probably want to specify an 'action' as
|
||||
@@ -270,19 +260,17 @@ class Router(object):
|
||||
|
||||
@webob.dec.wsgify
|
||||
def __call__(self, req):
|
||||
"""
|
||||
Route the incoming request to a controller based on self.map.
|
||||
If no match, return a 404.
|
||||
"""Route the incoming request to a controller based on self.map.
|
||||
If no match, return a 404.
|
||||
"""
|
||||
return self._router
|
||||
|
||||
@staticmethod
|
||||
@webob.dec.wsgify
|
||||
def _dispatch(req):
|
||||
"""
|
||||
Called by self._router after matching the incoming request to a route
|
||||
and putting the information into req.environ. Either returns 404
|
||||
or the routed WSGI app's response.
|
||||
"""Called by self._router after matching the incoming request to
|
||||
a route and putting the information into req.environ.
|
||||
Either returns 404 or the routed WSGI app's response.
|
||||
"""
|
||||
match = req.environ['wsgiorg.routing_args'][1]
|
||||
if not match:
|
||||
@@ -339,8 +327,7 @@ class Request(webob.Request):
|
||||
|
||||
|
||||
class Resource(object):
|
||||
"""
|
||||
WSGI app that handles (de)serialization and controller dispatch.
|
||||
"""WSGI app that handles (de)serialization and controller dispatch.
|
||||
|
||||
Reads routing information supplied by RoutesMiddleware and calls
|
||||
the requested action method upon its deserializer, controller,
|
||||
@@ -357,7 +344,7 @@ class Resource(object):
|
||||
"""
|
||||
|
||||
def __init__(self, controller, deserializer=None, serializer=None):
|
||||
"""
|
||||
"""Resource init.
|
||||
:param controller: object that implement methods created by routes lib
|
||||
:param deserializer: object that supports webob request deserialization
|
||||
through controller-like actions
|
||||
@@ -440,7 +427,7 @@ class ActionDispatcher(object):
|
||||
|
||||
|
||||
class DictSerializer(ActionDispatcher):
|
||||
"""Default request body serialization"""
|
||||
"""Default request body serialization."""
|
||||
|
||||
def serialize(self, data, action='default'):
|
||||
return self.dispatch(data, action=action)
|
||||
@@ -450,7 +437,7 @@ class DictSerializer(ActionDispatcher):
|
||||
|
||||
|
||||
class JSONDictSerializer(DictSerializer):
|
||||
"""Default JSON request body serialization"""
|
||||
"""Default JSON request body serialization."""
|
||||
|
||||
def default(self, data, result=None):
|
||||
def sanitizer(obj):
|
||||
@@ -465,7 +452,7 @@ class JSONDictSerializer(DictSerializer):
|
||||
|
||||
class XMLDictSerializer(DictSerializer):
|
||||
def __init__(self, metadata=None, xmlns=None):
|
||||
"""
|
||||
"""Default XML request body serialization.
|
||||
:param metadata: information needed to deserialize xml into
|
||||
a dictionary.
|
||||
:param xmlns: XML namespace to include with serialized xml
|
||||
@@ -563,14 +550,13 @@ class XMLDictSerializer(DictSerializer):
|
||||
|
||||
|
||||
class BlankSerializer(DictSerializer):
|
||||
"""Return raw data.
|
||||
"""
|
||||
"""Return raw data."""
|
||||
def default(self, data):
|
||||
return data
|
||||
|
||||
|
||||
class ResponseHeadersSerializer(ActionDispatcher):
|
||||
"""Default response headers serialization"""
|
||||
"""Default response headers serialization."""
|
||||
|
||||
def serialize(self, response, data, action):
|
||||
self.dispatch(response, data, action=action)
|
||||
@@ -580,7 +566,7 @@ class ResponseHeadersSerializer(ActionDispatcher):
|
||||
|
||||
|
||||
class ResponseSerializer(object):
|
||||
"""Encode the necessary pieces into a response object"""
|
||||
"""Encode the necessary pieces into a response object."""
|
||||
|
||||
def __init__(self, body_serializers=None, headers_serializer=None):
|
||||
self.body_serializers = {
|
||||
@@ -623,7 +609,7 @@ class ResponseSerializer(object):
|
||||
|
||||
|
||||
class RequestHeadersDeserializer(ActionDispatcher):
|
||||
"""Default request headers deserializer"""
|
||||
"""Default request headers deserializer."""
|
||||
|
||||
def deserialize(self, request, action):
|
||||
return self.dispatch(request, action=action)
|
||||
@@ -727,7 +713,7 @@ class RequestDeserializer(object):
|
||||
|
||||
|
||||
class TextDeserializer(ActionDispatcher):
|
||||
"""Default request body deserialization"""
|
||||
"""Default request body deserialization."""
|
||||
|
||||
def deserialize(self, request, action='default'):
|
||||
return self.dispatch(request, action=action)
|
||||
@@ -812,10 +798,10 @@ class JSONPatchDeserializer(TextDeserializer):
|
||||
|
||||
if change_op not in allowed_methods:
|
||||
msg = _("Method '{method}' is not allowed for a path with name "
|
||||
"'{name}'. Allowed operations are: '{ops}'").format(
|
||||
method=change_op,
|
||||
name=change_path,
|
||||
ops=', '.join(allowed_methods))
|
||||
"'{name}'. Allowed operations are: "
|
||||
"'{ops}'").format(method=change_op,
|
||||
name=change_path,
|
||||
ops=', '.join(allowed_methods))
|
||||
|
||||
raise webob.exc.HTTPForbidden(explanation=unicode(msg))
|
||||
|
||||
@@ -885,7 +871,7 @@ class JSONPatchDeserializer(TextDeserializer):
|
||||
|
||||
class XMLDeserializer(TextDeserializer):
|
||||
def __init__(self, metadata=None):
|
||||
"""
|
||||
"""XMLDeserializer.
|
||||
:param metadata: information needed to deserialize xml into
|
||||
a dictionary.
|
||||
"""
|
||||
@@ -926,20 +912,20 @@ class XMLDeserializer(TextDeserializer):
|
||||
return result
|
||||
|
||||
def find_first_child_named(self, parent, name):
|
||||
"""Search a nodes children for the first child with a given name"""
|
||||
"""Search a nodes children for the first child with a given name."""
|
||||
for node in parent.childNodes:
|
||||
if node.nodeName == name:
|
||||
return node
|
||||
return None
|
||||
|
||||
def find_children_named(self, parent, name):
|
||||
"""Return all of a nodes children who have the given name"""
|
||||
"""Return all of a nodes children who have the given name."""
|
||||
for node in parent.childNodes:
|
||||
if node.nodeName == name:
|
||||
yield node
|
||||
|
||||
def extract_text(self, node):
|
||||
"""Get the text field contained by the given node"""
|
||||
"""Get the text field contained by the given node."""
|
||||
if len(node.childNodes) == 1:
|
||||
child = node.childNodes[0]
|
||||
if child.nodeType == child.TEXT_NODE:
|
||||
@@ -962,7 +948,6 @@ class FormDataDeserializer(TextDeserializer):
|
||||
|
||||
def default(self, request):
|
||||
form_data_parts = request.POST
|
||||
result = []
|
||||
for key, value in form_data_parts.iteritems():
|
||||
if isinstance(value, basestring):
|
||||
form_data_parts[key] = self._from_json(value)
|
@@ -24,8 +24,8 @@ from murano.api.v1 import request_statistics
|
||||
from murano.api.v1 import router
|
||||
from murano.common import policy
|
||||
from murano.common import rpc
|
||||
from murano.common import wsgi
|
||||
from murano.openstack.common import timeutils
|
||||
from murano.openstack.common import wsgi
|
||||
from murano.tests.unit import base
|
||||
from murano.tests.unit import utils
|
||||
|
||||
|
Reference in New Issue
Block a user