~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/api/openstack/wsgi.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2013-02-22 09:27:29 UTC
  • mfrom: (1.1.68)
  • Revision ID: package-import@ubuntu.com-20130222092729-nn3gt8rf97uvts77
Tags: 2013.1.g3-0ubuntu1
[ Chuck Short ]
* New usptream release. 
* debian/patches/debian/patches/fix-ubuntu-tests.patch: Refreshed.
* debian/nova-baremetal.logrotate: Fix logfile path.
* debian/control, debian/nova-spiceproxy.{install, logrotate, upstart}:
  Add spice html5 proxy support.
* debian/nova-novncproxy.upstart: Start on runlevel [2345]
* debian/rules: Call testr directly since run_tests.sh -N gives weird return
  value when tests pass.
* debian/pyddist-overrides: Add websockify.
* debian/nova-common.postinst: Removed config file conversion, since
  the option is no longer available. (LP: #1110567)
* debian/control: Add python-pyasn1 as a dependency.
* debian/control: Add python-oslo-config as a dependency.
* debian/control: Suggest sysfsutils, sg3-utils, multipath-tools for fibre
  channel support.

[ Adam Gandelman ]
* debian/control: Fix typo (websocikfy -> websockify).

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from nova import exception
28
28
from nova.openstack.common import jsonutils
29
29
from nova.openstack.common import log as logging
 
30
from nova import utils
30
31
from nova import wsgi
31
32
 
32
33
 
150
151
        Does not do any body introspection, only checks header
151
152
 
152
153
        """
153
 
        if not "Content-Type" in self.headers:
 
154
        if "Content-Type" not in self.headers:
154
155
            return None
155
156
 
156
157
        content_type = self.content_type
181
182
 
182
183
 
183
184
class TextDeserializer(ActionDispatcher):
184
 
    """Default request body deserialization"""
 
185
    """Default request body deserialization."""
185
186
 
186
187
    def deserialize(self, datastring, action='default'):
187
188
        return self.dispatch(datastring, action=action)
217
218
        plurals = set(self.metadata.get('plurals', {}))
218
219
 
219
220
        try:
220
 
            node = minidom.parseString(datastring).childNodes[0]
 
221
            node = utils.safe_minidom_parse_string(datastring).childNodes[0]
221
222
            return {node.nodeName: self._from_xml_node(node, plurals)}
222
223
        except expat.ExpatError:
223
224
            msg = _("cannot understand XML")
245
246
            return result
246
247
 
247
248
    def find_first_child_named_in_namespace(self, parent, namespace, name):
248
 
        """Search a nodes children for the first child with a given name"""
 
249
        """Search a nodes children for the first child with a given name."""
249
250
        for node in parent.childNodes:
250
251
            if (node.localName == name and
251
252
                node.namespaceURI and
254
255
        return None
255
256
 
256
257
    def find_first_child_named(self, parent, name):
257
 
        """Search a nodes children for the first child with a given name"""
 
258
        """Search a nodes children for the first child with a given name."""
258
259
        for node in parent.childNodes:
259
260
            if node.localName == name:
260
261
                return node
261
262
        return None
262
263
 
263
264
    def find_children_named(self, parent, name):
264
 
        """Return all of a nodes children who have the given name"""
 
265
        """Return all of a nodes children who have the given name."""
265
266
        for node in parent.childNodes:
266
267
            if node.localName == name:
267
268
                yield node
268
269
 
269
270
    def extract_text(self, node):
270
 
        """Get the text field contained by the given node"""
271
 
        if len(node.childNodes) == 1:
272
 
            child = node.childNodes[0]
 
271
        """Get the text field contained by the given node."""
 
272
        ret_val = ""
 
273
        for child in node.childNodes:
273
274
            if child.nodeType == child.TEXT_NODE:
274
 
                return child.nodeValue
275
 
        return ""
 
275
                ret_val += child.nodeValue
 
276
        return ret_val
276
277
 
277
278
    def extract_elements(self, node):
278
 
        """Get only Element type childs from node"""
 
279
        """Get only Element type childs from node."""
279
280
        elements = []
280
281
        for child in node.childNodes:
281
282
            if child.nodeType == child.ELEMENT_NODE:
283
284
        return elements
284
285
 
285
286
    def find_attribute_or_element(self, parent, name):
286
 
        """Get an attribute value; fallback to an element if not found"""
 
287
        """Get an attribute value; fallback to an element if not found."""
287
288
        if parent.hasAttribute(name):
288
289
            return parent.getAttribute(name)
289
290
 
300
301
class MetadataXMLDeserializer(XMLDeserializer):
301
302
 
302
303
    def extract_metadata(self, metadata_node):
303
 
        """Marshal the metadata attribute of a parsed request"""
 
304
        """Marshal the metadata attribute of a parsed request."""
304
305
        metadata = {}
305
306
        if metadata_node is not None:
306
307
            for meta_node in self.find_children_named(metadata_node, "meta"):
310
311
 
311
312
 
312
313
class DictSerializer(ActionDispatcher):
313
 
    """Default request body serialization"""
 
314
    """Default request body serialization."""
314
315
 
315
316
    def serialize(self, data, action='default'):
316
317
        return self.dispatch(data, action=action)
320
321
 
321
322
 
322
323
class JSONDictSerializer(DictSerializer):
323
 
    """Default JSON request body serialization"""
 
324
    """Default JSON request body serialization."""
324
325
 
325
326
    def default(self, data):
326
327
        return jsonutils.dumps(data)
406
407
                if k in attrs:
407
408
                    result.setAttribute(k, str(v))
408
409
                else:
 
410
                    if k == "deleted":
 
411
                        v = str(bool(v))
409
412
                    node = self._to_xml_node(doc, metadata, k, v)
410
413
                    result.appendChild(node)
411
414
        else:
631
634
def action_peek_xml(body):
632
635
    """Determine action to invoke."""
633
636
 
634
 
    dom = minidom.parseString(body)
 
637
    dom = utils.safe_minidom_parse_string(body)
635
638
    action_node = dom.childNodes[0]
636
639
 
637
640
    return action_node.tagName
919
922
            msg = _("Malformed request body")
920
923
            return Fault(webob.exc.HTTPBadRequest(explanation=msg))
921
924
 
 
925
        if body:
 
926
            LOG.info(_("Action: '%(action)s', body: %(body)s") % locals())
 
927
        LOG.debug(_("Calling method %s") % meth)
 
928
 
922
929
        # Now, deserialize the request body...
923
930
        try:
924
931
            if content_type:
1176
1183
        # Replace the body with fault details.
1177
1184
        code = self.wrapped_exc.status_int
1178
1185
        fault_name = self._fault_names.get(code, "computeFault")
 
1186
        explanation = self.wrapped_exc.explanation
 
1187
        offset = explanation.find("Traceback")
 
1188
        if offset is not -1:
 
1189
            LOG.debug(_("API request failed, fault raised to the top of"
 
1190
                      " the stack. Detailed stacktrace %s") %
 
1191
                      explanation)
 
1192
            explanation = explanation[0:offset - 1]
 
1193
 
1179
1194
        fault_data = {
1180
1195
            fault_name: {
1181
1196
                'code': code,
1182
 
                'message': self.wrapped_exc.explanation}}
 
1197
                'message': explanation}}
1183
1198
        if code == 413:
1184
1199
            retry = self.wrapped_exc.headers.get('Retry-After', None)
1185
1200
            if retry: